From 9850ce0e51c1600005dc7e2829cde7dfb75f6bcf Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 22 Dec 2019 08:31:34 -0800 Subject: [PATCH] Add definitions for PTP pin ioctls for backwards kernel compatibility. Upcoming functionality will need to configure the input and output pins of PHC devices. However, this requires fairly recent kernel support. This patch adds the needed definitions for compiling with older kernel headers. In addition, kernel v5.4 introduced a second set of ioctls for the ancillary PTP Hardware Clock functionality. The original ioctls failed to enforce the various flags and reversed fields, but the second version has fixed the issues. Going forward, our user space PTP stack ought to use the newer ioctls (if available) from day one. Signed-off-by: Richard Cochran --- missing.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/missing.h b/missing.h index 8f92079..4726803 100644 --- a/missing.h +++ b/missing.h @@ -23,9 +23,10 @@ #ifndef HAVE_MISSING_H #define HAVE_MISSING_H -#include +#include #include #include +#include #include #ifndef ADJ_TAI @@ -60,6 +61,63 @@ enum { }; #endif +#ifdef PTP_EXTTS_REQUEST2 +#define PTP_EXTTS_REQUEST_FAILED "PTP_EXTTS_REQUEST2 failed: %m" +#else +#define PTP_EXTTS_REQUEST_FAILED "PTP_EXTTS_REQUEST failed: %m" +#define PTP_EXTTS_REQUEST2 PTP_EXTTS_REQUEST +#endif + +#ifdef PTP_PEROUT_REQUEST2 +#define PTP_PEROUT_REQUEST_FAILED "PTP_PEROUT_REQUEST2 failed: %m" +#else +#define PTP_PEROUT_REQUEST_FAILED "PTP_PEROUT_REQUEST failed: %m" +#define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST +#endif + +#ifndef PTP_PIN_SETFUNC + +/* from Linux kernel version 5.4 */ +struct compat_ptp_clock_caps { + int max_adj; /* Maximum frequency adjustment in parts per billon. */ + int n_alarm; /* Number of programmable alarms. */ + int n_ext_ts; /* Number of external time stamp channels. */ + int n_per_out; /* Number of programmable periodic signals. */ + int pps; /* Whether the clock supports a PPS callback. */ + int n_pins; /* Number of input/output pins. */ + /* Whether the clock supports precise system-device cross timestamps */ + int cross_timestamping; + int rsv[13]; /* Reserved for future use. */ +}; + +#define ptp_clock_caps compat_ptp_clock_caps + +enum ptp_pin_function { + PTP_PF_NONE, + PTP_PF_EXTTS, + PTP_PF_PEROUT, + PTP_PF_PHYSYNC, +}; + +struct ptp_pin_desc { + char name[64]; + unsigned int index; + unsigned int func; + unsigned int chan; + unsigned int rsv[5]; +}; + +#define PTP_PIN_SETFUNC _IOW(PTP_CLK_MAGIC, 7, struct ptp_pin_desc) + +#endif /*!PTP_PIN_SETFUNC*/ + +#ifdef PTP_PIN_SETFUNC2 +#define PTP_PIN_SETFUNC_FAILED "PTP_PIN_SETFUNC2 failed: %m" +#else +#define PTP_PIN_SETFUNC_FAILED "PTP_PIN_SETFUNC failed: %m" +#define PTP_PIN_SETFUNC2 PTP_PIN_SETFUNC +#endif + #ifndef LIST_FOREACH_SAFE #define LIST_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = LIST_FIRST((head)); \