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 48D1FC88E76 for ; Mon, 14 Sep 2026 11:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type: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=6V1zOf5lFb0pBWBYrj82SxULtmVhqr0F1KCzWuWhZP4=; b=uAeIrN7wd5oCay0Y/1TutEyav9 EWYKnh742JDDrs10EGgYEOKOu1l8PqB8hUH2ifRQbSABXt2psYaOe1rpQjg9HwmCoi1LEt5L1D7wm 58NQ01qURZ6SNKC7foFD0Fi51uTGFkKiuTbFYhDCYJ4jm+KsPOGRIStN9Bsv/wRdAlVQZ3SdESKV5 eJNNSYhUtw/3VM64dTzRPZwSuMhpc+wDc3cyKWIunaRr8seGg3NVefb6K1lE+2vU8GeIq58KumoOL GIYt3ay86ipr5Wt1sA/IvgvGFBe8u2CQ6hP//t8D4ATbaAzGFdyjpSU/QJtbyTTRYjbANGM6mTibW nYe1Lppw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x653m-00000003K8U-3Goz; Mon, 14 Sep 2026 11:41:18 +0000 Received: from bali.collaboradmins.com ([148.251.105.195]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x652L-00000003Iul-418x; Mon, 14 Sep 2026 11:39:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1789385987; bh=jzk/Hw+RMwYFWiQX14D3JvGuRlF3I6Kcci6JFjZ+Rhw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kglZ+1pCLAaMd32Ck52SsCESzA3bzkzVVVCjtzgbhVyZ4M6EZgNT64GJIAqf2Wekm hDVbe+mXuBB63TE3SeoxXlc/alqqof//rNNQxkXEdKSfHgsQlJHVpSoBS55DysPkvH wwTzbFjhi5Cs0OFszpUgzIfDx7iElQdSCbUJX60yRrCSGDCBf0pvsfd8CYKaau30tv EaHjjec1K2FU/f1UuQNmcBntzX4+IajLK3cdA5JtFO/tljVcULZarIvFx8dRIba7t0 ynbwj/LCyDERd1RtQl9DzgKJ7RITuoPksPxAJc02qxzm6Ea4ja3JLIhKT127trOZmG VCKcnG6lm5cAw== Received: from yukiji.home (unknown [100.64.0.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: laeyraud) by bali.collaboradmins.com (Postfix) with ESMTPSA id 22FAB17E07DC; Mon, 14 Sep 2026 13:39:46 +0200 (CEST) From: Louis-Alexis Eyraud Date: Mon, 14 Sep 2026 13:39:07 +0200 Subject: [PATCH v12 21/24] scsi: ufs: mediatek: Back up idle timer in per-instance struct MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260914-mt8196-ufs-v12-21-9279d7ef814d@collabora.com> References: <20260914-mt8196-ufs-v12-0-9279d7ef814d@collabora.com> In-Reply-To: <20260914-mt8196-ufs-v12-0-9279d7ef814d@collabora.com> To: Chunfeng Yun , Vinod Koul , Neil Armstrong , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Peter Wang , Chaotian Jing , Alim Akhtar , Avri Altman , Bart Van Assche , Stanley Jhu , "James E.J. Bottomley" , Philipp Zabel , Liam Girdwood , Mark Brown , Manivannan Sadhasivam , "Martin K. Petersen" Cc: kernel@collabora.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Nicolas Frattaroli , Louis-Alexis Eyraud X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1789385943; l=2715; i=louisalexis.eyraud@collabora.com; s=20250113; h=from:subject:message-id; bh=eDREcKfoNXLAMviPu/dYRbgFH1U4oQmTK8LePrPi/OU=; b=+V2pAzKnvTPRbSFBLcbv/V9Qw+vmZYTrBCuLglcudtJ9HCrbCGJGG+/p5zFhS02J2ozHJEbAZ Nzg1Jwboy+9DKdRxHWDs5rM9pEJtSzMs0HuW+NSIFHMV3xva/+X083x X-Developer-Key: i=louisalexis.eyraud@collabora.com; a=ed25519; pk=CHFBDB2Kqh4EHc6JIqFn69GhxJJAzc0Zr4e8QxtumuM= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260914_043950_229998_EF8CF94D X-CRM114-Status: GOOD ( 15.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Nicolas Frattaroli 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") Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Nicolas Frattaroli Reviewed-by: Chaotian Jing Signed-off-by: Louis-Alexis Eyraud --- drivers/ufs/host/ufs-mediatek.c | 19 ++++++++----------- drivers/ufs/host/ufs-mediatek.h | 1 + 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c index fc42e6baa47d..9cd852cadab5 100644 --- a/drivers/ufs/host/ufs-mediatek.c +++ b/drivers/ufs/host/ufs-mediatek.c @@ -1451,27 +1451,24 @@ static int ufs_mtk_pwr_change_notify(struct ufs_hba *hba, enum ufs_notify_change_status stage, 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->ahit = ufshcd_readl( + hba, REG_AUTO_HIBERNATE_IDLE_TIMER); ufs_mtk_auto_hibern8_disable(hba); } - ret = ufs_mtk_pre_pwr_change(hba, dev_req_params); - break; + return ufs_mtk_pre_pwr_change(hba, 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->ahit, + 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 6b81c8f76201..1fa14a83e8cd 100644 --- a/drivers/ufs/host/ufs-mediatek.h +++ b/drivers/ufs/host/ufs-mediatek.h @@ -188,6 +188,7 @@ struct ufs_mtk_host { u16 ref_clk_gating_wait_us; u32 ip_ver; bool legacy_ip_ver; + u32 ahit; bool mcq_set_intr; bool is_mcq_intr_enabled; -- 2.55.0