dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone
3b72dd
Backported commit f774703cb1eee058a346aec3341fee0be329bd6d
3b72dd
Author: Karthikkumar V <kvaloor@altiostar.com>
3b72dd
Date:   Fri Feb 26 06:54:07 2021 +0000
3b72dd
3b72dd
    Clock Class Threshold Feature addition for PTP4L
3b72dd
    
3b72dd
    This code changes brings in the ability to program the acceptable
3b72dd
    clockClass threshold beyond which device will move to holdover/free-run.
3b72dd
    Default clockClass threshold is 248.
3b72dd
    Example Use-Case:
3b72dd
    This is needed in the cases where T-SC/T-BC Slave might want to listen
3b72dd
    only on PRC clockCLass and anything beyond that might not be acceptible
3b72dd
    and would want to go to holdover (with SyncE backup or internal oscillator).
3b72dd
    
3b72dd
    Signed-off-by: Karthikkumar V <kvaloor@altiostar.com>
3b72dd
    Signed-off-by: Ramana Reddy <rreddy@altiostar.com>
3b72dd
3b72dd
diff --git a/clock.c b/clock.c
3b72dd
index c1fcff6..d584748 100644
3b72dd
--- a/clock.c
3b72dd
+++ b/clock.c
3b72dd
@@ -114,6 +114,7 @@ struct clock {
3b72dd
 	int utc_offset;
3b72dd
 	int time_flags;  /* grand master role */
3b72dd
 	int time_source; /* grand master role */
3b72dd
+	UInteger8 clock_class_threshold;
3b72dd
 	UInteger8 max_steps_removed;
3b72dd
 	enum servo_state servo_state;
3b72dd
 	enum timestamp_type timestamping;
3b72dd
@@ -978,6 +979,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 	c->default_dataset.localPriority =
3b72dd
 		config_get_int(config, NULL, "G.8275.defaultDS.localPriority");
3b72dd
 	c->max_steps_removed = config_get_int(config, NULL,"maxStepsRemoved");
3b72dd
+	c->clock_class_threshold = config_get_int(config, NULL, "clock_class_threshold");
3b72dd
 
3b72dd
 	/* Harmonize the twoStepFlag with the time_stamping option. */
3b72dd
 	if (config_harmonize_onestep(config)) {
3b72dd
@@ -1711,6 +1713,11 @@ UInteger8 clock_max_steps_removed(struct clock *c)
3b72dd
 	return c->max_steps_removed;
3b72dd
 }
3b72dd
 
3b72dd
+UInteger8 clock_get_clock_class_threshold(struct clock *c)
3b72dd
+{
3b72dd
+	return c->clock_class_threshold;
3b72dd
+}
3b72dd
+
3b72dd
 UInteger16 clock_steps_removed(struct clock *c)
3b72dd
 {
3b72dd
 	return c->cur.stepsRemoved;
3b72dd
diff --git a/clock.h b/clock.h
3b72dd
index e7daf97..845d54f 100644
3b72dd
--- a/clock.h
3b72dd
+++ b/clock.h
3b72dd
@@ -289,6 +289,13 @@ int clock_slave_only(struct clock *c);
3b72dd
  */
3b72dd
 UInteger8 clock_max_steps_removed(struct clock *c);
3b72dd
 
3b72dd
+/**
3b72dd
+ * Obtain the clock class threshold field from a clock's default data set.
3b72dd
+ * @param c  The clock instance.
3b72dd
+ * @return   Configured clock class threshold value.
3b72dd
+ */
3b72dd
+UInteger8 clock_get_clock_class_threshold(struct clock *c);
3b72dd
+
3b72dd
 /**
3b72dd
  * Obtain the steps removed field from a clock's current data set.
3b72dd
  * @param c  The clock instance.
3b72dd
diff --git a/config.c b/config.c
3b72dd
index c3deddb..bf1049f 100644
3b72dd
--- a/config.c
3b72dd
+++ b/config.c
3b72dd
@@ -231,6 +231,7 @@ struct config_item config_tab[] = {
3b72dd
 	GLOB_ITEM_INT("clockAccuracy", 0xfe, 0, UINT8_MAX),
3b72dd
 	GLOB_ITEM_INT("clockClass", 248, 0, UINT8_MAX),
3b72dd
 	GLOB_ITEM_STR("clockIdentity", "000000.0000.000000"),
3b72dd
+	GLOB_ITEM_INT("clock_class_threshold", CLOCK_CLASS_THRESHOLD_DEFAULT, 6, CLOCK_CLASS_THRESHOLD_DEFAULT),
3b72dd
 	GLOB_ITEM_ENU("clock_servo", CLOCK_SERVO_PI, clock_servo_enu),
3b72dd
 	GLOB_ITEM_ENU("clock_type", CLOCK_TYPE_ORDINARY, clock_type_enu),
3b72dd
 	GLOB_ITEM_ENU("dataset_comparison", DS_CMP_IEEE1588, dataset_comp_enu),
3b72dd
diff --git a/configs/default.cfg b/configs/default.cfg
3b72dd
index 9604219..b2ffa94 100644
3b72dd
--- a/configs/default.cfg
3b72dd
+++ b/configs/default.cfg
3b72dd
@@ -60,6 +60,7 @@ verbose			0
3b72dd
 summary_interval	0
3b72dd
 kernel_leap		1
3b72dd
 check_fup_sync		0
3b72dd
+clock_class_threshold	248
3b72dd
 #
3b72dd
 # Servo Options
3b72dd
 #
3b72dd
diff --git a/ds.h b/ds.h
3b72dd
index 9d9c417..dff6d5e 100644
3b72dd
--- a/ds.h
3b72dd
+++ b/ds.h
3b72dd
@@ -87,6 +87,7 @@ struct parent_ds {
3b72dd
 
3b72dd
 #define CURRENT_UTC_OFFSET  37 /* 1 Jan 2017 */
3b72dd
 #define INTERNAL_OSCILLATOR 0xA0
3b72dd
+#define CLOCK_CLASS_THRESHOLD_DEFAULT 248
3b72dd
 
3b72dd
 struct timePropertiesDS {
3b72dd
 	Integer16    currentUtcOffset;
3b72dd
diff --git a/port.c b/port.c
3b72dd
index 2bb974c..eb3b319 100644
3b72dd
--- a/port.c
3b72dd
+++ b/port.c
3b72dd
@@ -1870,6 +1870,14 @@ int process_announce(struct port *p, struct ptp_message *m)
3b72dd
 		return result;
3b72dd
 	}
3b72dd
 
3b72dd
+	if (m->announce.grandmasterClockQuality.clockClass >
3b72dd
+		clock_get_clock_class_threshold(p->clock)) {
3b72dd
+		pl_err(60, "port %hu: Master clock quality received is "
3b72dd
+			"greater than configured, ignoring master!",
3b72dd
+			portnum(p));
3b72dd
+		return result;
3b72dd
+	}
3b72dd
+
3b72dd
 	switch (p->state) {
3b72dd
 	case PS_INITIALIZING:
3b72dd
 	case PS_FAULTY:
3b72dd
diff --git a/ptp4l.8 b/ptp4l.8
3b72dd
index b04936a..ca76175 100644
3b72dd
--- a/ptp4l.8
3b72dd
+++ b/ptp4l.8
3b72dd
@@ -455,6 +455,11 @@ message is greater than or equal to the value of maxStepsRemoved the
3b72dd
 Announce message is not considered in the operation of the BMCA.
3b72dd
 The default value is 255.
3b72dd
 .TP
3b72dd
+.B clock_class_threshold
3b72dd
+The maximum clock class value from master, acceptible to sub-ordinate
3b72dd
+clock beyond which it moves out of lock state.
3b72dd
+The default value is 248.
3b72dd
+.TP
3b72dd
 
3b72dd
 .B domainNumber
3b72dd
 The domain attribute of the local clock.