From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 071ABD6ACFB for ; Thu, 18 Dec 2025 12:58:12 +0000 (UTC) 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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bq3hvsRPkRYjB6dZ8+RWDEQnvK+aOp5aD1gqb/SaxMw=; b=29KlltAcGqxWsn tiJsGqF0HjpiBKj8xy01N8XAmXPA245btMZML0g5Xc947j8UPP/GOe1FAKDuTjLn2FO8H8WKW+3JI u86sFr6b1tr0emY/aEDoFcQX+vb+RCP4BKlK4H07npePso+5AczS7XTZcg+9YrHYW+1DuRlKRz+jH k3/OHaP27+HWtDH0HyjG+R/qsWGY8vooHIL7GULcBbaSIyPzWzLjGDQDpv+wla760U7+3B6bGYaaJ XqSBsgecMt3MtAYCyaKZcdXNdnA/NeYLe03UGB4yCMRu0ll0xj7WNuiXEqZ/OO48H1AumJdfG9uGf hNsoW58bwNmxZ64DRGbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vWDa7-00000008TtI-1cou; Thu, 18 Dec 2025 12:58:11 +0000 Received: from sender4-pp-f112.zoho.com ([136.143.188.112]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vWDZx-00000008TgK-0Co7; Thu, 18 Dec 2025 12:58:08 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1766062672; cv=none; d=zohomail.com; s=zohoarc; b=GdHzPKu9i9wip+UiV+cFv3i7a/sQtvxTgBSXFvvEtXmKmKUyQlvgR/KCOnveGaXnYl5vdsLUXtdkEb7+FyjHCPL8chQwySGsH+vdky6Kx1vjrvO8bYKl+xGadHmRK/+E5xh9C7q/uxMEf41xjtkJWScftXe2Lt3unI24ppIEg4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1766062672; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=zjz39YGRx977pthRCrruwQeYKyCWBvSxk/yhQcEE+2o=; b=RQE3/Oz8m6YSvAkrQ7n0ZZhfO0dpfdOLevMioOGxOG1Ynjour5eJzQdoJKq7PSFTaKVP6frB8cPwDzUCB5qtVwOwD8E61Q+Rj1iNs/qOdu7hVZGKyn4SNtpEv6+eWaK+TJ/1drdVkwF/zqq/8K2b+A8G/LtQ3jPhzSXutMtYqKY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1766062672; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=zjz39YGRx977pthRCrruwQeYKyCWBvSxk/yhQcEE+2o=; b=Je4+786pevpxLbMQVNNXrfjw2mBZOIlsjPu9eTEyYfg4SP/UhBiGeNBjPJViV9es ZJ5iDpSrhkYwfDUGmq5+oRUdjH9TAA5x6kdmMCrXSKCbHOxPP/ovXVlTNSWe3XVMaN6 S7BGahYJBdkE1cSLN6DurGEZnSudH+J+16TfmbqE= Received: by mx.zohomail.com with SMTPS id 1766062671625400.16637177596033; Thu, 18 Dec 2025 04:57:51 -0800 (PST) From: Nicolas Frattaroli Date: Thu, 18 Dec 2025 13:55:12 +0100 Subject: [PATCH v4 22/25] scsi: ufs: mediatek: Back up idle timer in per-instance struct MIME-Version: 1.0 Message-Id: <20251218-mt8196-ufs-v4-22-ddec7a369dd2@collabora.com> References: <20251218-mt8196-ufs-v4-0-ddec7a369dd2@collabora.com> In-Reply-To: <20251218-mt8196-ufs-v4-0-ddec7a369dd2@collabora.com> To: Alim Akhtar , Avri Altman , Bart Van Assche , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Chunfeng Yun , Vinod Koul , Kishon Vijay Abraham I , Peter Wang , Stanley Jhu , "James E.J. Bottomley" , "Martin K. Petersen" , Philipp Zabel , Liam Girdwood , Mark Brown , Chaotian Jing , Neil Armstrong Cc: Louis-Alexis Eyraud , kernel@collabora.com, linux-scsi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org, Nicolas Frattaroli X-Mailer: b4 0.14.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251218_045801_173492_05C7756F X-CRM114-Status: GOOD ( 15.55 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org The MediaTek UFS driver uses a function-scope static variable to back up a hardware register across a power change in the ufs_mtk_pwr_change_notify function. This is dangerous, as it's only correct if only ever one instance of the driver is loaded, which isn't true if there's more than one device on a SoC that needs it, or it otherwise gets loaded a second time. Back it up into a member of the host struct instead, as this struct is per-instance. Rework the function to not use a pointless "ret" local as well. Fixes: f5ca8d0c7a63 ("scsi: ufs: host: mediatek: Disable auto-hibern8 during power mode changes") Signed-off-by: Nicolas Frattaroli --- drivers/ufs/host/ufs-mediatek.c | 20 ++++++++------------ drivers/ufs/host/ufs-mediatek.h | 1 + 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index 4e545cc414ac..147beb46a447 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -1416,28 +1416,24 @@ static int ufs_mtk_pwr_change_notify(struct ufs_hba *hba, const struct ufs_pa_layer_attr *dev_max_params, struct ufs_pa_layer_attr *dev_req_params) { - int ret = 0; - static u32 reg; + struct ufs_mtk_host *host = ufshcd_get_variant(hba); switch (stage) { case PRE_CHANGE: if (ufshcd_is_auto_hibern8_supported(hba)) { - reg = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); + host->hibernate_idle_timer = ufshcd_readl( + hba, REG_AUTO_HIBERNATE_IDLE_TIMER); ufs_mtk_auto_hibern8_disable(hba); } - ret = ufs_mtk_pre_pwr_change(hba, dev_max_params, - dev_req_params); - break; + return ufs_mtk_pre_pwr_change(hba, dev_max_params, dev_req_params); case POST_CHANGE: if (ufshcd_is_auto_hibern8_supported(hba)) - ufshcd_writel(hba, reg, REG_AUTO_HIBERNATE_IDLE_TIMER); - break; - default: - ret = -EINVAL; - break; + ufshcd_writel(hba, host->hibernate_idle_timer, + REG_AUTO_HIBERNATE_IDLE_TIMER); + return 0; } - return ret; + return -EINVAL; } static int ufs_mtk_unipro_set_lpm(struct ufs_hba *hba, bool lpm) diff --git a/drivers/ufs/host/ufs-mediatek.h b/drivers/ufs/host/ufs-mediatek.h index 9586fe9c0441..59fc432c84b5 100644 --- a/drivers/ufs/host/ufs-mediatek.h +++ b/drivers/ufs/host/ufs-mediatek.h @@ -189,6 +189,7 @@ struct ufs_mtk_host { u16 ref_clk_gating_wait_us; u32 ip_ver; bool legacy_ip_ver; + u32 hibernate_idle_timer; bool mcq_set_intr; bool is_mcq_intr_enabled; -- 2.52.0 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy