port.twoStepFlag.

When -1, inherit the global twoStepFlag value, otherwise enable two-step mode
for sync messages on port basis. One-step mode can be used only with hardware
time stamping. The default is -1 (as global twoStepFlag value).
---
 config.c |  1 +
 port.c   | 40 +++++++++++++++++++++++++++++++++++++++-
 ptp4l.8  |  4 ++++
 3 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/config.c b/config.c
index 4472d3d..13dcea8 100644
--- a/config.c
+++ b/config.c
@@ -291,6 +291,7 @@ struct config_item config_tab[] = {
        GLOB_ITEM_DBL("pi_proportional_exponent", -0.3, -DBL_MAX, DBL_MAX),
        GLOB_ITEM_DBL("pi_proportional_norm_max", 0.7, DBL_MIN, 1.0),
        GLOB_ITEM_DBL("pi_proportional_scale", 0.0, 0.0, DBL_MAX),
+       PORT_ITEM_INT("port.twoStepFlag", -1, -1, 1),
        GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
        GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
        GLOB_ITEM_STR("productDescription", ";;"),
diff --git a/port.c b/port.c
index 10bb9e1..95ce77a 100644
--- a/port.c
+++ b/port.c
@@ -3028,6 +3028,42 @@ err:
        msg_put(msg);
 }
 
+static enum timestamp_type port_harmonize_onestep(struct port *p, enum 
timestamp_type timestamping, int portTwoStepFlag)
+{
+       if (portTwoStepFlag < 0) {
+               // As global
+               return timestamping;
+       }
+
+       switch (timestamping) {
+       case TS_SOFTWARE:
+       case TS_LEGACY_HW:
+               if (!portTwoStepFlag) {
+                       pr_err("%s: one step is only possible "
+                              "with hardware time stamping", p->log_name);
+                       return timestamping;
+               }
+               break;
+       case TS_HARDWARE:
+               if (!portTwoStepFlag) {
+                       pr_debug("%s: upgrading to one step time stamping "
+                                "in order to match the port.twoStepFlag", 
p->log_name);
+                       return TS_ONESTEP;
+               }
+               break;
+       case TS_ONESTEP:
+       case TS_P2P1STEP:
+               if (portTwoStepFlag) {
+                       pr_debug("%s: degrading to two step time stamping, "
+                                    "in order to match the port.twoStepFlag", 
p->log_name);
+                       return TS_HARDWARE;
+               }
+               break;
+       }
+
+       return timestamping;
+}
+
 struct port *port_open(const char *phc_device,
                       int phc_index,
                       enum timestamp_type timestamping,
@@ -3039,6 +3075,7 @@ struct port *port_open(const char *phc_device,
        struct config *cfg = clock_config(clock);
        struct port *p = malloc(sizeof(*p));
        int i;
+       int portTwoStepFlag;
 
        if (!p) {
                return NULL;
@@ -3134,7 +3171,8 @@ struct port *port_open(const char *phc_device,
        p->tx_timestamp_offset <<= 16;
        p->link_status = LINK_UP;
        p->clock = clock;
-       p->timestamping = timestamping;
+       portTwoStepFlag = config_get_int(cfg, p->name, "port.twoStepFlag");
+       p->timestamping = port_harmonize_onestep(p, timestamping, 
portTwoStepFlag);
        p->portIdentity.clockIdentity = clock_identity(clock);
        p->portIdentity.portNumber = number;
        p->state = PS_INITIALIZING;
diff --git a/ptp4l.8 b/ptp4l.8
index fe9e150..65edf54 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -143,6 +143,10 @@ See UNICAST DISCOVERY OPTIONS, below.
 .SH PORT OPTIONS
 
 .TP
+.B port.twoStepFlag
+When -1, inherit the global twoStepFlag value, otherwise enable two-step mode
+for sync messages on port basis. One-step mode can be used only with hardware
+time stamping. The default is -1 (as global twoStepFlag value).
 .B delayAsymmetry
 The time difference in nanoseconds of the transmit and receive
 paths. This value should be positive when the server-to-client
-- 
2.31.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to