From: Yiwei Lin <s921975628@gmail.com>
To: alim.akhtar@samsung.com, avri.altman@sandisk.com, bvanassche@acm.org
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Yiwei Lin <s921975628@gmail.com>
Subject: [PATCH] ufs: sysfs: fix current_power_mode read without SSU
Date: Tue, 15 Sep 2026 01:00:32 +0800 [thread overview]
Message-ID: <20260914170032.5551-1-s921975628@gmail.com> (raw)
current_power_mode was generated by UFS_ATTRIBUTE(), which calls
ufshcd_rpm_get_sync() before issuing the query.
That resumes the UFS device WLUN, and ufshcd_wl_runtime_resume() sends
START STOP UNIT to bring the device back to Active. As a result
bCurrentPowerMode always read back as 0x11 (Active) no matter what
state the device was actually in. Sleep could never be observed through
sysfs.
Per the UFS spec, bCurrentPowerMode is the one attribute the device
must answer in any power mode, so there is no need to wake it.
Tested on hardware: with the device runtime-suspended, reading
current_power_mode used to return 0x11; after this change it returns
0x22 (Sleep), matching the device's real state.
Assisted-by: LLM
Signed-off-by: Yiwei Lin <s921975628@gmail.com>
---
drivers/ufs/core/ufs-sysfs.c | 59 +++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index 63e670d1a9d9e..36cffd535ab7d 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -1786,7 +1786,64 @@ out: \
static DEVICE_ATTR_RO(_name)
UFS_ATTRIBUTE(boot_lun_enabled, _BOOT_LU_EN);
-UFS_ATTRIBUTE(current_power_mode, _POWER_MODE);
+
+/*
+ * Per UFS spec, bCurrentPowerMode is the only attribute the device must
+ * respond to in any power mode. Read it without waking the device to
+ * Active: restore HBA clocks via pm_runtime_get_sync(hba->dev) only
+ * (avoids triggering ufshcd_wl_runtime_resume and its START STOP UNIT),
+ * exit Hibern8 if needed so the link can carry the UPIU, then query.
+ */
+static ssize_t current_power_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+ u32 value;
+ int ret;
+
+ down(&hba->host_sem);
+ if (!ufshcd_is_user_access_allowed(hba)) {
+ up(&hba->host_sem);
+ return -EBUSY;
+ }
+
+ ret = pm_runtime_get_sync(hba->dev);
+ if (ret < 0) {
+ pr_warn("%s: pm_runtime_get_sync failed %d\n", __func__, ret);
+ pm_runtime_put_noidle(hba->dev);
+ up(&hba->host_sem);
+ return ret;
+ }
+ ret = 0;
+
+ ufshcd_hold(hba);
+
+ if (ufshcd_is_link_hibern8(hba)) {
+ ret = ufshcd_uic_hibern8_exit(hba);
+ if (!ret)
+ ufshcd_set_link_active(hba);
+ else
+ dev_err(hba->dev, "%s: hibern8 exit failed %d\n",
+ __func__, ret);
+ }
+
+ if (!ret)
+ ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
+ QUERY_ATTR_IDN_POWER_MODE, 0, 0, &value);
+
+ ufshcd_release(hba);
+ pm_runtime_put(hba->dev);
+
+ if (ret) {
+ up(&hba->host_sem);
+ return -EINVAL;
+ }
+ ret = sysfs_emit(buf, "0x%08X\n", value);
+ up(&hba->host_sem);
+ return ret;
+}
+static DEVICE_ATTR_RO(current_power_mode);
+
UFS_ATTRIBUTE(active_icc_level, _ACTIVE_ICC_LVL);
UFS_ATTRIBUTE(ooo_data_enabled, _OOO_DATA_EN);
UFS_ATTRIBUTE(bkops_status, _BKOPS_STATUS);
--
2.34.1
next reply other threads:[~2026-09-14 17:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 17:00 Yiwei Lin [this message]
2026-09-14 17:53 ` Yiwei Lin
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=20260914170032.5551-1-s921975628@gmail.com \
--to=s921975628@gmail.com \
--cc=alim.akhtar@samsung.com \
--cc=avri.altman@sandisk.com \
--cc=bvanassche@acm.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@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®