2020-06-29 03:02:38 +08:00
|
|
|
/**
|
|
|
|
* @file ts2phc.h
|
|
|
|
* @brief Structure definitions for ts2phc
|
|
|
|
* @note Copyright 2020 Vladimir Oltean <olteanv@gmail.com>
|
|
|
|
* @note SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_TS2PHC_H
|
|
|
|
#define HAVE_TS2PHC_H
|
|
|
|
|
2020-07-28 07:51:28 +08:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <time.h>
|
ts2phc: instantiate a pmc node
This introduces the '-a' option in ts2phc, an option inspired from
phc2sys that puts the clocks in "automatic" mode. In this mode, ts2phc
listens, as a PMC, to port state change events from ptp4l, and detects
which port state machine, if any, has transitioned to PS_SLAVE. That
port's clock will become the synchronization master for the hierarchy
described by ts2phc.
The use case is a multi-switch DSA setup with boundary_clock_jbod, where
there is only one grandmaster, connected to one switch's port. The other
switches, connected together through a PPS signal, must adapt themselves
to this new source of time, while the switch connected to the GM must
not be synchronized by ts2phc because it is already synchronized by
ptp4l.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-07-28 07:48:06 +08:00
|
|
|
#include "pmc_common.h"
|
2020-07-28 07:51:28 +08:00
|
|
|
#include "servo.h"
|
|
|
|
|
2020-06-29 03:02:38 +08:00
|
|
|
struct ts2phc_slave_array;
|
|
|
|
|
2020-07-28 07:51:28 +08:00
|
|
|
#define SERVO_SYNC_INTERVAL 1.0
|
|
|
|
|
|
|
|
struct clock {
|
|
|
|
LIST_ENTRY(clock) list;
|
|
|
|
LIST_ENTRY(clock) dst_list;
|
|
|
|
clockid_t clkid;
|
|
|
|
int phc_index;
|
|
|
|
int state;
|
|
|
|
int new_state;
|
|
|
|
struct servo *servo;
|
|
|
|
enum servo_state servo_state;
|
|
|
|
char *name;
|
|
|
|
int no_adj;
|
|
|
|
int is_destination;
|
2020-08-01 22:45:00 +08:00
|
|
|
int is_ts_available;
|
|
|
|
tmv_t last_ts;
|
2020-07-28 07:51:28 +08:00
|
|
|
};
|
|
|
|
|
ts2phc: instantiate a pmc node
This introduces the '-a' option in ts2phc, an option inspired from
phc2sys that puts the clocks in "automatic" mode. In this mode, ts2phc
listens, as a PMC, to port state change events from ptp4l, and detects
which port state machine, if any, has transitioned to PS_SLAVE. That
port's clock will become the synchronization master for the hierarchy
described by ts2phc.
The use case is a multi-switch DSA setup with boundary_clock_jbod, where
there is only one grandmaster, connected to one switch's port. The other
switches, connected together through a PPS signal, must adapt themselves
to this new source of time, while the switch connected to the GM must
not be synchronized by ts2phc because it is already synchronized by
ptp4l.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-07-28 07:48:06 +08:00
|
|
|
struct port {
|
|
|
|
LIST_ENTRY(port) list;
|
|
|
|
unsigned int number;
|
|
|
|
int state;
|
|
|
|
struct clock *clock;
|
|
|
|
};
|
|
|
|
|
2020-06-29 03:02:38 +08:00
|
|
|
struct ts2phc_private {
|
|
|
|
struct ts2phc_master *master;
|
|
|
|
STAILQ_HEAD(slave_ifaces_head, ts2phc_slave) slaves;
|
|
|
|
unsigned int n_slaves;
|
|
|
|
struct ts2phc_slave_array *polling_array;
|
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
|
|
|
tmv_t perout_phase;
|
2020-06-29 03:02:38 +08:00
|
|
|
struct config *cfg;
|
ts2phc: instantiate a pmc node
This introduces the '-a' option in ts2phc, an option inspired from
phc2sys that puts the clocks in "automatic" mode. In this mode, ts2phc
listens, as a PMC, to port state change events from ptp4l, and detects
which port state machine, if any, has transitioned to PS_SLAVE. That
port's clock will become the synchronization master for the hierarchy
described by ts2phc.
The use case is a multi-switch DSA setup with boundary_clock_jbod, where
there is only one grandmaster, connected to one switch's port. The other
switches, connected together through a PPS signal, must adapt themselves
to this new source of time, while the switch connected to the GM must
not be synchronized by ts2phc because it is already synchronized by
ptp4l.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-07-28 07:48:06 +08:00
|
|
|
struct pmc_node node;
|
|
|
|
int state_changed;
|
2020-07-28 07:51:28 +08:00
|
|
|
struct clock *source;
|
ts2phc: instantiate a pmc node
This introduces the '-a' option in ts2phc, an option inspired from
phc2sys that puts the clocks in "automatic" mode. In this mode, ts2phc
listens, as a PMC, to port state change events from ptp4l, and detects
which port state machine, if any, has transitioned to PS_SLAVE. That
port's clock will become the synchronization master for the hierarchy
described by ts2phc.
The use case is a multi-switch DSA setup with boundary_clock_jbod, where
there is only one grandmaster, connected to one switch's port. The other
switches, connected together through a PPS signal, must adapt themselves
to this new source of time, while the switch connected to the GM must
not be synchronized by ts2phc because it is already synchronized by
ptp4l.
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-07-28 07:48:06 +08:00
|
|
|
LIST_HEAD(port_head, port) ports;
|
2020-07-28 07:51:28 +08:00
|
|
|
LIST_HEAD(clock_head, clock) clocks;
|
2020-06-29 03:02:38 +08:00
|
|
|
};
|
|
|
|
|
2020-07-28 07:51:28 +08:00
|
|
|
struct servo *servo_add(struct ts2phc_private *priv, struct clock *clock);
|
|
|
|
struct clock *clock_add(struct ts2phc_private *priv, const char *device);
|
2020-08-01 22:45:00 +08:00
|
|
|
void clock_add_tstamp(struct clock *clock, tmv_t ts);
|
2020-07-28 07:51:28 +08:00
|
|
|
void clock_destroy(struct clock *clock);
|
|
|
|
|
2020-06-29 03:02:38 +08:00
|
|
|
#include "ts2phc_master.h"
|
|
|
|
#include "ts2phc_slave.h"
|
|
|
|
|
|
|
|
#endif
|