ptp: add clock_index as a device attribute
Subsystems (3)
RFC 1/1 ptp: add clock_index as a device attribute
The PTP clock associated with a networking device is reported by the ETHTOOL_GET_TS_INFO ioctl, by using the ptp->index clock index variable.
In order to associate this clock index with the proper device, userspace applications make the assumption that /dev/ptpX has a clock index of X. If this assumption is wrong, such as if user space renames a device, then there isn't a mechanism to associate the clock index with the device.
Add a new device attribute to the device sysfs folder, clock_index, which will report the exact clock index of the device. This enables userspace applications to determine the clock_index of the PTP devices in a more robust way.
--- drivers/ptp/ptp_sysfs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/ptp/ptp_sysfs.c +9 -0
@@ -17,6 +17,14 @@ static ssize_t clock_name_show(struct device *dev, }static DEVICE_ATTR_RO (clock_name); +static ssize_t clock_index_show (struct device *dev, +struct device_attribute *attr,char *page) +{ +struct ptp_clock *ptp =dev_get_drvdata (dev); +return snprintf (page,PAGE_SIZE -1 ,"%d\n" , ptp->index); +} +static DEVICE_ATTR_RO (clock_index); +#define PTP_SHOW_INT (name, var) \ static ssize_t var##_show(struct device *dev, \ struct device_attribute *attr, char *page) \
@@ -150,6 +158,7 @@ static DEVICE_ATTR(pps_enable, 0220, NULL, pps_enable_store);static struct attribute *ptp_attrs[] = { &dev_attr_clock_name.attr, + &dev_attr_clock_index.attr, &dev_attr_max_adjustment.attr, &dev_attr_n_alarms.attr,
base-commit: 0c2a01dc27f68024108b7303002678bd72446a4e
Signature · 1 line
2.28.0.497.g54e85e7af1ac