2011-11-02 00:32:40 +08:00
|
|
|
/**
|
|
|
|
* @file missing.h
|
|
|
|
* @note Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When glibc offers the syscall, this will go away.
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_MISSING_H
|
|
|
|
#define HAVE_MISSING_H
|
|
|
|
|
2019-12-23 00:31:34 +08:00
|
|
|
#include <linux/ptp_clock.h>
|
2020-05-05 02:07:57 +08:00
|
|
|
#include <linux/version.h>
|
2011-11-02 00:32:40 +08:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/timex.h>
|
2019-12-23 00:31:34 +08:00
|
|
|
#include <time.h>
|
2011-11-02 00:32:40 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2014-06-22 15:22:54 +08:00
|
|
|
#ifndef ADJ_TAI
|
|
|
|
#define ADJ_TAI 0x0080
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 00:32:40 +08:00
|
|
|
#ifndef ADJ_NANO
|
|
|
|
#define ADJ_NANO 0x2000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ADJ_SETOFFSET
|
|
|
|
#define ADJ_SETOFFSET 0x0100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CLOCK_INVALID
|
|
|
|
#define CLOCK_INVALID -1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CLOCKFD 3
|
2018-03-28 09:26:54 +08:00
|
|
|
#define FD_TO_CLOCKID(fd) ((clockid_t) ((((unsigned int) ~fd) << 3) | CLOCKFD))
|
2011-11-02 00:32:40 +08:00
|
|
|
#define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3))
|
|
|
|
|
2013-09-04 08:19:30 +08:00
|
|
|
#ifndef HAVE_ONESTEP_SYNC
|
|
|
|
enum _missing_hwtstamp_tx_types {
|
|
|
|
HWTSTAMP_TX_ONESTEP_SYNC = 2,
|
2013-09-05 02:55:11 +08:00
|
|
|
};
|
2013-09-04 08:19:30 +08:00
|
|
|
#endif
|
|
|
|
|
2018-02-16 01:16:15 +08:00
|
|
|
#ifndef HAVE_ONESTEP_P2P
|
|
|
|
enum {
|
|
|
|
HWTSTAMP_TX_ONESTEP_P2P = 3,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2019-12-23 00:31:34 +08:00
|
|
|
#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
|
|
|
|
|
2020-05-05 02:07:57 +08:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
|
2019-12-23 00:31:34 +08:00
|
|
|
|
2020-05-05 02:07:57 +08:00
|
|
|
/* from upcoming Linux kernel version 5.8 */
|
2019-12-23 00:31:34 +08:00
|
|
|
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;
|
2020-05-05 02:07:57 +08:00
|
|
|
/* Whether the clock supports adjust phase */
|
|
|
|
int adjust_phase;
|
|
|
|
int rsv[12]; /* Reserved for future use. */
|
2019-12-23 00:31:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ptp_clock_caps compat_ptp_clock_caps
|
|
|
|
|
2020-05-05 02:07:57 +08:00
|
|
|
#endif /*LINUX_VERSION_CODE < 5.8*/
|
|
|
|
|
ts2phc_phc_master: make use of new kernel API for perout waveform
This API was introduced for 2 reasons:
1. Some hardware can emit PPS signals but not starting from arbitrary
absolute times, but rather phase-aligned to the beginning of a
second. We _could_ patch ts2phc to always specify a start time of
0.000000000 to PTP_PEROUT_REQUEST, but in practice, we would never
know whether that would actually work with all in-tree PHC drivers.
So there was a need for a new flag that only specifies the phase of
the periodic signal, and not the absolute start time.
2. Some hardware can, rather unfortunately, not distinguish between a
rising and a falling extts edge. And, since whatever rises also has
to fall before rising again, the strategy in ts2phc is to set a
'large' pulse width (half the period) and ignore the extts event
corresponding to the mid-way between one second and another. This is
all fine, but currently, ts2phc.pulsewidth is a read-only property in
the config file. The kernel is not instructed in any way to use this
value, it is simply that must be configured based on prior knowledge
of the PHC's implementation. This API changes that.
The introduction of a phase adjustment for the master PHC means we have
to adjust our approximation of the precise perout timestamp. We put that
code into a common function and convert all call sites to call that. We
also need to do the same thing for the edge ignoring logic.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-05-25 15:57:44 +08:00
|
|
|
/*
|
|
|
|
* Bits of the ptp_perout_request.flags field:
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PTP_PEROUT_ONE_SHOT
|
|
|
|
#define PTP_PEROUT_ONE_SHOT (1<<0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PTP_PEROUT_DUTY_CYCLE
|
|
|
|
#define PTP_PEROUT_DUTY_CYCLE (1<<1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PTP_PEROUT_PHASE
|
|
|
|
#define PTP_PEROUT_PHASE (1<<2)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,9,0)
|
|
|
|
|
|
|
|
/* from upcoming Linux kernel version 5.9 */
|
|
|
|
struct compat_ptp_perout_request {
|
|
|
|
union {
|
|
|
|
/*
|
|
|
|
* Absolute start time.
|
|
|
|
* Valid only if (flags & PTP_PEROUT_PHASE) is unset.
|
|
|
|
*/
|
|
|
|
struct ptp_clock_time start;
|
|
|
|
/*
|
|
|
|
* Phase offset. The signal should start toggling at an
|
|
|
|
* unspecified integer multiple of the period, plus this value.
|
|
|
|
* The start time should be "as soon as possible".
|
|
|
|
* Valid only if (flags & PTP_PEROUT_PHASE) is set.
|
|
|
|
*/
|
|
|
|
struct ptp_clock_time phase;
|
|
|
|
};
|
|
|
|
struct ptp_clock_time period; /* Desired period, zero means disable. */
|
|
|
|
unsigned int index; /* Which channel to configure. */
|
|
|
|
unsigned int flags;
|
|
|
|
union {
|
|
|
|
/*
|
|
|
|
* The "on" time of the signal.
|
|
|
|
* Must be lower than the period.
|
|
|
|
* Valid only if (flags & PTP_PEROUT_DUTY_CYCLE) is set.
|
|
|
|
*/
|
|
|
|
struct ptp_clock_time on;
|
|
|
|
/* Reserved for future use. */
|
|
|
|
unsigned int rsv[4];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ptp_perout_request compat_ptp_perout_request
|
|
|
|
|
|
|
|
#endif /*LINUX_VERSION_CODE < 5.8*/
|
|
|
|
|
2020-06-25 06:21:34 +08:00
|
|
|
#ifndef PTP_MAX_SAMPLES
|
|
|
|
#define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
|
|
|
|
#endif /* PTP_MAX_SAMPLES */
|
|
|
|
|
|
|
|
#ifndef PTP_SYS_OFFSET
|
|
|
|
|
|
|
|
#define PTP_SYS_OFFSET _IOW(PTP_CLK_MAGIC, 5, struct ptp_sys_offset)
|
|
|
|
|
|
|
|
struct ptp_sys_offset {
|
|
|
|
unsigned int n_samples; /* Desired number of measurements. */
|
|
|
|
unsigned int rsv[3]; /* Reserved for future use. */
|
|
|
|
/*
|
|
|
|
* Array of interleaved system/phc time stamps. The kernel
|
|
|
|
* will provide 2*n_samples + 1 time stamps, with the last
|
|
|
|
* one as a system time stamp.
|
|
|
|
*/
|
|
|
|
struct ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PTP_SYS_OFFSET */
|
|
|
|
|
|
|
|
#ifndef PTP_SYS_OFFSET_PRECISE
|
|
|
|
|
|
|
|
#define PTP_SYS_OFFSET_PRECISE \
|
|
|
|
_IOWR(PTP_CLK_MAGIC, 8, struct ptp_sys_offset_precise)
|
|
|
|
|
|
|
|
struct ptp_sys_offset_precise {
|
|
|
|
struct ptp_clock_time device;
|
|
|
|
struct ptp_clock_time sys_realtime;
|
|
|
|
struct ptp_clock_time sys_monoraw;
|
|
|
|
unsigned int rsv[4]; /* Reserved for future use. */
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PTP_SYS_OFFSET_PRECISE */
|
|
|
|
|
|
|
|
#ifndef PTP_SYS_OFFSET_EXTENDED
|
|
|
|
|
|
|
|
#define PTP_SYS_OFFSET_EXTENDED \
|
|
|
|
_IOWR(PTP_CLK_MAGIC, 9, struct ptp_sys_offset_extended)
|
|
|
|
|
|
|
|
struct ptp_sys_offset_extended {
|
|
|
|
unsigned int n_samples; /* Desired number of measurements. */
|
|
|
|
unsigned int rsv[3]; /* Reserved for future use. */
|
|
|
|
/*
|
|
|
|
* Array of [system, phc, system] time stamps. The kernel will provide
|
|
|
|
* 3*n_samples time stamps.
|
|
|
|
*/
|
|
|
|
struct ptp_clock_time ts[PTP_MAX_SAMPLES][3];
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PTP_SYS_OFFSET_EXTENDED */
|
|
|
|
|
2020-05-05 02:07:57 +08:00
|
|
|
#ifndef PTP_PIN_SETFUNC
|
|
|
|
|
2019-12-23 00:31:34 +08:00
|
|
|
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
|
|
|
|
|
2018-04-01 02:05:57 +08:00
|
|
|
#ifndef LIST_FOREACH_SAFE
|
|
|
|
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
|
|
|
|
for ((var) = LIST_FIRST((head)); \
|
|
|
|
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
|
|
|
|
(var) = (tvar))
|
|
|
|
#endif
|
|
|
|
|
2014-05-28 01:34:35 +08:00
|
|
|
#ifndef SIOCGHWTSTAMP
|
|
|
|
#define SIOCGHWTSTAMP 0x89b1
|
|
|
|
#endif
|
|
|
|
|
2014-11-01 19:27:14 +08:00
|
|
|
#ifndef SO_SELECT_ERR_QUEUE
|
|
|
|
#define SO_SELECT_ERR_QUEUE 45
|
|
|
|
#endif
|
|
|
|
|
2012-09-05 23:00:30 +08:00
|
|
|
#ifndef HAVE_CLOCK_ADJTIME
|
2011-11-02 00:32:40 +08:00
|
|
|
static inline int clock_adjtime(clockid_t id, struct timex *tx)
|
|
|
|
{
|
|
|
|
return syscall(__NR_clock_adjtime, id, tx);
|
|
|
|
}
|
2012-09-05 23:00:30 +08:00
|
|
|
#endif
|
2011-11-02 00:32:40 +08:00
|
|
|
|
2017-10-09 22:31:42 +08:00
|
|
|
#ifndef IFLA_BOND_MAX
|
|
|
|
enum {
|
|
|
|
IFLA_BOND_UNSPEC,
|
|
|
|
IFLA_BOND_MODE,
|
|
|
|
IFLA_BOND_ACTIVE_SLAVE,
|
|
|
|
IFLA_BOND_MIIMON,
|
|
|
|
IFLA_BOND_UPDELAY,
|
|
|
|
IFLA_BOND_DOWNDELAY,
|
|
|
|
IFLA_BOND_USE_CARRIER,
|
|
|
|
IFLA_BOND_ARP_INTERVAL,
|
|
|
|
IFLA_BOND_ARP_IP_TARGET,
|
|
|
|
IFLA_BOND_ARP_VALIDATE,
|
|
|
|
IFLA_BOND_ARP_ALL_TARGETS,
|
|
|
|
IFLA_BOND_PRIMARY,
|
|
|
|
IFLA_BOND_PRIMARY_RESELECT,
|
|
|
|
IFLA_BOND_FAIL_OVER_MAC,
|
|
|
|
IFLA_BOND_XMIT_HASH_POLICY,
|
|
|
|
IFLA_BOND_RESEND_IGMP,
|
|
|
|
IFLA_BOND_NUM_PEER_NOTIF,
|
|
|
|
IFLA_BOND_ALL_SLAVES_ACTIVE,
|
|
|
|
IFLA_BOND_MIN_LINKS,
|
|
|
|
IFLA_BOND_LP_INTERVAL,
|
|
|
|
IFLA_BOND_PACKETS_PER_SLAVE,
|
|
|
|
IFLA_BOND_AD_LACP_RATE,
|
|
|
|
IFLA_BOND_AD_SELECT,
|
|
|
|
IFLA_BOND_AD_INFO,
|
|
|
|
IFLA_BOND_AD_ACTOR_SYS_PRIO,
|
|
|
|
IFLA_BOND_AD_USER_PORT_KEY,
|
|
|
|
IFLA_BOND_AD_ACTOR_SYSTEM,
|
|
|
|
IFLA_BOND_TLB_DYNAMIC_LB,
|
|
|
|
__IFLA_BOND_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
|
|
|
|
#endif /*IFLA_BOND_MAX*/
|
|
|
|
|
2019-03-22 15:02:46 +08:00
|
|
|
#ifndef NLA_TYPE_MAX
|
|
|
|
enum {
|
|
|
|
NLA_UNSPEC,
|
|
|
|
NLA_U8,
|
|
|
|
NLA_U16,
|
|
|
|
NLA_U32,
|
|
|
|
NLA_U64,
|
|
|
|
NLA_STRING,
|
|
|
|
NLA_FLAG,
|
|
|
|
NLA_MSECS,
|
|
|
|
NLA_NESTED,
|
|
|
|
__NLA_TYPE_MAX,
|
|
|
|
};
|
|
|
|
#define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
|
|
|
|
#endif /*NLA_TYPE_MAX*/
|
|
|
|
|
2017-05-30 14:42:27 +08:00
|
|
|
#ifdef __UCLIBC__
|
|
|
|
|
|
|
|
#if (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L) && \
|
|
|
|
defined __UCLIBC_HAS_THREADS_NATIVE__
|
2012-02-20 01:25:21 +08:00
|
|
|
|
|
|
|
#include <sys/timerfd.h>
|
|
|
|
|
|
|
|
#else
|
2011-12-30 15:33:30 +08:00
|
|
|
|
2018-03-31 23:29:05 +08:00
|
|
|
#define TFD_TIMER_ABSTIME (1 << 0)
|
|
|
|
|
2013-06-14 17:47:58 +08:00
|
|
|
static inline int clock_nanosleep(clockid_t clock_id, int flags,
|
|
|
|
const struct timespec *request,
|
|
|
|
struct timespec *remain)
|
|
|
|
{
|
|
|
|
return syscall(__NR_clock_nanosleep, clock_id, flags, request, remain);
|
|
|
|
}
|
|
|
|
|
2011-12-30 15:33:30 +08:00
|
|
|
static inline int timerfd_create(int clockid, int flags)
|
|
|
|
{
|
|
|
|
return syscall(__NR_timerfd_create, clockid, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int timerfd_settime(int fd, int flags,
|
|
|
|
const struct itimerspec *new_value,
|
|
|
|
struct itimerspec *old_value)
|
|
|
|
{
|
|
|
|
return syscall(__NR_timerfd_settime, fd, flags, new_value, old_value);
|
|
|
|
}
|
2017-05-30 14:42:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /*__UCLIBC__*/
|
|
|
|
|
|
|
|
#include <sys/timerfd.h>
|
2011-12-30 15:33:30 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 00:32:40 +08:00
|
|
|
#endif
|