diff mbox series

[5/6] scsi: ufs: ufs-sysfs: Expose UFS power info

Message ID 1694411968-14413-6-git-send-email-quic_cang@quicinc.com (mailing list archive)
State Changes Requested
Headers show
Series Enable HS-G5 support on SM8550 | expand

Commit Message

Can Guo Sept. 11, 2023, 5:59 a.m. UTC
Having UFS power info available in sysfs makes it easier to tell the state
of the link during runtime considering we have a bounch of power saving
features and various combinations for backward compatiblity.

Signed-off-by: Can Guo <quic_cang@quicinc.com>
---
 drivers/ufs/core/ufs-sysfs.c | 71 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

Comments

Nitin Rawat Sept. 14, 2023, 11:33 a.m. UTC | #1
On 9/11/2023 11:29 AM, Can Guo wrote:
> Having UFS power info available in sysfs makes it easier to tell the state
> of the link during runtime considering we have a bounch of power saving
> features and various combinations for backward compatiblity.

Please fix spelling mistake - *bounch -> bunch


> 
> Signed-off-by: Can Guo <quic_cang@quicinc.com>
> ---
>   drivers/ufs/core/ufs-sysfs.c | 71 ++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 71 insertions(+)
> 
> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
> index c959064..53af490 100644
> --- a/drivers/ufs/core/ufs-sysfs.c
> +++ b/drivers/ufs/core/ufs-sysfs.c
> @@ -628,6 +628,76 @@ static const struct attribute_group ufs_sysfs_monitor_group = {
>   	.attrs = ufs_sysfs_monitor_attrs,
>   };
>   
> +static ssize_t gear_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.gear_rx);
> +}
> +
> +static ssize_t lane_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.lane_rx);
> +}
> +
> +static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.pwr_rx);
> +}
> +
> +static ssize_t rate_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.hs_rate);
> +}
> +
> +static ssize_t dev_pm_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%d\n", hba->curr_dev_pwr_mode);
> +}
> +
> +static ssize_t link_state_show(struct device *dev,
> +			       struct device_attribute *attr, char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%d\n", hba->uic_link_state);
> +}
> +
> +static DEVICE_ATTR_RO(gear);
> +static DEVICE_ATTR_RO(lane);
> +static DEVICE_ATTR_RO(mode);
> +static DEVICE_ATTR_RO(rate);
> +static DEVICE_ATTR_RO(dev_pm);
> +static DEVICE_ATTR_RO(link_state);
> +
> +static struct attribute *ufs_power_info_attrs[] = {
> +	&dev_attr_gear.attr,
> +	&dev_attr_lane.attr,
> +	&dev_attr_mode.attr,
> +	&dev_attr_rate.attr,
> +	&dev_attr_dev_pm.attr,
> +	&dev_attr_link_state.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group ufs_sysfs_power_info_group = {
> +	.name = "power_info",
> +	.attrs = ufs_power_info_attrs,
> +};
> +
>   static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
>   				  enum desc_idn desc_id,
>   				  u8 desc_index,
> @@ -1233,6 +1303,7 @@ static const struct attribute_group *ufs_sysfs_groups[] = {
>   	&ufs_sysfs_default_group,
>   	&ufs_sysfs_capabilities_group,
>   	&ufs_sysfs_monitor_group,
> +	&ufs_sysfs_power_info_group,
>   	&ufs_sysfs_device_descriptor_group,
>   	&ufs_sysfs_interconnect_descriptor_group,
>   	&ufs_sysfs_geometry_descriptor_group,


How about having one power mode attribute displaying all useful info 
(lane, gear, mode, rate).

Regards,
Nitin Rawat
Can Guo Sept. 15, 2023, 1:59 a.m. UTC | #2
Hi Nitin,

On 9/14/2023 7:33 PM, Nitin Rawat wrote:
>
>
> On 9/11/2023 11:29 AM, Can Guo wrote:
>> Having UFS power info available in sysfs makes it easier to tell the 
>> state
>> of the link during runtime considering we have a bounch of power saving
>> features and various combinations for backward compatiblity.
>
> Please fix spelling mistake - *bounch -> bunch
done
>
>
>>
>> Signed-off-by: Can Guo <quic_cang@quicinc.com>
>> ---
>>   drivers/ufs/core/ufs-sysfs.c | 71 
>> ++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 71 insertions(+)
>>
>> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
>> index c959064..53af490 100644
>> --- a/drivers/ufs/core/ufs-sysfs.c
>> +++ b/drivers/ufs/core/ufs-sysfs.c
>> @@ -628,6 +628,76 @@ static const struct attribute_group 
>> ufs_sysfs_monitor_group = {
>>       .attrs = ufs_sysfs_monitor_attrs,
>>   };
>>   +static ssize_t gear_show(struct device *dev, struct 
>> device_attribute *attr,
>> +             char *buf)
>> +{
>> +    struct ufs_hba *hba = dev_get_drvdata(dev);
>> +
>> +    return sysfs_emit(buf, "%u\n", hba->pwr_info.gear_rx);
>> +}
>> +
>> +static ssize_t lane_show(struct device *dev, struct device_attribute 
>> *attr,
>> +             char *buf)
>> +{
>> +    struct ufs_hba *hba = dev_get_drvdata(dev);
>> +
>> +    return sysfs_emit(buf, "%u\n", hba->pwr_info.lane_rx);
>> +}
>> +
>> +static ssize_t mode_show(struct device *dev, struct device_attribute 
>> *attr,
>> +             char *buf)
>> +{
>> +    struct ufs_hba *hba = dev_get_drvdata(dev);
>> +
>> +    return sysfs_emit(buf, "%u\n", hba->pwr_info.pwr_rx);
>> +}
>> +
>> +static ssize_t rate_show(struct device *dev, struct device_attribute 
>> *attr,
>> +             char *buf)
>> +{
>> +    struct ufs_hba *hba = dev_get_drvdata(dev);
>> +
>> +    return sysfs_emit(buf, "%u\n", hba->pwr_info.hs_rate);
>> +}
>> +
>> +static ssize_t dev_pm_show(struct device *dev, struct 
>> device_attribute *attr,
>> +               char *buf)
>> +{
>> +    struct ufs_hba *hba = dev_get_drvdata(dev);
>> +
>> +    return sysfs_emit(buf, "%d\n", hba->curr_dev_pwr_mode);
>> +}
>> +
>> +static ssize_t link_state_show(struct device *dev,
>> +                   struct device_attribute *attr, char *buf)
>> +{
>> +    struct ufs_hba *hba = dev_get_drvdata(dev);
>> +
>> +    return sysfs_emit(buf, "%d\n", hba->uic_link_state);
>> +}
>> +
>> +static DEVICE_ATTR_RO(gear);
>> +static DEVICE_ATTR_RO(lane);
>> +static DEVICE_ATTR_RO(mode);
>> +static DEVICE_ATTR_RO(rate);
>> +static DEVICE_ATTR_RO(dev_pm);
>> +static DEVICE_ATTR_RO(link_state);
>> +
>> +static struct attribute *ufs_power_info_attrs[] = {
>> +    &dev_attr_gear.attr,
>> +    &dev_attr_lane.attr,
>> +    &dev_attr_mode.attr,
>> +    &dev_attr_rate.attr,
>> +    &dev_attr_dev_pm.attr,
>> +    &dev_attr_link_state.attr,
>> +    NULL
>> +};
>> +
>> +static const struct attribute_group ufs_sysfs_power_info_group = {
>> +    .name = "power_info",
>> +    .attrs = ufs_power_info_attrs,
>> +};
>> +
>>   static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
>>                     enum desc_idn desc_id,
>>                     u8 desc_index,
>> @@ -1233,6 +1303,7 @@ static const struct attribute_group 
>> *ufs_sysfs_groups[] = {
>>       &ufs_sysfs_default_group,
>>       &ufs_sysfs_capabilities_group,
>>       &ufs_sysfs_monitor_group,
>> +    &ufs_sysfs_power_info_group,
>>       &ufs_sysfs_device_descriptor_group,
>>       &ufs_sysfs_interconnect_descriptor_group,
>>       &ufs_sysfs_geometry_descriptor_group,
>
>
> How about having one power mode attribute displaying all useful info 
> (lane, gear, mode, rate).

sysfs entry is meant for printing a single value instead of a line of 
strings.

>
> Regards,
> Nitin Rawat


Thanks,

Can Guo.
Manivannan Sadhasivam Sept. 19, 2023, 12:16 p.m. UTC | #3
On Sun, Sep 10, 2023 at 10:59:26PM -0700, Can Guo wrote:
> Having UFS power info available in sysfs makes it easier to tell the state
> of the link during runtime considering we have a bounch of power saving
> features and various combinations for backward compatiblity.
> 

Please move the sysfs patches to a separate series.

- Mani

> Signed-off-by: Can Guo <quic_cang@quicinc.com>
> ---
>  drivers/ufs/core/ufs-sysfs.c | 71 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 71 insertions(+)
> 
> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
> index c959064..53af490 100644
> --- a/drivers/ufs/core/ufs-sysfs.c
> +++ b/drivers/ufs/core/ufs-sysfs.c
> @@ -628,6 +628,76 @@ static const struct attribute_group ufs_sysfs_monitor_group = {
>  	.attrs = ufs_sysfs_monitor_attrs,
>  };
>  
> +static ssize_t gear_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.gear_rx);
> +}
> +
> +static ssize_t lane_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.lane_rx);
> +}
> +
> +static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.pwr_rx);
> +}
> +
> +static ssize_t rate_show(struct device *dev, struct device_attribute *attr,
> +			 char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%u\n", hba->pwr_info.hs_rate);
> +}
> +
> +static ssize_t dev_pm_show(struct device *dev, struct device_attribute *attr,
> +			   char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%d\n", hba->curr_dev_pwr_mode);
> +}
> +
> +static ssize_t link_state_show(struct device *dev,
> +			       struct device_attribute *attr, char *buf)
> +{
> +	struct ufs_hba *hba = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%d\n", hba->uic_link_state);
> +}
> +
> +static DEVICE_ATTR_RO(gear);
> +static DEVICE_ATTR_RO(lane);
> +static DEVICE_ATTR_RO(mode);
> +static DEVICE_ATTR_RO(rate);
> +static DEVICE_ATTR_RO(dev_pm);
> +static DEVICE_ATTR_RO(link_state);
> +
> +static struct attribute *ufs_power_info_attrs[] = {
> +	&dev_attr_gear.attr,
> +	&dev_attr_lane.attr,
> +	&dev_attr_mode.attr,
> +	&dev_attr_rate.attr,
> +	&dev_attr_dev_pm.attr,
> +	&dev_attr_link_state.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group ufs_sysfs_power_info_group = {
> +	.name = "power_info",
> +	.attrs = ufs_power_info_attrs,
> +};
> +
>  static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
>  				  enum desc_idn desc_id,
>  				  u8 desc_index,
> @@ -1233,6 +1303,7 @@ static const struct attribute_group *ufs_sysfs_groups[] = {
>  	&ufs_sysfs_default_group,
>  	&ufs_sysfs_capabilities_group,
>  	&ufs_sysfs_monitor_group,
> +	&ufs_sysfs_power_info_group,
>  	&ufs_sysfs_device_descriptor_group,
>  	&ufs_sysfs_interconnect_descriptor_group,
>  	&ufs_sysfs_geometry_descriptor_group,
> -- 
> 2.7.4
>
Bart Van Assche Oct. 26, 2023, 7:53 p.m. UTC | #4
On 9/10/23 22:59, Can Guo wrote:
> Having UFS power info available in sysfs makes it easier to tell the state
> of the link during runtime considering we have a bounch of power saving
> features and various combinations for backward compatiblity.

Since this patch introduces new sysfs attributes, it should include an
update for Documentation/ABI/testing/sysfs-driver-ufs.

Bart.
Can Guo Oct. 31, 2023, 4:46 a.m. UTC | #5
Hi Bart,

On 10/27/2023 3:53 AM, Bart Van Assche wrote:
> On 9/10/23 22:59, Can Guo wrote:
>> Having UFS power info available in sysfs makes it easier to tell the 
>> state
>> of the link during runtime considering we have a bounch of power saving
>> features and various combinations for backward compatiblity.
>
> Since this patch introduces new sysfs attributes, it should include an
> update for Documentation/ABI/testing/sysfs-driver-ufs.
>
> Bart.

Yes, changes to Documentation/ABI/testing/sysfs-driver-ufs. is in below 
patch.

https://patchwork.kernel.org/project/linux-scsi/patch/1694411968-14413-7-git-send-email-quic_cang@quicinc.com/

I will address your comments and combine them two in one change and 
re-submit.

Thanks for your review.


Best Regards,

Can Guo.
Can Guo Oct. 31, 2023, 8:08 a.m. UTC | #6
Hi Mani,

On 9/19/2023 8:16 PM, Manivannan Sadhasivam wrote:
> On Sun, Sep 10, 2023 at 10:59:26PM -0700, Can Guo wrote:
>> Having UFS power info available in sysfs makes it easier to tell the state
>> of the link during runtime considering we have a bounch of power saving
>> features and various combinations for backward compatiblity.
>>
> Please move the sysfs patches to a separate series.
>
> - Mani

Sure.


Thanks,

Can Guo.
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index c959064..53af490 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -628,6 +628,76 @@  static const struct attribute_group ufs_sysfs_monitor_group = {
 	.attrs = ufs_sysfs_monitor_attrs,
 };
 
+static ssize_t gear_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", hba->pwr_info.gear_rx);
+}
+
+static ssize_t lane_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", hba->pwr_info.lane_rx);
+}
+
+static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", hba->pwr_info.pwr_rx);
+}
+
+static ssize_t rate_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", hba->pwr_info.hs_rate);
+}
+
+static ssize_t dev_pm_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", hba->curr_dev_pwr_mode);
+}
+
+static ssize_t link_state_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct ufs_hba *hba = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", hba->uic_link_state);
+}
+
+static DEVICE_ATTR_RO(gear);
+static DEVICE_ATTR_RO(lane);
+static DEVICE_ATTR_RO(mode);
+static DEVICE_ATTR_RO(rate);
+static DEVICE_ATTR_RO(dev_pm);
+static DEVICE_ATTR_RO(link_state);
+
+static struct attribute *ufs_power_info_attrs[] = {
+	&dev_attr_gear.attr,
+	&dev_attr_lane.attr,
+	&dev_attr_mode.attr,
+	&dev_attr_rate.attr,
+	&dev_attr_dev_pm.attr,
+	&dev_attr_link_state.attr,
+	NULL
+};
+
+static const struct attribute_group ufs_sysfs_power_info_group = {
+	.name = "power_info",
+	.attrs = ufs_power_info_attrs,
+};
+
 static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
 				  enum desc_idn desc_id,
 				  u8 desc_index,
@@ -1233,6 +1303,7 @@  static const struct attribute_group *ufs_sysfs_groups[] = {
 	&ufs_sysfs_default_group,
 	&ufs_sysfs_capabilities_group,
 	&ufs_sysfs_monitor_group,
+	&ufs_sysfs_power_info_group,
 	&ufs_sysfs_device_descriptor_group,
 	&ufs_sysfs_interconnect_descriptor_group,
 	&ufs_sysfs_geometry_descriptor_group,