>From 532e29347d80695db45e5b59e979a954d0e7238b Mon Sep 17 00:00:00 2001
From: Erez Geva <erez.geva....@siemens.com>
Date: Thu, 14 Jun 2018 11:27:45 +0200
Subject: [PATCH] config: Add hardware time stamp filter setting mode

Add global option for the hardware time stamp setting.
The function could:
Normally set the filters as the PTP daemon require.
Check that the filters are proper but do not change them.
Full, set the RX filter to all and the TX filter as the PTP daemon require.

Signed-off-by: Erez Geva <erez.geva....@siemens.com>
---
 config.c |  8 ++++++++
 ptp4l.8  |  9 +++++++++
 ptp4l.c  |  1 +
 sk.c     | 36 ++++++++++++++++++++++++++++++------
 sk.h     | 15 +++++++++++++++
 5 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/config.c b/config.c
index 98e8f1c..669c1db 100644
--- a/config.c
+++ b/config.c
@@ -163,6 +163,13 @@ static struct config_enum delay_mech_enu[] = {
        { NULL, 0 },
 };
 
+static struct config_enum hwts_filter_enu[] = {
+       { "normal",  HWTS_FILTER_NORMAL  },
+       { "check",   HWTS_FILTER_CHECK   },
+       { "full",    HWTS_FILTER_FULL    },
+       { NULL, 0 },
+};
+
 static struct config_enum nw_trans_enu[] = {
        { "L2",    TRANS_IEEE_802_3 },
        { "UDPv4", TRANS_UDP_IPV4   },
@@ -214,6 +221,7 @@ struct config_item config_tab[] = {
        GLOB_ITEM_INT("G.8275.defaultDS.localPriority", 128, 1, UINT8_MAX),
        PORT_ITEM_INT("G.8275.portDS.localPriority", 128, 1, UINT8_MAX),
        GLOB_ITEM_INT("gmCapable", 1, 0, 1),
+       GLOB_ITEM_ENU("hwts_filter", HWTS_FILTER_NORMAL, hwts_filter_enu),
        PORT_ITEM_INT("hybrid_e2e", 0, 0, 1),
        PORT_ITEM_INT("ignore_transport_specific", 0, 0, 1),
        PORT_ITEM_INT("ingressLatency", 0, INT_MIN, INT_MAX),
diff --git a/ptp4l.8 b/ptp4l.8
index ae6e491..fb4a306 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -624,6 +624,15 @@ The time source is a single byte code that gives an idea 
of the kind
 of local clock in use. The value is purely informational, having no
 effect on the outcome of the Best Master Clock algorithm, and is
 advertised when the clock becomes grand master.
+.TP
+.B hwts_filter
+Select the hardware time stamp filter setting mode.
+Possible values are normal, check, full.
+Normal mode set the filters as needed.
+Check mode only check but do not set.
+Full mode set the receive filter to mark all packets with hardware time stamp,
+ so all applications can get them.
+The default is normal.
 
 .SH TIME SCALE USAGE
 
diff --git a/ptp4l.c b/ptp4l.c
index 9ef8169..3a9f084 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -191,6 +191,7 @@ int main(int argc, char *argv[])
        assume_two_step = config_get_int(cfg, NULL, "assume_two_step");
        sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync");
        sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout");
+       sk_hwts_filter_mode = config_get_int(cfg, NULL, "hwts_filter");
 
        if (config_get_int(cfg, NULL, "clock_servo") == CLOCK_SERVO_NTPSHM) {
                config_set_int(cfg, "kernel_leap", 0);
diff --git a/sk.c b/sk.c
index f18b2bf..d799cce 100644
--- a/sk.c
+++ b/sk.c
@@ -40,6 +40,7 @@
 
 int sk_tx_timeout = 1;
 int sk_check_fupsync;
+enum hwts_filter_mode sk_hwts_filter_mode = HWTS_FILTER_NORMAL;
 
 /* private methods */
 
@@ -51,16 +52,39 @@ static int hwts_init(int fd, const char *device, int 
rx_filter, int tx_type)
 
        memset(&ifreq, 0, sizeof(ifreq));
        memset(&cfg, 0, sizeof(cfg));
+       memset(&req, 0, sizeof(req));
 
        strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name) - 1);
 
        ifreq.ifr_data = (void *) &cfg;
-       cfg.tx_type    = tx_type;
-       cfg.rx_filter  = rx_filter;
-       req = cfg;
-       err = ioctl(fd, SIOCSHWTSTAMP, &ifreq);
-       if (err < 0)
-               return err;
+
+       req.tx_type   = tx_type;
+       req.rx_filter = rx_filter;
+
+       switch (sk_hwts_filter_mode) {
+       case HWTS_FILTER_CHECK:
+               err = ioctl(fd, SIOCGHWTSTAMP, &ifreq);
+               if (err < 0) {
+                       pr_err("ioctl SIOCGHWTSTAMP failed: %m");
+                       return err;
+               }
+               break;
+       case HWTS_FILTER_FULL:
+               cfg.tx_type   = tx_type;
+               cfg.rx_filter = HWTSTAMP_FILTER_ALL;
+               err = ioctl(fd, SIOCSHWTSTAMP, &ifreq);
+               if (err < 0)
+                       return err;
+               break;
+       default:
+       case HWTS_FILTER_NORMAL:
+               cfg.tx_type   = tx_type;
+               cfg.rx_filter = rx_filter;
+               err = ioctl(fd, SIOCSHWTSTAMP, &ifreq);
+               if (err < 0)
+                       return err;
+               break;
+       }
 
        if (memcmp(&cfg, &req, sizeof(cfg))) {
 
diff --git a/sk.h b/sk.h
index d91d5d8..a35ee43 100644
--- a/sk.h
+++ b/sk.h
@@ -23,6 +23,16 @@
 #include "address.h"
 #include "transport.h"
 
+/**
+ * Defines the available Hardware time-stamp setting modes.
+ */
+
+enum hwts_filter_mode {
+       HWTS_FILTER_NORMAL,    /* set hardware filters in normal way */
+       HWTS_FILTER_CHECK,     /* check filters but do not change them */
+       HWTS_FILTER_FULL,      /* Use time-stamp on all received packets */
+};
+
 /**
  * Contains timestamping information returned by the GET_TS_INFO ioctl.
  * @valid:            set to non-zero when the info struct contains valid data.
@@ -131,4 +141,9 @@ extern int sk_tx_timeout;
  */
 extern int sk_check_fupsync;
 
+/**
+ * Hardware time-stamp setting mode
+ */
+enum hwts_filter_mode sk_hwts_filter_mode;
+
 #endif
-- 
2.17.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to