aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ptp
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 /drivers/ptp
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>
Diffstat (limited to 'drivers/ptp')
-rw-r--r--drivers/ptp/ptp_chardev.c27
1 files changed, 27 insertions, 0 deletions
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) {