mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 10:41:38 -04:00
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 <[email protected]> Cc: Richard Cochran <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Acked-by: Richard Cochran <[email protected]> Signed-off-by: Christopher S. Hall <[email protected]> [jstultz: Commit subject tweaks] Signed-off-by: John Stultz <[email protected]>
This commit is contained in:
parent
f9677e0f83
commit
719f1aa4a6
4 changed files with 51 additions and 3 deletions
|
|
@ -22,6 +22,7 @@
|
|||
#include <linux/poll.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/timekeeping.h>
|
||||
|
||||
#include "ptp_private.h"
|
||||
|
||||
|
|
@ -120,11 +121,13 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
|
|||
struct ptp_clock_caps caps;
|
||||
struct ptp_clock_request req;
|
||||
struct ptp_sys_offset *sysoff = NULL;
|
||||
struct ptp_sys_offset_precise precise_offset;
|
||||
struct ptp_pin_desc pd;
|
||||
struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
|
||||
struct ptp_clock_info *ops = ptp->info;
|
||||
struct ptp_clock_time *pct;
|
||||
struct timespec64 ts;
|
||||
struct system_device_crosststamp xtstamp;
|
||||
int enable, err = 0;
|
||||
unsigned int i, pin_index;
|
||||
|
||||
|
|
@ -138,6 +141,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
|
|||
caps.n_per_out = ptp->info->n_per_out;
|
||||
caps.pps = ptp->info->pps;
|
||||
caps.n_pins = ptp->info->n_pins;
|
||||
caps.cross_timestamping = ptp->info->getcrosststamp != NULL;
|
||||
if (copy_to_user((void __user *)arg, &caps, sizeof(caps)))
|
||||
err = -EFAULT;
|
||||
break;
|
||||
|
|
@ -180,6 +184,29 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
|
|||
err = ops->enable(ops, &req, enable);
|
||||
break;
|
||||
|
||||
case PTP_SYS_OFFSET_PRECISE:
|
||||
if (!ptp->info->getcrosststamp) {
|
||||
err = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
err = ptp->info->getcrosststamp(ptp->info, &xtstamp);
|
||||
if (err)
|
||||
break;
|
||||
|
||||
ts = ktime_to_timespec64(xtstamp.device);
|
||||
precise_offset.device.sec = ts.tv_sec;
|
||||
precise_offset.device.nsec = ts.tv_nsec;
|
||||
ts = ktime_to_timespec64(xtstamp.sys_realtime);
|
||||
precise_offset.sys_realtime.sec = ts.tv_sec;
|
||||
precise_offset.sys_realtime.nsec = ts.tv_nsec;
|
||||
ts = ktime_to_timespec64(xtstamp.sys_monoraw);
|
||||
precise_offset.sys_monoraw.sec = ts.tv_sec;
|
||||
precise_offset.sys_monoraw.nsec = ts.tv_nsec;
|
||||
if (copy_to_user((void __user *)arg, &precise_offset,
|
||||
sizeof(precise_offset)))
|
||||
err = -EFAULT;
|
||||
break;
|
||||
|
||||
case PTP_SYS_OFFSET:
|
||||
sysoff = kmalloc(sizeof(*sysoff), GFP_KERNEL);
|
||||
if (!sysoff) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue