aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher S. Hall <christopher.s.hall@intel.com>2016-02-22 06:15:25 -0500
committerJohn Stultz <john.stultz@linaro.org>2016-03-03 17:23:43 -0500
commit719f1aa4a67199a3c4c68a03f94e5ec44d9d5f82 (patch)
tree0a6cdf499ae615abf88e8d826e0c63c431f54bdb
parentf9677e0f83080bb4186865868c359e72e1fac1ea (diff)
ptp: Add PTP_SYS_OFFSET_PRECISE for driver crosstimestamping
Currently, network /system cross-timestamping is performed in the PTP_SYS_OFFSET ioctl. The PTP clock driver reads gettimeofday() and the gettime64() callback provided by the driver. The cross-timestamp is best effort where the latency between the capture of system time (getnstimeofday()) and the device time (driver callback) may be significant. The getcrosststamp() callback and corresponding PTP_SYS_OFFSET_PRECISE ioctl allows the driver to perform this device/system correlation when for example cross timestamp hardware is available. Modern Intel systems can do this for onboard Ethernet controllers using the ART counter. There is virtually zero latency between captures of the ART and network device clock. The capabilities ioctl (PTP_CLOCK_GETCAPS), is augmented allowing applications to query whether or not drivers implement the getcrosststamp callback, providing more precise cross timestamping. Cc: Prarit Bhargava <prarit@redhat.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: kevin.b.stanton@intel.com Cc: kevin.j.clarke@intel.com Cc: hpa@zytor.com Cc: jeffrey.t.kirsher@intel.com Cc: netdev@vger.kernel.org Acked-by: Richard Cochran <richardcochran@gmail.com> Signed-off-by: Christopher S. Hall <christopher.s.hall@intel.com> [jstultz: Commit subject tweaks] Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--Documentation/ptp/testptp.c6
-rw-r--r--drivers/ptp/ptp_chardev.c27
-rw-r--r--include/linux/ptp_clock_kernel.h8
-rw-r--r--include/uapi/linux/ptp_clock.h13
4 files changed, 51 insertions, 3 deletions
diff --git a/Documentation/ptp/testptp.c b/Documentation/ptp/testptp.c
index 6c6247aaa7b9..d99012f41602 100644
--- a/Documentation/ptp/testptp.c
+++ b/Documentation/ptp/testptp.c
@@ -277,13 +277,15 @@ int main(int argc, char *argv[])
277 " %d external time stamp channels\n" 277 " %d external time stamp channels\n"
278 " %d programmable periodic signals\n" 278 " %d programmable periodic signals\n"
279 " %d pulse per second\n" 279 " %d pulse per second\n"
280 " %d programmable pins\n", 280 " %d programmable pins\n"
281 " %d cross timestamping\n",
281 caps.max_adj, 282 caps.max_adj,
282 caps.n_alarm, 283 caps.n_alarm,
283 caps.n_ext_ts, 284 caps.n_ext_ts,
284 caps.n_per_out, 285 caps.n_per_out,
285 caps.pps, 286 caps.pps,
286 caps.n_pins); 287 caps.n_pins,
288 caps.cross_timestamping);
287 } 289 }
288 } 290 }
289 291
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index da7bae991552..579fd65299a0 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -22,6 +22,7 @@
22#include <linux/poll.h> 22#include <linux/poll.h>
23#include <linux/sched.h> 23#include <linux/sched.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/timekeeping.h>
25 26
26#include "ptp_private.h" 27#include "ptp_private.h"
27 28
@@ -120,11 +121,13 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
120 struct ptp_clock_caps caps; 121 struct ptp_clock_caps caps;
121 struct ptp_clock_request req; 122 struct ptp_clock_request req;
122 struct ptp_sys_offset *sysoff = NULL; 123 struct ptp_sys_offset *sysoff = NULL;
124 struct ptp_sys_offset_precise precise_offset;
123 struct ptp_pin_desc pd; 125 struct ptp_pin_desc pd;
124 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); 126 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
125 struct ptp_clock_info *ops = ptp->info; 127 struct ptp_clock_info *ops = ptp->info;
126 struct ptp_clock_time *pct; 128 struct ptp_clock_time *pct;
127 struct timespec64 ts; 129 struct timespec64 ts;
130 struct system_device_crosststamp xtstamp;
128 int enable, err = 0; 131 int enable, err = 0;
129 unsigned int i, pin_index; 132 unsigned int i, pin_index;
130 133
@@ -138,6 +141,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
138 caps.n_per_out = ptp->info->n_per_out; 141 caps.n_per_out = ptp->info->n_per_out;
139 caps.pps = ptp->info->pps; 142 caps.pps = ptp->info->pps;
140 caps.n_pins = ptp->info->n_pins; 143 caps.n_pins = ptp->info->n_pins;
144 caps.cross_timestamping = ptp->info->getcrosststamp != NULL;
141 if (copy_to_user((void __user *)arg, &caps, sizeof(caps))) 145 if (copy_to_user((void __user *)arg, &caps, sizeof(caps)))
142 err = -EFAULT; 146 err = -EFAULT;
143 break; 147 break;
@@ -180,6 +184,29 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
180 err = ops->enable(ops, &req, enable); 184 err = ops->enable(ops, &req, enable);
181 break; 185 break;
182 186
187 case PTP_SYS_OFFSET_PRECISE:
188 if (!ptp->info->getcrosststamp) {
189 err = -EOPNOTSUPP;
190 break;
191 }
192 err = ptp->info->getcrosststamp(ptp->info, &xtstamp);
193 if (err)
194 break;
195
196 ts = ktime_to_timespec64(xtstamp.device);
197 precise_offset.device.sec = ts.tv_sec;
198 precise_offset.device.nsec = ts.tv_nsec;
199 ts = ktime_to_timespec64(xtstamp.sys_realtime);
200 precise_offset.sys_realtime.sec = ts.tv_sec;
201 precise_offset.sys_realtime.nsec = ts.tv_nsec;
202 ts = ktime_to_timespec64(xtstamp.sys_monoraw);
203 precise_offset.sys_monoraw.sec = ts.tv_sec;
204 precise_offset.sys_monoraw.nsec = ts.tv_nsec;
205 if (copy_to_user((void __user *)arg, &precise_offset,
206 sizeof(precise_offset)))
207 err = -EFAULT;
208 break;
209
183 case PTP_SYS_OFFSET: 210 case PTP_SYS_OFFSET:
184 sysoff = kmalloc(sizeof(*sysoff), GFP_KERNEL); 211 sysoff = kmalloc(sizeof(*sysoff), GFP_KERNEL);
185 if (!sysoff) { 212 if (!sysoff) {
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index b8b73066d137..6b15e168148a 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -38,6 +38,7 @@ struct ptp_clock_request {
38 }; 38 };
39}; 39};
40 40
41struct system_device_crosststamp;
41/** 42/**
42 * struct ptp_clock_info - decribes a PTP hardware clock 43 * struct ptp_clock_info - decribes a PTP hardware clock
43 * 44 *
@@ -67,6 +68,11 @@ struct ptp_clock_request {
67 * @gettime64: Reads the current time from the hardware clock. 68 * @gettime64: Reads the current time from the hardware clock.
68 * parameter ts: Holds the result. 69 * parameter ts: Holds the result.
69 * 70 *
71 * @getcrosststamp: Reads the current time from the hardware clock and
72 * system clock simultaneously.
73 * parameter cts: Contains timestamp (device,system) pair,
74 * where system time is realtime and monotonic.
75 *
70 * @settime64: Set the current time on the hardware clock. 76 * @settime64: Set the current time on the hardware clock.
71 * parameter ts: Time value to set. 77 * parameter ts: Time value to set.
72 * 78 *
@@ -105,6 +111,8 @@ struct ptp_clock_info {
105 int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta); 111 int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta);
106 int (*adjtime)(struct ptp_clock_info *ptp, s64 delta); 112 int (*adjtime)(struct ptp_clock_info *ptp, s64 delta);
107 int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts); 113 int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts);
114 int (*getcrosststamp)(struct ptp_clock_info *ptp,
115 struct system_device_crosststamp *cts);
108 int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts); 116 int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts);
109 int (*enable)(struct ptp_clock_info *ptp, 117 int (*enable)(struct ptp_clock_info *ptp,
110 struct ptp_clock_request *request, int on); 118 struct ptp_clock_request *request, int on);
diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h
index f0b7bfe5da92..ac6dded80ffa 100644
--- a/include/uapi/linux/ptp_clock.h
+++ b/include/uapi/linux/ptp_clock.h
@@ -51,7 +51,9 @@ struct ptp_clock_caps {
51 int n_per_out; /* Number of programmable periodic signals. */ 51 int n_per_out; /* Number of programmable periodic signals. */
52 int pps; /* Whether the clock supports a PPS callback. */ 52 int pps; /* Whether the clock supports a PPS callback. */
53 int n_pins; /* Number of input/output pins. */ 53 int n_pins; /* Number of input/output pins. */
54 int rsv[14]; /* Reserved for future use. */ 54 /* Whether the clock supports precise system-device cross timestamps */
55 int cross_timestamping;
56 int rsv[13]; /* Reserved for future use. */
55}; 57};
56 58
57struct ptp_extts_request { 59struct ptp_extts_request {
@@ -81,6 +83,13 @@ struct ptp_sys_offset {
81 struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1]; 83 struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
82}; 84};
83 85
86struct ptp_sys_offset_precise {
87 struct ptp_clock_time device;
88 struct ptp_clock_time sys_realtime;
89 struct ptp_clock_time sys_monoraw;
90 unsigned int rsv[4]; /* Reserved for future use. */
91};
92
84enum ptp_pin_function { 93enum ptp_pin_function {
85 PTP_PF_NONE, 94 PTP_PF_NONE,
86 PTP_PF_EXTTS, 95 PTP_PF_EXTTS,
@@ -124,6 +133,8 @@ struct ptp_pin_desc {
124#define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset) 133#define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
125#define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc) 134#define PTP_PIN_GETFUNC _IOWR(PTP_CLK_MAGIC, 6, struct ptp_pin_desc)
126#define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) 135#define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc)
136#define PTP_SYS_OFFSET_PRECISE \
137 _IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
127 138
128struct ptp_extts_event { 139struct ptp_extts_event {
129 struct ptp_clock_time t; /* Time event occured. */ 140 struct ptp_clock_time t; /* Time event occured. */