Commit 370b6f7f authored by Adam Wujek's avatar Adam Wujek

[FEATURE: #53] allow overwrite of the used PTP version

Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 3cf6cbbe
......@@ -132,6 +132,8 @@ int wrc_ptp_init(void)
/* copy default ppi config */
memcpy(&ppi->cfg, &__pp_default_instance_cfg, sizeof(__pp_default_instance_cfg));
ppi->ext_hooks =&pp_hooks; /* default value */
ppi->cfg.versionNumber = PP_VERSION_PTP;
ppi->cfg.minorVersionNumber = PP_MINOR_VERSION_PTP;
#if CONFIG_HAS_EXT_L1SYNC
ppi->protocol_extension = PPSI_EXT_L1S;
ppi->ext_hooks = &l1e_ext_hooks;
......@@ -142,6 +144,8 @@ int wrc_ptp_init(void)
L1E_DSPOR_BS(ppi)->rxCoherentIsRequired = TRUE;
L1E_DSPOR_BS(ppi)->txCoherentIsRequired = TRUE;
L1E_DSPOR_BS(ppi)->congruentIsRequired = TRUE;
ppi->cfg.versionNumber = PP_VERSION_PTP_HA;
ppi->cfg.minorVersionNumber = PP_MINOR_VERSION_PTP_HA;
#endif
#if CONFIG_HAS_EXT_WR
ppi->protocol_extension = PPSI_EXT_WR;
......@@ -149,6 +153,8 @@ int wrc_ptp_init(void)
ppi->ext_data = &wr_ext_data;
ppi->portDS->ext_dsport = &wr_dsport;
ppi->cfg.versionNumber = PP_VERSION_PTP_WR;
ppi->cfg.minorVersionNumber = PP_MINOR_VERSION_PTP_WR;
#endif
/* egressLatency and ingressLatency are overwritten on ptp_start */
......
......@@ -24,6 +24,7 @@
#include <minipc.h>
#include <ppsi/ppsi.h>
#include <ppsi/set-param.h>
#include <ppsi-wrs.h>
#include <libwr/shmem.h>
......@@ -254,6 +255,8 @@ static int set_extension(struct pp_instance *ppi, int extension)
break;
}
set_param_ptpVersion(ppi);
return 0;
}
......
......@@ -814,6 +814,19 @@ Some old keywords will be marked '@i{(deprecated)}', and will be removed in the
@item @t{udp} -- User Datagram Protocol
@end itemize
@item @b{ptpVersion} @i{[TextList]}
Defines PTP version number to be used for in all messages on a port
(@i{versionNumber} and @i{minorVersionNumber}):
@itemize @bullet
@item @t{default} -- Use the PTP according to the selected @i{extension}.
If no extension or @i{L1Sync} is used, PTP version is
set to v2.1 (IEEE1588-2019). If @i{White Rabbit}
extension is used then PTP version is set to
v2.0 (IEEE1588-2008).
@item @t{2.0} -- Force the use of PTP v2.0 (IEEE1588-2008)
@item @t{2.1} -- Force the use of v2.1 (IEEE1588-2019)
@end itemize
@item @b{scaledDelayCoefficient} @i{[Int64,Unit=RelativeDifference]]}
Defines the relative delay coefficient (alpha parameter).
When the feature '@i{asymmetryCorrectionEnable}' is enabled, this value
......
......@@ -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 36
#define WRS_PPSI_SHMEM_VERSION 37
/* Don't include the Following when this file is included in assembler. */
#ifndef __ASSEMBLY__
......
......@@ -107,6 +107,11 @@ struct pp_argline {
OPTION(struct pp_instance,func,k,t,NULL,cfg,1) \
OPTION_CLOSE()
#define INST_OPTION_FCT_NAMES(func,k,t,a) \
OPTION_OPEN() \
OPTION(struct pp_instance,func,k,t,a,cfg,1) \
OPTION_CLOSE()
#define INST_OPTION_STR(k,field) \
INST_OPTION(f_string,k,ARG_STR,NULL,field)
......@@ -149,7 +154,12 @@ struct pp_argline {
OPTION(struct pp_runtime_opts,func,k,t,a,field,0)\
OPTION_CLOSE()
#define RT_OPTION_FCT(func,k,t,a,field) \
#define RT_OPTION_FCT(func,k,t,field) \
OPTION_OPEN() \
OPTION(struct pp_runtime_opts,func,k,t,NULL,field,0) \
OPTION_CLOSE()
#define RT_OPTION_FCT_NAMES(func,k,t,a,field) \
OPTION_OPEN() \
OPTION(struct pp_runtime_opts,func,k,t,a,field,0) \
OPTION_CLOSE()
......
......@@ -161,7 +161,14 @@
#define PP_ALTERNATE_MASTER_FLAG 1
#define PP_TWO_STEP_FLAG 2
#define PP_VERSION_PTP 2
#define PP_MINOR_VERSION_PTP 0
#define PP_MINOR_VERSION_PTP 1
#define PP_MINOR_VERSION_PTP_0 0
#define PP_MINOR_VERSION_PTP_1 1
#define PP_VERSION_PTP_WR PP_VERSION_PTP
#define PP_MINOR_VERSION_PTP_WR PP_MINOR_VERSION_PTP_0
#define PP_VERSION_PTP_HA PP_VERSION_PTP
#define PP_MINOR_VERSION_PTP_HA PP_MINOR_VERSION_PTP_1
#define PP_HEADER_LENGTH 34
#define PP_ANNOUNCE_LENGTH 64
......
......@@ -193,6 +193,8 @@ struct pp_instance_cfg {
Boolean masterOnly; /* masterOnly */
Boolean asymmetryCorrectionEnable; /* asymmetryCorrectionPortDS.enable */
Boolean extAutonegEnable; /* extension autonegotiation (HA/WR) */
int versionNumber;
int minorVersionNumber;
};
/*
......
/*
* Copyright (C) 2023 CERN (www.cern.ch)
* Author: Adam Wujek
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#ifndef _PPSI_SET_PARAM_H_
#define _PPSI_SET_PARAM_H_
void set_param_ptpVersion(struct pp_instance *ppi);
#endif /* _PPSI_SET_PARAM_H_ */
......@@ -500,6 +500,41 @@ static int f_logMinPdelayReqInterval(struct pp_argline *l, int lineno,
return 0;
}
static int f_ptpVersion(struct pp_argline *l, int lineno,
struct pp_globals *ppg, union pp_cfg_arg *arg)
{
struct pp_instance *ppi;
if (ppg->cfg.cur_ppi_n < 0) {
pp_printf("Warning: ptpVersion can only be defined for an "
"instance (line %d)\n", lineno);
return -1;
}
ppi = CUR_PPI(ppg);
switch(arg->i) {
case PP_MINOR_VERSION_PTP_0:
case PP_MINOR_VERSION_PTP_1:
ppi->cfg.versionNumber = 2; /* same as PP_VERSION_PTP */
ppi->cfg.minorVersionNumber = arg->i;
break;
/* Use default PTP version (based on extension) */
case -1:
ppi->cfg.versionNumber = 0;
ppi->cfg.minorVersionNumber = 0;
return 0;
default:
ppi->cfg.versionNumber = 0;
ppi->cfg.minorVersionNumber = 0;
return -1;
}
return 0;
}
/* These are the tables for the parser */
static struct pp_argname arg_proto[] = {
{"raw", PPSI_PROTO_RAW},
......@@ -578,6 +613,13 @@ static struct pp_argname arg_bmca[] = {
{},
};
static struct pp_argname arg_ptpVersion[] = {
{"default", -1},
{"2.0", PP_MINOR_VERSION_PTP_0},
{"2.1", PP_MINOR_VERSION_PTP_1},
{},
};
static struct pp_argline pp_global_arglines[] = {
INST_OPTION_FCT(f_port, "link port", ARG_STR),
INST_OPTION_FCT(f_servo_pi, "servo-pi", ARG_INT2),
......@@ -596,6 +638,7 @@ static struct pp_argline pp_global_arglines[] = {
PP_MIN_ANNOUNCE_RECEIPT_TIMEOUT,PP_MAX_ANNOUNCE_RECEIPT_TIMEOUT),
INST_OPTION_FCT(f_logMinDelayReqInterval, "min-delay-req-interval logMinDelayReqInterval", ARG_INT),
INST_OPTION_FCT(f_logMinPdelayReqInterval, "min-pdelay-req-interval logMinPDelayReqInterval", ARG_INT),
INST_OPTION_FCT_NAMES(f_ptpVersion, "ptpVersion", ARG_NAMES, arg_ptpVersion),
#if CONFIG_HAS_EXT_L1SYNC
INST_OPTION_INT_RANGE("l1sync-interval logL1SyncInterval", ARG_INT, NULL, cfg.l1syncInterval,
......@@ -644,7 +687,7 @@ static struct pp_argline pp_global_arglines[] = {
RT_OPTION_INT_RANGE("gmDelayToGenPpsSec", ARG_INT, NULL, gmDelayToGenPpsSec,
PP_MIN_GM_DELAY_TO_GEN_PPS_SEC, PP_MAX_GM_DELAY_TO_GEN_PPS_SEC),
#if !CONFIG_HAS_CODEOPT_EPC_ENABLED && !CONFIG_HAS_CODEOPT_SO_ENABLED
RT_OPTION_FCT(f_bmca, "bmca", ARG_NAMES, arg_bmca, bmca),
RT_OPTION_FCT_NAMES(f_bmca, "bmca", ARG_NAMES, arg_bmca, bmca),
RT_OPTION_BOOL("slaveOnly",slaveOnly),
#else
#if CONFIG_HAS_CODEOPT_EPC_ENABLED
......
......@@ -20,6 +20,7 @@ OBJ-y += $D/fsm-table.o \
$D/msg.o \
$D/msg-p2p.o \
$D/servo.o \
$D/set-param.o \
$D/hooks.o \
$D/open-close.o
......
/*
* Copyright (C) 2024 CERN (www.cern.ch)
* Author: Adam Wujek
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <ppsi/ppsi.h>
#include <ppsi/set-param.h>
void set_param_ptpVersion(struct pp_instance *ppi)
{
/* If cfg.versionNumber is set use it, if not set version based on
* the used extension */
if (ppi->cfg.versionNumber) {
ppi->portDS->versionNumber = ppi->cfg.versionNumber;
ppi->portDS->minorVersionNumber = ppi->cfg.minorVersionNumber;
pp_diag(ppi, config, 3, "PTP version for port wri%d is set "
"manually to %d.%d\n",
ppi->port_idx + 1, ppi->cfg.versionNumber,
ppi->cfg.minorVersionNumber);
return;
}
switch (ppi->protocol_extension) {
#if CONFIG_HAS_EXT_WR
case PPSI_EXT_WR:
ppi->portDS->versionNumber = PP_VERSION_PTP_WR;
ppi->portDS->minorVersionNumber = PP_MINOR_VERSION_PTP_WR;
break;
#endif
#if CONFIG_HAS_EXT_L1SYNC
case PPSI_EXT_L1S:
ppi->portDS->versionNumber = PP_VERSION_PTP_HA;
ppi->portDS->minorVersionNumber = PP_MINOR_VERSION_PTP_HA;
break;
#endif
case PPSI_EXT_NONE:
ppi->portDS->versionNumber = PP_VERSION_PTP;
ppi->portDS->minorVersionNumber = PP_MINOR_VERSION_PTP;
break;
default:
break;
}
pp_diag(ppi, config, 3, "PTP version for port wri%d set to %d.%d based "
"on the used extension\n",
ppi->port_idx + 1, ppi->portDS->versionNumber,
ppi->portDS->minorVersionNumber);
return;
}
......@@ -7,6 +7,7 @@
*/
#include <ppsi/ppsi.h>
#include <ppsi/set-param.h>
/*
* Initialize parentDS
......@@ -104,8 +105,9 @@ int pp_initializing(struct pp_instance *ppi, void *buf, int len)
&DSDEF(ppi)->clockIdentity, PP_CLOCK_IDENTITY_LENGTH);
/* 1-based port number = index of this ppi in the global array */
port->portIdentity.portNumber = 1 + ppi - ppi->glbs->pp_instances;
port->versionNumber = PP_VERSION_PTP;
port->minorVersionNumber = PP_MINOR_VERSION_PTP;
/* Set PTP version depending on the set extension */
set_param_ptpVersion(ppi);
/* Init timers */
port->logAnnounceInterval=(Integer8)ppi->cfg.announce_interval;
......
......@@ -302,6 +302,9 @@ struct dump_info dump_ppsi_info[] = {
DUMP_FIELD_SIZE(char, cfg.iface_name, 16),
DUMP_FIELD(ppi_profile, cfg.profile),
DUMP_FIELD(delay_mechanism, cfg.delayMechanism),
DUMP_FIELD(UInteger4, cfg.versionNumber),
DUMP_FIELD(UInteger4, cfg.minorVersionNumber),
/* FIXME: other fields from cfg */
DUMP_FIELD(unsigned_long, ptp_tx_count),
......
......@@ -341,6 +341,8 @@ struct dump_info ppi_info [] = {
DUMP_FIELD_SIZE(char, cfg.port_name, 16),
DUMP_FIELD_SIZE(char, cfg.iface_name, 16),
DUMP_FIELD(ppi_profile, cfg.profile),
DUMP_FIELD(int, cfg.versionNumber),
DUMP_FIELD(int, cfg.minorVersionNumber),
DUMP_FIELD(int, cfg.announce_interval),
DUMP_FIELD(int, cfg.announce_receipt_timeout),
DUMP_FIELD(int, cfg.sync_interval),
......
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