mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Can Guo <can.guo@oss.qualcomm.com>
To: martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org, Can Guo <can.guo@oss.qualcomm.com>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Avri Altman <avri.altman@wdc.com>,
	Bart Van Assche <bvanassche@acm.org>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	Peter Wang <peter.wang@mediatek.com>,
	Huan Tang <tanghuan@vivo.com>,
	"Bao D. Nguyen" <quic_nguyenb@quicinc.com>,
	Daniel Lee <chullee@google.com>, Liu Song <liu.song13@zte.com.cn>,
	Ram Kumar Dwivedi <ram.dwivedi@oss.qualcomm.com>,
	Bean Huo <huobean@gmail.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2 2/2] scsi: ufs: core: Add a sysfs entry for ufshcd_state
Date: Tue, 24 Feb 2026 18:29:42 -0800	[thread overview]
Message-ID: <20260225022942.345564-3-can.guo@oss.qualcomm.com> (raw)
In-Reply-To: <20260225022942.345564-1-can.guo@oss.qualcomm.com>

Add a sysfs entry for ufshcd_state, such that userspace can check and
track the state transitions of hba.

Signed-off-by: Can Guo <can.guo@oss.qualcomm.com>
---
 Documentation/ABI/testing/sysfs-driver-ufs |  9 +++++++++
 drivers/ufs/core/ufs-sysfs.c               | 18 ++++++++++++++++++
 drivers/ufs/core/ufshcd.c                  |  2 ++
 3 files changed, 29 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs
index 665819308b40..339bb1befc9c 100644
--- a/Documentation/ABI/testing/sysfs-driver-ufs
+++ b/Documentation/ABI/testing/sysfs-driver-ufs
@@ -1778,3 +1778,12 @@ Description:
 		notification from UFSHCI UECDME.
 
 		The attribute is read/write.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/ufshcd_state
+What:		/sys/bus/platform/devices/*.ufs/ufshcd_state
+Date:		February 2026
+Contact:	Can Guo <can.guo@oss.qualcomm.com>
+Description:
+		This attribute shows the state of ufshcd.
+
+		The attribute is read only.
diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index 99af3c73f1af..10804ec6e252 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -97,6 +97,14 @@ static const char * const ufs_hid_states[] = {
 	[DEFRAG_NOT_REQUIRED]	= "defrag_not_required",
 };
 
+static const char * const ufshcd_states[] = {
+	[UFSHCD_STATE_RESET]			= "reset",
+	[UFSHCD_STATE_OPERATIONAL]		= "operational",
+	[UFSHCD_STATE_EH_SCHEDULED_NON_FATAL]	= "eh_scheduled_non_fatal",
+	[UFSHCD_STATE_EH_SCHEDULED_FATAL]	= "eh_scheduled_fatal",
+	[UFSHCD_STATE_ERROR]			= "error",
+};
+
 static const char *ufs_hid_state_to_string(enum ufs_hid_state state)
 {
 	if (state < NUM_UFS_HID_STATES)
@@ -633,6 +641,14 @@ static ssize_t dme_qos_notification_store(struct device *dev,
 	return count;
 }
 
+static ssize_t ufshcd_state_show(struct device *dev,
+				 struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%s\n", ufshcd_states[hba->ufshcd_state]);
+}
+
 static DEVICE_ATTR_RW(rpm_lvl);
 static DEVICE_ATTR_RO(rpm_target_dev_state);
 static DEVICE_ATTR_RO(rpm_target_link_state);
@@ -650,6 +666,7 @@ static DEVICE_ATTR_RO(critical_health);
 static DEVICE_ATTR_RW(device_lvl_exception_count);
 static DEVICE_ATTR_RO(device_lvl_exception_id);
 static DEVICE_ATTR_RW(dme_qos_notification);
+static DEVICE_ATTR_RO(ufshcd_state);
 
 static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_rpm_lvl.attr,
@@ -669,6 +686,7 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = {
 	&dev_attr_device_lvl_exception_count.attr,
 	&dev_attr_device_lvl_exception_id.attr,
 	&dev_attr_dme_qos_notification.attr,
+	&dev_attr_ufshcd_state.attr,
 	NULL
 };
 
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index c6c7de7a0603..32a508e1582e 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -7917,6 +7917,8 @@ static void ufshcd_process_probe_result(struct ufs_hba *hba,
 		hba->ufshcd_state = UFSHCD_STATE_OPERATIONAL;
 	spin_unlock_irqrestore(hba->host->host_lock, flags);
 
+	sysfs_notify(&hba->dev->kobj, NULL, "ufshcd_state");
+
 	trace_ufshcd_init(hba, ret,
 			  ktime_to_us(ktime_sub(ktime_get(), probe_start)),
 			  hba->curr_dev_pwr_mode, hba->uic_link_state);
-- 
2.34.1


  parent reply	other threads:[~2026-02-25  2:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260225022942.345564-1-can.guo@oss.qualcomm.com>
2026-02-25  2:29 ` [PATCH v2 1/2] scsi: ufs: core: Add support to notify userspace of UniPro QoS events Can Guo
2026-02-25 18:48   ` Bart Van Assche
2026-03-01  9:09     ` Can Guo
2026-02-25  2:29 ` Can Guo [this message]
2026-02-25 18:59   ` [PATCH v2 2/2] scsi: ufs: core: Add a sysfs entry for ufshcd_state Bart Van Assche
2026-03-01 12:40     ` Can Guo

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=20260225022942.345564-3-can.guo@oss.qualcomm.com \
    --to=can.guo@oss.qualcomm.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=adrian.hunter@intel.com \
    --cc=alim.akhtar@samsung.com \
    --cc=avri.altman@wdc.com \
    --cc=bvanassche@acm.org \
    --cc=chullee@google.com \
    --cc=huobean@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=liu.song13@zte.com.cn \
    --cc=martin.petersen@oracle.com \
    --cc=peter.wang@mediatek.com \
    --cc=quic_nguyenb@quicinc.com \
    --cc=ram.dwivedi@oss.qualcomm.com \
    --cc=tanghuan@vivo.com \
    /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®