Commit eb21e3fa authored by Adam Wujek's avatar Adam Wujek

Merge wrpc-v5 into master

Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parents 61f7d34d 851c4244
......@@ -4,6 +4,9 @@ A := arch-$(ARCH)
CFLAGS += -Itools
# needed for --gc-sections option of ld
PPSI_O_LDFLAGS = --entry=main
OBJ-y += $A/unix-startup.o \
$A/main-loop.o \
$A/unix-io.o \
......@@ -14,7 +17,8 @@ OBJ-y += $A/unix-startup.o \
lib/dump-funcs.o \
lib/drop.o \
lib/assert.o \
lib/div64.o
lib/div64.o \
lib/time-arith.o
# The user can set TIME=, but we pick unix time by default
TIME ?= unix
......
/*
* Copyright (C) 2011 CERN (www.cern.ch)
* Copyright (C) 2011-2022 CERN (www.cern.ch)
* Author: Alessandro Rubini
*
* Released to the public domain
......@@ -24,8 +24,26 @@ static int run_all_state_machines(struct pp_globals *ppg)
int j;
int delay_ms = 0, delay_ms_j;
/* TODO: check if in GM mode and initialized */
for (j = 0; j < ppg->nlinks; j++) {
struct pp_instance *ppi = INST(ppg, j);
int old_lu = ppi->link_up;
/* TODO: add the proper discovery of link_up */
ppi->link_up = 1;
if (old_lu != ppi->link_up) {
pp_diag(ppi, fsm, 1, "iface %s went %s\n",
ppi->iface_name, ppi->link_up ? "up" : "down");
if (ppi->link_up) {
ppi->state = PPS_INITIALIZING;
/* TODO: Get calibration values here */
}
}
delay_ms_j = pp_state_machine(ppi, NULL, 0);
/* delay_ms is the least delay_ms among all instances */
......@@ -35,6 +53,22 @@ static int run_all_state_machines(struct pp_globals *ppg)
delay_ms = delay_ms_j;
}
/* BMCA must run at least once per announce interval 9.2.6.8 */
if (pp_gtimeout(ppg, PP_TO_BMC)) {
/* Calculation of erbest, ebest, ... */
bmc_calculate_ebest(ppg);
pp_gtimeout_reset(ppg, PP_TO_BMC);
delay_ms = 0;
/* TODO: Check PLL state if needed/available */
} else {
/* check if the BMC timeout is the next to run */
int delay_bmca;
if ((delay_bmca = pp_gnext_delay_1(ppg, PP_TO_BMC)) < delay_ms)
delay_ms = delay_bmca;
}
return delay_ms;
}
......@@ -48,8 +82,6 @@ void unix_main_loop(struct pp_globals *ppg)
for (j = 0; j < ppg->nlinks; j++) {
ppi = INST(ppg, j);
/* just tell that the links are up */
ppi->link_up = TRUE;
/*
* The main loop here is based on select. While we are not
......@@ -62,32 +94,14 @@ void unix_main_loop(struct pp_globals *ppg)
delay_ms = run_all_state_machines(ppg);
while (1) {
int i;
/*
* If Ebest was changed in previous loop, run best
* master clock before checking for new packets, which
* would affect port state again
*/
if (ppg->ebest_updated) {
for (j = 0; j < ppg->nlinks; j++) {
int new_state;
struct pp_instance *ppi = INST(ppg, j);
new_state = bmc(ppg);
if (new_state != ppi->state) {
ppi->state = new_state;
ppi->is_new_state = 1;
}
}
ppg->ebest_updated = 0;
}
int packet_available;
i = unix_net_ops.check_packet(ppg, delay_ms);
packet_available = unix_net_ops.check_packet(ppg, delay_ms);
if (i < 0)
if (packet_available < 0)
continue;
if (i == 0) {
if (packet_available == 0) {
delay_ms = run_all_state_machines(ppg);
continue;
}
......@@ -99,7 +113,7 @@ void unix_main_loop(struct pp_globals *ppg)
delay_ms = -1;
for (j = 0; j < ppg->nlinks; j++) {
int tmp_d;
int tmp_d, i;
ppi = INST(ppg, j);
if ((ppi->ch[PP_NP_GEN].pkt_present) ||
......
/*
* Copyright (C) 2011 CERN (www.cern.ch)
* Copyright (C) 2011-2022 CERN (www.cern.ch)
* Author: Alessandro Rubini
*
* Released to the public domain
......@@ -23,16 +23,36 @@
#include <ppsi/ppsi.h>
#include "ppsi-unix.h"
char *format_hex(char *s, const unsigned char *mac, int cnt);
char *format_hex8(char *s, const unsigned char *mac);
/* ppg and fields */
static struct pp_globals ppg_static;
static defaultDS_t defaultDS;
static currentDS_t currentDS;
static parentDS_t parentDS;
static timePropertiesDS_t timePropertiesDS;
static struct pp_servo servo;
extern struct pp_ext_hooks pp_hooks;
/**
* Enable/disable asymmetry correction
*/
static void enable_asymmetryCorrection(struct pp_instance *ppi, Boolean enable ) {
if ((ppi->asymmetryCorrectionPortDS.enable = enable) == TRUE ) {
/* Enabled: The delay asymmetry will be calculated */
ppi->asymmetryCorrectionPortDS.scaledDelayCoefficient =
(ppi->cfg.scaledDelayCoefficient != 0) ?
ppi->cfg.scaledDelayCoefficient :
(RelativeDifference)(ppi->cfg.delayCoefficient * REL_DIFF_TWO_POW_FRACBITS);
ppi->portDS->delayAsymCoeff =
pp_servo_calculateDelayAsymCoefficient(ppi->asymmetryCorrectionPortDS.scaledDelayCoefficient);
}
ppi->asymmetryCorrectionPortDS.constantAsymmetry =
picos_to_interval(ppi->cfg.constantAsymmetry_ps);
}
int main(int argc, char **argv)
{
struct pp_globals *ppg;
......@@ -45,6 +65,15 @@ int main(int argc, char **argv)
pp_printf("PPSi. Commit %s, built on " __DATE__ "\n", PPSI_VERSION);
/* So far allow more than one instance of PPSi running on the same
* machine.
TODO: to be considered to allow only one instance of PPSi to run
* at the same time.
* Potential problems my be in:
* shmem (not used in arch-unix)
* race of setting of time if more than one instance run as slave
*/
ppg = &ppg_static;
ppg->defaultDS = &defaultDS;
ppg->currentDS = &currentDS;
......@@ -62,16 +91,17 @@ int main(int argc, char **argv)
exit(1);
}
/* Before the configuration is parsed, set defaults */
/* Set default configuration value for all instances */
for (i = 0; i < ppg->max_links; i++) {
ppi = INST(ppg, i);
ppi->proto = PP_DEFAULT_PROTO;
ppi->delayMechanism = MECH_E2E;
memcpy(&INST(ppg, i)->cfg, &__pp_default_instance_cfg,
sizeof(__pp_default_instance_cfg));
}
/* Set offset here, so config parsing can override it */
if (adjtimex(&t) >= 0)
timePropertiesDS.currentUtcOffset = t.tai;
memset(&t, 0, sizeof(t));
if (adjtimex(&t) >= 0) {
ppg->timePropertiesDS->currentUtcOffset = (Integer16)t.tai;
}
if (pp_parse_cmdline(ppg, argc, argv) != 0)
return -1;
......@@ -79,6 +109,8 @@ int main(int argc, char **argv)
/* If no item has been parsed, provide a default file or string */
if (ppg->cfg.cfg_items == 0)
pp_config_file(ppg, 0, PP_DEFAULT_CONFIGFILE);
/* No config found, add default */
if (ppg->cfg.cfg_items == 0)
pp_config_string(ppg, strdup("link 0; iface eth0; proto udp"));
......@@ -87,27 +119,118 @@ int main(int argc, char **argv)
ppi = INST(ppg, i);
ppi->ch[PP_NP_EVT].fd = -1;
ppi->ch[PP_NP_GEN].fd = -1;
ppi->servo = &servo;
ppi->glbs = ppg;
ppi->vlans_array_len = CONFIG_VLAN_ARRAY_SIZE,
ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
ppi->delayMechanism = ppi->cfg.delayMechanism;
ppi->ext_hooks= &pp_hooks;
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
ppi->servo = calloc(1, sizeof(*ppi->servo));
ppi->ext_hooks = &pp_hooks;
ppi->ptp_support = TRUE;
if (ppi->portDS) {
switch (ppi->cfg.profile) {
case PPSI_PROFILE_WR:
#if CONFIG_HAS_PROFILE_WR
ppi->protocol_extension = PPSI_EXT_WR;
/* Add WR extension portDS */
if ( !(ppi->portDS->ext_dsport =
wrs_shm_alloc(ppsi_head,
sizeof(struct wr_dsport))
)
) {
goto exit_out_of_memory;
}
/* Allocate WR data extension */
if (! (ppi->ext_data =
wrs_shm_alloc(ppsi_head,
sizeof(struct wr_data))
)
) {
goto exit_out_of_memory;
}
/* Set WR extension hooks */
ppi->ext_hooks = &wr_ext_hooks;
enable_asymmetryCorrection(ppi, TRUE);
#else
fprintf(stderr, "ppsi: Profile WR not supported");
exit(1);
#endif
break;
case PPSI_PROFILE_HA:
#if CONFIG_HAS_PROFILE_HA
if (!enable_l1Sync(ppi, TRUE))
goto exit_out_of_memory;
/* Force mandatory attributes - Do not take care of the configuration */
L1E_DSPOR_BS(ppi)->rxCoherentIsRequired = TRUE;
L1E_DSPOR_BS(ppi)->txCoherentIsRequired = TRUE;
L1E_DSPOR_BS(ppi)->congruentIsRequired = TRUE;
L1E_DSPOR_BS(ppi)->L1SyncEnabled = TRUE;
L1E_DSPOR_BS(ppi)->optParamsEnabled = FALSE;
enable_asymmetryCorrection(ppi, TRUE);
#else
fprintf(stderr, "ppsi: Profile HA not supported");
exit(1);
#endif
break;
case PPSI_PROFILE_PTP :
/* Do not take care of L1SYNC */
enable_asymmetryCorrection(ppi,
ppi->cfg.asymmetryCorrectionEnable);
ppi->protocol_extension = PPSI_EXT_NONE;
break;
case PPSI_PROFILE_CUSTOM :
#if CONFIG_HAS_PROFILE_CUSTOM
ppi->protocol_extension = PPSI_EXT_NONE; /* can be changed ...*/
#if CONFIG_HAS_EXT_L1SYNC
if (ppi->cfg.l1SyncEnabled) {
if (!enable_l1Sync(ppi, TRUE))
goto exit_out_of_memory;
/* Read L1SYNC parameters */
L1E_DSPOR_BS(ppi)->rxCoherentIsRequired = ppi->cfg.l1SyncRxCoherencyIsRequired;
L1E_DSPOR_BS(ppi)->txCoherentIsRequired = ppi->cfg.l1SyncTxCoherencyIsRequired;
L1E_DSPOR_BS(ppi)->congruentIsRequired = ppi->cfg.l1SyncCongruencyIsRequired;
L1E_DSPOR_BS(ppi)->optParamsEnabled = ppi->cfg.l1SyncOptParamsEnabled;
if (L1E_DSPOR_BS(ppi)->optParamsEnabled) {
L1E_DSPOR_OP(ppi)->timestampsCorrectedTx = ppi->cfg.l1SyncOptParamsTimestampsCorrectedTx;
}
}
enable_asymmetryCorrection(ppi, ppi->cfg.asymmetryCorrectionEnable);
#endif
#else
fprintf(stderr, "ppsi: Profile CUSTOM not supported");
exit(1);
#endif
break;
}
/* Parameters profile independent */
ppi->timestampCorrectionPortDS.egressLatency = picos_to_interval(ppi->cfg.egressLatency_ps);
ppi->timestampCorrectionPortDS.ingressLatency = picos_to_interval(ppi->cfg.ingressLatency_ps);
ppi->timestampCorrectionPortDS.messageTimestampPointLatency = 0;
ppi->portDS->masterOnly = ppi->cfg.masterOnly; /* can be overridden in pp_init_globals() */
} else {
goto exit_out_of_memory;
}
/* The following default names depend on TIME= at build time */
ppi->n_ops = &DEFAULT_NET_OPS;
ppi->t_ops = &DEFAULT_TIME_OPS;
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
ppi->__tx_buffer = malloc(PP_MAX_FRAME_LENGTH);
ppi->__rx_buffer = malloc(PP_MAX_FRAME_LENGTH);
if (!ppi->portDS || !ppi->__tx_buffer || !ppi->__rx_buffer) {
fprintf(stderr, "ppsi: out of memory\n");
exit(1);
goto exit_out_of_memory;
}
}
pp_init_globals(ppg, &__pp_default_rt_opts);
seed = time(NULL);
......@@ -117,4 +240,21 @@ int main(int argc, char **argv)
unix_main_loop(ppg);
return 0; /* never reached */
exit_out_of_memory:
fprintf(stderr, "ppsi: out of memory\n");
exit(1);
}
char *format_hex(char *s, const unsigned char *mac, int cnt)
{
int i;
*s = '\0';
for (i = 0; i < cnt; i++) {
pp_sprintf(s, "%s%02x:", s, mac[i]);
}
/* remove last colon */
s[cnt * 3 - 1] = '\0'; /* cnt * strlen("FF:") - 1 */
return s;
}
/hal_minirpc.c
......@@ -36,24 +36,49 @@ arch-spec-o = $(patsubst %.c,%.o,$(arch-spec-c))
OBJ-y += $(arch-spec-o)
# build symbolic links for libwr
hal_headers = hal_shmem.h \
libwr_headers = hal_shmem.h \
generic_fsm.h\
sfp_lib.h\
util.h\
shmem.h \
timeout.h
hal_headers_in_ppsi= $(addprefix $A/include/libwr/,$(hal_headers))
libwr_headers_in_ppsi= $(addprefix $A/include/libwr/,$(libwr_headers))
all: $(TARGET)
$(arch-spec-o) : $(libwr_headers_in_ppsi)
$(arch-spec-o) : $(hal_headers_in_ppsi)
$(hal_headers_in_ppsi):
$(libwr_headers_in_ppsi):
@f=$(notdir $@); \
echo "Creating symbolic link to $$f";\
echo "Creating symbolic link to include/libwr/$$f";\
ln -sf ../../../../libwr/include/libwr/$$f $@
# build symbolic links for source files in libwr
libwr_source = hal_minirpc.c
libwr_source_in_ppsi= $(addprefix $A,/$(libwr_source))
$(arch-spec-o) : $(libwr_source_in_ppsi)
$(libwr_source_in_ppsi):
@f=$(notdir $@); \
echo "Creating symbolic link to $$f";\
ln -sf ../../libwr/$$f $@
# build symbolic links for userspace files from wrs
wrs_userspace_headers = hal_exports.h
wrs_userspace_headers_in_ppsi = $(addprefix $A/include/,$(wrs_userspace_headers))
$(arch-spec-o): $(wrs_userspace_headers_in_ppsi)
$(wrs_userspace_headers_in_ppsi):
@f=$(notdir $@); \
echo "Creating symbolic link to include/$$f";\
ln -sf ../../../include/$$f $@
export size_db_file:=size_wrs_db.txt
export size_info_file:=size_wrs_info.txt
......@@ -77,7 +102,10 @@ $(MINIPC_LIB):
OBJ-y += $(MINIPC_LIB)
clean::
rm -f $(hal_headers_in_ppsi)
rm -f \
$(libwr_headers_in_ppsi) \
$(libwr_source_in_ppsi) \
$(wrs_userspace_headers_in_ppsi)
# to build the target, we need -lstd again, in case we call functions that
# were not selected yet (e.g., pp_init_globals() ).
......
#ifndef __HAL_EXPORTS_C
#define __HAL_EXPORTS_C
#include <minipc.h>
#include <hal_exports.h>
/* Export structures, shared by server and client for argument matching */
struct minipc_pd __rpcdef_check_running = {
.name = "check_running",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_END,
},
};
//int halexp_reset_port(const char *port_name);
struct minipc_pd __rpcdef_reset_port = {
.name = "reset_port",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *),
MINIPC_ARG_END,
},
};
//int halexp_calibration_cmd(const char *port_name, int command, int on_off);
struct minipc_pd __rpcdef_calibration_cmd = {
.name = "calibration_cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
//int halexp_lock_cmd(const char *port_name, int command, int priority);
struct minipc_pd __rpcdef_lock_cmd = {
.name = "lock_cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
//int halexp_pps_cmd(int cmd, hexp_pps_params_t *params);
struct minipc_pd __rpcdef_pps_cmd = {
.name = "pps_cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT, hexp_pps_params_t),
MINIPC_ARG_END,
},
};
//int halexp_info_cmd(hexp_info_params_t *params);
struct minipc_pd __rpcdef_port_update_cmd = {
.name = "info_cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT, hexp_port_info_params_t),
MINIPC_ARG_END,
},
};
#endif
#ifndef __HAL_EXPORTS_H
#define __HAL_EXPORTS_H
#include <stdint.h>
#define HAL_MAX_PORTS 32
#define WRSW_HAL_SERVER_ADDR "wrsw_hal"
// checks if the calibration unit is idle
#define HEXP_CAL_CMD_CHECK_IDLE 1
// enables/disables transmission of calibration pattern
#define HEXP_CAL_CMD_TX_PATTERN 2
// requests a measurement of TX delta
#define HEXP_CAL_CMD_TX_MEASURE 4
// requests a measurement of RX delta
#define HEXP_CAL_CMD_RX_MEASURE 5
#define HEXP_CAL_RESP_BUSY 1
#define HEXP_CAL_RESP_OK 0
#define HEXP_CAL_RESP_ERROR -1
#define HEXP_LOCK_CMD_START 1
#define HEXP_LOCK_CMD_CHECK 2
#define HEXP_LOCK_CMD_ENABLE_TRACKING 3
#define HEXP_LOCK_CMD_RESET 4
#define HEXP_LOCK_STATUS_UNLOCKED 0
#define HEXP_LOCK_STATUS_LOCKED 1
#define HEXP_LOCK_STATUS_RELOCK_ERROR 2
#define HEXP_LOCK_STATUS_ERROR 3
#define HEXP_PPSG_CMD_GET 0
#define HEXP_PPSG_CMD_ADJUST_PHASE 1
#define HEXP_PPSG_CMD_ADJUST_SEC 2
#define HEXP_PPSG_CMD_ADJUST_NSEC 3
#define HEXP_PPSG_CMD_POLL 4
#define HEXP_PPSG_CMD_SET_VALID 5
#define HEXP_PPSG_CMD_SET_TIMING_MODE 6
#define HEXP_PPSG_CMD_GET_TIMING_MODE 7
#define HEXP_PPSG_CMD_GET_TIMING_MODE_STATE 8
#define HEXP_ON 1
#define HEXP_OFF 0
#define HEXP_FREQ 0
#define HEXP_PHASE 1
/////////////////added by ML//////////
#define HEXP_EXTSRC_CMD_CHECK 0
#define HEXP_EXTSRC_STATUS_LOCKED 0
#define HEXP_LOCK_STATUS_BUSY 1
#define HEXP_EXTSRC_STATUS_NOSRC 2
/////////////////////////////////////
#define HAL_TIMING_MODE_GRAND_MASTER 0
#define HAL_TIMING_MODE_FREE_MASTER 1
#define HAL_TIMING_MODE_BC 2
#define HAL_TIMING_MODE_DISABLED 3
#define HAL_TIMING_MODE_TMDT_UNLOCKED 0
#define HAL_TIMING_MODE_TMDT_LOCKED 1
#define HAL_TIMING_MODE_TMDT_HOLDHOVER 2
typedef struct {
char port_name[16];
int pps_valid;
uint32_t current_phase_shift;
int32_t adjust_phase_shift;
int64_t adjust_sec;
int32_t adjust_nsec;
uint64_t current_sec;
uint32_t current_nsec;
uint32_t timing_mode;
} hexp_pps_params_t;
#define PORT_MODE_OTHER 0
#define PORT_MODE_SLAVE 1
#define PORT_MODE_MASTER 2
typedef struct {
char name[16]; // Interface name
int synchronized; // <>0 : Master/Slave are synchronized
int mode; // PORT_MODE_XXXX
}hexp_port_info_t;
typedef struct {
int numberPortInterfaces;
hexp_port_info_t hIFace[HAL_MAX_PORTS];
} hexp_port_info_params_t;
/* Port modes (hal_port_state.mode) */
#define HEXP_PORT_MODE_WR_MASTER 1
#define HEXP_PORT_MODE_WR_SLAVE 2
#define HEXP_PORT_MODE_NON_WR 3
#define HEXP_PORT_MODE_WR_M_AND_S 4
#define HEXP_PORT_MODE_NONE 5
#define FIX_ALPHA_FRACBITS 40
/*
#define HEXP_PORT_TSC_RISING 1
#define HEXP_PORT_TSC_FALLING 2
*/
extern struct minipc_pd __rpcdef_lock_cmd;
extern struct minipc_pd __rpcdef_pps_cmd;
extern struct minipc_pd __rpcdef_port_update_cmd;
/* Prototypes of functions that call on rpc */
extern int halexp_lock_cmd(const char *port_name, int command, int priority);
extern int halexp_pps_cmd(int cmd, hexp_pps_params_t *params);
#endif
......@@ -2,5 +2,6 @@
/timeout.h
/hal_shmem.h
/sfp_lib.h
/shmem.h
/util.h
#ifndef __PPSI_EXPORTS_H
#define __PPSI_EXPORTS_H
#include <stdio.h>
#include <stdlib.h>
#define PPSIEXP_COMMAND_WR_TRACKING 1
#define PPSIEXP_COMMAND_L1SYNC_TRACKING 2
/* Export structures, shared by server and client for argument matching */
#ifdef PPSI_EXPORT_STRUCTURES
struct minipc_pd __rpcdef_cmd = {
.name = "cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
#endif /* PTP_EXPORT_STRUCTURES */
#endif /* __PPSI_EXPORTS_H */
......@@ -7,33 +7,20 @@
#include <ppsi/ppsi.h>
#include <ppsi-wrs.h>
#include <hal_exports.h>
/* minipc Encoding of the supported commands */
#define PTPDEXP_COMMAND_WR_TRACKING 1
#define PTPDEXP_COMMAND_L1SYNC_TRACKING 2
static struct minipc_pd __rpcdef_cmd = {
.name = "cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
#define PPSI_EXPORT_STRUCTURES
#include <ppsi_exports.h>
/* Execute command coming ipc */
static int wrsipc_cmd(int cmd, int value)
{
if(cmd == PTPDEXP_COMMAND_WR_TRACKING) {
if(cmd == PPSIEXP_COMMAND_WR_TRACKING) {
if ( CONFIG_HAS_EXT_WR ) {
wrh_servo_enable_tracking(value);
return 0;
}
}
if(cmd == PTPDEXP_COMMAND_L1SYNC_TRACKING) {
if(cmd == PPSIEXP_COMMAND_L1SYNC_TRACKING) {
if ( CONFIG_HAS_EXT_L1SYNC ) {
wrh_servo_enable_tracking(value);
return 0;
......
......@@ -70,7 +70,7 @@ int wrs_update_port_info(struct pp_globals *ppg) {
}
}
}
ret = minipc_call(hal_ch, DEFAULT_TO, &__rpcdef_port_update_cmd,
ret = minipc_call(hal_ch, DEFAULT_TO, &__rpcdef_port_info_cmd,
&rval, &infos);
if (ret < 0)
......
......@@ -22,7 +22,6 @@
#include <signal.h>
#include <minipc.h>
#include <hal_exports.h>
#include <ppsi/ppsi.h>
#include <ppsi-wrs.h>
......@@ -441,7 +440,6 @@ int main(int argc, char **argv)
*/
enablePPS=(WRS_ARCH_G(ppg)->timingModeLockingState== WRH_TM_LOCKING_STATE_LOCKED &&
ppg->defaultDS->clockQuality.clockClass == PP_PTP_CLASS_GM_LOCKED) ||
ppg->defaultDS->clockQuality.clockClass == PP_FRUNNING_CLOCK_CLASS ||
GOPTS(ppg)->forcePpsGen;
TOPS(ppi)->enable_timing_output(ppg,enablePPS);
}
......
......@@ -35,7 +35,7 @@
@setchapternewpage off
@set update-month February 2020
@set update-month October 2022
@set release __RELEASE_GIT_ID__
@finalout
......@@ -44,7 +44,7 @@
@title PPSi Manual
@subtitle @value{update-month} (@value{release})
@subtitle Documentation about ``PTP Ported to Silicon''
@author A. Rubini, A.Colosimo and J-C Bau for CERN (be-co-ht)
@author A. Rubini, A.Colosimo, A.Wujek, J-C Bau for CERN
@end titlepage
@headings single
......@@ -60,6 +60,9 @@
PPSi (@sc{ptp} Ported to Silicon) is an application which, in
its basic operation, implements @sc{ieee} 1588-2019 specification in a way
that is portable to several architectures, including OS-less ones.
The current version of PPSi is compatible with @sc{ieee} 1588-2008
(@sc{ptp} version 2) and includes a number of optional features specified
in @sc{ieee} 1588-2019 (@sc{ptp} version 2.1).
This manual is mainly aimed at developers: people who are working with
@sc{ptp} and/or White Rabbit and need to use the protocol in their own
......@@ -76,8 +79,9 @@ shortened to @i{WR} in this manual.
WR is a multi-lab research project that aims at synchronizing
thousands of I/O devices distributed in a network several kilometers
wide; its software protocol is an extension of @sc{ptp}. A WR network is
made up of two devices: the @i{WR Switch} and the @i{WR Node}. White
wide; its software protocol is an extension of @sc{ptp}, @sc{wr-ptp}.
A WR network is
made up of two types of devices: the @i{WR Switch} and the @i{WR Node}. White
Rabbit is developed at ohwr.org:
@url{https://www.ohwr.org/project/white-rabbit}.
......@@ -94,27 +98,23 @@ implementation used in WR, running both standard @sc{ptp} and
The algorithm and computation routines regarding the basic @sc{ieee} 1588
are derived from the @i{PTPd} project, v.2.1.0 (see AUTHORS for details
about copyright); but as of March 2013 very little remains of the original
code base. In addition to the basic feature set we inherited from @i{PTPd},
we support raw Ethernet frames (@t{ETH_P_1588}), according to Annex F of the
specification and support for protocol extensions.
code base. In addition to the basic feature set the project inherited from
@i{PTPd}, the PPSI supports raw Ethernet frames (@t{ETH_P_1588}),
according to Annex F of the @sc{ieee} 1588 and support for protocol extensions.
We thank Danilo Sabato for fixing the @i{bare} architectures
Authors thank Danilo Sabato for fixing the @i{bare} architectures
(see @ref{Architectures}).
The home page of the PPSi project and the source repository are:
@indentedblock
@itemize @bullet
@item @url{https://www.ohwr.org/project/ppsi}
@item ssh://git@@ohwr.org:7999/project/ppsi.git
@end itemize
@end indentedblock
@url{https://www.ohwr.org/project/ppsi}
@c ##########################################################################
@node Status Features and Bugs
@chapter Status, Features, Bugs
This document tries to summarize the status of
the project, but we are working a lot on the package,
the project, but the development is still being done on the package,
so information here may be slightly out of date with respect to code.
The software package is designed to be modular: each of architectures,
......@@ -125,8 +125,8 @@ protocols and timing engine
@node Build-time Configuration
@section Build-time Configuration
After release 2013.11 we added to PPSi the Kconfig configuration
engine. Configuration is now performed by running ``@t{make
PPSi uses the Kconfig configuration
engine. Configuration is performed by running ``@t{make
menuconfig}'' or equivalent command.
A number of ready-to use configuration files are distributed in the
......@@ -142,8 +142,8 @@ running the standard @sc{ptp} version 2 protocol.
When building PPSi, the user can specify which architecture to build
for, by selecting it in @t{make menuconfig} or equivalent configuration
command. When cross-compiling, you need to tell your cross-compiler
prefix in the configuration step, or override it at build time
command. When cross-compiling, it is need to tell cross-compiler
a prefix in the configuration step, or override it at build time
by passing @t{CROSS_COMPILE=} on the command line.
The package currently supports the following architectures:
......@@ -156,8 +156,8 @@ The package currently supports the following architectures:
environment. The architecture is usually tested over the Linux
kernel using the standard GNU libraries. Most of the code relies
on standard @sc{posix} conventions, so this architecture most
likely works on @sc{bsd} and other variants as well. We may
change naming accordingly, after identifying the weak
likely works on @sc{bsd} and other variants as well. In the future
the name may change accordingly, after identifying the weak
(i.e. unportable) points. This architecture supports the standard
protocol on both @sc{udp} and raw Ethernet, also both at the
same time thanks to the per-link split of I/O methods.
......@@ -170,16 +170,18 @@ The package currently supports the following architectures:
separate architecture, even if the switch itself is a Linux
system running on an ARM processor. The switch is a complex
system, with several daemons cooperating through an IPC
mechanism: the standard main loop for a standalone Unix daemon
and shared memory mechanisms: the standard main loop for a
standalone Unix daemon
doesn't apply to the WR switch, and modelling it as a
separate architecture is the simplest and cleanest approach,
in our opinion (even if it leads to some code duplication).
separate architecture is the simplest and cleanest approach
(even if it leads to some code duplication).
The architectures relies on @i{time-wrs}.
@item wrpc
The @i{White Rabbit PTP Core} architecture is a port of PPSi to
run on our I/O devices. The @i{wrpc} is a ``@i{core}'', i.e. a
run on I/O devices. inside a Field Programmable Gate Array
(FPGA) chip. The @i{wrpc} is a ``@i{core}'', i.e. a
logic block, that runs in WR-capable I/O cards. Most such cards
are developed as open hardware on @i{ohwr.org}; examples are
the @sc{spec} (a PCIe carrier for FMC devices) and the @sc{svec}
......@@ -196,13 +198,13 @@ The package currently supports the following architectures:
to simulate a master and a slave exchanging ptp frames.
Arch-specific configuration options are implemented in
@i{arch-sim/sim-conf.c}. Use of the simulator is briefly
descibed in @ref{Configuring the Simulator}.
described in @ref{Configuring the Simulator}.
@item bare-i386
This architecture uses system calls towards the Linux kernel but
does not rely on standard libraries. The port only supports
raw Ethernet frames and is thought to be a validation for our
raw Ethernet frames and is thought to be a validation for
@i{freestanding} ports. The process built as @i{bare-i386}
runs on conventional x86 Linux hosts and demonstrates that
PPSi works properly with no added dependencies on external
......@@ -219,9 +221,9 @@ The package currently supports the following architectures:
@end table
We plan, over time, to support microcontrollers (a beta version for
ARM7 is working, and we are considering Cortex-M) and @i{bare-arm} (to
be tested on the WR switch).
@c We plan, over time, to support microcontrollers (a beta version for
@c ARM7 is working, and we are considering Cortex-M) and @i{bare-arm} (to
@c be tested on the WR switch).
@c ==========================================================================
@node Protocols
......@@ -229,36 +231,51 @@ be tested on the WR switch).
At build time, the user can select the standard protocol (selected by
default by most architectures) or an extension.
The code base only includes one extension, White Rabbit, which is the
default choice when building for one of the WR architectures.
Nothing in PPSi
prevents our fellow developers to support their own @i{ptp} extension
using PPSi.
The code base includes three extensions:
@indentedblock
@itemize @bullet
@item White Rabbit (WR) - specified in "White Rabbit Specification", v2.0:
@url{http://white-rabbit.web.cern.ch/documents/WhiteRabbitSpec.v2.0.pdf},
@item Layer 1 Syntonization (L1Sync, a.k.a. High Accuracy) - the experimental
implementation of a profile specified in Annex L of @sc{ieee} 1588-2019.
@item @i{Custom} - the experimental profile that allows free access to all
options and attributes
@end itemize
@end indentedblock
White Rabbit extension is the default choice when building for one of the
WR architectures.
The selection of the used extension (or standard PTP) is done in run-time by
a proper configuration.
PPSi can be easily expanded with a support of a new @i{ptp} profile.
Each extension lives in a subdirectory called @t{proto-ext-}@i{name}.
Source files in that directory may override the implementation for the
standard protocol (which lives in @t{proto-standard}) to provide their
own functionalities. To simplify writing extensions, the @i{proto-standard}
own functionalities. There is also a subdirectory @t{proto-ext-common}
which holds common code for all available extensions.
To simplify writing extensions, the @i{proto-standard}
functions already provide @i{hooks} so the extension itself can provide
callbacks while still using the basic @sc{ptp} engine.
The set of callbacks is currently based on the needs of
WR, but we are willing to accept patches to provide more hooks as
needed.
WR and L1Sync, but it can be easily expanded if more hooks are needed.
If you plan to write your own protocol extension within PPSi, please
refer to how @i{proto-ext-whiterabbit} is implemented.
The implementation of @i{proto-ext-whiterabbit} can act as a good reference
for future implementations of protocol extension.
@c ==========================================================================
@node Time Functions and Network Operations
@section Time Functions and Network Operations
PPSi supports custom implementations of time functions, so you can
easily port the daemon to your own timing primitives.
PPSi supports custom implementations of time functions, so it can
easily port the daemon to a new timing primitives.
The subdirectories named @i{time-xxxx} are used to implement timing
functions; timing includes the methods that are part of two data
structures: @i{pp_time_operations} and @i{pp_network_operations}. The
former structure deals with getting and setting system time, while the
former structure deals with getting and setting system/WR time, while the
latter deals with frame tx and rx. Network operations are concerned
with timestamping the actual I/O, and that's why they are considered
part of the ``timing'' of PPSi.
......@@ -272,28 +289,21 @@ suggests Unix timing code ('@t{TIME?=unix}'). The choice for '@t{TIME=}'
is not currently selected using Kconfig, because nobody is expected
to diverge from the default choice for the architecture being built.
If you want to support a different timing engine within the Unix build
system, you can use '@t{make TIME=xyz}' to request building
To support a different timing engine within the Unix build
system, '@t{make TIME=xyz}' can be used to request building
the @i{time-xxxx} subdirectory. Please note that the Unix time
structures are built anyways for '@t{CONFIG_ARCH=unix}',
so you can piggy-back on those
functions, either within your own methods or by replacing the
so it can piggy-back on those
functions, either within own methods or by replacing the
@t{ppi->t_ops} and @t{ppi->n_ops} for the communications links that do
not include your own hardware support.
not include the hardware support.
@c ==========================================================================
@node Features
@section Features
This is a summary of current and planned features for the PPSi
package. As said, we are still working on it, so the following
list may be not up to date with software developments by the time you
read it.
The following list of features doesn't consider known bugs, which are
listed in the following sections. Please consider such bugs transient
mishaps, as we are working on them right now; anyways, it would be
unfair to hide them.
package.
@table @r
......@@ -303,93 +313,114 @@ unfair to hide them.
it detects that its peers are not able to speak the extended
protocol. Many extensions are now supported in
a single build. In a near future, the new protocol extension L1SYNC
used by the High Acurracy (@sc{HA}) profile will be released.
used by the High Accuracy (@sc{HA}) profile will be released.
@item Support both hosted and freestanding environments.
This is already supported, though we still lack a microcontroller
implementation, and our only freestanding environment is @i{wrpc},
running on an LM32 processor.
This is already supported, though PPSi still lacks a microcontroller
implementation, and the only freestanding environment is @i{wrpc},
running on an LM32 or RISCV soft-processor.
@item Support multi-link operation.
@item Support multi-PTP link operation.
The daemon manages several links at the same time, being master
slave or auto-detect independently on each link.
The @i{best master clock} algorithm is run globally,
The daemon manages several PTP links at the same time, being configured
as master/slave or auto-detecting its role on each link using
@i{best master clock algorithm} (BMCA).
The @i{BMCA} is run globally,
but communication and timeouts are managed per-link.
@item Support both @sc{udp} and raw Ethernet.
We already do that. We use the multi-link operation to
PPSi uses the multi PTP-link operation to
support both @sc{udp} and raw Ethernet on the same network
interface. Also, we support @sc{udp} in the WR switch,
to allow progressive and seamless migration to WR if you already
support @sc{ptp} in your network with a @sc{udp}-only implementation.
interface (physical port). PPSi supports @sc{udp} in the WR switch,
to allow progressive and seamless migration to WR network of devices
that already support @sc{ptp} with a @sc{udp}-only implementation.
@item Support fall-back master links.
This is needed for WR, and is being worked on.
We need to track more than one master in order to switch over
This feature is only partly implemented. With the help of BMCA it is
possible to track more than one master (other are passive).
However, the reconfiguration takes number of seconds.
The tracking of more than one master with a switch over
from one to the other within a few milliseconds and with no
time glitches.
time glitches is not available now.
@item Support hardware timestamping where available.
This is not yet implemented for the generic protocol, but we
plan to add at least @i{time-linux-tstamp} soon.
@item Support @sc{bsd} specifics.
Unfortunately the @i{hosted} part of the packages is slightly
too much Linux-dependent. We plan to support the @sc{bsd}
variants as well, hoping to get interest and patches from some
@sc{bsd} developer.
Hardware timestamping is supported in WR devices.
However, This is not yet implemented for the generic protocol.
@item Allow architectures to state their capabilities.
Currently the command-line arguments are a an all-or-nothing thing.
Currently the command-line arguments are an all-or-nothing thing.
But, for example, @i{bare} architectures don't support
@sc{udp} and other architectures may not support raw Ethernet.
We plan to allow architectures to state their capabilities to
It is planed to allow architectures to state their capabilities to
report proper errors when the user tries to set up unimplemented
configurations.
@item Support run-time enable/disable of diagnostics.
We want to allow run-time modification of diagnostics flags
with a per-link granularity. Currently we have configuration-based
It is planned to allow run-time modification of diagnostics flags
with a per-link granularity. Currently there are configuration-based
per-link diagnostic flags and global diagnostic
flags that can be changed
flags. Only some architectures allows that it can be changed
at run time (for example, arch-wrpc offers that through a shell
command). We think this feature is useful
when you run more than a pair of interfaces and have problems
on some of the links but not all of them.
command). It is believed that this feature is useful
for systems with more than a pair of interfaces and have problems
on some of the links but not all of them.
@item Access of internal structures in run-time
PPSi keeps almost all of its internal data in shared memory.
Thanks to this the internal state can be exported and monitored by
external tools. For example SNMP agent implemented on WR Switch uses
this mechanism to provide monitoring data for external tools.
The dumps of PPSi's memory (of live or crashed process) can be used to
investigate the internal state. There are tools,
@t{wrs_dump_shmem} (for WR Switch) and @t{wrpc-dump} (for WR Node) that
can translate binary dumps into user-friendly text form.
PPSi increases a special counter before and after each write to
the shared memory increases, which can ensure the data consistency.
@item Runtime re-configuration
Currently, the configuration of PPSi is provided at startup and
only some parameters on a limited number of architectures (WR node)
can be changed. It would be very useful to be able to
change some of the @sc{ptp} and extensions configuration without
the need of restarting PPSi (and resynchronizing). Such runtime
re-configuration could include ClockClass priority, packet rate
or enable/allowed extensions. Implementing full run-time reconfiguration
is on project's todo list.
@end table
@c ==========================================================================
@node Bugs
@section Bugs
As of 2013-05 the project suffers from these known bugs:
@itemize
@item All frames must be sent according to a pseudo-random distribution;
this is mostly in place but must be audited project-wide.
@item We removed @i{peer-delay} support. We plan to add it back, and
actually move White Rabbit to use @i{peer-delay} @sc{ptp} instead of
@i{end-to-end} @sc{ptp}.
@item The servo for standard-@sc{ptp} must be audited. We are doing
it now using @i{arch-sim} support,
@item @sc{udp} over @sc{IPV6} is not yet supported.
@end itemize
@c @node Bugs
@c @section Bugs
@c
@c As of 2013-05 the project suffers from these known bugs:
@c
@c @itemize
@c @item All frames must be sent according to a pseudo-random distribution;
@c this is mostly in place but must be audited project-wide.
@c @item We removed @i{peer-delay} support. We plan to add it back, and
@c actually move White Rabbit to use @i{peer-delay} @sc{ptp} instead of
@c @i{end-to-end} @sc{ptp}.
@c @item The servo for standard-@sc{ptp} must be audited. We are doing
@c it now using @i{arch-sim} support,
@c @item @sc{udp} over @sc{IPV6} is not yet supported.
@c @end itemize
@c ##########################################################################
@node Configuration
@chapter Configuration
PPSi support configuration files and individual configuration items
PPSi supports configuration files and individual configuration items
passed on the command line. Such support is currently not available
for freestanding architectures (the @i{bare} ones and @i{wrpc-sw}).
......@@ -401,16 +432,17 @@ semicolon as a separator.
If no configuration file is specified, the program reads the default
one, which is architecture-specific (thus, the default configuration
file is processed after all the command line configuration items. The
file is processed after all the command line configuration items; to change
the order use explicitly the @t{-f} parameter). The
default file name is @t{/etc/ppsi.conf}. The source tree of PPSi includes
two example configuration files in its own @t{/etc} subdirectory.
Configuration is made of global options and port-specific options.
To configure a port, use either @t{port <name>} or @t{link <name>}
followed by its options.
The parser allocates a new @sc{ptp} state machine for each new port, but
The parser allocates a new @sc{ptp} instance for each new port, but
allows changing configuration of an existing port. For instance, to
enable frame diagnostics for a specific port, you can use:
enable frame diagnostics for a specific port, the following command can be used:
@smallexample
./ppsi -f /etc/ppsi.conf -C "port eth1-raw-ptp; diagnostics 02"
......@@ -423,30 +455,26 @@ architecture-specific table and an extension-specific table.
Currently, only @i{arch-sim} has specific configuration items.
The list of global and port specific configuration items are described
in the following section but also in code source files: @t{lib/conf.c} and
in the following section but also in code source file @t{lib/conf.c} and
@t{pp_global_arglines} array.
@quotation Note
most current command-line options are going to be turned into
configuration options. This applies to the priorities, intervals and
thresholds, as well as the @i{slave-only} flag.
@end quotation
@c ==========================================================================
@node PPSi base configuration
@section PPSi base configuration
As said before, the PPSi configuration is separated into different sections.
All keywords belonging to the 'global options' can be defined anywhere in the configuration
but to increase the readability, we suggest defining them at the beginning.
The PPSi configuration is separated into different sections.
All keywords belonging to the 'global options' can be defined anywhere in
the configuration, but to increase the readability, it is suggested to define
them at the beginning.
The 'port-specific' section always begins with the keywork 'port' or 'link'. Then all
The 'port-specific' section always begins with the keyword 'port' or 'link'. Then all
following 'port-specific' keywords will be associated to this port until
a new keyword 'port' or 'link' appears.
@anchor{arg-types}
An option is a key/value(s) pair separated by at least a space character '@t{key value(s)}'. The '@t{value(s)}' entry
depends on the option type. Few types are supported by PPSi:
An option is a key/value(s) pair separated by at least a space character, e.g.: '@t{key value(s)}'. The '@t{value(s)}' entry
depends on the option type. The following value types are supported by PPSi:
@table @code
......@@ -460,7 +488,7 @@ This is a 64 bits integer value in the range from -9 223 372 036 854 775 808 to
This is an array of 2 Int16.
@item Double
This is a 64 bit floating point in the range 1.7E +/- 308 (15 digits).
A value can be expressed using this two available notations:
A value can be expressed using two available notations:
- E notation: 1.6E-1
- Decimal notation: 0.16
@item Boolean
......@@ -469,36 +497,40 @@ and '@t{f/false/0/off/n/no}' for 'False'.
@item String
This is free text.
@item TextList
The option value has to be select in a list of predefined text. For each choice we can also use different way
to refer to the same choice.
For example, the selection of the delay mechanism allows 2 choices (peer-to-peer or end-to-end) but for each choice
we are free to use a different text for the selection :
This is a list of predefined choices specified with predefined text.
For each choice, it can use more than one predefined text.
For example, the selection of the delay mechanism allows two predefined
choices (peer-to-peer or end-to-end), but for each choice it is possible to
use a number of different texts for the selection:
@example
. end-to_end: "request-response","delay","e2e"
. peer-to-peer: "peer-delay","pdelay","p2p"
end-to_end: "request-response","delay","e2e"
peer-to-peer: "peer-delay","pdelay","p2p"
@end example
@end table
For some options, multiple keyword names can be used ( e.g. "mechanism", "dm"). New keyword names have been added
to be more explicit but at the same time old key names have not been suppressed just to keep the backward compatibility.
For some options, multiple keyword names (@t{key}) can be used, e.g. "mechanism", "dm". New keyword names have been added
to be more explicit but at the same time old keyword names have not been suppressed just to keep the backward compatibility.
Some old keywords will be marked '@i{(deprecated)}', and will be removed in the future.
@heading List of global options
@heading List of global options (i.e. keywords)
@table @code
@item @b{clock-class} @i{[Int32]}
An attribute defining the TAI traceability, synchronization state and
expected performance of the time or frequency distributed by a
Boundary Clock or Ordinary Clock.
For more details please refer to the IEEE 1588 standard
@item @b{clock-accuracy} @i{[Int32]}
An attribute defining the accuracy of the Local Clock (e.g. local
oscillator) of a Boundary Clock or Ordinary Clock.
For more details please refer to the IEEE 1588 standard.
@item @b{clock-allan-variance} @i{[Int32]}
An attribute defining the stability of the Local Clock of a
Boundary Clock or Ordinary Clock.
For more details please refer to the IEEE 1588 standard
@item @b{time-source} @i{[Int32]}
The source of time used by the grandmaster (or free-running master).
......@@ -513,22 +545,25 @@ Some old keywords will be marked '@i{(deprecated)}', and will be removed in the
@item @b{priority1} @i{[Int32]}
A user configurable designation that a clock belongs to an ordered
set of PTP devices from which a PTP Master is selected.
For more details please refer to the IEEE 1588-2019 standard.
For more details please refer to the IEEE 1588 standard.
@item @b{priority2} @i{[Int32]}
A user configurable designation that provides finer grained ordering
among otherwise equivalent PTP devices.
For more details please refer to the IEEE 1588-2019 standard.
For more details please refer to the IEEE 1588 standard.
@item @b{forcePpsGen} @i{[Boolean]}
Configuration of the PPS output. By default, the PPS is generated all the time
only when the clock class is set to 6 (Grand master) or to 193 (Free Running master).
When this option is set, the PPS is generated all the time for all clock class.
Configuration of the PPS output. By default, the PPS is generated
only when the clock class is set to 6 (Grandmaster), or to 193
(Free-running master), or when the PTP device is a PTP Slave, i.e.
it is synchronized via port in Slave state to a PTP Master.
@item @b{ptpFallbackPpsGen} @i{[Boolean]}
if activated, enables the PPS generation if a slave instance
programmed to use an extension protocol (WR, L1Sync, ...) is falling back
to PTP communication only.
If set, PPS is generated even if a PTP Device with enabled
protocol extension (WR, L1Sync, ...) is synchronized using standard
PTP communication only. Note: by default, a PTP device that is a
a PTP slave and has protocol extension enabled will generate PPS
only if the protocol extension is active on the Slave port.
@item @b{ptpPpsThresholdMs} @i{[Int32]}
This option defines the threshold corresponding to the offset from the
......@@ -540,14 +575,15 @@ Some old keywords will be marked '@i{(deprecated)}', and will be removed in the
than the threshold value + 20%.
@item @b{gmDelayToGenPpsSec} @i{[Int32]}
If this option is set to a value greater than 0, it allows the PPS generation
when the device becomes Grand-Master by BMCA. The value represent a delay in seconds to respect before
to start the PPS generation.
If this option is set to a value greater than 0, it allows PPS generation
when the PTP device becomes Grandmaster by BMCA (i.e. it is configured to be
a Boundary Clock). The value represent a delay in seconds between the
moment the PTP Device becomes Grandmaster and the start of PPS generation.
@item @b{externalPortConfigurationEnabled} @i{[Boolean]}
This option is used to force the state of all port instances. The BMCA is then disabled
in PPSi.
When enabled, the port-specific option @t{desiredState} must be defined for each port instance
When enabled, the port-specific option @t{desiredState} must be defined for each port instance.
For more details please refer to the IEEE 1588-2019 (clause 17.6.2)
@item @b{slaveOnly} @i{[Boolean]}
......@@ -565,13 +601,13 @@ Some old keywords will be marked '@i{(deprecated)}', and will be removed in the
@table @code
@item @b{port} @i{[String]}
@itemx @b{link} @i{[String]}
Defines a named port instance. The argument correspond to the instance name.
Defines a named PTP port instance. The argument correspond to the instance name.
@item @b{iface} @i{[String]}
Defines the physical port interface name to use (e.g. "eth0", "wri1", ...)
@item @b{proto} @i{[TextList]}
Defines the network transport protocol to use :
Defines the network transport protocol (mapping) to use :
@example
. "raw" : Raw Ethernet
. "udp" : User Datagram Protocol
......@@ -583,6 +619,7 @@ Some old keywords will be marked '@i{(deprecated)}', and will be removed in the
@example
. "none", "ptp": Default PTP profile
. "whiterabbit", "wr": White Rabbit profile
. "highaccuracy", "ha": High Accuracy profile
@end example
@item @b{mechanism} @i{[TextList]}
......@@ -598,48 +635,55 @@ Some old keywords will be marked '@i{(deprecated)}', and will be removed in the
(refer to the IEEE 1588-2019 - clause 9.2.2.2).
This option cannot be used if the global option '@i{externalPortConfiguration}' is
enabled.
If this option is not set, then the standard BMCA algorithm will be used.
If this option is not set, then the standard BMCA algorithm is used.
@item @b{sync-interval} @i{[Int32,Unit=logarithm to the base 2]} @i{(deprecated)}
@itemx @b{logSyncInterval} @i{[Int32,Unit=logarithm to the base 2]}
The mean time interval between transmission of successive
Sync messages.
Sync messages. For more details please refer to the IEEE 1588 standard.
@item @b{announce-interval} @i{[Int32,Unit=logarithm to the base 2]} @i{(deprecated)}
@itemx @b{logAnnounceInterval} @i{[Int32,Unit=logarithm to the base 2]}
The mean time interval between transmissions of successive
Announce messages.
Announce messages. For more details please refer to the IEEE 1588 standard.
@item @b{in-delay-req-interval} @i{[Int32,Unit=logarithm to the base 2]} @i{(deprecated)}
@item @b{min-delay-req-interval} @i{[Int32,Unit=logarithm to the base 2]} @i{(deprecated)}
@itemx @b{logMinDelayReqInterval} @i{[Int32,Unit=logarithm to the base 2]}
The minDelayRequestInterval specifies the minimum permitted
mean time interval between successive Delay_Req messages.
This option as a meaning only when 'end-to-end' delay mechanism is selected.
This option is effective only when 'end-to-end' delay mechanism is selected.
For more details please refer to the IEEE 1588 standard.
@item @b{min-pdelay-req-interval} @i{[Int32,Unit=logarithm to the base 2]} @i{(deprecated)}
@itemx @b{logMinPDelayReqInterval} @i{[Int32,Unit=logarithm to the base 2]}
The minPDelayRequestInterval specifies the minimum permitted
mean time interval between successive Pdelay_Req messages.
This option as a meaning only when 'peer-to-peer' delay mechanism is selected.
This option is effective only when 'peer-to-peer' delay mechanism is selected.
For more details please refer to the IEEE 1588 standard.
@item @b{announce-receipt-timeout} @i{[Int32]} @i{(deprecated)}
@itemx @b{announceReceiptTimeout} @i{[Int32]}
The announceReceiptTimeout specifies the number of announceIntervals
that must pass without receipt of an Announce message before the
occurrence of the event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES.
For more details please refer to the IEEE 1588 standard.
@item @b{asymmetryCorrectionEnable} @i{[Boolean]}
When enabled, it tells the servo to calculate and take the delay asymmetry into account.
This option can be forced enabled by the profile in use (white rabbit,..). The PTP
profile does not use by default this feature.
When enabled, this feature calculates delay asymmetry which is then used in the
computation of offset from master in the PTP servo.
This feature is obligatorily enabled in some profiles when used (e.g. White Rabbit,..).
In the Default PTP Profile, this feature is not used by default.
For more details please refer to the IEEE 15882-2019 standard.
@item @b{constantAsymmetry} @i{[Int64,Unit=picoseconds]}
When '@i{asymmetryCorrectionEnable}' feature is used, this option leave the possibility to define
a constant value that will be added to the calculation of the delay asymmetry.
When '@i{asymmetryCorrectionEnable}' feature is used, this parameter allows fine-adjustment
of the calculated delay asymmetry. The provided value of @i{constantAsymmetry}
will be added to the calculation of the delay asymmetry.
For more details please refer to the IEEE 15882-2019 standard.
@item @b{desiredState} @i{[TextList]}
When the option '@i{externalPortConfigurationEnabled}' is enabled, this option indicates
the PTP port state to apply :
When the option '@i{externalPortConfigurationEnabled}' is enabled, this parameter indicates
the PTP state to apply on a PTP Port :
@example
. "initializing": Initializing state
. "faulty" : Faulty state
......@@ -649,38 +693,48 @@ Some old keywords will be marked '@i{(deprecated)}', and will be removed in the
. "master" : Master state
. "passive" : Passive state
. "uncalibrated": Uncalibrated state
. "slave" : Slave state. During synchronization
with a master, the port instance can
transition to UNCALIBRATED state.
. "slave" : Slave state. During synchronization
with a master, the port instance can
transition to UNCALIBRATED state.
@end example
@item @b{egressLatency} @i{[Int64,Unit=picoseconds]}
Defines the transmission constant delays.
Defines the transmission constant delays (tx fixed delta).
For more details please refer to the IEEE 15882-2019 standard.
@item @b{ingressLatency} @i{[Int64,Unit=picoseconds]}
Defines the reception constant delays.
Defines the reception constant delays (rx fixed delata).
For more details please refer to the IEEE 15882-2019 standard.
@item @b{delayCoefficient} @i{[Double]}
When the option '@i{asymmetryCorrectionEnable}' is enabled, it defines
the asymmetry alpha delay coefficient.
Defines the relative delay coefficient (alpha parameter). When the feature
'@i{asymmetryCorrectionEnable}' is enabled, this value is used in
calculation of the delay asymmetry.
For more details please refer to the IEEE 15882-2019 standard.
@item @b{scaledDelayCoefficient} @i{[Int64,Unit=RelativeDifference]]}
When the option '@i{asymmetryCorrectionEnable}' is enabled, it defines
the asymmetry alpha delay coefficient. It overwrites the option
Defines the relative delay coefficient (alpha parameter). When the feature
'@i{asymmetryCorrectionEnable}' is enabled, this value is used in
calculation of the delay asymmetry. It overwrites the parameter
'@i{delayCoefficient}' if set by providing a value expressed with a
better resolution.
better resolution.
For more details please refer to the IEEE 15882-2019 standard.
@item @b{servo-pi} @i{[Int16[2]]}
Change the default PTP servo parameters. The first argument correspond to the
proportionnal coefficient and the second to the integral one.
If set, it overrides the default PTP servo parameters.
The first argument correspond to the
proportional coefficient and the second to the integral one.
@item @b{diagnostic} @i{[String]}
Change the diagnostic level. @xref{Diagnostics,,Diagnostics}.
@item @b{diagnostic} @i{[String]}
Change the diagnostic level. @xref{Diagnostics,,Diagnostics}.
@item @b{vlan} @i{[String]}
Specify vlans. @xref{VLAN Support,,VLAN Support}.
@end table
@c ==========================================================================
@node Extension specific configuration
@node Extension-specific configuration
@section Extension specific configuration
@subsection White Rabbit extension
......@@ -693,21 +747,20 @@ No specific options are needed when the White Rabbit profile is selected.
Configuration, for @t{arch-unix} and @t{arch-wrs}, allows to provide
some fault injection.
In particular, the program allows dropping frames, in both the TX and RX
paths. The configuration values state how many frames are dropped every
1000. Dropping is randomized, but the user can set the seed to ensure
a repeatable dropping sequence.
Dropping transmitted frames is performed by reporting success (and the
Dropping of transmitted frames is performed by reporting success (and the
timestamp), while no frame is actually sent. A diagnostic message
is generated at @t{frames} level 1, but other than that nothing
happens. Actually, @t{arch-wrs} needs to actually send a frame in
happens. Please note that @t{arch-wrs} needs to actually send a frame in
order to get a timestamp back; in this case the program modifies the
frame, to use a wrong Ethernet type or a wrong UDP port.
Dropping received frames is performed by actually receiving (and
timestamping), but returning a special error code to the caller.
Dropping of received frames is performed by actually receiving (and
timestamping) the frames, but returning a special error code to the caller.
Again, PPSi creates a diagnostic message at @t{frames} level 1.
The following configuration lines are supported:
......@@ -722,7 +775,7 @@ The following configuration lines are supported:
@end table
The randomization see can be passed by pre-setting the environment
The randomization seed can be passed by pre-setting the environment
variable @t{PPSI_DROP_SEED} to a decimal numeric value. For example:
@smallexample
......@@ -736,15 +789,15 @@ before starting the daemon.
@node Configuring the Simulator
@section Configuring the Simulator
To run the PPSi simulator you need to rely on diagnostics and specific
To run the PPSi simulator it is need to rely on diagnostics and specific
configuration items. The configuration items are defined in
@i{arch-sim/sim-conf.c} and are not individually documented here at
this point.
After building with ``@t{make sim_defconfig}'', you can look at how
After building with ``@t{make sim_defconfig}'', it can be checked how
PPSi behaves in different situation. For example, to see how the servo
works with default parameters you can activate servo messages at level
2, and only look at the offset from master:
works with default parameters activate servo messages at level
2, and only display the offset from master:
@smallexample
./ppsi -d 0002 | grep 'Offset from master'
......@@ -758,9 +811,9 @@ The simulator runs by default for one hour of simulated time (in a
fraction of a second of running time), and the initial offset from
master to slave is 0.9 seconds.
To pass configuration options, you can use the @t{-C} command line option.
so, for example, to start with 0.1 seconds of offset and 1000 ns of
transmission jitter, you can run like this:
To pass configuration options, @t{-C} command line option can be used.
For example, to start with 0.1 seconds of offset and 1000 ns of
transmission jitter:
@smallexample
./ppsi -d 0002 -C "sim_init_master_time .1; sim_jit_ns 1000"
......@@ -771,7 +824,7 @@ transmission jitter, you can run like this:
@node VLAN Support
@chapter VLAN Support
PPSi can support vlans, or use support the Operating System offers.
PPSi can support vlans, or use the support offered by the Operating System.
@c ==========================================================================
@node OS VLAN
......@@ -791,87 +844,88 @@ both raw Ethernet and UDP can be used.
Freestanding architectures, like the WR PTP Core (@t{arch-wrpc}) can't
rely on the underlying Operating System, so the daemon must read and
write vlan Ethernet headers by itself -- in this situation UDP is not
supported, unless your own architecture's network operations build and
supported, unless an architecture's network operations build and
decode IP and UDP headers (in official PPSi no such support is there).
Another situation where PPSi should deal with vlans directly is when
you want a port to be master on several vlans at the same time, but
a port it to be a master on several vlans at the same time, but
this is only supported for @i{mandated} masters, at this point in
time. A mandated master is a port configured either as '@t{master}'
(externalPortConfiguration enabled) or as '@t{masterOnly}'
in the configuration file. If you want to run multiple vlans on the
same physical ports, without forcing the port to be a mandated master,
you can create multiple PTP interfaces, one per vlan, all relying on
in the configuration file. To run multiple vlans on the
same physical port, without forcing the port to be a mandated master,
create multiple PTP interfaces, one per vlan, all relying on
the same physical port (or different OS-specific vlan ports).
When running a fully-PTP network in end-to-end mode, you won't usually
When running a fully-PTP network in end-to-end mode, it won't usually
need to configure multiple vlans on a single port. In particular, this
never happens in a White Rabbit network, because each link connects
two clocks, without any non-compliant switches in the middle.
However, if you have
transparent clocks or normal switches, you may want to behave
as a master for the whole network connected to your port, which may
two WR-PTP devices, without any non-compliant switches in the middle.
However, for
transparent clocks or normal switches, it is possible to have
a master for the whole network connected to a given port, which may
be split in several vlans. Clearly this only applies to a @i{trunk}
port in your PTP switch or workstation.
port in PTP switch or workstation.
To support this we rely on @i{Kconfig} and architecture-specific
The support of VLANs rely on @i{Kconfig} and architecture-specific
code, in the following way.
@itemize @bullet
@item Each architecture states, in @t{Kconfig}, whether it supports
vlans (@t{SUPPORT_VLAN}) and multiple vlans (@t{SUPPORT_MULTIPLE_VLAN}).
vlans (@t{ARCH_SUPPORT_VLAN}) and multiple vlans (@t{ARCH_SUPPORT_MULTIPLE_VLAN}).
@item The configuration parser (@t{lib/conf.c}) accepts a @t{vlan}
keyword, specifying one or more vlans. If several, they are
comma-separated.
@item Configuration fails (and PPSi refuses to start) if the architecture
has no vlan support, or of multiple vlans are specified for an
architecture that supports one vlan only.
has no vlan support and vlan is specified, or multiple vlans are specified
for an architecture that supports one vlan only.
@item Configuration fails also if several vlans are specified for
a port that is not a mandated master.
a port that is not a @i{mandated} master.
@end itemize
When only one vlan is specified, the network operations for the
architecture are responsible: they must do the right thing. Currently,
@t{wrpc} builds and decodes Ethernet frames (FIXME: NOT YET), ignoring
architecture are responsible to handle it in a proper way. Currently,
@t{wrpc} builds and decodes Ethernet frames, ignoring
any received frame not belonging to the proper vlan. Code for @t{wrs} and
@t{unix} handles a single vlan like multiple ones; I thought
about automatically creating the vlan-specific interface, but that
would be very Linux-specific and I see no real need for it.
@t{unix} handles a single vlan like multiple ones (NOTE:
automatically creating the vlan-specific interface was considered, but that
would be very Linux-specific and there was no real need for it).
When multiple vlans are specified for a master port, current code
(i.e. @t{arch-wrs} and @t{arch-unix}) binds to @t{ETH_P_ALL}, in order
to receive all frames from that interface, and thus be able to tell
which vlan they belong to. A multiple-vlan master sends announce and
sync (plus follow-up) to all vlans at the same time, and will reply to
delay requests using the same vlan it receives it from. Frames from
delay requests using the same vlan it receives it from, limited to the
list of configured vlans. Frames from
other vlans, as well as non-PTP frames, are ignored.
Because of the @t{ETH_P_ALL} binding, a multiple-vlan master port will
receive all the non-PTP traffic that flows on the interface. Please be
warned that this may increase the load on your PPSi process. With the
warned that this may increase the load on the PPSi process. With the
current release of the White Rabbit Switch this is not a problem,
because the switching core routes only PTP frames to the CPU. This
applies to single-vlan ports, because PPSi is not creating the
Linux-specific interface to have the kernel select traffic for us.
Linux-specific interface to have the kernel select traffic.
@c ==========================================================================
@node Note about vlans in Linux
@section Note about vlans in Linux
The choices described above depend on how vlans work in Linux (the
architecture we use in the White Rabbit Switch, and the one we support
architecture that is used in the White Rabbit Switch, and the one supported
in @t{arch-unix}).
If a packet socket is bound to a specific Ethernet protocol (for
example, the PTP Ethernet type, 0x88f7), on a generic Ethernet port
like @t{eth0}, it receives all frames for that @i{ethertype}, whether
or not they are tagged on the wire. To our knowledge there is no way,
in this situation, to tell whether the frame was tagged, and which tag
or not they are tagged on the wire. To authors' knowledge in this situation,
it is not possible to tell whether the frame was tagged, and which tag
were there if any. Only traffic to vlan-specific ports, like
@t{eth0.20}, si guaranteed to belong to vlan 20 (or a double-tagged
@t{eth0.20}, is guaranteed to belong to vlan 20 (or a double-tagged
frame, whose external tag is 20).
Only a socket bound to all @i{ethertypes} (i.e. @t{ETH_P_ALL}) is able
......@@ -879,11 +933,11 @@ to receive auxiliary metadata that reports whether the frame was
tagged and which tag it was carrying.
The behavior above depends on how hardware acceleration for tags work,
and even if it is suboptimal for this use case, we don't know about
and even if it is suboptimal for this use case, authors don't know about
alternatives. Thus, a PPSi port configured for vlan frames, is bound
to the base ethernet port, but it must receive all @i{ethertypes}.
If this is not ok for your configuration, you can create your own
If this is not ok for an configuration, it is advised to create a new
vlan-aware Linux port and bind to it. It works correctly with smaller
CPU overhead, but more administrative work.
......@@ -892,8 +946,10 @@ CPU overhead, but more administrative work.
@chapter PTP Clock Class
The clock class value (@t{clockClass}), a field of the `clock quality'
structure, can be specified in the configuration file for the architectures
that support such a file.
structure defined by the IEEE1588 standard, can be specified in
the configuration file for the architectures
that support such a file (e.g. White Rabbit Switch) or be set in run-time (e.g.
White Rabbit Node).
@c ==========================================================================
@node Default device attributes
......@@ -998,13 +1054,13 @@ timePropertiesDS.timeTraceable = FALSE
@node Clock class degradation
@section Clock class degradation
PPSi manage clock class degradation for a set of clock classes and update accordently
clock and time property field.
As certain clock and time properties may be set in the PPSi configuration, so when a clock class
PPSi manages clock class degradation for a set of clock classes and updates accordingly
clock & time property field.
As certain clock & time properties may be set in the PPSi configuration, so when a clock class
is degraded, all updated clock and time fields are changed in a way to never set them to a better
value than their configured one. In such a case, they will remain unchanged.
The following table show how a clock class is degraded when the PLL is in holdhover or unlocked:
The following table show how a clock class is degraded when the PLL is in holdover or unlocked:
@table @code
@item @b{PTP_GM_LOCKED(6)} - PLL holdover detected
......@@ -1117,9 +1173,7 @@ a clock that may be a slave of another clock.
@node Diagnostics
@chapter Diagnostics
During development of PPSi, diagnostic support used several
techniques, but finally we converged on the one described here, that
is here to stay. The idea is that we need to add verbosity
The PPSi verbosity can be controlled
per-feature and per-port. This fine-grained control is expected to be
important while developing features or while diagnosing problems on
new architectures.
......@@ -1138,8 +1192,8 @@ macros use the logical OR of both flags, so developers can activate
diagnostics on either a single link or globally.
The diagnostic flags are split into topics (called @i{things}). For
each diagnostic thing the header defines a few bits; so we can have
diagnostic levels for each of them, but we suggest only using level 1
each diagnostic thing the header defines a few bits; there is
diagnostic levels for each of them, but it is suggested to use only level 1
and 2 -- the rationale is in the header itself.
The @i{things} currently defined are:
......@@ -1162,7 +1216,7 @@ addition of new masters as well.
@item Extensions: extension-specific information.
@item Configuration: at level 1 PPSi reports errors, at level 2 all
configuration items being parsed (from either files or command line).
configuration items being parsed (from either file or command line).
@end itemize
......@@ -1186,8 +1240,8 @@ of the @i{pp_diag} function:
@end example
The function acts like @i{printf}, with the leading arguments @t{ppi},
@t{thing} (which is one of the names fsm, time, frames, servo, bmc,
ext) and @t{level}, which should be 1 or 2. For example, the code
@t{thing} (which is one of the names @i{fsm}, @i{time}, @i{frames}, @i{servo},
@i{bmc}, @i{ext}) and @t{level}, which should be 1 or 2. For example, the code
setting system time includes this diagnostic line:
@example
......@@ -1195,9 +1249,9 @@ setting system time includes this diagnostic line:
tp.tv_sec, tp.tv_nsec);
@end example
Finally, if you need to shrink the size of your binary file, you can
build PPSi with no diagnostic code at all (i.e., the compiler won't
even generate the function calls), you can define @t{PPSI_NO_DIAG} in
Finally, to shrink the size of binary file, PPSi can be
build with no diagnostic code at all (i.e., the compiler won't
even generate the function calls), in this case define @t{PPSI_NO_DIAG} in
@t{CFLAGS} while building. This can be achieved by setting
@t{USER_CFLAGS}:
......@@ -1210,12 +1264,12 @@ commented.
@c ==========================================================================
@node Older Diagnostics
@section Older Diagnostics
We introduced the diagnostic macros described above at the beginning
of March 2013. Earlier code used a less-structured approach, which
has later been removed. If you used @t{PP_PRINTF}, it's gone by now.
@c @node Older Diagnostics
@c @section Older Diagnostics
@c
@c We introduced the diagnostic macros described above at the beginning
@c of March 2013. Earlier code used a less-structured approach, which
@c has later been removed. If you used @t{PP_PRINTF}, it's gone by now.
@c ==========================================================================
@node Printf
......@@ -1229,15 +1283,16 @@ in its own subdirectory. Please check @i{pp_printf/README} for more
details about the size of this implementation and the different
implementation choices.
By avoiding calls to the real @i{printf} function we allow the PPSi
code base to be built for freestanding implementations without ugly
@t{#ifdef} tricks in the code. Please note that @i{pp_printf} and
By avoiding calls to the real @i{printf} function
the code base can be built for freestanding implementations without ugly
@t{#ifdef} tricks in the code.
Please note that @i{pp_printf} and
@i{printf} can coexist: for example the hosted version of PPSi links
with the standard library without any problem; in that case
@i{pp_printf} relies on @i{fputs} to write to @i{stdout}.
If your run-time environment already includes an implementation
of @i{pp_printf}, you can build with @t{CONFIG_NO_PRINTF} set. For
If a run-time environment already includes an implementation
of @i{pp_printf}, it can build with @t{CONFIG_NO_PRINTF} set. For
example:
@example
......@@ -1246,18 +1301,11 @@ example:
The resulting @t{ppsi.o} will include undefined references to the
@t{pp_printf} symbol, which must be provided externally. This is how
we build for @i{arch-wrpc}, which already includes its own
implementation if @i{pp_printf}. In that specific situation we still
link the @i{libc} provided by the compiler, but we don't want to lift
the build for @i{arch-wrpc} is done, which already includes its own
implementation of @i{pp_printf}. In that specific situation
the @i{libc} is provided by the compiler, but it is not using
its own @i{printf} which would bring in most of @i{newlib} and would
overflow our available RAM by a huge amount.
If your freestanding environment provides a @i{printf} that you want
to use, and which is not called @i{pp_printf}, you may use the
@t{PROVIDE} keyword in your linker script. You can find an example in
the @i{wrpc-sw} package, which maps @i{mprintf} to @i{pp_printf} at
link time, in order to accept external code that calls @i{mprintf},
which we don't provide any more.
overflow the available RAM by a huge amount.
@c ##########################################################################
@node Tools
......@@ -1341,8 +1389,8 @@ refers to a parallel port. When passed a pathname, the program assumes
it is a serial port and it toggles the DTR and RTS modem control signals
(on pins 4 and 7 of the DB9 male connector).
By setting the @t{VERBOSE} environment variable you ask the program
to report how late it was before and after generating the rising
By setting the @t{VERBOSE} environment variable the program
reports how late it was before and after generating the rising
edge:
@example
......@@ -1356,7 +1404,7 @@ edge:
@t{pps-out} can be used to verify on a scope the level of
synchronization of two or more computers, but please note that the
user-space software-only approach shows some jitter; on my systems the
user-space software-only approach shows some jitter; on example systems the
delay is usually a few microseconds, up to around a dozen (in general,
use of the parallel port has less delay and less jitter). In any case
this offers a second source to check what NTP or @sc{ptp} daemons report.
......@@ -1388,9 +1436,8 @@ that are bigger than 0.5ms, to avoid excessive reporting of false
positives that are simply due to process latencies induced by the
system workload.
By running this program you can see the effect of @i{tools/jmptime},
or the insertion of a leap second (which is why I wrote this program
in June 2012).
By running this program the user can see the effect of @i{tools/jmptime},
or the insertion of a leap second.
For example, this is what @i{chktime} reports when running
``@t{jmptime .002}''. The program doesn't need superuser privileges:
......@@ -1416,11 +1463,11 @@ Adjustments requested by this program cannot be reported by
than half a millisecond, because the change in clock speed affects
both @t{CLOCK_REALTIME} and @t{CLOCK_MONOTONIC}.
You can see adjustment in one host by comparing with the time of another
host, for example using @i{tools/mtp}, described next.
The adjustment can be seen in one host by comparing with the time of another
host, for example using @i{tools/mtp}, described in the next section.
The following example shows how on my host the kernel adjusts the time by
15ms every 30s (i.e. 0.05%):
The following example shows how on an example host the kernel adjusts the time
by 15ms every 30s (i.e. 0.05%):
@example
# ./tools/adjtime .15; sleep 30; ./tools/adjtime 0
......@@ -1440,7 +1487,7 @@ being used in the core PPSi program). It is meant to check adjustment
and get acquainted with the involved values.
The numerical argument of the system call is parts-per-million scaled
by 16 bits. So for example half @i{ppm} is passed as 32768.
by 16 bits. For example half @i{ppm} is passed as 32768.
The following are example uses of the program on an ntp-driven host:
......@@ -1460,20 +1507,21 @@ The following are example uses of the program on an ntp-driven host:
@node mtp
@section mtp
The directory @i{tools/mtp} includes a few example programs I wrote for
The directory @i{tools/mtp} includes a few example programs written by
Alessandro for
an article about time synchronization. MTP means ``mini time protocol'';
it uses the T1, T2, T3, T4 idea to report the time difference between
two hosts. The program comes in two flavors: UDP and raw Ethernet.
To run a listening server on one host, you can run the program in
To run a listening server on one host, run the program in
@i{listen} mode:
@example
tornado% ./tools/mtp/mtp_udp -l
@end example
On the other host, you can run the client that reports the time
difference it measures, you can pass either an IP address or an host
On the other host, run the client that reports the time
difference it measures, pass either an IP address or an host
name:
@example
......@@ -1481,8 +1529,8 @@ name:
0: rtt 0.000459000 delta 0.099351500
@end example
You can continuously monitor the difference by running the program in a
loop:
It is possible to continuously monitor the difference by running the program in
a loop:
@example
morgana% while true; do ./tools/mtp/mtp_udp tornado; sleep 0.1; done
......@@ -1500,9 +1548,7 @@ The @i{MAKEALL} script, in the top-level directory of PPSi builds the
program for all known configurations, picking them from @t{configs/}.
Developers are urged to run it
before committing each patch, to ensure they are not breaking the
program for configurations they are not using -- but sometimes I
forgot to do that myself and committed trivially-incomplete changes.
program for configurations they are not using.
It may happen, however, that some developers experience errors or
warnings that others didn't notice, because of differences in compiler
version or library versions.
......@@ -1537,8 +1583,8 @@ whatever it needs. Similarly, @t{CROSS_COMPILE} may be set by sub-Makefiles
but please let the environment override it (as no custom pathnames
should be edited before building and the pristine package can be used).
The basic state machine is in @i{./fsm.c}. It's a simple file released in
the public domain as we'd like the idea to be reused and the code
The basic state machine is in @i{./fsm.c}. It is a simple file released in
the public domain as authors would like the idea to be reused and the code
itself is not worth copylefting -- even thought the file is not completely
independent from PPSi itself.
......@@ -1548,8 +1594,8 @@ Additionally, "@t{CONFIG_PRINTF_XINT}" or one of the other @i{pp_printf}
configurations can be set to override the default. By default PPSi
builds the ``full'' implementation.
This state-machine source refers to a specific state machine by the
name @i{pp_state_table}. The table is picked from a
The state-machine source (i.e.@i{./fsm.c}) refers to a specific state machine
by the name @i{pp_state_table}. The table is picked from a
library: either from the extension being selected or the @i{proto-standard} one.
The table includes pointers to functions, and such names
will select which other object files are picked up from the libraries.
......@@ -1562,13 +1608,13 @@ leaving the final link to the chosen architecture, so for example
@i{arch-unix} adds @t{ppsi} to the @t{all} target.
Since code and data space is a problem in the freestanding world (for
example, the whole ptp may need to fit in 64kB RAM including data and
example, the whole PPSi may need to fit in 64kB RAM including data and
stack), each state in the state machine of the standard protocol must
be implemented as a separate file. This allows an extension not using
that particular function to save the overhead of binary size.
Clearly an extension may implement several functions in the same file,
if they are known to be all used in the final binary or of it uses
@t{-ffunction-sections} and @t{-fdata-sections}).
@t{-ffunction-sections} and @t{-fdata-sections}.
@c ##########################################################################
......@@ -1576,22 +1622,22 @@ if they are known to be all used in the final binary or of it uses
@chapter Licensing
The code is licensed according to the GNU LGPL, version 2.1 or later.
Some files are individually released to the public domain, when we
think they are especially simple or generic.
Some files are individually released to the public domain, when authors
thought they are especially simple or generic.
Both the full and the partial printf code is distributed according to
the GPL-2, as it comes from the Linux kernel. This means that any
code using our diagnostics fall under the GPL requirements; you may
compile and use the diagnostic code internally with your own
proprietary code but you can't distribute binaries with diagnostics
without the complete source code and associated rights. You may avoid
the GPL requirements by using different printf implementations; if so
we'd love to have them contributed back in the package.
code using PPSi's diagnostics fall under the GPL requirements; one may
compile and use the diagnostic code internally with own
proprietary code but it can not distribute binaries with diagnostics
without the complete source code and associated rights. One may avoid
the GPL requirements by using different printf implementations; in such case
please contribute back this into the package.
The same issue about the GPL license applies to the @i{div64_32}
function. We need this implementation in our @i{wrpc} code base
because the default @i{libgcc} division is very big, and we are always
tight with our in-FPGA memory space.
function. This implementation is needed in @i{wrpc} code base
because the default @i{libgcc} division is very big, and @i{wrpc} is always
tight with in-FPGA memory space.
For binaries without diagnostic code and the size-optimized division,
the LGPL applies, as detailed below.
......@@ -1601,9 +1647,9 @@ For licensing purposes, any `arch-name' or `time-name' subdirectory
themselves" (quoting the LPGL text).
Code in the directories provided here is all LGPL, and
you may add your own drop-in subdirectories. The LGPL requirements for
one may add own drop-in subdirectories. The LGPL requirements for
source distribution and associated permissions won't apply to any such
subdirectory that you may add, even if technically such code is not
subdirectory that might be added, even if technically such code is not
linked as a library.
@c ##########################################################################
......@@ -1613,7 +1659,7 @@ linked as a library.
The coding style is the one inherited from Linux kernel project (see
@i{Documentation/CodingStyle} in the kernel sources). However,
structures, constants and field names defined by @sc{ieee} 1588 are kept in
the suggested "CamelCase" form. Similarly, the typedefs are left, even
the suggested "camelCase" form. Similarly, the typedefs are left, even
if they are really a pain to deal with. Most of this stuff is in
include/ppsi/ieee1588_types.h file.
......@@ -1625,7 +1671,7 @@ Some prefixes to the @sc{ieee} naming are added, in order to improve
readability:
@t{EN} means "enumeration type". For instance, Enumeration Time Source
(defined in the spec at table 7, page 57) becomes @t{ENTimeSource}.
(defined in IEEE 1588-2008 at table 7, page 57) becomes @t{ENTimeSource}.
@t{PPM_} means "ppsi message", and is used for message types.
......@@ -1636,7 +1682,7 @@ definition.
@t{DS} means "data set", and is used for the standard Data Sets (e.g.
@i{DSCurrent} is the "Current Data Set"). The concept of data sets is
defined in the specification at chapter 8, page 63.
defined in IEEE 1588-2008 in chapter 8, page 63.
@c ##########################################################################
@node Command Line
......@@ -1651,17 +1697,12 @@ The command:
./ppsi --help
@end example
will print help about command line options (we also support the
will print help about command line options (it also support the
question-mark like the original ptp, but it's a bad choice because it
is a shell wildcard that should be escaped). Actually, all multi-char
options will print the help at this point in time, because we only
support since-char options; we don't want to rely on @i{getopt} which
is not available for all architectures, nor we want to implement
complex parsing.
@b{Note:} most current command-line options are going to be turned into
configuration options. This applies to the priorities, intervals and
thresholds, as well as the @i{slave-only} flag.
options will print the help at this point in time, because only
since-char options are supported. It is intended to avoid dependency on
@i{getopt} which is not available for all architectures.
For standard operation, simply run @t{./ppsi} with no options. It will
work like the PTPd executable, with the automatic choice of
......@@ -1683,16 +1724,17 @@ a list of the other ones please see the help message.
Pass a single configuration item, or several of them using
the semicolon as separator. See @ref{Configuration} for details.
@item -d
@item -d <string>
Diagnostics. This options receives the string of diagnostic
levels for fsm, time, frames, servo, bmc, extension (in that order).
See @ref{Diagnostic Macros} for details.
@item -e
@item -t
Do not adjust the system clock.
Run in Ethernet mode (by default PPSi uses UDP if the architecture
supports it).
@item -w NUMBER
specify meanDelay filter stiffness.
@item -g
......
......@@ -10,7 +10,7 @@
#define __WRH_H__
/* Please increment WRS_PPSI_SHMEM_VERSION if you change any exported data structure */
#define WRS_PPSI_SHMEM_VERSION 35
#define WRS_PPSI_SHMEM_VERSION 36
/* Don't include the Following when this file is included in assembler. */
#ifndef __ASSEMBLY__
......
......@@ -25,7 +25,8 @@ static struct cmd_line_opt cmd_line_list[] = {
{"-C CONFIG_ITEM", "set configuration options as stated in CONFIG_ITEM\n\t"
"CONFIG_ITEM must be a valid config string, enclosed by \" \""},
{"-f FILE", "read configuration file"},
{"-d STRING", "diagnostic level (see diag-macros.h)"},
{"-d STRING", "diagnostic level (see diag-macros.h)\n\t"
"FSM, Time, Frames, Servo, BMC, Extension, Configuration"},
CMD_LINE_SEPARATOR,
{"-t", "do not adjust the system clock"},
{"-w NUMBER", "specify meanDelay filter stiffness"},
......
......@@ -9,5 +9,6 @@
#ifndef __L1SYNC_EXT_CONSTANTS_H__
#define __L1SYNC_EXT_CONSTANTS_H__
#define TLV_TYPE_L1_SYNC 0x8001u
#endif /* __L1SYNC_EXT_CONSTANTS_H__ */
......@@ -6,6 +6,7 @@
*/
#include <ppsi/ppsi.h>
#include "l1e-constants.h"
#define MSG_OFFSET_HEADER 0u
#define MSG_OFFSET_HEADER_MESSAGE_LENGTH (MSG_OFFSET_HEADER+2u)
......
......@@ -147,6 +147,29 @@ static unsigned long bare_calc_timeout(struct pp_instance *ppi, int millisec)
return now_ms + millisec;
}
static int bare_get_GM_lock_state(struct pp_globals *ppg,
pp_timing_mode_state_t *state)
{
*state = PP_TIMING_MODE_STATE_LOCKED;
return 0;
}
static int bare_enable_timing_output(struct pp_globals *ppg, int enable)
{
static int prev_enable = 0;
if (prev_enable != enable) {
pp_diag(NULL, time, 2, "%s dummy timing output\n",
enable ? "enable" : "disable");
prev_enable = enable;
return 0;
}
return 0;
}
struct pp_time_operations bare_time_ops = {
.get_utc_time = bare_time_get_utc_time,
.get_utc_offset = bare_time_get_utc_offset,
......@@ -158,4 +181,6 @@ struct pp_time_operations bare_time_ops = {
.adjust_offset = bare_time_adjust_offset,
.adjust_freq = bare_time_adjust_freq,
.calc_timeout = bare_calc_timeout,
.get_GM_lock_state = bares_get_GM_lock_state,
.enable_timing_output = bare_enable_timing_output
};
......@@ -144,8 +144,26 @@ static unsigned long sim_calc_timeout(struct pp_instance *ppi, int millisec)
return millisec + SIM_PPI_ARCH(ppi)->time.current_ns / 1000LL / 1000LL;
}
static int sim_get_GM_lock_state(struct pp_globals *ppg,
pp_timing_mode_state_t *state)
{
*state = PP_TIMING_MODE_STATE_LOCKED;
return 0;
}
static int sim_enable_timing_output(struct pp_globals *ppg, int enable)
{
static int prev_enable = 0;
if (prev_enable != enable) {
pp_diag(NULL, time, 2, "%s dummy timing output\n",
enable ? "enable" : "disable");
prev_enable = enable;
return 0;
}
return 0;
}
......@@ -161,5 +179,6 @@ const struct pp_time_operations sim_time_ops = {
.adjust_freq = sim_adjust_freq,
.init_servo = sim_init_servo,
.calc_timeout = sim_calc_timeout,
.get_GM_lock_state = sim_get_GM_lock_state,
.enable_timing_output = sim_enable_timing_output
};
......@@ -22,7 +22,7 @@
#include <ppsi/ppsi.h>
#include "ptpdump.h"
#include "../arch-unix/ppsi-unix.h"
#include "../arch-unix/include/ppsi-unix.h"
/* unix_recv_msg uses recvmsg for timestamp query */
static int unix_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
......
......@@ -11,6 +11,7 @@
#include <time.h>
#include <sys/timex.h>
#include <ppsi/ppsi.h>
#include "../arch-unix/include/ppsi-unix.h"
#ifndef MOD_TAI
#define MOD_TAI 0x80
......@@ -280,6 +281,29 @@ static unsigned long unix_calc_timeout(struct pp_instance *ppi, int millisec)
return now_ms + millisec;
}
static int unix_get_GM_lock_state(struct pp_globals *ppg,
pp_timing_mode_state_t *state)
{
*state = PP_TIMING_MODE_STATE_LOCKED;
return 0;
}
static int unix_enable_timing_output(struct pp_globals *ppg, int enable)
{
static int prev_enable = 0;
if (prev_enable != enable) {
pp_diag(NULL, time, 2, "%s dummy timing output\n",
enable ? "enable" : "disable");
prev_enable = enable;
return 0;
}
return 0;
}
const struct pp_time_operations unix_time_ops = {
.get_utc_time = unix_time_get_utc_time,
.get_utc_offset = unix_time_get_utc_offset,
......@@ -291,5 +315,6 @@ const struct pp_time_operations unix_time_ops = {
.adjust_freq = unix_time_adjust_freq,
.init_servo = unix_time_init_servo,
.calc_timeout = unix_calc_timeout,
.get_GM_lock_state = unix_get_GM_lock_state,
.enable_timing_output = unix_enable_timing_output
};
......@@ -431,10 +431,11 @@ static int wrs_time_get(struct pp_instance *ppi, struct pp_time *t)
static int wrs_time_set(struct pp_instance *ppi, const struct pp_time *t)
{
if ( WRS_ARCH_I(ppi)->timingMode==WRH_TM_GRAND_MASTER) {
// Grand master mode
// We delegate the time setup to the wr_date tool has
// it can take time to adjust the time
system("/wr/bin/wr_date -v set host &");
/* Grand master mode
* We delegate the time setup to the wr_date script as it can
* take time to adjust the time. Let it know that we call it
* from the ppsi */
system("/etc/init.d/wr_date ppsi &");
} else {
struct pp_time diff, now;
int msec;
......
/*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdio.h>
#include <string.h>
#include "ptpdump.h"
#include <ppsi/ieee1588_types.h> /* from ../include */
#include "decent_types.h"
#include <ppsi/lib.h>
#include "../proto-ext-whiterabbit/wr-constants.h"
#include "../proto-ext-l1sync/l1e-constants.h"
#define WR_MODE_ON_MASK 0x8
#define CALIBRATED_MASK 0x4
#define WR_CONFIG_MASK 0x3
static int dump_vlan(char *prefix, int vlan);
static int dumpstruct(char *p1, char *p2, char *name, void *ptr, int size)
{
int ret, i;
unsigned char *p = ptr;
ret = printf("%s%s%s (size %i)\n", p1, p2, name, size);
for (i = 0; i < size; ) {
if ((i & 0xf) == 0)
ret += printf("%s%s", p1, p2);
ret += printf("%02x", p[i]);
i++;
ret += printf(i & 3 ? " " : i & 0xf ? " " : "\n");
}
if (i & 0xf)
ret += printf("\n");
return ret;
}
#if __STDC_HOSTED__
static void dump_time(char *prefix, const struct pp_time *t)
{
struct timeval tv;
struct tm tm;
tv.tv_sec = t->secs;
tv.tv_usec = (t->scaled_nsecs >> 16) / 1000;
localtime_r(&tv.tv_sec, &tm);
printf("%sTIME: (%li - 0x%lx) %02i:%02i:%02i.%06li%s\n", prefix,
tv.tv_sec, tv.tv_sec,
tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec,
is_incorrect(t) ? " invalid" : "");
}
#else
static void dump_time(char *prefix, const struct pp_time *t)
{
printf("%sTIME: (%li - 0x%lx) %li.%06li%s\n", prefix,
(long)t->secs, (long)t->secs, (long)t->secs,
(long)(t->scaled_nsecs >> 16) / 1000,
is_incorrect(t) ? " invalid" : "");
}
#endif
/* Returns the header size, used by the caller to adjust the next pointer */
static int dump_eth(char *prefix, struct ethhdr *eth)
{
unsigned char *d = eth->h_dest;
unsigned char *s = eth->h_source;
int proto = ntohs(eth->h_proto);
int ret;
char mac_s[20];
char mac_d[20];
/* Between eth header and payload may be a VLAN tag;
* NOTE: We cannot distinguish between both cases looking at
* the content of a vlan variable, because vlan number may come from
* frame itself or from the socket (CMSG) */
if (proto == 0x8100) {
ret = sizeof(struct pp_vlanhdr); /* ETH header + VLAN tag */
/* Get the proto knowing that there is a VLAN tag */
proto = ntohs(((struct pp_vlanhdr *)eth)->h_proto);
} else
ret = sizeof(struct ethhdr);
printf("%sETH: %04x (%s -> %s)\n", prefix, proto,
format_mac(mac_s, s),
format_mac(mac_d, d));
return ret;
}
static void dump_ip(char *prefix, struct iphdr *ip)
{
unsigned int s = ntohl(ip->saddr);
unsigned int d = ntohl(ip->daddr);
printf("%sIP: %i (%i.%i.%i.%i -> %i.%i.%i.%i) len %i\n", prefix,
ip->protocol,
(s >> 24) & 0xff, (s >> 16) & 0xff, (s >> 8) & 0xff, s & 0xff,
(d >> 24) & 0xff, (d >> 16) & 0xff, (d >> 8) & 0xff, d & 0xff,
ntohs(ip->tot_len));
}
static void dump_udp(char *prefix, struct udphdr *udp)
{
printf("%sUDP: (%i -> %i) len %i\n", prefix,
ntohs(udp->source), ntohs(udp->dest), ntohs(udp->len));
}
/* Helpers for fucking data structures */
static void dump_1stamp(char *prefix, char *s, struct stamp *t)
{
uint64_t sec = (uint64_t)(ntohs(t->sec.msb)) << 32;
sec |= (uint64_t)(ntohl(t->sec.lsb));
printf("%s%s%lu.%09i\n", prefix,
s, (unsigned long)sec, (int)ntohl(t->nsec));
}
static void dump_1quality(char *prefix, char *s, ClockQuality *q)
{
printf("%s%s%02x-%02x-%04x\n", prefix, s, (unsigned int) q->clockClass,
(unsigned int) q->clockAccuracy, (unsigned int) q->offsetScaledLogVariance);
}
static void dump_1clockid(char *prefix, char *s, ClockIdentity i)
{
printf("%s%s%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n", prefix, s,
i.id[0], i.id[1], i.id[2], i.id[3],
i.id[4], i.id[5], i.id[6], i.id[7]);
}
static void dump_1port(char *prefix, char *s, unsigned char *p)
{
printf("%s%s%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\n",
prefix, s,
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9]);
}
/* Helpers for each message types */
static void dump_msg_announce(char *prefix, struct ptp_announce *p)
{
ClockQuality grandmasterClockQuality;
memcpy( &grandmasterClockQuality,&p->grandmasterClockQuality, sizeof(ClockQuality));
grandmasterClockQuality.offsetScaledLogVariance=ntohs(grandmasterClockQuality.offsetScaledLogVariance);
dump_1stamp(prefix, "MSG-ANNOUNCE: stamp ",
&p->originTimestamp);
dump_1quality(prefix, "MSG-ANNOUNCE: grandmaster-quality ",
&grandmasterClockQuality);
printf("%sMSG-ANNOUNCE: grandmaster-prio %i %i\n", prefix,
p->grandmasterPriority1, p->grandmasterPriority2);
dump_1clockid(prefix, "MSG-ANNOUNCE: grandmaster-id ",
p->grandmasterIdentity);
}
static void dump_msg_sync_etc(char *prefix, char *s, struct ptp_sync_etc *p)
{
dump_1stamp(prefix, s, &p->stamp);
}
static void dump_msg_resp_etc(char *prefix, char *s, struct ptp_sync_etc *p)
{
dump_1stamp(prefix, s, &p->stamp);
dump_1port(prefix, s, p->port);
}
/* TLV dumper, now white-rabbit aware */
static int wr_dump_tlv(char *prefix, struct ptp_tlv *tlv, int totallen)
{
/* the field includes 6 bytes of the header, ecludes 4 of them. Bah! */
int explen = ntohs(tlv->len) + 4;
#ifdef CONFIG_PROFILE_WR
{
static char *wr_message_name[] = {
"SLAVE_PRESENT",
"LOCK",
"LOCKED",
"CALIBRATE",
"CALIBRATED",
"WR_MODE_ON",
};
uint16_t messageId;
char *messageId_str = NULL;
if (ntohs(tlv->type) != TLV_TYPE_ORG_EXTENSION
|| memcmp(tlv->oui, "\x08\x00\x30", 3) /* WR_TLV_ORGANIZATION_ID */
/* WR_TLV_MAGIC_NUMBER, WR_TLV_WR_VERSION_NUMBER */
|| memcmp(tlv->subtype, "\xDE\xAD\x01", 3)
) {
return 0;
}
printf("%sTLV: type %04x len %i oui %02x:%02x:%02x "
"sub %02x:%02x:%02x\n", prefix, ntohs(tlv->type), explen,
tlv->oui[0], tlv->oui[1], tlv->oui[2],
tlv->subtype[0], tlv->subtype[1], tlv->subtype[2]);
if (explen > totallen) {
printf("%sTLV: too short (expected %i, total %i)\n", prefix,
explen, totallen);
return totallen;
}
messageId = (tlv->data[0] << 8) + tlv->data[1];
if (SLAVE_PRESENT <= messageId && messageId <= WR_MODE_ON)
messageId_str = wr_message_name[messageId - SLAVE_PRESENT];
if (messageId == ANN_SUFIX)
messageId_str = "ANN_SUFIX";
if (messageId_str) {
printf("%sTLV: messageId %s(0x%x)\n", prefix, messageId_str,
messageId);
switch(messageId){
case SLAVE_PRESENT:
case LOCK:
case LOCKED:
case WR_MODE_ON:
/* no more to be printed */
break;
case CALIBRATE:
if (totallen < 8 || explen < 8) { /* 2+1+1+4 */
printf("%sTLV: too short (expected %i, total "
"%i)\n", prefix, explen, totallen);
return totallen;
}
printf("%sTLV: calSendPattern %s, calRetry %u, "
"calPeriod %d\n",
prefix,
tlv->data[2] ? "True":"False",
tlv->data[3],
(tlv->data[4] << 24) + (tlv->data[5] << 16)
+ (tlv->data[6] << 8) + tlv->data[7]
);
break;
case CALIBRATED:
/* TODO: print as ints */
if (totallen < 18 || explen < 18) { /* 2+8+8 */
printf("%sTLV: too short (expected %i, total "
"%i)\n", prefix, explen, totallen);
return totallen;
}
dumpstruct(prefix, "TLV: ", "deltaTx", &tlv->data[2],
8);
dumpstruct(prefix, "TLV: ", "deltaRx", &tlv->data[10],
8);
break;
case ANN_SUFIX:
{
int flags = tlv->data[3]; /* data[2] is unused */
char *wr_config_str;
if (totallen < 4 || explen < 4) { /* 2+2 */
printf("%sTLV: too short (expected %i, total "
"%i)\n", prefix, explen, totallen);
return totallen;
}
switch (flags & WR_CONFIG_MASK) {
case NON_WR:
wr_config_str = "NON_WR";
break;
case WR_S_ONLY:
wr_config_str = "WR_S_ONLY";
break;
case WR_M_ONLY:
wr_config_str = "WR_M_ONLY";
break;
case WR_M_AND_S:
wr_config_str = "WR_M_AND_S";
break;
default:
wr_config_str="";
break;
}
printf("%sTLV: wrFlags: wrConfig %s, calibrated %s, "
"wrModeOn %s\n",
prefix,
wr_config_str,
flags & CALIBRATED_MASK ? "True":"False",
flags & WR_MODE_ON_MASK ? "True":"False"
);
break;
}
}
}
return explen;
}
#else
return 0;
#endif
}
static int l1sync_dump_tlv(char *prefix, struct l1sync_tlv *tlv, int totallen)
{
int explen = ntohs(tlv->len) + 4;
if ( CONFIG_HAS_EXT_L1SYNC ) {
if (ntohs(tlv->type) != TLV_TYPE_L1_SYNC) {
/* Non L1Sync TLV */
return 0;
}
printf("%sTLV: type %04x len %i conf %02x act %02x\n",
prefix,
ntohs(tlv->type), explen,
(int) tlv->config,
(int) tlv->active);
if (explen > totallen) {
printf("%sTLV: too short (expected %i, total %i)\n", prefix,
explen, totallen);
return totallen;
}
/* Now dump non-l1sync tlv in binary, count only payload */
if (ntohs(tlv->len) > explen - sizeof(*tlv))
dumpstruct(prefix, "TLV: ", "tlv-content",
tlv->data, explen - sizeof(*tlv));
return explen;
} else
return 0;
}
/* Dump unknown TLV */
static int unknown_dump_tlv(char *prefix, struct ptp_tlv *tlv, int totallen)
{
int tlv_len = ntohs(tlv->len);
int explen = tlv_len + 4;
printf("%sTLV: Unknown, type %04x len %i\n",
prefix,
ntohs(tlv->type), tlv_len);
if (explen > totallen) {
printf("%sTLV: too short (expected %i, total %i)\n", prefix,
explen, totallen);
return totallen;
}
/* Now dump non-wr tlv in binary, count only payload */
if (tlv_len > explen - sizeof(*tlv))
dumpstruct(prefix, "TLV: ", "tlv-content",
tlv->data, explen - sizeof(*tlv));
return tlv_len + 4;
}
/* A big function to dump the ptp information */
static void dump_payload(char *prefix, void *pl, int len)
{
struct ptp_header *h = pl;
void *msg_specific = (void *)(h + 1);
int donelen = 34; /* packet length before tlv */
int version = h->versionPTP_and_reserved & 0xf;
int messageType = h->type_and_transport_specific & 0xf;
char *cfptr = (void *)&h->correctionField;
if (version != 2) {
printf("%sVERSION: unsupported (%i)\n", prefix, version);
goto out;
}
printf("%sVERSION: %i (type %i, len %i, domain %i)\n", prefix,
version, messageType,
ntohs(h->messageLength), h->domainNumber);
printf("%sFLAGS: 0x%02x%02x (correction 0x%08x:%08x %08u)\n",
prefix, (unsigned) h->flagField[0],(unsigned) h->flagField[1],
ntohl(*(int *)cfptr),
ntohl(*(int *)(cfptr + 4)),
ntohl(*(int *)(cfptr + 4)));
dump_1port(prefix, "PORT: ", h->sourcePortIdentity);
printf("%sREST: seq %i, ctrl %i, log-interval %i\n", prefix,
ntohs(h->sequenceId), h->controlField, h->logMessageInterval);
#define CASE(t, x) case PPM_ ##x: printf("%sMESSAGE: (" #t ") " #x "\n", prefix)
switch(messageType) {
CASE(E, SYNC);
dump_msg_sync_etc(prefix, "MSG-SYNC: ", msg_specific);
donelen = 44;
break;
CASE(E, DELAY_REQ);
dump_msg_sync_etc(prefix, "MSG-DELAY_REQ: ", msg_specific);
donelen = 44;
break;
CASE(G, FOLLOW_UP);
dump_msg_sync_etc(prefix, "MSG-FOLLOW_UP: ", msg_specific);
donelen = 44;
break;
CASE(G, DELAY_RESP);
dump_msg_resp_etc(prefix, "MSG-DELAY_RESP: ", msg_specific);
donelen = 54;
break;
CASE(G, ANNOUNCE);
dump_msg_announce(prefix, msg_specific);
donelen = 64;
break;
CASE(G, SIGNALING);
dump_1port(prefix, "MSG-SIGNALING: target-port ", msg_specific);
donelen = 44;
break;
#if __STDC_HOSTED__ /* Avoid pdelay dump within ppsi, we don't use it */
CASE(E, PDELAY_REQ);
dump_msg_sync_etc(prefix, "MSG-PDELAY_REQ: ", msg_specific);
donelen = 54;
break;
CASE(E, PDELAY_RESP);
dump_msg_resp_etc(prefix, "MSG-PDELAY_RESP: ", msg_specific);
donelen = 54;
break;
CASE(G, PDELAY_R_FUP);
dump_msg_resp_etc(prefix, "MSG-PDELAY_RESP_FOLLOWUP: ",
msg_specific);
donelen = 54;
break;
CASE(G, MANAGEMENT);
/* FIXME */
break;
#endif
}
/*
* Dump any trailing TLV, but ignore a trailing 2-long data hunk.
* The trailing zeroes appear with less-than-minimum Eth messages.
*/
while (donelen < len && len - donelen > 2) {
int n = len - donelen;
int ret;
switch ( messageType) {
case PPM_ANNOUNCE :
if ((ret = wr_dump_tlv(prefix, pl + donelen, n))) {
donelen += ret;
} else {
donelen += unknown_dump_tlv(prefix, pl + donelen, n);
}
break;
case PPM_SIGNALING :
if ((ret = l1sync_dump_tlv(prefix, pl + donelen, n))) {
donelen += ret;
} else if ((ret = wr_dump_tlv(prefix, pl + donelen, n))) {
donelen += ret;
} else {
/* Unknown TLV */
donelen += unknown_dump_tlv(prefix, pl + donelen, n);
}
break;
default :
goto out;
}
}
out:
/* Finally, binary dump of it all */
dumpstruct(prefix, "DUMP: ", "payload", pl, len);
}
/* This dumps a complete udp frame, starting from the eth header */
int dump_udppkt(char *prefix, void *buf, int len, const struct pp_time *t,
int vlan)
{
struct ethhdr *eth = buf;
struct iphdr *ip;
struct udphdr *udp;
void *payload;
if (t)
dump_time(prefix, t);
dump_vlan(prefix, vlan);
ip = buf + dump_eth(prefix, eth);
dump_ip(prefix, ip);
udp = (void *)(ip + 1);
dump_udp(prefix, udp);
payload = (void *)(udp + 1);
dump_payload(prefix, payload, len - (payload - buf));
return 0;
}
/* This dumps the payload only, used for udp frames without headers */
int dump_payloadpkt(char *prefix, void *buf, int len, const struct pp_time *t)
{
if (t)
dump_time(prefix, t);
dump_payload(prefix, buf, len);
return 0;
}
/* This dumps everything, used for raw frames with headers and ptp payload */
int dump_1588pkt(char *prefix, void *buf, int len, const struct pp_time *t,
int vlan)
{
struct ethhdr *eth = buf;
void *payload;
if (t)
dump_time(prefix, t);
dump_vlan(prefix, vlan);
payload = buf + dump_eth(prefix, eth);
dump_payload(prefix, payload, len - (payload - buf));
return 0;
}
static int dump_vlan(char *prefix, int vlan)
{
if (vlan >= 0)
printf("%sVLAN %i\n", prefix, vlan);
return 0;
}
......@@ -6,6 +6,7 @@
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <unistd.h>
static unsigned long unix_calc_timeout(void)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment