@@ -140,3 +140,15 @@ Description:
PPS events to the Linux PPS subsystem. To enable PPS
events, write a "1" into the file. To disable events,
write a "0" into the file.
+
+What: /sys/class/ptp/ptp<N>/ts_point
+Date: October 2024
+Contact: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
+Description:
+ This file provides control over the point in time in
+ which the HW timestamp is latched. As specified in IEEE
+ 802.3cx, the latch point can be either at the beginning
+ or after the end of Start of Frame Delimiter (SFD).
+ Value "1" means the timestamp is latched at the
+ beginning of the SFD. Value "2" means that timestamp is
+ latched after the end of SFD.
@@ -28,6 +28,46 @@ static ssize_t max_phase_adjustment_show(struct device *dev,
}
static DEVICE_ATTR_RO(max_phase_adjustment);
+static ssize_t ts_point_show(struct device *dev, struct device_attribute *attr,
+ char *page)
+{
+ struct ptp_clock *ptp = dev_get_drvdata(dev);
+ enum ptp_ts_point point;
+ int err;
+
+ if (!ptp->info->get_ts_point)
+ return -EOPNOTSUPP;
+ err = ptp->info->get_ts_point(ptp->info, &point);
+ if (err)
+ return err;
+
+ return sysfs_emit(page, "%d\n", point);
+}
+
+static ssize_t ts_point_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct ptp_clock *ptp = dev_get_drvdata(dev);
+ enum ptp_ts_point point;
+ int err;
+ u8 val;
+
+ if (!ptp->info->set_ts_point)
+ return -EOPNOTSUPP;
+ if (kstrtou8(buf, 0, &val))
+ return -EINVAL;
+ if (val <= PTP_TS_POINT_NONE || val > PTP_TS_POINT_MAX)
+ return -EINVAL;
+ point = val;
+
+ err = ptp->info->set_ts_point(ptp->info, point);
+ if (err)
+ return err;
+
+ return count;
+}
+static DEVICE_ATTR(ts_point, 0660, ts_point_show, ts_point_store);
+
#define PTP_SHOW_INT(name, var) \
static ssize_t var##_show(struct device *dev, \
struct device_attribute *attr, char *page) \
@@ -335,6 +375,7 @@ static struct attribute *ptp_attrs[] = {
&dev_attr_pps_enable.attr,
&dev_attr_n_vclocks.attr,
&dev_attr_max_vclocks.attr,
+ &dev_attr_ts_point.attr,
NULL
};
@@ -363,6 +404,9 @@ static umode_t ptp_is_attribute_visible(struct kobject *kobj,
} else if (attr == &dev_attr_max_phase_adjustment.attr) {
if (!info->adjphase || !info->getmaxphase)
mode = 0;
+ } else if (attr == &dev_attr_ts_point.attr) {
+ if (!info->get_ts_point && !info->set_ts_point)
+ mode = 0;
}
return mode;
@@ -159,6 +159,14 @@ struct ptp_system_timestamp {
* scheduling time (>=0) or negative value in case further
* scheduling is not required.
*
+ * @set_ts_point: Request change of timestamp latch point, as the timestamp
+ * could be latched at the beginning or after the end of start
+ * frame delimiter (SFD), as described in IEEE 802.3cx
+ * specification.
+ *
+ * @get_ts_point: Obtain the timestamp measurement latch point, counterpart of
+ * .set_ts_point() for getting currently configured value.
+ *
* Drivers should embed their ptp_clock_info within a private
* structure, obtaining a reference to it using container_of().
*
@@ -195,6 +203,10 @@ struct ptp_clock_info {
int (*verify)(struct ptp_clock_info *ptp, unsigned int pin,
enum ptp_pin_function func, unsigned int chan);
long (*do_aux_work)(struct ptp_clock_info *ptp);
+ int (*set_ts_point)(struct ptp_clock_info *ptp,
+ enum ptp_ts_point point);
+ int (*get_ts_point)(struct ptp_clock_info *ptp,
+ enum ptp_ts_point *point);
};
struct ptp_clock;
@@ -253,4 +253,22 @@ struct ptp_extts_event {
unsigned int rsv[2]; /* Reserved for future use. */
};
+/**
+ * enum ptp_ts_point - possible timestamp latch points (IEEE 802.3cx)
+ *
+ * @PTP_TS_POINT_NONE: no timestamp latch point was provided
+ * @PTP_TS_POINT_SFD: timestamp latched at the beginning of sending Start
+ * of Frame Delimiter (SFD)
+ * @PTP_TS_POINT_POST_SFD: timestamp latched after the end of sending Start
+ * of Frame Delimiter (SFD)
+ */
+enum ptp_ts_point {
+ PTP_TS_POINT_NONE = 0,
+ PTP_TS_POINT_SFD,
+ PTP_TS_POINT_POST_SFD,
+
+ /* private: */
+ PTP_TS_POINT_MAX
+};
+
#endif