From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40E93606A31C for ; Sat, 28 Nov 2026 00:44:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=mkG1Fmv8; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CD5Od50N DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=KNUd9OxGo4vx2eHKfRASYjt8yZw3O89SAJN7ejcgxAc=; b=mkG1Fmv8LHrKlyd/ac9Q1bMFep 3Ep81Pyd0s8LtOPEbfmqR3MCI8OrBq6a0LbUvFMOkXHxKCbMcLefnovB2qUvjkaKGAGVrrJHeHruN pwhAlsatYNRm2lDk3gnMS1n1+mO5v3RRIQU+XF2kHDqyud0PnP9LZ3GuLP7UNVY9pj8fT3I0IhFVo Us1wNRQLTIkL43ifcJOnZhaJkU9frBU4KmM+mVh4sSIn6oUI4I0Wu+27jYWHhMCyUqKETXcl8xOe6 MoQUSQqAcQaKz5BatIP0RJNj0o7qZrlEsJrbkmtg6wLfmwXeSXhSlvo3AFXeZkIg5E2JJqqQpLfUU 8w4ZYeKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xX6YE-00000000Epr-0vcb; Sat, 28 Nov 2026 00:44:26 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xX6YA-00000000EpE-0Me0 for linux-riscv@lists.infradead.org; Sat, 28 Nov 2026 00:44:23 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 3EBED61251; Sat, 28 Nov 2026 00:44:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D8F11F0089B; Sat, 28 Nov 2026 00:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795826660; bh=617ht0+271aJEWj5NKC+RogwfXVw7QuuuxCq4hvGCmU=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=CD5Od50N/heCpUoiJ47KEDjOxuuRF+skA+3a7THX3KSNNY3XsSfeLZloHLOf4ivfs EPFIuPon2hqTzo8t2QXYmxlo5Vz4MSRwCS6X5rpy1xaNYBOJzM1oVjsLlOW95Nha1r 0fgsDu1t+rXIRA+UsPS8UzE71DpPuw8rumNKZkxzzcJnuDbQDNJFCIEzrZ+x3bJXKn RPz36bWz7kQPCKhdCBIJIRIm05I++QeJeBX4AMdE9g3XFI377pnh6hN4oAjo/zIn++ S6RyB49tXYVE4Qv6VEryeqBX0KLi51XDgh5T144q1vaIayfNk949AJJ/Wtq5nj4h7H 5JvnNiDHjIaDA== Date: Sat, 28 Nov 2026 00:44:17 +0000 From: Yixun Lan To: thomas@exein.io Cc: linux-kernel@vger.kernel.org, "Martin K. Petersen" , Avri Altman , Aurelien Jarno , linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, "James E.J. Bottomley" , Alim Akhtar , Bart Van Assche , linux-scsi@vger.kernel.org Subject: Re: [PATCH] scsi: ufs: spacemit: k3: change to FASTAUTO before the FAST power mode Message-ID: <20261128004417-GKB27669@kernel.org> References: <20261124-fastauto-v1-1-32ec8da5af04@exein.io> X-Archived-By: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20261124-fastauto-v1-1-32ec8da5af04@exein.io> X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Thomas Roos, Thanks for bringing up of this, and sending the patch. On 09:11 Tue 24 Nov , Thomas Roos via B4 Relay wrote: > From: Thomas Roos > > The SpacemiT vendor kernel and U-Boot never change the link straight to > FAST: they change to FASTAUTO at the target gear/rate first, wait > 100 ms, and only then to FAST. A direct FAST change kills the link at > the M-PHY PLL rate change: on the K3 CoM260 IFX (YMTC YMUS8B5TH1A1C1) > every mode except HS-G1 rate A fails with DL errors 0x80000002 / > 0x80000001 / 0x80002000 and PA_ERR 0x80000010, and the disk is lost. > I actually do get report of this issue on YMTC UFS chip, but haven't seen problem with Kingston UFS chip > Do the FASTAUTO step in the PRE_CHANGE hook; the core then sends the > FAST request. With this the link runs at HS-G3 rate B on two lanes. > > Skip the step only when the link already runs in FAST with the > requested parameters, judged by PA_PWRMODE and not by hba->pwr_info > alone. After a LINERESET, ufshcd_err_handler() restores the power mode > with ufshcd_config_pwr_mode(hba, &hba->pwr_info, UFSHCD_PMC_POLICY_FORCE): > the requested parameters equal hba->pwr_info, but the link has fallen > back to a slow mode, and the forced FAST request would kill it again. > > The step also writes ANA_HSGEAR_CTRL_ATTR = 0x25 and waits for the PLL > lock, as ufs_spacemit_apply_dev_quirks() does at probe. Every POST_CHANGE > clears the attribute, so without this a LINERESET recovery would run the > FASTAUTO and FAST changes with a different analog setting than probe. > Vendor provide similar patch for this, but I'm rather skeptical on it as a proper fix and ask them to clarify with IP/UFS chip vendor.. FYI, I'd expect to see basic UFS patch merged first, then we can address this issue separately. Besides, I do have several boards on hand, but none of them shipped with YMTC UFS, so need someone to help reviewing and testing the patch. > Assisted-by: claude-opus-5-5 > Signed-off-by: Thomas Roos > --- > This applies on top of v8 of "scsi: ufs: spacemit: k3: Add UFS Host > Controller driver": > https://lore.kernel.org/r/20261116-08-k3-ufs-support-v8-2-e3b256972dd4@kernel.org > > Yixun, feel free to fold it into the next version of the series. > I'd prefer it iterated as a separate patch on top of mine, thanks > Tested on a K3 CoM260 IFX (YMTC YMUS8B5TH1A1C1) on 7.3.4 with the > equivalent v7-based driver: without the change only HS-G1 rate A works; Just curious, is "HS-G1 rate A" mode stable without this patch? or any specific change needed to change to this mode? > with it the link runs at HS-G3 rate B x2 and the rootfs on UFS is > stable. Builds without warnings at W=1 on top of v8. > > The restore path was exercised with this patch: a test-only debugfs > hook drops the link to PWM-G1 SLOWAUTO behind the core (raw reads fall > from ~900 MB/s to 1 MB/s), then a PA generic error is injected through > the ufshcd debugfs saved_uic_err. In 6 of 6 runs the restore went > through FASTAUTO back to G3B FAST, with reads at 850-980 MB/s again and > a matching write/read-back. That setup keeps the PHY on rate B, so it > does not reproduce a LINERESET that also resets the PLL rate. > > The FASTAUTO step open-codes the attribute writes of the core's > ufshcd_dme_change_power_mode(). A core helper that takes an explicit > PA_PWRMODE value and leaves hba->pwr_info alone would avoid that; I kept > it in the driver for now. > --- > drivers/ufs/host/ufs-spacemit.c | 96 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 96 insertions(+) > > diff --git a/drivers/ufs/host/ufs-spacemit.c b/drivers/ufs/host/ufs-spacemit.c > index eb2ad50..04380a0 100644 > --- a/drivers/ufs/host/ufs-spacemit.c > +++ b/drivers/ufs/host/ufs-spacemit.c > @@ -343,6 +343,87 @@ static int ufs_spacemit_negotiate_pwr_mode(struct ufs_hba *hba, > return ret; > } > > +/* > + * As in the vendor kernel and U-Boot: change to FASTAUTO at the target > + * gear/rate first and only then (from the core) to FAST. A direct FAST > + * change kills the link after the M-PHY PLL rate change, so only HS-G1A > + * would work. > + */ > +static int ufs_spacemit_fastauto_step(struct ufs_hba *hba, > + struct ufs_pa_layer_attr *p) > +{ > + int ret; > + > + /* > + * Restore the value and PLL lock wait of ufs_spacemit_apply_dev_quirks() > + * at probe: every POST_CHANGE resets it, which matters for a LINERESET > + * recovery. > + */ > + ufshcd_dme_set(hba, UIC_ARG_MIB(ANA_HSGEAR_CTRL_ATTR), 0x25); > + ret = ufs_spacemit_wait_mphy_pll_lock(hba); > + if (ret) > + return ret; > + > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_RXGEAR), p->gear_rx); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_ACTIVERXDATALANES), p->lane_rx); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_RXTERMINATION), 1); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TXGEAR), p->gear_tx); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_ACTIVETXDATALANES), p->lane_tx); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_TXTERMINATION), 1); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_HSSERIES), p->hs_rate); > + /* as in ufshcd_dme_change_power_mode() */ > + if (!(hba->quirks & UFSHCD_QUIRK_SKIP_DEF_UNIPRO_TIMEOUT_SETTING)) { > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA0), > + DL_FC0ProtectionTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA1), > + DL_TC0ReplayTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA2), > + DL_AFC0ReqTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA3), > + DL_FC1ProtectionTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA4), > + DL_TC1ReplayTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(PA_PWRMODEUSERDATA5), > + DL_AFC1ReqTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(DME_LocalFC0ProtectionTimeOutVal), > + DL_FC0ProtectionTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(DME_LocalTC0ReplayTimeOutVal), > + DL_TC0ReplayTimeOutVal_Default); > + ufshcd_dme_set(hba, UIC_ARG_MIB(DME_LocalAFC0ReqTimeOutVal), > + DL_AFC0ReqTimeOutVal_Default); > + } > + > + ret = ufshcd_uic_change_pwr_mode(hba, FASTAUTO_MODE << 4 | FASTAUTO_MODE); > + if (ret) > + return ret; > + msleep(100); > + > + return ufs_spacemit_wait_mphy_pll_lock(hba); > +} > + > +/* > + * True if the link already runs in FAST with the gear, lanes and rate of > + * @p, so no FASTAUTO step is needed. Read PA_PWRMODE rather than trust > + * hba->pwr_info alone: after a LINERESET the error handler restores the > + * mode with UFSHCD_PMC_POLICY_FORCE and parameters equal to hba->pwr_info > + * while the link has fallen back to a slow mode, and the forced FAST > + * request from there kills the link. > + */ > +static bool ufs_spacemit_link_in_fast(struct ufs_hba *hba, > + struct ufs_pa_layer_attr *p) > +{ > + u32 mode; > + > + if (memcmp(p, &hba->pwr_info, sizeof(*p))) > + return false; > + > + if (ufshcd_dme_get(hba, UIC_ARG_MIB(PA_PWRMODE), &mode)) > + return false; > + > + return ((mode >> PWRMODE_RX_OFFSET) & PWRMODE_MASK) == FAST_MODE && > + (mode & PWRMODE_MASK) == FAST_MODE; > +} > + > static int ufs_spacemit_pwr_change_notify(struct ufs_hba *hba, > enum ufs_notify_change_status status, > struct ufs_pa_layer_attr *dev_req_params) > @@ -356,6 +437,21 @@ static int ufs_spacemit_pwr_change_notify(struct ufs_hba *hba, > > switch (status) { > case PRE_CHANGE: > + /* the core sends the FAST request after this hook */ > + if (dev_req_params->pwr_rx == FAST_MODE && > + dev_req_params->pwr_tx == FAST_MODE && > + !ufs_spacemit_link_in_fast(hba, dev_req_params)) { > + /* > + * The core ignores the result. If the FASTAUTO PMC > + * failed outside a PM operation, the link is marked > + * broken and the FAST request is not sent; if only the > + * PLL lock wait timed out, the link already runs at > + * the target rate. > + */ > + ret = ufs_spacemit_fastauto_step(hba, dev_req_params); > + if (ret) > + dev_warn(hba->dev, "FASTAUTO step failed: %d\n", ret); > + } > break; > case POST_CHANGE: > ret = ufs_spacemit_wait_mphy_pll_lock(hba); > > --- > base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 > change-id: 20261123-fastauto-306d20d17590 > prerequisite-message-id: <20261116-08-k3-ufs-support-v8-0-e3b256972dd4@kernel.org> > prerequisite-patch-id: 70385741c42f21fbc79b3ef967e48cb8214e5cd0 > prerequisite-patch-id: 5198841accdd660ed1597e92dcdef85a6accc8cd > > Best regards, > -- > Thomas Roos > > -- Yixun Lan (dlan) _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv