Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: ufs: core: Print UFSHCD capabilities in controller's sysfs node

Userspace may want to manually control when the data should go into
WriteBooster buffer. The control happens via "wb_on" node, but presently,
there is no simple way to check if WriteBooster is supported and
enabled.

Expose the Write Booster and Clock Scaling capabilities to be able to
determine if the Write Booster is available and if its manual control is
blocked by Clock Scaling mechanism.

Link: https://lore.kernel.org/r/20220829081845.v8.1.Ibf9efc9be50783eeee55befa2270b7d38552354c@changeid
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Daniil Lunev <dlunev@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Daniil Lunev and committed by
Martin K. Petersen
2286ade0 9806d1b8

+72
+37
Documentation/ABI/testing/sysfs-driver-ufs
··· 1600 1600 1601 1601 The file is read only. 1602 1602 1603 + Contact: Daniil Lunev <dlunev@chromium.org> 1604 + What: /sys/bus/platform/drivers/ufshcd/*/capabilities/ 1605 + What: /sys/bus/platform/devices/*.ufs/capabilities/ 1606 + Date: August 2022 1607 + Description: The group represents the effective capabilities of the 1608 + host-device pair. i.e. the capabilities which are enabled in the 1609 + driver for the specific host controller, supported by the host 1610 + controller and are supported and/or have compatible 1611 + configuration on the device side. 1612 + 1613 + Contact: Daniil Lunev <dlunev@chromium.org> 1614 + What: /sys/bus/platform/drivers/ufshcd/*/capabilities/clock_scaling 1615 + What: /sys/bus/platform/devices/*.ufs/capabilities/clock_scaling 1616 + Date: August 2022 1617 + Contact: Daniil Lunev <dlunev@chromium.org> 1618 + Description: Indicates status of clock scaling. 1619 + 1620 + == ============================ 1621 + 0 Clock scaling is not supported. 1622 + 1 Clock scaling is supported. 1623 + == ============================ 1624 + 1625 + The file is read only. 1626 + 1627 + What: /sys/bus/platform/drivers/ufshcd/*/capabilities/write_booster 1628 + What: /sys/bus/platform/devices/*.ufs/capabilities/write_booster 1629 + Date: August 2022 1630 + Contact: Daniil Lunev <dlunev@chromium.org> 1631 + Description: Indicates status of Write Booster. 1632 + 1633 + == ============================ 1634 + 0 Write Booster can not be enabled. 1635 + 1 Write Booster can be enabled. 1636 + == ============================ 1637 + 1638 + The file is read only. 1639 + 1603 1640 What: /sys/class/scsi_device/*/device/hpb_param_sysfs/activation_thld 1604 1641 Date: February 2021 1605 1642 Contact: Avri Altman <avri.altman@wdc.com>
+35
drivers/ufs/core/ufs-sysfs.c
··· 325 325 .attrs = ufs_sysfs_ufshcd_attrs, 326 326 }; 327 327 328 + static ssize_t clock_scaling_show(struct device *dev, struct device_attribute *attr, 329 + char *buf) 330 + { 331 + struct ufs_hba *hba = dev_get_drvdata(dev); 332 + 333 + return sysfs_emit(buf, "%d\n", ufshcd_is_clkscaling_supported(hba)); 334 + } 335 + 336 + static ssize_t write_booster_show(struct device *dev, struct device_attribute *attr, 337 + char *buf) 338 + { 339 + struct ufs_hba *hba = dev_get_drvdata(dev); 340 + 341 + return sysfs_emit(buf, "%d\n", ufshcd_is_wb_allowed(hba)); 342 + } 343 + 344 + static DEVICE_ATTR_RO(clock_scaling); 345 + static DEVICE_ATTR_RO(write_booster); 346 + 347 + /* 348 + * See Documentation/ABI/testing/sysfs-driver-ufs for the semantics of this 349 + * group. 350 + */ 351 + static struct attribute *ufs_sysfs_capabilities_attrs[] = { 352 + &dev_attr_clock_scaling.attr, 353 + &dev_attr_write_booster.attr, 354 + NULL 355 + }; 356 + 357 + static const struct attribute_group ufs_sysfs_capabilities_group = { 358 + .name = "capabilities", 359 + .attrs = ufs_sysfs_capabilities_attrs, 360 + }; 361 + 328 362 static ssize_t monitor_enable_show(struct device *dev, 329 363 struct device_attribute *attr, char *buf) 330 364 { ··· 1214 1180 1215 1181 static const struct attribute_group *ufs_sysfs_groups[] = { 1216 1182 &ufs_sysfs_default_group, 1183 + &ufs_sysfs_capabilities_group, 1217 1184 &ufs_sysfs_monitor_group, 1218 1185 &ufs_sysfs_device_descriptor_group, 1219 1186 &ufs_sysfs_interconnect_descriptor_group,