From nobody Fri May 8 03:09:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27E7CC433F5 for ; Thu, 12 May 2022 11:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353336AbiELLW1 (ORCPT ); Thu, 12 May 2022 07:22:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353131AbiELLV2 (ORCPT ); Thu, 12 May 2022 07:21:28 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23E37306; Thu, 12 May 2022 04:21:27 -0700 (PDT) Received: from fraeml706-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4KzTmR2pmqz687hF; Thu, 12 May 2022 19:18:31 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml706-chm.china.huawei.com (10.206.15.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 12 May 2022 13:21:25 +0200 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 12 May 2022 12:21:23 +0100 From: John Garry To: , CC: , , , John Garry Subject: [PATCH 1/3] scsi: libsas: Refactor sas_ata_hard_reset() Date: Thu, 12 May 2022 19:15:32 +0800 Message-ID: <1652354134-171343-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1652354134-171343-1-git-send-email-john.garry@huawei.com> References: <1652354134-171343-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create function sas_ata_wait_after_reset() from sas_ata_hard_reset() as some LLDDs may want to check for a remote ATA phy is up after reset. Signed-off-by: John Garry Reviewed-by: Xiang Chen Tested-by: Yihang Li --- drivers/scsi/libsas/sas_ata.c | 41 +++++++++++++++++++++++------------ include/scsi/sas_ata.h | 7 ++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index d34c82e24d9a..d35c9296f738 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -358,22 +358,14 @@ static int sas_ata_printk(const char *level, const st= ruct domain_device *ddev, return r; } =20 -static int sas_ata_hard_reset(struct ata_link *link, unsigned int *class, - unsigned long deadline) +int sas_ata_wait_after_reset(struct domain_device *dev, unsigned long dead= line) { - int ret =3D 0, res; - struct sas_phy *phy; - struct ata_port *ap =3D link->ap; + struct sata_device *sata_dev =3D &dev->sata_dev; int (*check_ready)(struct ata_link *link); - struct domain_device *dev =3D ap->private_data; - struct sas_internal *i =3D dev_to_sas_internal(dev); - - res =3D i->dft->lldd_I_T_nexus_reset(dev); - if (res =3D=3D -ENODEV) - return res; - - if (res !=3D TMF_RESP_FUNC_COMPLETE) - sas_ata_printk(KERN_DEBUG, dev, "Unable to reset ata device?\n"); + struct ata_port *ap =3D sata_dev->ap; + struct ata_link *link =3D &ap->link; + struct sas_phy *phy; + int ret; =20 phy =3D sas_get_local_phy(dev); if (scsi_is_sas_phy_local(phy)) @@ -386,6 +378,27 @@ static int sas_ata_hard_reset(struct ata_link *link, u= nsigned int *class, if (ret && ret !=3D -EAGAIN) sas_ata_printk(KERN_ERR, dev, "reset failed (errno=3D%d)\n", ret); =20 + return ret; +} +EXPORT_SYMBOL_GPL(sas_ata_wait_after_reset); + +static int sas_ata_hard_reset(struct ata_link *link, unsigned int *class, + unsigned long deadline) +{ + struct ata_port *ap =3D link->ap; + struct domain_device *dev =3D ap->private_data; + struct sas_internal *i =3D dev_to_sas_internal(dev); + int ret; + + ret =3D i->dft->lldd_I_T_nexus_reset(dev); + if (ret =3D=3D -ENODEV) + return ret; + + if (ret !=3D TMF_RESP_FUNC_COMPLETE) + sas_ata_printk(KERN_DEBUG, dev, "Unable to reset ata device?\n"); + + ret =3D sas_ata_wait_after_reset(dev, deadline); + *class =3D dev->sata_dev.class; =20 ap->cbl =3D ATA_CBL_SATA; diff --git a/include/scsi/sas_ata.h b/include/scsi/sas_ata.h index d47dea70855d..a1df4f9d57a3 100644 --- a/include/scsi/sas_ata.h +++ b/include/scsi/sas_ata.h @@ -34,6 +34,7 @@ void sas_resume_sata(struct asd_sas_port *port); void sas_ata_end_eh(struct ata_port *ap); int sas_execute_ata_cmd(struct domain_device *device, u8 *fis, int force_phy_id); +int sas_ata_wait_after_reset(struct domain_device *dev, unsigned long dead= line); #else =20 =20 @@ -91,6 +92,12 @@ static inline int sas_execute_ata_cmd(struct domain_devi= ce *device, u8 *fis, { return 0; } + +static inline int sas_ata_wait_after_reset(struct domain_device *dev, + unsigned long deadline) +{ + return -ETIMEDOUT; +} #endif =20 #endif /* _SAS_ATA_H_ */ --=20 2.26.2 From nobody Fri May 8 03:09:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23BCCC433F5 for ; Thu, 12 May 2022 11:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353139AbiELLWK (ORCPT ); Thu, 12 May 2022 07:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353150AbiELLVa (ORCPT ); Thu, 12 May 2022 07:21:30 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B02B6D67; Thu, 12 May 2022 04:21:28 -0700 (PDT) Received: from fraeml705-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4KzTlp1Nw3z6GD8h; Thu, 12 May 2022 19:17:58 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml705-chm.china.huawei.com (10.206.15.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 12 May 2022 13:21:26 +0200 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 12 May 2022 12:21:25 +0100 From: John Garry To: , CC: , , , John Garry Subject: [PATCH 2/3] scsi: hisi_sas: Use sas_ata_wait_after_reset() in IT nexus reset Date: Thu, 12 May 2022 19:15:33 +0800 Message-ID: <1652354134-171343-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1652354134-171343-1-git-send-email-john.garry@huawei.com> References: <1652354134-171343-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We have seen errors like this when a SATA device is probed: [524.566298] hisi_sas_v3_hw 0000L74:02.0: erroneous completion iptt=3D4096 = ... [524.582827] sas: TMF task open reject failed 500e004aaaaaaaa00 Since commit 21c7e972475e ("scsi: hisi_sas: Disable SATA disk phy for severe I_T nexus reset failure"), we issue an ATA softreset to disks after a phy reset to ensure that they are in sound working order. If the softreset is issued before the remote phy has come back up then the softreset will fail (errors as above). Remedy this by waiting for the phy to come back up after the reset. Signed-off-by: John Garry Reviewed-by: Xiang Chen Tested-by: Yihang Li --- drivers/scsi/hisi_sas/hisi_sas_main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/= hisi_sas_main.c index 4bda2f6cb352..997f27e2f1e5 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1710,13 +1710,18 @@ static int hisi_sas_debug_I_T_nexus_reset(struct do= main_device *device) /* report PHY down if timed out */ if (rc =3D=3D -ETIMEDOUT) hisi_sas_phy_down(hisi_hba, sas_phy->id, 0, GFP_KERNEL); - } else if (sas_dev->dev_status !=3D HISI_SAS_DEV_INIT) { - /* - * If in init state, we rely on caller to wait for link to be - * ready; otherwise, except phy reset is fail, delay. - */ - if (!rc) - msleep(2000); + return rc; + } + + if (rc) + return rc; + + /* Remote phy */ + if (dev_is_sata(device)) { + rc =3D sas_ata_wait_after_reset(device, + HISI_SAS_WAIT_PHYUP_TIMEOUT); + } else { + msleep(2000); } =20 return rc; --=20 2.26.2 From nobody Fri May 8 03:09:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22D1DC433EF for ; Thu, 12 May 2022 11:22:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353299AbiELLWC (ORCPT ); Thu, 12 May 2022 07:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353188AbiELLVc (ORCPT ); Thu, 12 May 2022 07:21:32 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D3F42983F; Thu, 12 May 2022 04:21:30 -0700 (PDT) Received: from fraeml704-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4KzTmW1tSHz687hF; Thu, 12 May 2022 19:18:35 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml704-chm.china.huawei.com (10.206.15.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 12 May 2022 13:21:28 +0200 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 12 May 2022 12:21:26 +0100 From: John Garry To: , CC: , , , John Garry Subject: [PATCH 3/3] scsi: hisi_sas: Fix rescan after deleting a disk Date: Thu, 12 May 2022 19:15:34 +0800 Message-ID: <1652354134-171343-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1652354134-171343-1-git-send-email-john.garry@huawei.com> References: <1652354134-171343-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Removing an ATA device via sysfs means that the device may not be found through re-scanning: root@ubuntu:/home/john# lsscsi [0:0:0:0] disk SanDisk LT0200MO P404 /dev/sda [0:0:1:0] disk ATA HGST HUS724040AL A8B0 /dev/sdb [0:0:8:0] enclosu 12G SAS Expander RevB - root@ubuntu:/home/john# echo 1 > /sys/block/sdb/device/delete root@ubuntu:/home/john# echo "- - -" > /sys/class/scsi_host/host0/scan root@ubuntu:/home/john# lsscsi [0:0:0:0] disk SanDisk LT0200MO P404 /dev/sda [0:0:8:0] enclosu 12G SAS Expander RevB - root@ubuntu:/home/john# The problem is that the rescan of the device may conflict with the device in being re-initialized, as follows: - In the rescan we call hisi_sas_slave_alloc() in store_scan() -> sas_user_scan() -> [__]scsi_scan_target() -> scsi_probe_and_add_lunc() -> scsi_alloc_sdev() -> hisi_sas_slave_alloc() -> hisi_sas_init_device() In hisi_sas_init_device() we issue an IT nexus reset for ATA devices - That IT nexus causes the remote PHY to go down and this triggers a bcast event - In parallel libsas processes the bcast event, finds that the phy is down and marks the device as gone The hard reset issued in hisi_sas_init_device() is unncessary - as described in the code comment - so remove it. Also set dev status as HISI_SAS_DEV_NORMAL as the hisi_sas_init_device() call. Fixes: 36c6b7613ef1 ("scsi: hisi_sas: Initialise devices in .slave_alloc ca= llback") Signed-off-by: John Garry Tested-by: Yihang Li Reviewed-by: Xiang Chen --- drivers/scsi/hisi_sas/hisi_sas_main.c | 47 ++++++++++----------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/= hisi_sas_main.c index 997f27e2f1e5..6803751dc4b1 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -709,8 +709,6 @@ static int hisi_sas_init_device(struct domain_device *d= evice) struct scsi_lun lun; int retry =3D HISI_SAS_DISK_RECOVER_CNT; struct hisi_hba *hisi_hba =3D dev_to_hisi_hba(device); - struct device *dev =3D hisi_hba->dev; - struct sas_phy *local_phy; =20 switch (device->dev_type) { case SAS_END_DEVICE: @@ -729,30 +727,18 @@ static int hisi_sas_init_device(struct domain_device = *device) case SAS_SATA_PM_PORT: case SAS_SATA_PENDING: /* - * send HARD RESET to clear previous affiliation of - * STP target port + * If an expander is swapped when a SATA disk is attached then + * we should issue a hard reset to clear previous affiliation + * of STP target port, see SPL (chapter 6.19.4). + * + * However we don't need to issue a hard reset here for these + * reasons: + * a. When probing the device, libsas/libata already issues a + * hard reset in sas_probe_sata() -> ata_sas_async_probe(). + * Note that in hisi_sas_debug_I_T_nexus_reset() we take care + * to issue a hard reset by checking the dev status (=3D=3D INIT). + * b. When resetting the controller, this is simply unnecessary. */ - local_phy =3D sas_get_local_phy(device); - if (!scsi_is_sas_phy_local(local_phy) && - !test_bit(HISI_SAS_RESETTING_BIT, &hisi_hba->flags)) { - unsigned long deadline =3D ata_deadline(jiffies, 20000); - struct sata_device *sata_dev =3D &device->sata_dev; - struct ata_host *ata_host =3D sata_dev->ata_host; - struct ata_port_operations *ops =3D ata_host->ops; - struct ata_port *ap =3D sata_dev->ap; - struct ata_link *link; - unsigned int classes; - - ata_for_each_link(link, ap, EDGE) - rc =3D ops->hardreset(link, &classes, - deadline); - } - sas_put_local_phy(local_phy); - if (rc) { - dev_warn(dev, "SATA disk hardreset fail: %d\n", rc); - return rc; - } - while (retry-- > 0) { rc =3D hisi_sas_softreset_ata_disk(device); if (!rc) @@ -768,15 +754,19 @@ static int hisi_sas_init_device(struct domain_device = *device) =20 int hisi_sas_slave_alloc(struct scsi_device *sdev) { - struct domain_device *ddev; + struct domain_device *ddev =3D sdev_to_domain_dev(sdev); + struct hisi_sas_device *sas_dev =3D ddev->lldd_dev; int rc; =20 rc =3D sas_slave_alloc(sdev); if (rc) return rc; - ddev =3D sdev_to_domain_dev(sdev); =20 - return hisi_sas_init_device(ddev); + rc =3D hisi_sas_init_device(ddev); + if (rc) + return rc; + sas_dev->dev_status =3D HISI_SAS_DEV_NORMAL; + return 0; } EXPORT_SYMBOL_GPL(hisi_sas_slave_alloc); =20 @@ -826,7 +816,6 @@ static int hisi_sas_dev_found(struct domain_device *dev= ice) dev_info(dev, "dev[%d:%x] found\n", sas_dev->device_id, sas_dev->dev_type); =20 - sas_dev->dev_status =3D HISI_SAS_DEV_NORMAL; return 0; =20 err_out: --=20 2.26.2