From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Peter Wang <peter.wang@mediatek.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Sasha Levin <sashal@kernel.org>,
matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
linux-scsi@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH AUTOSEL 6.17-6.6] scsi: ufs: host: mediatek: Disable auto-hibern8 during power mode changes
Date: Sat, 25 Oct 2025 11:56:21 -0400 [thread overview]
Message-ID: <20251025160905.3857885-150-sashal@kernel.org> (raw)
In-Reply-To: <20251025160905.3857885-1-sashal@kernel.org>
From: Peter Wang <peter.wang@mediatek.com>
[ Upstream commit f5ca8d0c7a6388abd5d8023cc682e1543728cc73 ]
Disable auto-hibern8 during power mode transitions to prevent unintended
entry into auto-hibern8. Restore the original auto-hibern8 timer value
after completing the power mode change to maintain system stability and
prevent potential issues during power state transitions.
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
YES
Summary
- The change disables Auto-Hibern8 (AH8) around UFS power mode
transitions and restores the prior timer afterward. This prevents
unintended AH8 entry while the link is being reconfigured, which can
cause timeouts or recovery events during transitions. The fix is
small, self-contained, and limited to the Mediatek UFS host driver.
What the patch does
- Saves current AH8 timer and disables AH8 in PRE_CHANGE:
- drivers/ufs/host/ufs-mediatek.c:1472–1476
- Reads `REG_AUTO_HIBERNATE_IDLE_TIMER` into a static `reg` and
calls `ufs_mtk_auto_hibern8_disable(hba)`.
- Disables AH8 in a helper and ensures the link is up before proceeding:
- drivers/ufs/host/ufs-mediatek.c:1436–1461
- Writes 0 to `REG_AUTO_HIBERNATE_IDLE_TIMER` (disables AH8), waits
for the host idle state, then waits for `VS_LINK_UP`. On failure,
warns and triggers `ufshcd_force_error_recovery(hba)` and returns
`-EBUSY`.
- Restores the previous AH8 timer in POST_CHANGE:
- drivers/ufs/host/ufs-mediatek.c:1480–1483
Why this fixes a bug
- Power mode transitions involve DME configuration and link parameter
changes (see setup/adaptation in `ufs_mtk_pre_pwr_change()`:
drivers/ufs/host/ufs-mediatek.c:1405–1434). If the link enters AH8
mid-transition, the controller and device can deadlock or time out,
requiring error recovery. Temporarily disabling AH8 ensures the link
stays in the expected state while power mode changes occur and
restores normal power-saving afterwards.
- The helper already used in suspend PRE_CHANGE (drivers/ufs/host/ufs-
mediatek.c:1748–1751) shows the driver’s established pattern to
disable AH8 before low-power transitions; extending this to power mode
changes closes a similar race.
Scope and risk
- Scope: One driver file; no UFS core changes; no architectural shifts.
Uses existing helpers (`ufshcd_is_auto_hibern8_supported`,
`ufshcd_readl/writel`, `ufs_mtk_wait_*`,
`ufshcd_force_error_recovery`).
- Regression risk: Low. Behavior change is to temporarily disable AH8
only during power mode changes and then restore the previous timer.
- Note: `ufs_mtk_pwr_change_notify()` stores the old AH8 timer in a
function-scope static (`reg`) (drivers/ufs/host/ufs-
mediatek.c:1469). While typical Mediatek systems have a single UFS
host and power mode changes are serialized, a static variable is
theoretically shared if multiple controllers triggered this
concurrently. In practice, impact is negligible on common
configurations.
- Note: The PRE_CHANGE path does not propagate the return of
`ufs_mtk_auto_hibern8_disable()` (drivers/ufs/host/ufs-
mediatek.c:1473–1478). The helper triggers error recovery internally
and returns `-EBUSY`, so recovery still occurs, but the immediate
PRE_CHANGE return value won’t reflect the failure. A tiny follow-up
improvement would propagate this error directly (as done later in-
tree).
Evidence of established pattern
- Other vendor drivers also manage AH8 around sensitive transitions,
supporting this approach:
- Hisilicon disables/adjusts AH8 during link setup:
drivers/ufs/host/ufs-hisi.c:234–237
- Spreadtrum disables AH8 during suspend PRE_CHANGE:
drivers/ufs/host/ufs-sprd.c:185–190
Stable backport criteria
- Fixes a real operational bug (unintended AH8 mid-transition),
observable as timeouts or recovery during power mode changes.
- Small, targeted change in a single vendor driver; minimal risk to
other subsystems.
- No new features or architectural changes; follows established patterns
in UFS vendor drivers.
- While the commit message lacks an explicit Fixes/Stable tag, the
change aligns well with stable policy as a platform-specific
reliability fix.
Recommendation
- Backport to stable: YES.
- Optional but advisable: include the small follow-up that returns an
error immediately on idle wait timeout (to propagate the PRE_CHANGE
failure) to match the improved error handling now seen in-tree.
drivers/ufs/host/ufs-mediatek.c | 53 +++++++++++++++++++--------------
1 file changed, 30 insertions(+), 23 deletions(-)
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 91081d2aabe44..3defb5f135e33 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -1400,19 +1400,49 @@ static int ufs_mtk_pre_pwr_change(struct ufs_hba *hba,
return ret;
}
+static int ufs_mtk_auto_hibern8_disable(struct ufs_hba *hba)
+{
+ int ret;
+
+ /* disable auto-hibern8 */
+ ufshcd_writel(hba, 0, REG_AUTO_HIBERNATE_IDLE_TIMER);
+
+ /* wait host return to idle state when auto-hibern8 off */
+ ufs_mtk_wait_idle_state(hba, 5);
+
+ ret = ufs_mtk_wait_link_state(hba, VS_LINK_UP, 100);
+ if (ret) {
+ dev_warn(hba->dev, "exit h8 state fail, ret=%d\n", ret);
+
+ ufshcd_force_error_recovery(hba);
+
+ /* trigger error handler and break suspend */
+ ret = -EBUSY;
+ }
+
+ return ret;
+}
+
static int ufs_mtk_pwr_change_notify(struct ufs_hba *hba,
enum ufs_notify_change_status stage,
const struct ufs_pa_layer_attr *dev_max_params,
struct ufs_pa_layer_attr *dev_req_params)
{
int ret = 0;
+ static u32 reg;
switch (stage) {
case PRE_CHANGE:
+ if (ufshcd_is_auto_hibern8_supported(hba)) {
+ reg = 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;
case POST_CHANGE:
+ if (ufshcd_is_auto_hibern8_supported(hba))
+ ufshcd_writel(hba, reg, REG_AUTO_HIBERNATE_IDLE_TIMER);
break;
default:
ret = -EINVAL;
@@ -1646,29 +1676,6 @@ static void ufs_mtk_dev_vreg_set_lpm(struct ufs_hba *hba, bool lpm)
}
}
-static int ufs_mtk_auto_hibern8_disable(struct ufs_hba *hba)
-{
- int ret;
-
- /* disable auto-hibern8 */
- ufshcd_writel(hba, 0, REG_AUTO_HIBERNATE_IDLE_TIMER);
-
- /* wait host return to idle state when auto-hibern8 off */
- ufs_mtk_wait_idle_state(hba, 5);
-
- ret = ufs_mtk_wait_link_state(hba, VS_LINK_UP, 100);
- if (ret) {
- dev_warn(hba->dev, "exit h8 state fail, ret=%d\n", ret);
-
- ufshcd_force_error_recovery(hba);
-
- /* trigger error handler and break suspend */
- ret = -EBUSY;
- }
-
- return ret;
-}
-
static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op,
enum ufs_notify_change_status status)
{
--
2.51.0
next prev parent reply other threads:[~2025-10-25 16:15 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251025160905.3857885-1-sashal@kernel.org>
2025-10-25 15:53 ` [PATCH AUTOSEL 6.17] wifi: mt76: improve phy reset on hw restart Sasha Levin
2025-10-25 15:53 ` [PATCH AUTOSEL 6.17-6.12] Bluetooth: btusb: Add new VID/PID 13d3/3633 for MT7922 Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17] extcon: axp288: Fix wakeup source leaks on device unbind Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17] wifi: mt76: mt7996: Set def_wcid pointer in mt7996_mac_sta_init_link() Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.12] ASoC: mediatek: Use SND_JACK_AVOUT for HDMI/DP jacks Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-6.6] wifi: mt76: mt7996: Temporarily disable EPCS Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17] scsi: ufs: core: Change MCQ interrupt enable flow Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-6.1] scsi: ufs: host: mediatek: Fix invalid access in vccqx handling Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17-6.1] scsi: ufs: host: mediatek: Change reset sequence for improved stability Sasha Levin
2025-10-25 15:56 ` Sasha Levin [this message]
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17-6.6] char: Use list_del_init() in misc_deregister() to reinitialize list pointer Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17-6.12] wifi: mt76: mt76_eeprom_override to int Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] wifi: mt76: mt7996: disable promiscuous mode by default Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] scsi: ufs: host: mediatek: Fix PWM mode switch issue Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.6] scsi: ufs: host: mediatek: Enhance recovery on hibernation exit failure Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] wifi: mt76: mt7996: fix memory leak on mt7996_mcu_sta_key_tlv error Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17] extcon: fsa9480: Fix wakeup source leaks on device unbind Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] wifi: mt76: mt7925: add pci restore for hibernate Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] scsi: ufs: host: mediatek: Fix adapt issue after PA_Init Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.1] wifi: mt76: mt7921: Add 160MHz beamformee capability for mt7922 device Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.6] scsi: ufs: core: Disable timestamp functionality if not supported Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.1] scsi: ufs: host: mediatek: Assign power mode userdata before FASTAUTO mode change Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17] Bluetooth: btusb: Add new VID/PID 13d3/3627 for MT7925 Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-5.4] extcon: adc-jack: Fix wakeup source leaks on device unbind Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17] wifi: mt76: mt7996: support writing MAC TXD for AddBA Request Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] mei: make a local copy of client uuid in connect Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.1] ftrace: Fix softlockup in ftrace_module_enable Sasha Levin
2025-10-25 19:25 ` Steven Rostedt
2025-10-28 17:48 ` Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.6] scsi: ufs: host: mediatek: Fix auto-hibern8 timer configuration Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.12] scsi: ufs: host: mediatek: Fix unbalanced IRQ enable issue Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.1] scsi: ufs: host: mediatek: Enhance recovery on resume failure Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] wifi: mt76: use altx queue for offchannel tx on connac+ Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17] wifi: mt76: mt7996: Fix mt7996_reverse_frag0_hdr_trans for MLO Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-6.12] scsi: ufs: host: mediatek: Correct system PM flow Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.15] page_pool: always add GFP_NOWARN for ATOMIC allocations Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251025160905.3857885-150-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=matthias.bgg@gmail.com \
--cc=patches@lists.linux.dev \
--cc=peter.wang@mediatek.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®