[PATCH v3 2/2] ufs: core: print UFSHCD capabilities in controller's sysfs node

From: Daniil Lunev
Date: Thu Jul 28 2022 - 22:05:45 EST


Allows userspace to check if Clock Scaling, Write Booster and Inline
Crypto Engine functionality can be enabled.

Signed-off-by: Daniil Lunev <dlunev@xxxxxxxxxxxx>

---

Changes in v3:
* Expose each capability individually.
* Update documentation to represent new scheme.

Changes in v2:
* Add documentation entry for the new sysfs node.

Documentation/ABI/testing/sysfs-driver-ufs | 39 ++++++++++++++++++++
drivers/ufs/core/ufs-sysfs.c | 41 ++++++++++++++++++++++
2 files changed, 80 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs
index 6b248abb1bd71..805d76f7d7aef 100644
--- a/Documentation/ABI/testing/sysfs-driver-ufs
+++ b/Documentation/ABI/testing/sysfs-driver-ufs
@@ -1591,6 +1591,45 @@ Description: This entry shows the status of HPB.

The file is read only.

+What: /sys/bus/platform/drivers/ufshcd/*/capabilities/clock_scaling
+What: /sys/bus/platform/devices/*.ufs/capabilities/clock_scaling
+Date: July 2022
+Contact: Daniil Lunev <dlunev@xxxxxxxxxxxx>
+Description: Indicates status of clock scaling.
+
+ == ============================
+ 0 Clock scaling is not enabled.
+ 1 Clock scaling is enabled.
+ == ============================
+
+ The file is read only.
+
+What: /sys/bus/platform/drivers/ufshcd/*/capabilities/write_booster
+What: /sys/bus/platform/devices/*.ufs/capabilities/write_booster
+Date: July 2022
+Contact: Daniil Lunev <dlunev@xxxxxxxxxxxx>
+Description: Indicates status of Write Booster.
+
+ == ============================
+ 0 Write Booster can not be enabled.
+ 1 Write Booster can be enabled.
+ == ============================
+
+ The file is read only.
+
+What: /sys/bus/platform/drivers/ufshcd/*/capabilities/crypto
+What: /sys/bus/platform/devices/*.ufs/capabilities/crypto
+Date: July 2022
+Contact: Daniil Lunev <dlunev@xxxxxxxxxxxx>
+Description: Indicates status of Inline Crypto Engine support.
+
+ == ============================
+ 0 Inline Crypto Engine can not be used.
+ 1 Inline Crypto Engine can be used.
+ == ============================
+
+ The file is read only.
+
What: /sys/class/scsi_device/*/device/hpb_param_sysfs/activation_thld
Date: February 2021
Contact: Avri Altman <avri.altman@xxxxxxx>
diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index 0a088b47d5570..4a3e58d545fe5 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -279,6 +279,46 @@ static const struct attribute_group ufs_sysfs_default_group = {
.attrs = ufs_sysfs_ufshcd_attrs,
};

+static ssize_t clock_scaling_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+
+ return sysfs_emit(buf, "%d\n", ufshcd_is_clkscaling_supported(hba));
+}
+
+static ssize_t write_booster_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+
+ return sysfs_emit(buf, "%d\n", ufshcd_is_wb_allowed(hba));
+}
+
+static ssize_t crypto_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct ufs_hba *hba = dev_get_drvdata(dev);
+
+ return sysfs_emit(buf, "%d\n", ufshcd_is_crypto_supported(hba));
+}
+
+static DEVICE_ATTR_RO(clock_scaling);
+static DEVICE_ATTR_RO(write_booster);
+static DEVICE_ATTR_RO(crypto);
+
+static struct attribute *ufs_sysfs_capabilities_attrs[] = {
+ &dev_attr_clock_scaling.attr,
+ &dev_attr_write_booster.attr,
+ &dev_attr_crypto.attr,
+ NULL
+};
+
+static const struct attribute_group ufs_sysfs_capabilities_group = {
+ .name = "capabilities",
+ .attrs = ufs_sysfs_capabilities_attrs,
+};
+
static ssize_t monitor_enable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1134,6 +1174,7 @@ static const struct attribute_group ufs_sysfs_attributes_group = {

static const struct attribute_group *ufs_sysfs_groups[] = {
&ufs_sysfs_default_group,
+ &ufs_sysfs_capabilities_group,
&ufs_sysfs_monitor_group,
&ufs_sysfs_device_descriptor_group,
&ufs_sysfs_interconnect_descriptor_group,
--
2.31.0