Re: [Linuxptp-devel] Is intel i350 ptp driver broken?

2023-05-26 Thread Richard Cochran
On Fri, May 26, 2023 at 03:02:43PM +0800, egg car wrote:

> It's a bit complicated to use, I see why they use 'struct timecounter'
> instead of hardware PHC
> counter, and in this case all the timestamp regs cannot be used directly.
> Needs more time to find out how to fix this, either the driver or 'ts2phc'
> program.

Don't try to "fix" ts2phc.  That won't make the device driver work any better.

Thanks,
Richard




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


Re: [Linuxptp-devel] [PATCH] clock: Fix summary interval in free-running mode.

2023-05-20 Thread Richard Cochran
On Thu, May 18, 2023 at 04:26:54PM +0200, Miroslav Lichvar wrote:
> In the free-running mode the stats are updated only once per the
> frequency estimation interval instead of once per sync message. The
> stats max_count calculation didn't account for that, which caused a
> reduced rate of printed summaries. Fix the calculation for this case.
> 
> Signed-off-by: Miroslav Lichvar 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Avoid switching PHC when phc_index is negative

2023-05-20 Thread Richard Cochran
On Tue, May 16, 2023 at 05:10:07PM +0300, Eyal Itkin via Linuxptp-devel wrote:
> A Boundary Clock might choose to switch a PHC when jbod is active,
> and the transition will be based on the port's phc_index. However,
> when using the slave event monitoring + free_running the phc_index
> is -1, thus causing a fault in the transition.
> 
> Hence, avoid switching the PHC in case phc_index is negative.
> 
> Signed-off-by: Eyal Itkin 
> Reviewed-by: Rahul Rameshbabu 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH 1/1] clock: Fix best master log message when D0 is better than Erbest

2023-05-20 Thread Richard Cochran
On Sun, Mar 12, 2023 at 09:07:04PM -0400, Vincent Cheng wrote:
> When local clock data set is better than remote server, log message says 
> remote
> server is best master.

The message means that the given clock was selected as best from among
the foreign clocks.

>  The port states are correct.
> 
> ex. local clock is clock class 6 and remote server on port 1 is clock class 7.
> 
>   ptp4l[5709.306]: selected best master clock 080027.fffe.fd
>   ptp4l[5709.306]: port 1 (enp0s8): assuming the grand master role

I agree that the message could be confusing.  Maybe we should change
it to: "best foreign clock is 080027.fffe.fd" ?

> @@ -2179,7 +2179,7 @@ static void handle_state_decision_event(struct clock *c)
>   best = fc;
>   }
>  
> - if (best) {
> + if (best && c->dscmp(>dataset, clock_default_ds(c)) > 0) {
>   best_id = best->dataset.identity;

I won't take this patch, because 'best_id' is used later on in this
function, and it isn't clear whether this change affects the logic.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Avoid switching PHC while free_running

2023-05-16 Thread Richard Cochran
On Tue, May 16, 2023 at 01:34:56PM +, Eyal Itkin wrote:
> Our use case is using the Slave Event Monitoring feature alongside 
> free_running so to implement an external servo - on a BC with jbod.

I would encourage you to contribute the servo.  After all, the code is
modular with PI, linear regulator, etc...

> Alternatively, we saw that a similar commit
> (fd94d9af9f82e410574a05e672e3f92b7c165655) was merged recently to
> include a check for a negative phc_index. If it is preferred, we can
> adjust our commit to include a similar check (negative phc_index vs
> free_running) given that the use of a negative phc_index is the
> de-facto bug we are trying to fix.

Sure.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Fix port_nrate_calculate first ingress sampling after clock jump.

2023-05-12 Thread Richard Cochran
On Tue, Apr 04, 2023 at 12:32:57PM +0800, Merlin He wrote:
> port_nrate_calculate() sampling the first ingress1 before slave clock
> jumping, if the offset of master and slave is too large, this may
> results in an extremly small nrate_ratio value, and cause the nagative
> delay issue.

I don't understand the issue.

Can you provide an example how to reproduce it?

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Avoid switching PHC while free_running

2023-05-12 Thread Richard Cochran
On Mon, May 01, 2023 at 02:17:21PM +0300, Eyal Itkin via Linuxptp-devel wrote:
> A Boundary Clock might choose to switch a PHC when jbod is active,
> and the transition will be based on the port's phc_index. However,
> while free_running the phc_index is -1, thus causing a fault in the
> transition.

Seems like BC and free_running is a contradiction in terms.

What is the use case?

Thanks,
Richard




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


[Linuxptp-devel] [PATCH] ts2phc: Fix memory leak on initial error path.

2023-05-10 Thread Richard Cochran
The ts2phc program keeps track of the allocated configuration in its
"private" data structure, duly freeing it during the cleanup method.
However, the assignment of the priv.cfg field occurs after many
possible calls to the ts2phc_cleanup() function, resulting in a memory
leak.  Fix the issue by assigning the field prior to the first
invocation of the cleanup method.

Signed-off-by: Richard Cochran 
---
 ts2phc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ts2phc.c b/ts2phc.c
index db5ea3f..3d3 100644
--- a/ts2phc.c
+++ b/ts2phc.c
@@ -577,6 +577,7 @@ int main(int argc, char *argv[])
ts2phc_cleanup();
return -1;
}
+   priv.cfg = cfg;
priv.agent = pmc_agent_create();
if (!priv.agent) {
ts2phc_cleanup();
@@ -662,7 +663,6 @@ int main(int argc, char *argv[])
print_set_level(config_get_int(cfg, NULL, "logging_level"));
 
STAILQ_INIT();
-   priv.cfg = cfg;
 
snprintf(uds_local, sizeof(uds_local), "/var/run/ts2phc.%d",
 getpid());
-- 
2.30.2



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


Re: [Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-05-10 Thread Richard Cochran
On Sun, Apr 30, 2023 at 01:50:34PM -0700, Richard Cochran wrote:
> Thanks for finding this.  I'd like to fix it in a simpler way.

FWIW I am going ahead with my patch.

@Miroslav it changes the default value for one field, and so the test
suite would need the following change.

Thanks,
Richard

---
diff --git a/20-pmc b/20-pmc
index e585897..3d1ef27 100755
--- a/20-pmc
+++ b/20-pmc
@@ -337,13 +337,13 @@ requests_replies=(
version   0
grandmasterID 0x
grandmasterTimeInaccuracy 4294967295
-   networkTimeInaccuracy 0
+   networkTimeInaccuracy 4294967295
totalTimeInaccuracy   4294967295
123456.fffe.780102-2 seq 0 RESPONSE MANAGEMENT 
POWER_PROFILE_SETTINGS_NP 
version   0
grandmasterID 0x
grandmasterTimeInaccuracy 4294967295
-   networkTimeInaccuracy 0
+   networkTimeInaccuracy 4294967295
totalTimeInaccuracy   4294967295"
 )
 


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


Re: [Linuxptp-devel] [PATCH v2 1/1] msg: append TLV onto all PTP event messages

2023-05-09 Thread Richard Cochran
On Tue, May 09, 2023 at 09:43:11AM +0800, Tan Tee Min wrote:
> According to IEEE Std 1588-2019 Chapter 6.4 PTP message classes,
> all PTP messages can be extended by means of a standard Type,
> Length, Value (TLV) extension mechanism.
> 
> Avnu conformance tests for 802.1AS-2020 do validate whether the device
> can properly ignore unknown TLVs in received PTP messages.
> 
> With the present code, we observed "bad message" error when the device
> receives Sync, Pdelay_Req and Pdelay_Resp event messages with unknown TLV
> appended. This error is due to PTP event messages are not enabled/allowed
> to carry TLV yet.
> 
> To fix the problem, we have to append TLV onto the PTP event messages.
> 
> v2: Fix commit message
> 
> Signed-off-by: Tan Tee Min 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Fix detection of VLAN over bond support in case the driver does not support SIOCGHWTSTAMP ioctl.

2023-05-09 Thread Richard Cochran
On Mon, May 08, 2023 at 05:17:57PM +0800, Hangbin Liu wrote:
> On Tue, May 2, 2023 at 10:56 PM Martin Pecka  wrote:
> >
> > Fixes issue "Bug caused by commit afeabf3 "ptp4l: add VLAN over bond 
> > support" on kernel 4.9" reported on linuxptp-devel.
> >
> > SIOCGHWTSTAMP ioctl is optional according to Linux timestamping.txt 
> > document, but the code failed to set any HW timestamping when the ioctl was 
> > actually not supported. For now, VLAN over bond support requires that the 
> > driver supports SIOCGHWTSTAMP ioctl (but this limitation can be removed in 
> > the future).
> >
> > Signed-off-by: Martin Pecka 
> 
> Acked-by: Hangbin Liu 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] sk: Reset timestamping mode on exit, use locks

2023-05-09 Thread Richard Cochran
On Tue, May 09, 2023 at 02:02:05PM +0200, Andrew Zaborowski wrote:
> Per https://www.kernel.org/doc/Documentation/networking/timestamping.txt
> section 3:
> "User space is responsible to ensure that multiple processes don't interfere
> with each other and that the settings are reset."
> 
> Add locking for the interface's HW timestamping mode to ensure that in a
> setup with multiple ptp4l sessions sharing interfaces the sessions don't
> overwrite each other's timestamping mode and that there is one session
> responsible for resetting the mode on exit.

We already have a way to implement "sessions don't overwrite each
other's timestamping mode and that there is one session responsible
for resetting the mode on exit."

   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.

How do you use that?

1. Set mode globally using hwstamp_ctl
2. Start ptp4l with --hwts_filter=check
3. done.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] sk: Reset timestamping mode on exit, use locks

2023-05-09 Thread Richard Cochran
On Tue, May 09, 2023 at 02:02:05PM +0200, Andrew Zaborowski wrote:
> Per https://www.kernel.org/doc/Documentation/networking/timestamping.txt
> section 3:
> "User space is responsible to ensure that multiple processes don't interfere
> with each other and that the settings are reset."
> 
> Add locking for the interface's HW timestamping mode to ensure that in a
> setup with multiple ptp4l sessions sharing interfaces the sessions don't
> overwrite each other's timestamping mode and that there is one session
> responsible for resetting the mode on exit.

This functionality really belongs in the kernel.  Only the kernel can
arbitrate sharing of hardware resources.

If you really think such functionality is needed, please take it to
netdev or lkml.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v2 1/1] msg: append TLV onto all PTP event messages

2023-05-09 Thread Richard Cochran
On Tue, May 09, 2023 at 01:35:59PM +, Woojung.Huh--- via Linuxptp-devel 
wrote:
> Do I miss or misunderstand something?

The intent of the standards appears to be to allow TLVs on any PTP
message.

Thanks,
Richard





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


Re: [Linuxptp-devel] [PATCH 1/1] msg: append TLV onto all PTP event messages

2023-05-08 Thread Richard Cochran
On Mon, May 08, 2023 at 05:46:30PM +0800, Tan Tee Min wrote:

> We are working towards the Avnu conformance tests for 802.1AS-2020, and
> actually Avnu do validate whether the device can properly ignore unknown
> TLVs in received PTP messages.
> 
> Without this implementation, we observe "bad message" error when the device
> receives Sync, Pdelay_Req and Pdelay_Resp event messages with unknown TLV
> appended.

This is important information.  You need to put that into your commit
log message, as it explains the reason why your change is needed.

A proper commit log message contains three elements:

1. Context
2. Problem
3. Solution

Your log message only gave the Context.
It failed to state the problem or the solution.

Thanks,
Richard


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


Re: [Linuxptp-devel] Bug caused by commit afeabf3 "ptp4l: add VLAN over bond support" on kernel 4.9

2023-05-01 Thread Richard Cochran
On Mon, May 01, 2023 at 06:29:59PM +0200, Martin Pecka wrote:

> > A driver which supports hardware time stamping must support the
> > SIOCSHWTSTAMP ioctl and update the supplied struct hwtstamp_config with
> > the actual values as described in the section on SIOCSHWTSTAMP.  It
> > should also support SIOCGHWTSTAMP.
> The support for SIOCGHWTSTAMP is optional.
> 
> So it seems to me wrong to test for the bonded PHC support using this ioctl,
> which is only optional.

+1

> 1. Check errno not only for EINVAL, but also for EOPNOTSUPP. This would
> solve the issue for me (and Jetsons in general), but would probably leave
> some users with bonded PHCs whose drivers do not support SIOCGHWTSTAMP
> without the possibility to use the bonded PHC.

+1

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Clear pending errors on sockets.

2023-04-30 Thread Richard Cochran
On Wed, Apr 26, 2023 at 02:44:27PM +0200, Miroslav Lichvar wrote:
> When the netlink socket of a port (used for receiving link up/down
> events) had an error (e.g. ENOBUFS due to the kernel sending too many
> messages), ptp4l switched the port to the faulty state, but it kept
> getting POLLERR on the socket and logged "port 1: unexpected socket
> error" in an infinite loop.
> 
> Unlike the PTP event and general sockets, the netlink sockets cannot be
> closed in the faulty state as they are needed to receive the link up event.
> 
> Instead, receive and clear the error on all descriptors getting POLLERR
> with getsockopt(SO_ERROR).

Never seen that before.  Learn something new every day...

> Include the error in the log message together
> with the descriptor index to make it easier to debug issues like this in
> future.
> 
> Signed-off-by: Miroslav Lichvar 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] Bug caused by commit afeabf3 "ptp4l: add VLAN over bond support" on kernel 4.9

2023-04-30 Thread Richard Cochran
On Thu, Mar 30, 2023 at 11:16:44AM +0800, Hangbin Liu wrote:
> Richard, what do you think?

This code in hwts_init is wrong:

cfg.flags = HWTSTAMP_FLAG_BONDED_PHC_INDEX;
/* Fall back without flag if user run new build on old kernel */
if (ioctl(fd, SIOCGHWTSTAMP, ) == -EINVAL)
init_ifreq(, , device);

As `man ioctl` says:

 RETURN VALUE
   Usually, on success zero is returned.  A few ioctl() requests  use  the
   return  value  as an output parameter and return a nonnegative value on
   success.  On error, -1 is returned, and errno is set appropriately.

So I think what you meant to write is this:

cfg.flags = HWTSTAMP_FLAG_BONDED_PHC_INDEX;
err = ioctl(fd, SIOCGHWTSTAMP, );
if (err < 0) {
/* Fall back without flag if user run new build on old kernel */
if (errno == EINVAL) {
init_ifreq(, , device);
} else {
pr_err("ioctl SIOCGHWTSTAMP failed: %m");
return err;
}
}

@Martin would that also fix your issue?

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Fix power profile config option range to UINT32_MAX

2023-04-30 Thread Richard Cochran
On Mon, Apr 24, 2023 at 12:21:57PM -0700, Jacob Keller wrote:
> The power profile configuration options added in commit 7059a05a3fb2
> ("Introduce the power profile.") specify their maximum range as INT_MAX.
> The values are stored as UInteger32 values and the default value is
> 0x. On most platforms, a signed integer cannot hold 0x, and
> on these platforms ptp4l is unable to read the default configuration file:
> 
>   $ ./ptp4l -f configs/default.cfg -i eno0
>   0x is an out of range value for option 
> power_profile.2011.grandmasterTimeInaccuracy at line 44
>   failed to parse configuration file configs/default.cfg

Jacob,

Thanks for finding this.  I'd like to fix it in a simpler way.
Do you agree?

Thanks,
Richard

---
>From 5cfba921f9bf1f97028c5f999c399e9bb554cfd7 Mon Sep 17 00:00:00 2001
From: Richard Cochran 
Date: Sun, 30 Apr 2023 13:32:06 -0700
Subject: [PATCH] power profile: Fix regression in the default configuration
 file.

The recently added power profile introduced a regression when reading
the default configuration file:

  $ ./ptp4l -f configs/default.cfg -m -q
  0x is an out of range value for option 
power_profile.2011.grandmasterTimeInaccuracy at line 44
  failed to parse configuration file configs/default.cfg

Root cause is the fact that the value 0x exceeds the range of
the signed, four byte integer used in the configuration logic.

Considering that the power profile's "Inaccuracy" field uses
0x as a special value meaning "unknown", expand the range
of these options to include -1 as that special value.

Fixes: 7059a05a3fb2182e851217c8872cf47126ec4c4c ("Introduce the power profile.")
Reported-by: Jacob Keller 
Signed-off-by: Richard Cochran 
---
 config.c| 6 +++---
 configs/default.cfg | 6 +++---
 ptp4l.8 | 7 +++
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/config.c b/config.c
index cb4421f..b104f1b 100644
--- a/config.c
+++ b/config.c
@@ -309,9 +309,9 @@ struct config_item config_tab[] = {
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_ENU("power_profile.version", IEEE_C37_238_VERSION_NONE, 
ieee_c37_238_enu),
-   PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0x, 0, INT_MAX),
-   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
INT_MAX),
-   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
INT_MAX),
+   PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0x, -1, INT_MAX),
+   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0x, 
-1, INT_MAX),
+   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, -1, 
INT_MAX),
PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
diff --git a/configs/default.cfg b/configs/default.cfg
index a21ec66..00429b9 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -41,9 +41,9 @@ BMCAptp
 inhibit_announce0
 inhibit_delay_req   0
 ignore_source_id0
-power_profile.2011.grandmasterTimeInaccuracy   0x
-power_profile.2011.networkTimeInaccuracy   0
-power_profile.2017.totalTimeInaccuracy 0x
+power_profile.2011.grandmasterTimeInaccuracy   -1
+power_profile.2011.networkTimeInaccuracy   -1
+power_profile.2017.totalTimeInaccuracy -1
 power_profile.grandmasterID0
 power_profile.version  none
 #
diff --git a/ptp4l.8 b/ptp4l.8
index bb678c9..09ff108 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -365,22 +365,21 @@ the interface, or the device specified by the \fB-p\fP 
option.
 Specifies the time inaccuracy of the GM in nanoseconds.  Relevant only
 when power_profile.version is 2011.  This value may be changed
 dynamically using the POWER_PROFILE_SETTINGS_NP management message.
-The default is 0x.
+The default is -1 meaning unknown inaccuracy.
 
 .TP
 .B power_profile.2011.networkTimeInaccuracy
 Specifies the time inaccuracy of the network in nanoseconds.  Relevant
 only when power_profile.version is 2011.  This value may be changed
 dynamically using the POWER_PROFILE_SETTINGS_NP management message.
-The default is 0x.
+The default is -1 meaning unknown inaccuracy.
 
 .TP
 .B power_profile.2017.totalTimeInaccuracy
 Specifies the sum of the GM, network, and local node inaccuracies in
 nanoseconds.  Relevant only when power_profile.version is 2017.  This
 value may be changed dynamically using the POWER_PROFILE_SETTINGS_NP
-management message.  The default is 0x meaning unkno

Re: [Linuxptp-devel] bugs when reading ptp4l configuration files

2023-04-30 Thread Richard Cochran
On Wed, Mar 29, 2023 at 11:30:49AM -0700, Jacob Keller wrote:

> This appears to be caused by using a base of 0 to strtol which then
> interprets leading 0 numbers as octal. This is probably done in order to
> get handling of '0x' prefixed numbers as well, but the leading 0 ->
> octal interpretation is much less common.

Actually this convention is widely used.  After all, strtol is part of
the standard C library and has been forever:

 strtol(): POSIX.1-2001, POSIX.1-2008, C89, C99 SVr4, 4.3BSD.

> The manual page does use several '0x' prefixed values but does not seem
> to call out octal values or the implicit conversions.

Yeah, could be easily added into the doc...

Thanks,
Richard




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


Re: [Linuxptp-devel] [PATCH] Use lock file to check if uds_address in use

2023-04-30 Thread Richard Cochran
On Tue, Feb 28, 2023 at 01:47:03AM +0100, Andrew Zaborowski wrote:
> Use a lock file to be able to log an error when the UDS socket's path is
> in use by another instance, avoid silently unlink()ing it.
> 
> There's no way for multiple instances (e.g. in a multi-domain setup) to
> bind() to the same address, there's nothing like SO_REUSEADDR for unix
> sockets.  Just unlinking the socket makes for a behaviour that's
> initially confusing to the user, and creates a race condition where
> one instane's bind() call can happen between another instane's unlink()
> and bind() causing the latter to fail.  Resort to logging an error when
> uds_{,ro_}address is in use.

I think this adds unneeded complexity to the code base for little
benefit.  The issues you describe can be avoided by writing correct
start up scripts.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v2] ntpshm: Invalidate SHM data before releasing the servo

2023-04-30 Thread Richard Cochran
On Thu, Mar 16, 2023 at 03:47:47PM +0100, Maciek Machnikowski wrote:
> The SHM is not cleared upon servo release when exiting the tool. This
> leaves the last update in the shared memory region marked as valid.
> 
> Users may not expect such behavior. If the configuration changed, or the
> tool was restarted to reset the state after an unexpected clock step
> (e.g. after system suspend), an incorrec timestamp might be accepted by
> the consumer
> 
> To prevent such behavior - invalidate the SHM data when releasing
> the SHM servo.
> 
> v2: Fix commit message
> 
> Signed-off-by: Maciek Machnikowski 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH 1/1] msg: append TLV onto all PTP event messages

2023-04-30 Thread Richard Cochran
On Wed, Mar 01, 2023 at 01:04:34PM +0800, Tan Tee Min wrote:
> According to IEEE Std 1588-2019 Chapter 6.4 PTP message classes,
> all PTP messages can be extended by means of a standard
> Type, Length, Value (TLV) extension mechanism.

Since the present code does not append any TLVs on such message types,
this change is not needed.  The patch will become relevant if/when the
use case is implemented, not before.

Thanks,
Richard




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


Re: [Linuxptp-devel] [PATCH v1] lstab: Update leapfile validity

2023-04-29 Thread Richard Cochran
On Thu, Apr 27, 2023 at 09:58:13AM +0200, Maciek Machnikowski wrote:
> No leap seconds will happen till the end of 2023.

(Only twelve more years of this BS to endure.  ;^)

> Update leapfile
> validity accordingly.
> 
> Signed-off-by: Maciek Machnikowski 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] port: Don't switch to PHC with SW timestamping.

2023-04-29 Thread Richard Cochran
On Wed, Mar 15, 2023 at 11:44:11AM +0100, Miroslav Lichvar wrote:
> When ptp4l was configured to use SW timestamping, but the interface
> supported also HW timestamping, ptp4l detected a change of the PHC on
> start, switched to it from the system clock, and tried to control the
> PHC using SW timestamps.
> 
> Don't switch the PHC if the current PHC index is -1, which is expected
> with SW timestamping and in the free-running mode.
> 
> Fixes: afeabf3c90ed ("ptp4l: add VLAN over bond support")
> Signed-off-by: Miroslav Lichvar 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v2 0/1] Last (?) patch before version 4 release

2023-04-29 Thread Richard Cochran
On Wed, Apr 26, 2023 at 09:33:05AM +0200, Maciek Machnikowski wrote:
> Is it still possible to get those 2 patches into 4.0?

Yes.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v2] ts2phc: Prevent reporting poll error when received termination signal

2023-04-29 Thread Richard Cochran
On Tue, Apr 11, 2023 at 03:08:40PM +0200, Maciek Machnikowski wrote:
> Currently ts2phc prints "poll failed" error to the LOG_EMERG when
> the poll for tod fails. This causes error print on all terminals
> when the tool gets terminated using SIGINT (ex. by pressing CTRL+C).
> 
> v2: Properly handle poll interrupt to prevent the error
> 
> Signed-off-by: Maciek Machnikowski 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v2] ts2phc: Fix potential null-pointer dereference

2023-04-29 Thread Richard Cochran
On Mon, Mar 13, 2023 at 09:31:43PM +0100, Maciek Machnikowski wrote:
> An unallocated pmc_agent may be dereferenced in the pmc_agent_destroy
> called by the ts2phc_cleanup().
> Check if the agent was allocated before releasing it.
> 
> v2: Fixed coding standard
> 
> Signed-off-by: Maciek Machnikowski 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v3 0/6] Use precise frequency for TX SYNC messages

2023-04-25 Thread Richard Cochran
On Tue, Apr 25, 2023 at 06:23:53PM +0200, Luigi 'Comio' Mantellini wrote:
> Any review on this patchset?

I'm working on releasing v4.0.  Once that is done, I'll start
reviewing new stuff once again.

Without having looked at your patch series, I've wanted to convert
from one shot to periodic timers just because it looks better (even
though it doesn't affect conformance or performance).

But shouldn't Annouce messages be periodic, too?

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH 1/6] Add doubly attached clock support

2023-04-24 Thread Richard Cochran
On Mon, Apr 24, 2023 at 10:45:56AM +0200, Stephan Wurm wrote:

> @@ -210,6 +219,40 @@ enum port_state ptp_fsm(enum port_state state, enum 
> fsm_event event, int mdiff)

> + case PS_PASSIVE_SLAVE:
> + switch (event) {
> + case EV_DESIGNATED_DISABLED:
> + next = PS_DISABLED;
> + break;
> + case EV_FAULT_DETECTED:
> + next = PS_FAULTY;
> + break;
> + case EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES:
> + next = PS_MASTER;
> + break;
> + case EV_SYNCHRONIZATION_FAULT:
> + next = PS_LISTENING;
> + break;
> + case EV_RS_MASTER:
> + next = PS_PRE_MASTER;
> + break;
> + case EV_RS_GRAND_MASTER:
> + next = PS_GRAND_MASTER;
> + break;
> + case EV_RS_PASSIVE:
> + next = PS_PASSIVE;
> + break;
> + case EV_RS_SLAVE:
> + next = PS_SLAVE;
> + break;

You can't just add random states into the ieee 1588 state machine.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v2 0/1] Last (?) patch before version 4 release

2023-04-17 Thread Richard Cochran
On Mon, Apr 17, 2023 at 11:07:10AM +0200, Miroslav Lichvar wrote:

> As for the 4.0 release, can you please have a look at this bug fix?
> https://www.mail-archive.com/linuxptp-devel@lists.sourceforge.net/msg06420.html

+1


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


Re: [Linuxptp-devel] [PATCH] Set controlField to zero in message headers

2023-04-15 Thread Richard Cochran
On Thu, Mar 16, 2023 at 02:58:33PM +0100, Andrew Zaborowski wrote:

> I was now made aware that Avnu conformance tests for 802.1AS-2011 do
> validate the 3 different values required in the control field in that
> version of IEEE802.1AS.  While 1588-2008 did already say that the use
> of this field on the receiver is "deprecated", 802.1AS-2011 does not
> say anything like this.  There's value for Avnu in having an option to
> go back to those values and perhaps shipping a "gPTP-2011.cfg" file
> with that option enabled.  Would you be open to have this upstream?

That was twelve years ago.  We needn't take such an overly pedantic
test seriously.  I'll just update the home page to say, "supports
802.1AS-2020".

Thanks,
Richard


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


[Linuxptp-devel] [PATCH v2 0/1] Last (?) patch before version 4 release

2023-04-15 Thread Richard Cochran
Based on Erez's review, I expanded Christopher's patch to remove the
control field codes completely.  I've tested this with the following
hardware, and nothing broke:

Intel I210
Intel X550T
LabX Titanium 411 AVB switch

Please give this a try with your favorite hardware time stamping
device.  I'd like to know how many devices stop working when the
controlField is clear.

@Christopher are you okay with this change?

Thanks,
Richard


Christopher S M Hall (1):
  Set controlField to zero in message headers

 msg.h| 9 -
 nsm.c| 1 -
 pmc_common.c | 1 -
 port.c   | 9 -
 port_signaling.c | 1 -
 tc.c | 1 -
 6 files changed, 22 deletions(-)

-- 
2.30.2



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


[Linuxptp-devel] [PATCH v2 1/1] Set controlField to zero in message headers

2023-04-15 Thread Richard Cochran
From: Christopher S M Hall 

IEEE1588-2019 and 802.1AS-2020 both require the field to be 0 in
transmitted messages except when the "version 1 hardware option" is set
(IEEE1588-2019 C.4.2) and only with IPv4.  Since ptp4l isn't padding
the UDP messages to 124 bytes as required for compatibility with the
"V.1 Hardware" implementations, assume that we're not dealing with such
hardware, do not implement the option as defined in C.4.2.

Since the default behaviour changes, in principle this could break
things.  It is similar to 2a2532d66121 ("Bump to IEEE 1588-2019 version")
however, where ptp4l switches the version field to the IEEE1588-2019
value.

[ RPC: Remove every last trace of the control field codes. ]

Signed-off-by: Andrew Zaborowski 
Signed-off-by: Richard Cochran 
---
 msg.h| 9 -
 nsm.c| 1 -
 pmc_common.c | 1 -
 port.c   | 9 -
 port_signaling.c | 1 -
 tc.c | 1 -
 6 files changed, 22 deletions(-)

diff --git a/msg.h b/msg.h
index b7423ee..9fba51b 100644
--- a/msg.h
+++ b/msg.h
@@ -83,15 +83,6 @@ struct hw_timestamp {
tmv_t sw;
 };
 
-enum controlField {
-   CTL_SYNC,
-   CTL_DELAY_REQ,
-   CTL_FOLLOW_UP,
-   CTL_DELAY_RESP,
-   CTL_MANAGEMENT,
-   CTL_OTHER,
-};
-
 struct ptp_header {
uint8_t tsmt; /* transportSpecific | messageType */
uint8_t ver;  /* minorVersionPTP   | versionPTP  */
diff --git a/nsm.c b/nsm.c
index 8d4a362..9f9db5e 100644
--- a/nsm.c
+++ b/nsm.c
@@ -394,7 +394,6 @@ static int nsm_request(struct nsm *nsm, char *target)
msg->header.correction = -asymmetry;
msg->header.sourcePortIdentity = nsm->port_identity;
msg->header.sequenceId = nsm->sequence_id++;
-   msg->header.control= CTL_DELAY_REQ;
msg->header.logMessageInterval = 0x7f;
 
msg->address = dst;
diff --git a/pmc_common.c b/pmc_common.c
index a03f191..9e251c4 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -563,7 +563,6 @@ static struct ptp_message *pmc_message(struct pmc *pmc, 
uint8_t action)
msg->header.domainNumber   = pmc->domain_number;
msg->header.sourcePortIdentity = pmc->port_identity;
msg->header.sequenceId = pmc->sequence_id++;
-   msg->header.control= CTL_MANAGEMENT;
msg->header.logMessageInterval = 0x7f;
 
msg->management.targetPortIdentity = pmc->target;
diff --git a/port.c b/port.c
index 3453716..76f817c 100644
--- a/port.c
+++ b/port.c
@@ -1544,7 +1544,6 @@ static int port_pdelay_request(struct port *p)
msg->header.correction = -p->asymmetry;
msg->header.sourcePortIdentity = p->portIdentity;
msg->header.sequenceId = p->seqnum.delayreq++;
-   msg->header.control= CTL_OTHER;
msg->header.logMessageInterval = port_is_ieee8021as(p) ?
p->logPdelayReqInterval : 0x7f;
 
@@ -1608,7 +1607,6 @@ int port_delay_request(struct port *p)
msg->header.correction = -p->asymmetry;
msg->header.sourcePortIdentity = p->portIdentity;
msg->header.sequenceId = p->seqnum.delayreq++;
-   msg->header.control= CTL_DELAY_REQ;
msg->header.logMessageInterval = 0x7f;
 
if (p->hybrid_e2e) {
@@ -1660,7 +1658,6 @@ int port_tx_announce(struct port *p, struct address *dst, 
uint16_t sequence_id)
msg->header.domainNumber   = clock_domain_number(p->clock);
msg->header.sourcePortIdentity = p->portIdentity;
msg->header.sequenceId = sequence_id;
-   msg->header.control= CTL_OTHER;
msg->header.logMessageInterval = p->logAnnounceInterval;
 
msg->header.flagField[1] = tp.flags;
@@ -1743,7 +1740,6 @@ int port_tx_sync(struct port *p, struct address *dst, 
uint16_t sequence_id)
msg->header.domainNumber   = clock_domain_number(p->clock);
msg->header.sourcePortIdentity = p->portIdentity;
msg->header.sequenceId = sequence_id;
-   msg->header.control= CTL_SYNC;
msg->header.logMessageInterval = p->logSyncInterval;
 
if (p->timestamping != TS_ONESTEP && p->timestamping != TS_P2P1STEP) {
@@ -1779,7 +1775,6 @@ int port_tx_sync(struct port *p, struct address *dst, 
uint16_t sequence_id)
fup->header.domainNumber   = clock_domain_number(p->clock);
fup->header.sourcePortIdentity = p->portIdentity;
fup->header.sequenceId = sequence_id;
-   fup->header.control= CTL_FOLLOW_UP;
fup->header.logMessageInterval = p->logSyncInterval;
 
fup->follow_up.preciseOriginTimestamp = tmv_to_Timestamp(msg->hwts.ts);
@@ -2130,7 +2125,6 @@

Re: [Linuxptp-devel] [PATCH v1] tz2alt: Add tz2alt to .gitignore

2023-04-12 Thread Richard Cochran
On Tue, Apr 11, 2023 at 03:16:47PM +0200, Maciek Machnikowski wrote:
> Add tz2alt to .gitignore list
> 
> Signed-off-by: Maciek Machnikowski 

Applied.

Thanks,
Richard


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


Re: [Linuxptp-devel] [RFC PATCH v1 2/8] Add configuration options for CMLDS

2023-03-21 Thread Richard Cochran
On Mon, Mar 20, 2023 at 09:04:59PM -0700, Kishen Maloor wrote:
> Yes, we would configure CMLDS just once per physical port on a PTP node.

Okay, so the code should check this.

(Haven't reviewed yet, maybe you handle that already?)

Thanks,
Richard


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


Re: [Linuxptp-devel] [RFC PATCH v1 2/8] Add configuration options for CMLDS

2023-03-20 Thread Richard Cochran
On Mon, Mar 20, 2023 at 02:40:30PM -0700, Kishen Maloor wrote:
> On 3/20/23 12:31 PM, Richard Cochran wrote:
> > On Sun, Mar 19, 2023 at 10:36:48PM -0400, Kishen Maloor wrote:
> > 
> >> 'run_cmlds': This per-port setting (0/1) declares that a port
> >> will perform the role of a CMLDS Link Port (IEEE 1588, clause 16.6.1)
> >> and execute CMLDS Pdelay transactions
> > 
> > How many ports may have run_cmlds == 1 ?
> 
> We may configure 'run_cmlds=1' on as many (links) ports as we need.

But there should be at most one cmlds on a given physical port, right?

Thanks,
Richard


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


Re: [Linuxptp-devel] [RFC PATCH v1 2/8] Add configuration options for CMLDS

2023-03-20 Thread Richard Cochran
On Sun, Mar 19, 2023 at 10:36:48PM -0400, Kishen Maloor wrote:

> 'run_cmlds': This per-port setting (0/1) declares that a port
> will perform the role of a CMLDS Link Port (IEEE 1588, clause 16.6.1)
> and execute CMLDS Pdelay transactions

How many ports may have run_cmlds == 1 ?

Thanks,
Richard




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


Re: [Linuxptp-devel] Two ptp4l processes working on the same network interface

2023-03-15 Thread Richard Cochran
On Wed, Mar 15, 2023 at 01:14:50PM +0200, Kamil Zaripov wrote:

> The issue is ptp4l does not support out of the box creating two
> ports on the same network interfaces with different
> network_transport configuration values. I want to discuss how
> linuxptp code can be patched so user can do such thing?

I think this can be pretty simple.  Allow interface names like:

   eth0 eth0:foo eth0:bar

Then simply drop :xyz suffix when actually calling the ioctl.

The only difficulty is sanity checking that:

- At most one UDPv4 and one UDPv6 are present.

- The inferface supports HWTSTAMP_FILTER_PTP_V2_EVENT.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Add option to bind raw and UDP sockets to interface

2023-03-14 Thread Richard Cochran
On Tue, Mar 14, 2023 at 12:38:06PM +0200, Kamil Zaripov wrote:
> Can you explain the problems you see with timestamping in the interface on 
> top of a bridge?

When a MAC joins a bridge, the MAC is no longer avaiable as a network
interface.  This is how the bridge thing is implemented in Linux.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Return 1 from port_is_ieee8021as if asCapable true

2023-03-14 Thread Richard Cochran
On Tue, Mar 14, 2023 at 07:42:19PM +0100, Andrew Zaborowski wrote:
> On Tue, 7 Mar 2023 at 16:35, Richard Cochran  wrote:
> > On Tue, Mar 07, 2023 at 04:21:52PM +0100, Andrew Zaborowski wrote:
> > > The (minor) problem this attempts to solve, and I didn't state that,
> > > is the confusing semantics and reduced utility of port_is_ieee8021as
> > > if one relies on the name.
> >
> > So there is no bug.  Just the code is confusing, right?  Then you must
> > ensure that the patch does not actually change the program's behavior.
> 
> Whether it's a bug depends on what users expect from asCapable=true.
> Or if it has any users in the first place, but it is present in some
> of the shipped config files.

IIRc the whole (and only) point of asCapable=1 is too circumvent the
normal port qualification logic in 802.1as, just for the "automotive"
profile.
 
> With asCapable=true your PdelayReq messages have their
> header.logMessageInterval set to 0x7f.  802.1AS says it should be set
> to the value of currentLogPdelayReqInterval.
> currentLogPdelayReqInterval of 0x7f means that no PdelayReqs should be
> sent, so in theory no PdelayReq with the value of 0x7f should go out.

But the automotive profile doesn't care about this.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Add option to bind raw and UDP sockets to interface

2023-03-13 Thread Richard Cochran
On Mon, Mar 13, 2023 at 12:25:28PM +0200, Kamil Zaripov wrote:
> 
> > On 13 Mar 2023, at 03:56, Richard Cochran  wrote:
> > 
> > We don't support PTP on top of bridge interfaces, because the kernel
> > does not support that, and it would be difficult to add.
> 

> Ok, but actually it is possible to do it using this patch and it
> works pretty good in my case (two VLAN’s on top of bridge which
> include Intel I210 interface with PTP capabilities) on the several
> hundreds machines for several years.

"It works for me" is not a strong argument.  This software stack must
work for everyone.  Time stamping on top of a bridge interface won't
fly in general, if I'm not mistaken.

> If you think that it is useless we drop this patch, no problem. If
> you think that implementation is bad we can discuss how can we make
> it better.

The implementation would need work, but first the use case must be
clarified.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v1] ts2phc: Fix potential null-pointer dereference

2023-03-13 Thread Richard Cochran
On Mon, Mar 13, 2023 at 03:07:27PM +0100, Maciek Machnikowski wrote:
> An unallocated pmc_agent may be dereferenced in the pmc_agent_destroy
> called by the ts2phc_cleanup().
> Check if the agent was allocated before releasing it.
> 
> Signed-off-by: Maciek Machnikowski 
> ---
>  ts2phc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/ts2phc.c b/ts2phc.c
> index 4393059..ba08f99 100644
> --- a/ts2phc.c
> +++ b/ts2phc.c
> @@ -38,7 +38,8 @@ static void ts2phc_cleanup(struct ts2phc_private *priv)
>   if (priv->cfg)
>   config_destroy(priv->cfg);
>  
> - pmc_agent_destroy(priv->agent);
> + if(priv->agent)
> + pmc_agent_destroy(priv->agent);

CodingStyle - space after 'if'

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Add option to bind raw and UDP sockets to interface

2023-03-12 Thread Richard Cochran
On Fri, Mar 10, 2023 at 05:31:29PM +0200, Kamil Zaripov wrote:

> However in a bit more complex network configuration when your VLAN
> interface is created on top of bridge that includes “hardware”

We don't support PTP on top of bridge interfaces, because the kernel
does not support that, and it would be difficult to add.

> interface your VLAN interface doesn’t support same timestamping
> capabilities as “hardware” interface, obviously:

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v6 00/10] Dynamic sync direction for ts2phc

2023-03-12 Thread Richard Cochran
On Tue, Feb 28, 2023 at 06:59:17AM -0800, Richard Cochran wrote:
> On Tue, Feb 28, 2023 at 12:03:15PM +0100, Maciek Machnikowski wrote:
> > Can we add it to the configs/ts2phc*.cfg for the 4.0 release?
> 
> That is not a critical bug, IMO.

v4.0 is delayed, and so feel free to submit a patch for this.

Thanks,
Richard


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


Re: [Linuxptp-devel] Code freeze for 4.0 release

2023-03-12 Thread Richard Cochran
On Wed, Feb 22, 2023 at 09:51:56PM +0100, Erez wrote:
> Great :-)
> Will your power profile patch be included?

Yes.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Add option to bind raw and UDP sockets to interface

2023-03-10 Thread Richard Cochran
On Fri, Mar 10, 2023 at 01:00:51PM +0200, Zaripov Kamil wrote:
> This patch allows to set interface name in 'iface:bind' format where:
> - 'iface' is network interface that supports PTP
> - 'bind' is network interface to bind socket
> This feature can be useful if you have one physical network interface that
> serves two or more logical local networks separated with VLAN tags. If you
> have to serve PTP clients on both of this local networks you need to bind
> to different interfaces representing different VLANs.
> 
> Most part of this patch just adjusting code where we read configuration
> for interface so we can set different settings for 'eth0:vlan1' and
> 'eth0:vlan2', for example.

Um, unless I'm mistaken, this is unneeded, because you can specify a
VLAN interface just like a normal interface.  In the kernel, the VLAN
interface stacks on top of the physical one and passes the time
stamping APIs through.

Thanks,
Richard


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


Re: [Linuxptp-devel] ts2phc: rising/falling edge discrimination, generic driver

2023-03-08 Thread Richard Cochran
On Wed, Mar 08, 2023 at 02:07:37PM +, Jürgen Appel via Linuxptp-devel wrote:
> I noticed that the servo.c -code has a SERVO_LOCKED_STABLE state that is not 
> used. 

It is used.  See clock.c and port.c.

Thanks,
Richard


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


Re: [Linuxptp-devel] ts2phc: rising/falling edge discrimination, generic driver

2023-03-08 Thread Richard Cochran
On Wed, Mar 08, 2023 at 02:07:37PM +, Jürgen Appel via Linuxptp-devel wrote:
> After the user has set the PHC approximately to the intended time and offset:

Not very user friendly.  The software should do this automatically.

> phc_ctl /dev/ptp3 -- set adjust $(grep -v '^#' 
> /usr/share/zoneinfo/leap-seconds.list | tail -1 | awk '{ print $2 }')

Ugh.

> ts2phc will keep the phc locked, no matter what happens to the system time.

Locked to the original guess.

> This allows locking different PHCs to different time domains, 
> even if those clocks drift more than a second away.

Assuming no discontinuities, ever.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Return 1 from port_is_ieee8021as if asCapable true

2023-03-07 Thread Richard Cochran
On Tue, Mar 07, 2023 at 04:21:52PM +0100, Andrew Zaborowski wrote:

> The (minor) problem this attempts to solve, and I didn't state that,
> is the confusing semantics and reduced utility of port_is_ieee8021as
> if one relies on the name.

So there is no bug.  Just the code is confusing, right?  Then you must
ensure that the patch does not actually change the program's behavior.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v1 1/2] msg: Enable changing PTP message header version

2023-03-07 Thread Richard Cochran
On Tue, Mar 07, 2023 at 04:13:50PM +0100, Maciek Machnikowski wrote:
> Some hardware can't properly timestamp packets with the new PTP
> header version 2.1. This patch introduces a global var ptp_hdr_ver
> that can be changed externally to allow legacy PTP version to be
> advertised.

As previously discussed, I won't support borken hardware going forward.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Return 1 from port_is_ieee8021as if asCapable true

2023-03-06 Thread Richard Cochran
On Tue, Mar 07, 2023 at 12:54:55AM +0100, Andrew Zaborowski wrote:
> It seems that port_is_ieee8021as(p) returning zero if p->as_capable ==
> ALWAYS_CAPABLE was originally intended for skipping checks in
> port_capable but this is quite unclear.

Maybe you should ask your Intel colleague what he had in mind?

> There are only three callers
> left in the current code and this quirk doesn't seem to make them any
> more compliant with either 802.1AS version or the Automotive profile.

More compliant?  Either something complies or not.

> On the other hand

Where was the first hand?

> the calculation of neighborRateRatio (in the Rx path)
> can now depend on the return value of port_is_ieee8021as() which seems
> to have been the intention, rather than on whether p->follow_up_info is
> set.  The description of follow_up_info in the man page implies it
> rather affects the Tx path.

It can be used on the client.

> (The NRR will also need to be calculated
> in a future CMLDS instance, with or without 802.1AS, so this if clause
> will change again).

Sorry, but this is completely incomprehensible.

A proper commit message has three elements:

1. context
2. problem
3. solution

You need to clearly state the problem.

(no) thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Set controlField to zero in message headers

2023-02-28 Thread Richard Cochran
On Tue, Feb 28, 2023 at 07:38:44PM +0100, Andrew Zaborowski wrote:
> Hi Richard and Erez,
> 
> On Tue, 28 Feb 2023 at 16:02, Richard Cochran  
> wrote:
> > On Tue, Feb 28, 2023 at 09:36:07AM +0100, Erez wrote:
> > > May break when using non Linuxptp, as far as I understand, linuxptp only
> > > sets the field, but never checks the value.
> >
> > The risk is that some hardware implementations may check those fields
> > and then fail to generate time stamps.
> >
> > In the case of the PTP minor version field, there are already two
> > known bad HW devices that fail when the field is non-zero.  Of course,
> > this violates 1588-2008, but it proves the point that vendors don't
> > follow the standard.
> 
> Ok, that was a concern but I didn't know how likely it would be.
> Given this would you agree to zeroing those values based on a setting?

No, I just wanted to point out the risk.  So far, HW vendors track
record has been abysmal.  If there is a way to do wrong, then somebody
sure will.

The SW should zero the controlField unconditionally as called out in
1588-2019 clause 13.3.2.13.  Previously I overlooked this silly detail
because the change is not identified in 19.4 "Compatibility ... to
IEEE Std 1588-2008".

Anyhow, since we advertise PTP v2.1 then we should really clear the
controlField.  As a general rule, linuxptp doesn't make special hacks
for broken hardware designs.

I want this change in linuxptp version 4.0 together with the PTP 2.1
version bump, and so that will delay the release to allow some minimum
soak time.

Thanks,
Richard



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


Re: [Linuxptp-devel] [PATCH v6 00/10] Dynamic sync direction for ts2phc

2023-02-28 Thread Richard Cochran
On Tue, Feb 28, 2023 at 12:03:15PM +0100, Maciek Machnikowski wrote:
> Can we add it to the configs/ts2phc*.cfg for the 4.0 release?

That is not a critical bug, IMO.

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Set controlField to zero in message headers

2023-02-28 Thread Richard Cochran
On Tue, Feb 28, 2023 at 09:36:07AM +0100, Erez wrote:
> On Tue, 28 Feb 2023 at 01:49, Andrew Zaborowski 
> > Since the default behaviour changes, in principle this could break
> >
> 
> May break when using non Linuxptp, as far as I understand, linuxptp only
> sets the field, but never checks the value.

The risk is that some hardware implementations may check those fields
and then fail to generate time stamps.

In the case of the PTP minor version field, there are already two
known bad HW devices that fail when the field is non-zero.  Of course,
this violates 1588-2008, but it proves the point that vendors don't
follow the standard.

As a result, customers of those vendors get on our list and complain
the linuxptp is broken!

Thanks,
Richard


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


Re: [Linuxptp-devel] The new application 'tz2alt' is missed in .gitignore

2023-02-26 Thread Richard Cochran
On Mon, Feb 27, 2023 at 12:04:33AM +0100, Erez wrote:
> Hi Richard,
> 
> You forgot to add  'tz2alt' to .gitignore.

Thanks, I'll add that in,

Richard


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


Re: [Linuxptp-devel] [PATCH v6 05/11] tlv: Encode and decode alternate time offset indicator TLVs.

2023-02-26 Thread Richard Cochran
On Sat, Feb 25, 2023 at 02:35:23PM -0800, Hal Murray wrote:
> 
> richardcoch...@gmail.com said:
> >> +  NTOHS(atoi->type);
> >> +  NTOHS(atoi->length);
> > These two lines are wrong.  The net/host conversion of type and length
> > already happened in suffix_post_recv() in msg.c 
> 
> They may be wrong in the sense of duplicating work that has already been 
> done, 
> but they are also wrong in the sense of not doing anything.
> 
> NTOHS doesn't update it's argument.  It returns a result which isn't being 
> stored anyplace.

In tlv.c NTOHS is a macro and not a function.  It doesn't return anything at 
all.

#define HTONS(x) (x) = htons(x)

See?

Thanks,
Richard




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


Re: [Linuxptp-devel] [PATCH v6 05/11] tlv: Encode and decode alternate time offset indicator TLVs.

2023-02-25 Thread Richard Cochran
On Mon, Feb 20, 2023 at 12:57:53PM -0800, Richard Cochran wrote:

> +static int alttime_offset_post_recv(struct tlv_extra *extra)
> +{
> + struct TLV *tlv = extra->tlv;
> + struct alternate_time_offset_indicator_tlv *atoi =
> + (struct alternate_time_offset_indicator_tlv *) tlv;
> +
> + if (tlv->length < sizeof(struct alternate_time_offset_indicator_tlv) +
> + atoi->displayName.length - sizeof(struct TLV)) {
> + return -EBADMSG;
> + }
> +
> + NTOHS(atoi->type);
> + NTOHS(atoi->length);

These two lines are wrong.  The net/host conversion of type and length
already happened in suffix_post_recv() in msg.c

> + /* Message alignment broken by design. */
> + net2host32_unaligned(>currentOffset);
> + net2host32_unaligned(>jumpSeconds);
> + flip16(>timeOfNextJump.seconds_msb);
> + net2host32_unaligned(>timeOfNextJump.seconds_lsb);
> +
> + return 0;
> +}
> +
> +static void alttime_offset_pre_send(struct tlv_extra *extra)
> +{
> + struct alternate_time_offset_indicator_tlv *atoi;
> +
> + atoi = (struct alternate_time_offset_indicator_tlv *) extra->tlv;
> +
> + HTONS(atoi->type);
> + HTONS(atoi->length);

These two are also wrong.  The host/net conversion happens in
suffix_pre_send().

> + /* Message alignment broken by design. */
> + host2net32_unaligned(>currentOffset);
> + host2net32_unaligned(>jumpSeconds);
> + flip16(>timeOfNextJump.seconds_msb);
> + host2net32_unaligned(>timeOfNextJump.seconds_lsb);
> +}
> +

I took the liberty of fixing these bugs while merging this series.

With the correction of removing those four lines, Wireshark can decode
the ALTERNATE_TIME_OFFSET_INDICATOR TLV, eg:

Alternate time offset indicator TLV
tlvType: Alternate time offset indicator (9)
lengthField: 22
keyField: 0
currentOffset: 3563
jumpSeconds: -1679796001
timeOfNextJump: 641f9910
displayName: Vienna
length: 6
displayName: Vienna


Thanks,
Richard




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


Re: [Linuxptp-devel] [PATCH 1/1] port: add ptpTimescale to the flag field for 802.1AS-2011

2023-02-24 Thread Richard Cochran
On Fri, Feb 24, 2023 at 02:25:03PM +, Woojung.Huh--- via Linuxptp-devel 
wrote:

> Agree that 802.1AS-2011 and 802.1AS-2021-Cor1 are marked as All for 
> ptpTimescale.
> However, this is updated (fixed) in 802.1AS-2020 to message type "Announce"
> which aligns to 1588-2008 and 1588-2019. 
> May need second eye to confirm which direction is right way to do.

This is clearly a bug in 802.1AS-2011.  There are a bunch of other
obvious mistakes in that publication.

Thanks,
Richard


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


[Linuxptp-devel] Code freeze for 4.0 release

2023-02-22 Thread Richard Cochran
Dear Devs,

I'll be releasing 4.0 in the next day or two.  I won't be taking any
new stuff until after the release.  If you have any last minute
critical bug fixes, please let me know ASAP.

Thanks,
Richard


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


[Linuxptp-devel] [PATCH v6 03/11] Introduce the power profile.

2023-02-20 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 config.c| 15 -
 configs/default.cfg |  5 +
 port.c  | 53 +
 port_private.h  |  3 +++
 power_profile.h | 31 ++
 ptp4l.8 | 38 
 tlv.h   |  8 +++
 7 files changed, 152 insertions(+), 1 deletion(-)
 create mode 100644 power_profile.h

diff --git a/config.c b/config.c
index f028b88..cb4421f 100644
--- a/config.c
+++ b/config.c
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "ether.h"
 #include "hash.h"
+#include "power_profile.h"
 #include "print.h"
 #include "util.h"
 
@@ -66,7 +67,7 @@ typedef union {
char *s;
 } any_t;
 
-#define CONFIG_LABEL_SIZE 32
+#define CONFIG_LABEL_SIZE 64
 
 #define CFG_ITEM_STATIC (1 << 0) /* statically allocated, not to be freed */
 #define CFG_ITEM_LOCKED (1 << 1) /* command line value, may not be changed */
@@ -190,6 +191,13 @@ static struct config_enum hwts_filter_enu[] = {
{ NULL, 0 },
 };
 
+static struct config_enum ieee_c37_238_enu[] = {
+   { "none", IEEE_C37_238_VERSION_NONE },
+   { "2011", IEEE_C37_238_VERSION_2011 },
+   { "2017", IEEE_C37_238_VERSION_2017 },
+   { NULL, 0 },
+};
+
 static struct config_enum nw_trans_enu[] = {
{ "L2",TRANS_IEEE_802_3 },
{ "UDPv4", TRANS_UDP_IPV4   },
@@ -300,6 +308,11 @@ 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_ENU("power_profile.version", IEEE_C37_238_VERSION_NONE, 
ieee_c37_238_enu),
+   PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0x, 0, INT_MAX),
+   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
INT_MAX),
+   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
INT_MAX),
+   PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
GLOB_ITEM_INT("priority1", 128, 0, UINT8_MAX),
GLOB_ITEM_INT("priority2", 128, 0, UINT8_MAX),
GLOB_ITEM_STR("productDescription", ";;"),
diff --git a/configs/default.cfg b/configs/default.cfg
index 297a99d..a21ec66 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -41,6 +41,11 @@ BMCAptp
 inhibit_announce0
 inhibit_delay_req   0
 ignore_source_id0
+power_profile.2011.grandmasterTimeInaccuracy   0x
+power_profile.2011.networkTimeInaccuracy   0
+power_profile.2017.totalTimeInaccuracy 0x
+power_profile.grandmasterID0
+power_profile.version  none
 #
 # Run time options
 #
diff --git a/port.c b/port.c
index 92f3ee3..23697a5 100644
--- a/port.c
+++ b/port.c
@@ -453,6 +453,46 @@ static int follow_up_info_append(struct ptp_message *m)
return 0;
 }
 
+static int ieee_c37_238_append(struct port *p, struct ptp_message *m)
+{
+   struct ieee_c37_238_2017_tlv *p17;
+   struct ieee_c37_238_2011_tlv *p11;
+   struct tlv_extra *extra;
+
+   switch (p->pwr.version) {
+   case IEEE_C37_238_VERSION_NONE:
+   return 0;
+   case IEEE_C37_238_VERSION_2011:
+   extra = msg_tlv_append(m, sizeof(*p11));
+   if (!extra) {
+   return -1;
+   }
+   p11 = (struct ieee_c37_238_2011_tlv *) extra->tlv;
+   p11->type = TLV_ORGANIZATION_EXTENSION;
+   p11->length = sizeof(*p11) - sizeof(p11->type) - 
sizeof(p11->length);
+   memcpy(p11->id, ieeec37_238_id, sizeof(ieeec37_238_id));
+   p11->subtype[2] = 1;
+   p11->grandmasterID = p->pwr.grandmasterID;
+   p11->grandmasterTimeInaccuracy = 
p->pwr.grandmasterTimeInaccuracy;
+   p11->networkTimeInaccuracy = p->pwr.networkTimeInaccuracy;
+   break;
+   case IEEE_C37_238_VERSION_2017:
+   extra = msg_tlv_append(m, sizeof(*p17));
+   if (!extra) {
+   return -1;
+   }
+   p17 = (struct ieee_c37_238_2017_tlv *) extra->tlv;
+   p17->type = TLV_ORGANIZATION_EXTENSION;
+   p17->length = sizeof(*p17) - sizeof(p17->type) - 
sizeof(p17->length);
+   memcpy(p17->id, ieeec37_238_id, sizeof(ieeec37_238_id));
+   p17->subtype[2] = 2;
+   p17->grandmasterID = p->pwr.grandmasterID;
+   p17->totalTimeInaccuracy = p->pwr.totalTimeInaccuracy;

[Linuxptp-devel] [PATCH v6 04/11] Add a custom management message for power profile settings.

2023-02-20 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 pmc.c| 15 +++
 pmc_common.c | 37 +
 port.c   | 20 +++-
 tlv.c| 20 
 tlv.h|  1 +
 5 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/pmc.c b/pmc.c
index e218ca4..793a790 100644
--- a/pmc.c
+++ b/pmc.c
@@ -157,6 +157,7 @@ static void pmc_show_signaling(struct ptp_message *msg, 
FILE *fp)
 
 static void pmc_show(struct ptp_message *msg, FILE *fp)
 {
+   struct ieee_c37_238_settings_np *pwr;
struct unicast_master_table_np *umtn;
struct grandmaster_settings_np *gsn;
struct port_service_stats_np *pssp;
@@ -572,6 +573,20 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
phn->phc_index,
phn->flags);
break;
+   case MID_POWER_PROFILE_SETTINGS_NP:
+   pwr = (struct ieee_c37_238_settings_np *) mgt->data;
+   fprintf(fp, "POWER_PROFILE_SETTINGS_NP "
+   IFMT "version   %hu"
+   IFMT "grandmasterID 0x%04hx"
+   IFMT "grandmasterTimeInaccuracy %u"
+   IFMT "networkTimeInaccuracy %u"
+   IFMT "totalTimeInaccuracy   %u",
+   pwr->version,
+   pwr->grandmasterID,
+   pwr->grandmasterTimeInaccuracy,
+   pwr->networkTimeInaccuracy,
+   pwr->totalTimeInaccuracy);
+   break;
case MID_LOG_ANNOUNCE_INTERVAL:
mtd = (struct management_tlv_datum *) mgt->data;
fprintf(fp, "LOG_ANNOUNCE_INTERVAL "
diff --git a/pmc_common.c b/pmc_common.c
index 1dd89f6..bb7d087 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -28,6 +28,7 @@
 #include "tlv.h"
 #include "transport.h"
 #include "pmc_common.h"
+#include "power_profile.h"
 
 #define BAD_ACTION   -1
 #define BAD_ID   -1
@@ -154,6 +155,7 @@ struct management_id idtab[] = {
{ "PORT_SERVICE_STATS_NP", MID_PORT_SERVICE_STATS_NP, do_get_action },
{ "UNICAST_MASTER_TABLE_NP", MID_UNICAST_MASTER_TABLE_NP, do_get_action 
},
{ "PORT_HWCLOCK_NP", MID_PORT_HWCLOCK_NP, do_get_action },
+   { "POWER_PROFILE_SETTINGS_NP", MID_POWER_PROFILE_SETTINGS_NP, 
do_set_action },
 };
 
 static void do_get_action(struct pmc *pmc, int action, int index, char *str)
@@ -168,6 +170,7 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
 {
int cnt, code = idtab[index].code, freq_traceable, leap_59, leap_61,
ptp_timescale, time_traceable, utc_off_valid;
+   struct ieee_c37_238_settings_np pwr;
struct grandmaster_settings_np gsn;
struct management_tlv_datum mtd;
struct subscribe_events_np sen;
@@ -302,6 +305,37 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
}
pmc_send_set_action(pmc, code, , sizeof(pnp));
break;
+   case MID_POWER_PROFILE_SETTINGS_NP:
+   cnt = sscanf(str, " %*s %*s "
+"version   %hu "
+"grandmasterID %hx "
+"grandmasterTimeInaccuracy %u "
+"networkTimeInaccuracy %u "
+"totalTimeInaccuracy   %u ",
+,
+,
+,
+,
+);
+   if (cnt != 5) {
+   fprintf(stderr, "%s SET needs 5 values\n",
+   idtab[index].name);
+   break;
+   }
+   switch (pwr.version) {
+   case IEEE_C37_238_VERSION_NONE:
+   case IEEE_C37_238_VERSION_2011:
+   case IEEE_C37_238_VERSION_2017:
+   pmc_send_set_action(pmc, code, , sizeof(pwr));
+   break;
+   default:
+   fprintf(stderr, "\nusage: set PROFILE_SETTINGS_NP 
version "
+   "%hu (none), %hu (2011), or %hu (2017)\n\n",
+   IEEE_C37_238_VERSION_NONE,
+   IEEE_C37_238_VERSION_2011,
+   IEEE_C37_238_VERSION_2017);
+   }
+   break;
}
 }
 
@@ -573,6 +607,9 @@ static int pmc_tlv_datalen(struct pmc *pmc, int id)
case MID_PORT_HWCLOCK_NP:
len += sizeof(struct 

[Linuxptp-devel] [PATCH v6 11/11] Introduce a time zone helper program.

2023-02-20 Thread Richard Cochran
The ptp4l program supports up to four time zones via the
ALTERNATE_TIME_OFFSET_INDICATOR TLV.  Introduce a helper program that
leverages the local time zone database to monitor for changes in
daylight savings time and publishing them.

Signed-off-by: Richard Cochran 
---
 makefile |   7 +-
 tz2alt.8 | 126 ++
 tz2alt.c | 379 +++
 3 files changed, 510 insertions(+), 2 deletions(-)
 create mode 100644 tz2alt.8
 create mode 100644 tz2alt.c

diff --git a/makefile b/makefile
index 0f8f185..3e3b8b3 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ CC= $(CROSS_COMPILE)gcc
 VER = -DVER=$(version)
 CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
 LDLIBS = -lm -lrt -pthread $(EXTRA_LDFLAGS)
-PRG= ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster ts2phc
+PRG= ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster ts2phc tz2alt
 FILTERS= filter.o mave.o mmedian.o
 SERVOS = linreg.o ntpshm.o nullf.o pi.o refclock_sock.o servo.o
 TRANSP = raw.o transport.o udp.o udp6.o uds.o
@@ -35,7 +35,7 @@ OBJ   = bmc.o clock.o clockadj.o clockcheck.o config.o 
designated_fsm.o \
  unicast_fsm.o unicast_service.o util.o version.o
 
 OBJECTS= $(OBJ) hwstamp_ctl.o nsm.o phc2sys.o phc_ctl.o pmc.o 
pmc_agent.o \
- pmc_common.o sysoff.o timemaster.o $(TS2PHC)
+ pmc_common.o sysoff.o timemaster.o $(TS2PHC) tz2alt.o
 SRC= $(OBJECTS:.o=.c)
 DEPEND = $(OBJECTS:.o=.d)
 srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
@@ -72,6 +72,9 @@ ts2phc: config.o clockadj.o hash.o interface.o msg.o phc.o 
pmc_agent.o \
  pmc_common.o print.o $(SERVOS) sk.o $(TS2PHC) tlv.o transport.o raw.o \
  udp.o udp6.o uds.o util.o version.o
 
+tz2alt: config.o hash.o interface.o lstab.o msg.o phc.o pmc_common.o print.o \
+ sk.o tlv.o $(TRANSP) tz2alt.o util.o version.o
+
 version.o: .version version.sh $(filter-out version.d,$(DEPEND))
 
 .version: force
diff --git a/tz2alt.8 b/tz2alt.8
new file mode 100644
index 000..66a6605
--- /dev/null
+++ b/tz2alt.8
@@ -0,0 +1,126 @@
+.TH TS2ALT 8 "February 2023" "linuxptp"
+.SH NAME
+tz2alt - Monitors daylight savings time changes and publishes them to PTP 
stack.
+
+.SH SYNOPSIS
+.B ts2alt
+[
+.B \-hmqv
+] [
+.BI \-f " conf"
+] [
+.BI \-k " key"
+] [
+.BI \-p " period"
+] [
+.BI \-w " window"
+] [
+.BI \-z " timezone"
+] [
+.I long-options
+]
+.I .\|.\|.
+
+.SH DESCRIPTION
+.B tz2alt
+leverages the local time zone database to monitor for changes in
+daylight savings time and publishes the pending changes to the PTP
+stack.
+
+.SH OPTIONS
+.TP
+.BI \-f " config"
+Read configuration from the specified file.
+No configuration file is read by default.
+.TP
+.BI \-h
+Displays the command line help summary.
+.TP
+.BI \-l " print-level"
+Sets the maximum syslog level of messages which should be printed or
+sent to the system logger. The default is 6 (LOG_INFO).
+.TP
+.B \-m
+Prints log messages to the standard output.
+.TP
+.B \-q
+Prevents sending log messages to the system logger.
+.TP
+.B \-v
+Prints the software version and exits.
+
+.SH LONG OPTIONS
+
+Each and every configuration file option (see below) may also appear
+as a "long" style command line argument.  For example, the use_syslog
+option may be set using either of these two forms.
+
+.RS
+\f(CW\-\-use_syslog 1   \-\-use_syslog=1\fP
+.RE
+
+Option values given on the command line override values in the global
+section of the configuration file.
+
+.SH CONFIGURATION FILE
+
+The configuration file is divided into sections. Each section starts with a
+line containing its name enclosed in brackets and it follows with settings.
+Each setting is placed on a separate line, it contains the name of the
+option and the value separated by whitespace characters. Empty lines and lines
+starting with # are ignored.
+
+.SH GLOBAL OPTIONS
+
+.TP
+.B domainNumber
+The domain attribute of the local clock.
+The default is 0.
+
+.TP
+.B leapfile
+The path to the current leap seconds definition file. In a Debian
+system this file is provided by the tzdata package and can be found at
+/usr/share/zoneinfo/leap-seconds.list. If a leapfile is configured it
+will be reloaded if modified. The default is an empty string, which
+causes the program to use a hard coded table that reflects the known
+leap seconds on the date of the software's release.
+
+.TP
+.B logging_level
+The maximum logging level of messages which should be printed.
+The default is 6 (LOG_INFO).
+
+.TP
+.B message_tag
+The tag which is added to all messages printed to the standard output
+or system log.  The default is an empty string (which cannot be set in
+the configuration file as the option requires an argument).
+
+.TP
+.B transportSpecific
+The transport specific field. Must be in the range 0 to 255.
+The default is 0.
+
+.TP
+.B use_syslog
+Print messages to the system log if enabled.  The default is 

[Linuxptp-devel] [PATCH v6 08/11] Add the ALTERNATE_TIME_OFFSET_NAME management message.

2023-02-20 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 clock.c  | 21 +++-
 pmc.c|  9 +
 pmc_common.c | 56 +++-
 tlv.c| 11 +++
 tlv.h|  5 +
 5 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/clock.c b/clock.c
index cc85081..67c0044 100644
--- a/clock.c
+++ b/clock.c
@@ -381,6 +381,7 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
  struct ptp_message *rsp, int id)
 {
struct alternate_time_offset_properties *atop;
+   struct alternate_time_offset_name *aton;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
@@ -461,6 +462,16 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
mtd->val = c->tds.flags & PTP_TIMESCALE;
datalen = sizeof(*mtd);
break;
+   case MID_ALTERNATE_TIME_OFFSET_NAME:
+   key = clock_alttime_offset_get_key(req);
+   if (key >= MAX_TIME_ZONES) {
+   break;
+   }
+   aton = (struct alternate_time_offset_name *) tlv->data;
+   aton->keyField = key;
+   ptp_text_copy(>displayName, >tz[key].display_name);
+   datalen = sizeof(*aton) + aton->displayName.length;
+   break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
key = clock_alttime_offset_get_key(req);
if (key >= MAX_TIME_ZONES) {
@@ -558,6 +569,7 @@ static int clock_management_set(struct clock *c, struct 
port *p,
int id, struct ptp_message *req, int *changed)
 {
struct alternate_time_offset_properties *atop;
+   struct alternate_time_offset_name *aton;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
@@ -579,6 +591,14 @@ static int clock_management_set(struct clock *c, struct 
port *p,
*changed = 1;
respond = 1;
break;
+   case MID_ALTERNATE_TIME_OFFSET_NAME:
+   aton = (struct alternate_time_offset_name *) tlv->data;
+   key = aton->keyField;
+   if (key < MAX_TIME_ZONES &&
+   !static_ptp_text_copy(>tz[key].display_name, 
>displayName)) {
+   respond = 1;
+   }
+   break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) tlv->data;
key = atop->keyField;
@@ -1594,7 +1614,6 @@ int clock_manage(struct clock *c, struct port *p, struct 
ptp_message *msg)
case MID_ACCEPTABLE_MASTER_TABLE:
case MID_ACCEPTABLE_MASTER_MAX_TABLE_SIZE:
case MID_ALTERNATE_TIME_OFFSET_ENABLE:
-   case MID_ALTERNATE_TIME_OFFSET_NAME:
case MID_ALTERNATE_TIME_OFFSET_MAX_KEY:
case MID_TRANSPARENT_CLOCK_DEFAULT_DATA_SET:
case MID_PRIMARY_DOMAIN:
diff --git a/pmc.c b/pmc.c
index fd8b978..35dddba 100644
--- a/pmc.c
+++ b/pmc.c
@@ -158,6 +158,7 @@ static void pmc_show_signaling(struct ptp_message *msg, 
FILE *fp)
 static void pmc_show(struct ptp_message *msg, FILE *fp)
 {
struct alternate_time_offset_properties *atop;
+   struct alternate_time_offset_name *aton;
struct ieee_c37_238_settings_np *pwr;
struct unicast_master_table_np *umtn;
struct grandmaster_settings_np *gsn;
@@ -361,6 +362,14 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
fprintf(fp, "TIMESCALE_PROPERTIES "
IFMT "ptpTimescale %d", mtd->val & PTP_TIMESCALE ? 1 : 
0);
break;
+   case MID_ALTERNATE_TIME_OFFSET_NAME:
+   aton = (struct alternate_time_offset_name *) mgt->data;
+   fprintf(fp, "ALTERNATE_TIME_OFFSET_NAME "
+   IFMT "keyField   %hhu"
+   IFMT "displayName%s",
+   aton->keyField,
+   text2str(>displayName));
+   break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) mgt->data;
next_jump = atop->timeOfNextJump.seconds_msb;
diff --git a/pmc_common.c b/pmc_common.c
index 7ab73aa..20f7b22 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -79,6 +79,7 @@ static void do_get_action(struct pmc *pmc, int action, int 
index, char *str);
 static void do_set_action(struct pmc *pmc, int action, int index, char *str);
 static void not_supported(struct pmc *pmc, int action, int index, char *str);
 static void null_management(struct pmc *pmc, int action, int index, char *str);
+stati

[Linuxptp-devel] [PATCH v6 06/11] Prepare clock based storage of up to four time zones.

2023-02-20 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 clock.c | 19 ---
 tz.h| 13 +
 2 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 tz.h

diff --git a/clock.c b/clock.c
index 1e51dd8..2d5b3eb 100644
--- a/clock.c
+++ b/clock.c
@@ -42,6 +42,7 @@
 #include "rtnl.h"
 #include "tlv.h"
 #include "tsproc.h"
+#include "tz.h"
 #include "uds.h"
 #include "util.h"
 
@@ -79,6 +80,15 @@ struct clock_subscriber {
time_t expiration;
 };
 
+struct time_zone {
+   bool enabled;
+   int32_t current_offset;
+   int32_t jump_seconds;
+   uint16_t next_jump_msb;
+   uint32_t next_jump_lsb;
+   struct static_ptp_text display_name;
+};
+
 struct clock {
enum clock_type type;
struct config *config;
@@ -137,6 +147,7 @@ struct clock {
struct monitor *slave_event_monitor;
int step_window_counter;
int step_window;
+   struct time_zone tz[MAX_TIME_ZONES];
 };
 
 struct clock the_clock;
@@ -896,19 +907,17 @@ int clock_required_modes(struct clock *c)
 struct clock *clock_create(enum clock_type type, struct config *config,
   const char *phc_device)
 {
+   int conf_phc_index, i, max_adj = 0, phc_index, required_modes = 0, sfl, 
sw_ts;
enum servo_type servo = config_get_int(config, NULL, "clock_servo");
char ts_label[IF_NAMESIZE], phc[32], *tmp;
enum timestamp_type timestamping;
-   int phc_index, conf_phc_index, required_modes = 0;
struct clock *c = _clock;
-   int max_adj = 0, sw_ts;
const char *uds_ifname;
double fadj = 0.0;
struct port *p;
unsigned char oui[OUI_LEN];
struct interface *iface;
struct timespec ts;
-   int sfl;
 
clock_gettime(CLOCK_REALTIME, );
srandom(ts.tv_sec ^ ts.tv_nsec);
@@ -1205,6 +1214,10 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
c->dad.pds.observedParentClockPhaseChangeRate= 0x7fff;
c->dad.ptl = c->ptl;
 
+   for (i = 0; i < MAX_TIME_ZONES; i++) {
+   c->tz[i].display_name.max_symbols = MAX_TZ_DISPLAY_NAME;
+   }
+
clock_sync_interval(c, 0);
 
LIST_INIT(>subscribers);
diff --git a/tz.h b/tz.h
new file mode 100644
index 000..14f0dbb
--- /dev/null
+++ b/tz.h
@@ -0,0 +1,13 @@
+/**
+ * @file tz.h
+ * @brief Implements time zone constants.
+ * @note Copyright (C) 2021 Richard Cochran 
+ * @note SPDX-License-Identifier: GPL-2.0+
+ */
+#ifndef HAVE_TZ_H
+#define HAVE_TZ_H
+
+#define MAX_TZ_DISPLAY_NAME10
+#define MAX_TIME_ZONES 4
+
+#endif
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v6 05/11] tlv: Encode and decode alternate time offset indicator TLVs.

2023-02-20 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 tlv.c | 58 ++
 tlv.h | 26 ++
 2 files changed, 84 insertions(+)

diff --git a/tlv.c b/tlv.c
index 66d797a..81982c6 100644
--- a/tlv.c
+++ b/tlv.c
@@ -78,6 +78,22 @@ static uint16_t flip16(void *p)
return v;
 }
 
+static void host2net32_unaligned(void *p)
+{
+   int32_t v;
+   memcpy(, p, sizeof(v));
+   v = htonl(v);
+   memcpy(p, , sizeof(v));
+}
+
+static void net2host32_unaligned(void *p)
+{
+   int32_t v;
+   memcpy(, p, sizeof(v));
+   v = ntohl(v);
+   memcpy(p, , sizeof(v));
+}
+
 static int64_t host2net64_unaligned(void *p)
 {
int64_t v;
@@ -112,6 +128,43 @@ static bool tlv_array_invalid(struct TLV *tlv, size_t 
base_size, size_t item_siz
return (tlv->length == expected_length) ? false : true;
 }
 
+static int alttime_offset_post_recv(struct tlv_extra *extra)
+{
+   struct TLV *tlv = extra->tlv;
+   struct alternate_time_offset_indicator_tlv *atoi =
+   (struct alternate_time_offset_indicator_tlv *) tlv;
+
+   if (tlv->length < sizeof(struct alternate_time_offset_indicator_tlv) +
+   atoi->displayName.length - sizeof(struct TLV)) {
+   return -EBADMSG;
+   }
+
+   NTOHS(atoi->type);
+   NTOHS(atoi->length);
+   /* Message alignment broken by design. */
+   net2host32_unaligned(>currentOffset);
+   net2host32_unaligned(>jumpSeconds);
+   flip16(>timeOfNextJump.seconds_msb);
+   net2host32_unaligned(>timeOfNextJump.seconds_lsb);
+
+   return 0;
+}
+
+static void alttime_offset_pre_send(struct tlv_extra *extra)
+{
+   struct alternate_time_offset_indicator_tlv *atoi;
+
+   atoi = (struct alternate_time_offset_indicator_tlv *) extra->tlv;
+
+   HTONS(atoi->type);
+   HTONS(atoi->length);
+   /* Message alignment broken by design. */
+   host2net32_unaligned(>currentOffset);
+   host2net32_unaligned(>jumpSeconds);
+   flip16(>timeOfNextJump.seconds_msb);
+   host2net32_unaligned(>timeOfNextJump.seconds_lsb);
+}
+
 static int mgt_post_recv(struct management_tlv *m, uint16_t data_len,
 struct tlv_extra *extra)
 {
@@ -1065,6 +1118,8 @@ int tlv_post_recv(struct tlv_extra *extra)
}
break;
case TLV_ALTERNATE_TIME_OFFSET_INDICATOR:
+   result = alttime_offset_post_recv(extra);
+   break;
case TLV_AUTHENTICATION_2008:
case TLV_AUTHENTICATION_CHALLENGE:
case TLV_SECURITY_ASSOCIATION_UPDATE:
@@ -1128,7 +1183,10 @@ void tlv_pre_send(struct TLV *tlv, struct tlv_extra 
*extra)
unicast_negotiation_pre_send(tlv);
break;
case TLV_PATH_TRACE:
+   break;
case TLV_ALTERNATE_TIME_OFFSET_INDICATOR:
+   alttime_offset_pre_send(extra);
+   break;
case TLV_AUTHENTICATION_2008:
case TLV_AUTHENTICATION_CHALLENGE:
case TLV_SECURITY_ASSOCIATION_UPDATE:
diff --git a/tlv.h b/tlv.h
index a08c74a..15df2bb 100644
--- a/tlv.h
+++ b/tlv.h
@@ -175,6 +175,32 @@ struct grant_unicast_xmit_tlv {
uint8_t flags;
 } PACKED;
 
+struct alternate_time_offset_indicator_tlv {
+   Enumeration16   type;
+   UInteger16  length;
+   UInteger8   keyField;
+   /* Message alignment broken by design. */
+   Integer32   currentOffset;
+   Integer32   jumpSeconds;
+   struct {
+   uint16_t   seconds_msb; /* 16 bits + */
+   uint32_t   seconds_lsb; /* 32 bits = 48 bits*/
+   } PACKED timeOfNextJump;
+   struct PTPText  displayName;
+} PACKED;
+
+struct alternate_time_offset_properties {
+   UInteger8   keyField;
+   /* Message alignment broken by design. */
+   Integer32   currentOffset;
+   Integer32   jumpSeconds;
+   struct {
+   uint16_t   seconds_msb; /* 16 bits + */
+   uint32_t   seconds_lsb; /* 32 bits = 48 bits*/
+   } PACKED timeOfNextJump;
+   uint8_t pad;
+} PACKED;
+
 struct management_tlv {
Enumeration16 type;
UInteger16length;
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v6 10/11] pmc: Convert internal helper function into global method.

2023-02-20 Thread Richard Cochran
The function to set the alternate time offset name, a.k.a. time zone, will
be used by the time zone stand alone program.  Make the function into a
public PMC method.

Signed-off-by: Richard Cochran 
---
 pmc_common.c | 5 ++---
 pmc_common.h | 2 ++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/pmc_common.c b/pmc_common.c
index f5f6ec4..a03f191 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -79,7 +79,6 @@ static void do_get_action(struct pmc *pmc, int action, int 
index, char *str);
 static void do_set_action(struct pmc *pmc, int action, int index, char *str);
 static void not_supported(struct pmc *pmc, int action, int index, char *str);
 static void null_management(struct pmc *pmc, int action, int index, char *str);
-static int send_set_aton(struct pmc *pmc, int id, uint8_t key, const char 
*name);
 
 static const char *action_string[] = {
"GET",
@@ -233,7 +232,7 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
idtab[index].name);
break;
}
-   send_set_aton(pmc, code, key, display_name);
+   pmc_send_set_aton(pmc, code, key, display_name);
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
memset(, 0, sizeof(atop));
@@ -762,7 +761,7 @@ int pmc_send_set_action(struct pmc *pmc, int id, void 
*data, int datasize)
return 0;
 }
 
-static int send_set_aton(struct pmc *pmc, int id, uint8_t key, const char 
*name)
+int pmc_send_set_aton(struct pmc *pmc, int id, uint8_t key, const char *name)
 {
struct alternate_time_offset_name *aton;
struct management_tlv *mgt;
diff --git a/pmc_common.h b/pmc_common.h
index 8bea2e0..6fb2fae 100644
--- a/pmc_common.h
+++ b/pmc_common.h
@@ -41,6 +41,8 @@ int pmc_send_get_action(struct pmc *pmc, int id);
 
 int pmc_send_set_action(struct pmc *pmc, int id, void *data, int datasize);
 
+int pmc_send_set_aton(struct pmc *pmc, int id, uint8_t key, const char *name);
+
 struct ptp_message *pmc_recv(struct pmc *pmc);
 
 int pmc_target(struct pmc *pmc, struct PortIdentity *pid);
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v6 00/11] Profile support for IEEE C37.238-2011 and IEEE C37.238-2017

2023-02-20 Thread Richard Cochran
ChangeLog
~
v6:
 Add new configuration options into default.cfg and man page
 Make pmc SET command ready for 2106 (Miroslav)
 Use SPDX tag for new file tz.h 
v5:
 Rename tztool to tz2alt
 Provide man page for tz2alt
 Fix year 2106 bug
v4:
 Preserve all 48 bits of "next jump" (v3 review feedback from Erez Geva)
 Accept the full range for domainNumber (suggested by v.nosikov)
v3:
 Initial RFC
v2, v1:
 never published

The Power Profile specifies two new TLVs:

1. IEEE_C37_238 TLV

   - New configuration option to enable the TLV.

   - New configuration options for grandmasterID and default
 totalTimeInaccuracy.

   - New custom management message for changing totalTimeInaccuracy at
 run time. This message allows switching the TLV from the 2017
 format into the 2011 format by specifying grandmasterTimeInaccuracy
 and networkTimeInaccuracy.

2. ALTERNATE_TIME_OFFSET_INDICATOR TLV

   - New custom management message for enabling the TLV and setting
 the TLV values.

   - New helper program that computes the values from the local time
 and the Linux time zone data base and then sends the values to
 ptp4l. This method assumes that the local Linux system time and
 the PHC clock are synchronized.

Thanks,
Richard


Richard Cochran (11):
  Accept the full range for domainNumber.
  tlv: Encode and decode power profile TLVs.
  Introduce the power profile.
  Add a custom management message for power profile settings.
  tlv: Encode and decode alternate time offset indicator TLVs.
  Prepare clock based storage of up to four time zones.
  Add the ALTERNATE_TIME_OFFSET_PROPERTIES management message.
  Add the ALTERNATE_TIME_OFFSET_NAME management message.
  Implement the ALTERNATE_TIME_OFFSET_ENABLE management message.
  pmc: Convert internal helper function into global method.
  Introduce a time zone helper program.

 clock.c | 188 --
 clock.h |   8 +
 config.c|  17 +-
 configs/default.cfg |   5 +
 makefile|   7 +-
 pmc.c   |  49 ++
 pmc_common.c| 136 +++-
 pmc_common.h|   2 +
 port.c  |  76 -
 port_private.h  |   3 +
 power_profile.h |  31 
 ptp4l.8 |  38 +
 tlv.c   | 146 +
 tlv.h   |  64 
 tz.h|  13 ++
 tz2alt.8| 126 +++
 tz2alt.c| 379 
 util.h  |   7 +
 18 files changed, 1278 insertions(+), 17 deletions(-)
 create mode 100644 power_profile.h
 create mode 100644 tz.h
 create mode 100644 tz2alt.8
 create mode 100644 tz2alt.c

-- 
2.30.2



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


[Linuxptp-devel] [PATCH v6 07/11] Add the ALTERNATE_TIME_OFFSET_PROPERTIES management message.

2023-02-20 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 clock.c  | 70 +---
 pmc.c| 17 +
 pmc_common.c | 27 +++-
 tlv.c| 21 
 util.h   |  7 ++
 5 files changed, 137 insertions(+), 5 deletions(-)

diff --git a/clock.c b/clock.c
index 2d5b3eb..cc85081 100644
--- a/clock.c
+++ b/clock.c
@@ -157,6 +157,32 @@ static int clock_resize_pollfd(struct clock *c, int 
new_nports);
 static void clock_remove_port(struct clock *c, struct port *p);
 static void clock_stats_display(struct clock_stats *s);
 
+uint8_t clock_alttime_offset_get_key(struct ptp_message *req)
+{
+   struct management_tlv_datum *mtd;
+   struct management_tlv *mgt =
+   (struct management_tlv *) req->management.suffix;
+
+   /*
+* The data field of incoming management request messages is
+* normally ignored.  Indeed it can even be empty.  However
+* the ALTERNATE_TIME_OFFSET requests are exceptional because
+* the key field selects one of the configured time zones.
+*
+* Provide the first time zone for an empty GET, and validate
+* the length of the request when non-empty.
+*/
+   if (mgt->length == sizeof(mgt->id)) {
+   return 0;
+   }
+   if (mgt->length < sizeof(mgt->id) + sizeof(*mtd)) {
+   return MAX_TIME_ZONES;
+   }
+   mtd = (struct management_tlv_datum *) mgt->data;
+
+   return mtd->val;
+}
+
 static void remove_subscriber(struct clock_subscriber *s)
 {
LIST_REMOVE(s, list);
@@ -354,6 +380,7 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
  struct ptp_message *req,
  struct ptp_message *rsp, int id)
 {
+   struct alternate_time_offset_properties *atop;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
@@ -363,6 +390,7 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
struct PTPText *text;
uint16_t duration;
int datalen = 0;
+   uint8_t key;
 
extra = tlv_extra_alloc();
if (!extra) {
@@ -433,6 +461,24 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
mtd->val = c->tds.flags & PTP_TIMESCALE;
datalen = sizeof(*mtd);
break;
+   case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
+   key = clock_alttime_offset_get_key(req);
+   if (key >= MAX_TIME_ZONES) {
+   break;
+   }
+   atop = (struct alternate_time_offset_properties *) tlv->data;
+   atop->keyField = key;
+   /* Message alignment broken by design. */
+   memcpy(>currentOffset, >tz[key].current_offset,
+  sizeof(atop->currentOffset));
+   memcpy(>jumpSeconds, >tz[key].jump_seconds,
+  sizeof(atop->jumpSeconds));
+   memcpy(>timeOfNextJump.seconds_lsb, 
>tz[key].next_jump_lsb,
+  sizeof(atop->timeOfNextJump.seconds_lsb));
+   memcpy(>timeOfNextJump.seconds_msb, 
>tz[key].next_jump_msb,
+  sizeof(atop->timeOfNextJump.seconds_msb));
+   datalen = sizeof(*atop);
+   break;
case MID_TIME_STATUS_NP:
tsn = (struct time_status_np *) tlv->data;
tsn->master_offset = tmv_to_nanoseconds(c->master_offset);
@@ -511,11 +557,12 @@ static int clock_management_get_response(struct clock *c, 
struct port *p,
 static int clock_management_set(struct clock *c, struct port *p,
int id, struct ptp_message *req, int *changed)
 {
-   int respond = 0;
-   struct management_tlv *tlv;
-   struct management_tlv_datum *mtd;
+   struct alternate_time_offset_properties *atop;
struct grandmaster_settings_np *gsn;
+   struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
+   struct management_tlv *tlv;
+   int key, respond = 0;
 
tlv = (struct management_tlv *) req->management.suffix;
 
@@ -532,6 +579,22 @@ static int clock_management_set(struct clock *c, struct 
port *p,
*changed = 1;
respond = 1;
break;
+   case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
+   atop = (struct alternate_time_offset_properties *) tlv->data;
+   key = atop->keyField;
+   if (key < MAX_TIME_ZONES) {
+   /* Message alignment broken by design. */
+   memcpy(>tz[key].current_offset, >currentOffset,
+  sizeof(c->tz[key].current_offset));
+ 

[Linuxptp-devel] [PATCH v6 01/11] Accept the full range for domainNumber.

2023-02-20 Thread Richard Cochran
IEEE Std C37.238 invented its own rules with respect to the range of
values allowed for the domainNumber attribute.  The profile

"complies with IEEE Std 1588-2008 with the exception of the use of
the reserved domain 254. The value 254 is an exception granted to
this profile."

In addition, Table 2 of IEEE Std 1588-2019 presents an incoherent
Swiss cheese of allowed ranges, depending sdoId and network transport.

Avoid the standardized madness by allowing the user to simply choose
any domainNumber they want.

Signed-off-by: Richard Cochran 
---
 config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.c b/config.c
index 9b86b35..f028b88 100644
--- a/config.c
+++ b/config.c
@@ -248,7 +248,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("delay_response_timeout", 0, 0, UINT8_MAX),
GLOB_ITEM_INT("dscp_event", 0, 0, 63),
GLOB_ITEM_INT("dscp_general", 0, 0, 63),
-   GLOB_ITEM_INT("domainNumber", 0, 0, 127),
+   GLOB_ITEM_INT("domainNumber", 0, 0, 255),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX),
PORT_ITEM_INT("fault_reset_interval", 4, INT8_MIN, INT8_MAX),
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v6 02/11] tlv: Encode and decode power profile TLVs.

2023-02-20 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 tlv.c | 36 
 tlv.h | 24 
 2 files changed, 60 insertions(+)

diff --git a/tlv.c b/tlv.c
index 7a2a4fa..fb807e8 100644
--- a/tlv.c
+++ b/tlv.c
@@ -35,6 +35,7 @@
(tlv->length < sizeof(struct type) - sizeof(struct TLV))
 
 uint8_t ieee8021_id[3] = { IEEE_802_1_COMMITTEE };
+uint8_t ieeec37_238_id[3] = { IEEE_C37_238_PROFILE };
 uint8_t itu_t_id[3] = { ITU_T_COMMITTEE };
 
 static TAILQ_HEAD(tlv_pool, tlv_extra) tlv_pool =
@@ -680,6 +681,7 @@ static void nsm_resp_pre_send(struct tlv_extra *extra)
 
 static int org_post_recv(struct organization_tlv *org)
 {
+   struct ieee_c37_238_2017_tlv *p;
struct follow_up_info_tlv *f;
struct msg_interface_rate_tlv *m;
 
@@ -718,6 +720,24 @@ static int org_post_recv(struct organization_tlv *org)
}
 
}
+   if (0 == memcmp(org->id, ieeec37_238_id, sizeof(ieeec37_238_id))) {
+   if (org->subtype[0] || org->subtype[1]) {
+   return 0;
+   }
+   switch (org->subtype[2]) {
+   case 1:
+   case 2:
+   /* Layout of 2011 and 2017 messages is compatible. */
+   if (org->length + sizeof(struct TLV) !=
+   sizeof(struct ieee_c37_238_2017_tlv))
+   goto bad_length;
+   p = (struct ieee_c37_238_2017_tlv *) org;
+   NTOHS(p->grandmasterID);
+   NTOHL(p->reserved1);
+   NTOHL(p->totalTimeInaccuracy);
+   break;
+   }
+   }
return 0;
 bad_length:
return -EBADMSG;
@@ -725,6 +745,7 @@ bad_length:
 
 static void org_pre_send(struct organization_tlv *org)
 {
+   struct ieee_c37_238_2017_tlv *p;
struct follow_up_info_tlv *f;
struct msg_interface_rate_tlv *m;
 
@@ -754,6 +775,21 @@ static void org_pre_send(struct organization_tlv *org)
break;
}
}
+   if (0 == memcmp(org->id, ieeec37_238_id, sizeof(ieeec37_238_id))) {
+   if (org->subtype[0] || org->subtype[1]) {
+   return;
+   }
+   switch (org->subtype[2]) {
+   case 1:
+   case 2:
+   /* Layout of 2011 and 2017 messages is compatible. */
+   p = (struct ieee_c37_238_2017_tlv *) org;
+   HTONS(p->grandmasterID);
+   HTONL(p->reserved1);
+   HTONL(p->totalTimeInaccuracy);
+   break;
+   }
+   }
 }
 
 static int slave_delay_timing_data_post_revc(struct tlv_extra *extra)
diff --git a/tlv.h b/tlv.h
index ec22e2f..3d838b7 100644
--- a/tlv.h
+++ b/tlv.h
@@ -213,6 +213,8 @@ struct nsm_resp_tlv_foot {
 /* Organizationally Unique Identifiers */
 #define IEEE_802_1_COMMITTEE 0x00, 0x80, 0xC2
 extern uint8_t ieee8021_id[3];
+#define IEEE_C37_238_PROFILE 0x1C, 0x12, 0x9D
+extern uint8_t ieeec37_238_id[3];
 
 struct organization_tlv {
Enumeration16 type;
@@ -300,6 +302,28 @@ struct follow_up_info_tlv {
Integer32 scaledLastGmPhaseChange;
 } PACKED;
 
+struct ieee_c37_238_2011_tlv {
+   Enumeration16 type;
+   UInteger16length;
+   Octet id[3];
+   Octet subtype[3];
+   UInteger16grandmasterID;
+   UInteger32grandmasterTimeInaccuracy;
+   UInteger32networkTimeInaccuracy;
+   Octet pad[2];
+} PACKED;
+
+struct ieee_c37_238_2017_tlv {
+   Enumeration16 type;
+   UInteger16length;
+   Octet id[3];
+   Octet subtype[3];
+   UInteger16grandmasterID;
+   UInteger32reserved1;
+   UInteger32totalTimeInaccuracy;
+   Octet pad[2];
+} PACKED;
+
 struct msg_interval_req_tlv {
Enumeration16 type;
UInteger16length;
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v6 09/11] Implement the ALTERNATE_TIME_OFFSET_ENABLE management message.

2023-02-20 Thread Richard Cochran
If the local PTP management client enables a time zone, append the
matching TLV to outgoing Announce messages.

Signed-off-by: Richard Cochran 
---
 clock.c  | 80 ++--
 clock.h  |  8 ++
 pmc.c|  8 ++
 pmc_common.c | 17 ++-
 port.c   |  3 ++
 5 files changed, 113 insertions(+), 3 deletions(-)

diff --git a/clock.c b/clock.c
index 67c0044..75d7c40 100644
--- a/clock.c
+++ b/clock.c
@@ -157,6 +157,43 @@ static int clock_resize_pollfd(struct clock *c, int 
new_nports);
 static void clock_remove_port(struct clock *c, struct port *p);
 static void clock_stats_display(struct clock_stats *s);
 
+static int clock_alttime_offset_append(struct clock *c, int key, struct 
ptp_message *m)
+{
+   struct alternate_time_offset_indicator_tlv *atoi;
+   struct tlv_extra *extra;
+   int tlv_len;
+
+   tlv_len = sizeof(*atoi) + c->tz[key].display_name.length;
+   if (tlv_len % 2) {
+   tlv_len++;
+   }
+   extra = msg_tlv_append(m, tlv_len);
+   if (!extra) {
+   return -1;
+   }
+   atoi = (struct alternate_time_offset_indicator_tlv *) extra->tlv;
+   atoi->type = TLV_ALTERNATE_TIME_OFFSET_INDICATOR;
+   atoi->length = tlv_len - sizeof(atoi->type) - sizeof(atoi->length);
+   atoi->keyField = key;
+
+   /* Message alignment broken by design. */
+   memcpy(>currentOffset, >tz[key].current_offset,
+  sizeof(atoi->currentOffset));
+
+   memcpy(>jumpSeconds, >tz[key].jump_seconds,
+  sizeof(atoi->jumpSeconds));
+
+   memcpy(>timeOfNextJump.seconds_lsb, >tz[key].next_jump_lsb,
+  sizeof(atoi->timeOfNextJump.seconds_lsb));
+
+   memcpy(>timeOfNextJump.seconds_msb, >tz[key].next_jump_msb,
+  sizeof(atoi->timeOfNextJump.seconds_msb));
+
+   ptp_text_copy(>displayName, >tz[key].display_name);
+
+   return 0;
+}
+
 uint8_t clock_alttime_offset_get_key(struct ptp_message *req)
 {
struct management_tlv_datum *mtd;
@@ -462,6 +499,16 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
mtd->val = c->tds.flags & PTP_TIMESCALE;
datalen = sizeof(*mtd);
break;
+   case MID_ALTERNATE_TIME_OFFSET_ENABLE:
+   key = clock_alttime_offset_get_key(req);
+   if (key >= MAX_TIME_ZONES) {
+   break;
+   }
+   mtd = (struct management_tlv_datum *) tlv->data;
+   mtd->val = key;
+   mtd->reserved = c->tz[key].enabled ? 1 : 0;
+   datalen = sizeof(*mtd);
+   break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
key = clock_alttime_offset_get_key(req);
if (key >= MAX_TIME_ZONES) {
@@ -574,7 +621,7 @@ static int clock_management_set(struct clock *c, struct 
port *p,
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
struct management_tlv *tlv;
-   int key, respond = 0;
+   int k, key, respond = 0;
 
tlv = (struct management_tlv *) req->management.suffix;
 
@@ -591,6 +638,20 @@ static int clock_management_set(struct clock *c, struct 
port *p,
*changed = 1;
respond = 1;
break;
+   case MID_ALTERNATE_TIME_OFFSET_ENABLE:
+   mtd = (struct management_tlv_datum *) tlv->data;
+   key = mtd->val;
+   if (key == 0xff) {
+   for (k = 0; k < MAX_TIME_ZONES; k++) {
+   c->tz[k].enabled = mtd->reserved & 1 ? true : 
false;
+   }
+   respond = 1;
+   }
+   if (key < MAX_TIME_ZONES) {
+   c->tz[key].enabled = mtd->reserved & 1 ? true : false;
+   respond = 1;
+   }
+   break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
aton = (struct alternate_time_offset_name *) tlv->data;
key = aton->keyField;
@@ -896,6 +957,22 @@ static int forwarding(struct clock *c, struct port *p)
 
 /* public methods */
 
+int clock_append_timezones(struct clock *c, struct ptp_message *m)
+{
+   int err = 0, i;
+
+   for (i = 0; i < MAX_TIME_ZONES; i++) {
+   if (!c->tz[i].enabled) {
+   continue;
+   }
+   err = clock_alttime_offset_append(c, i, m);
+   if (err) {
+   break;
+   }
+   }
+   return err;
+}
+
 UInteger8 clock_class(struct clock *c)
 {
return c->dds.clockQuality.clockClass;
@@ -1613,7 +1690,6 @@ int clock_manage(struct clock *c, struct port *p, struct 
ptp_message *msg)
case MID_GRANDMASTER_CLUSTER_TABL

Re: [Linuxptp-devel] [PATCH v5 07/11] Add the ALTERNATE_TIME_OFFSET_PROPERTIES management message.

2023-02-19 Thread Richard Cochran
On Wed, Feb 15, 2023 at 03:20:06PM +0100, Miroslav Lichvar wrote:
> With this patch it works for me (new test in the testsuite):

Thanks for the patch, and thanks for the super awesome test suite!  It
lets us develop with confidence.

Richard


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


Re: [Linuxptp-devel] [PATCH 0/6] man pages: Spring Cleaning

2023-02-17 Thread Richard Cochran
On Thu, Feb 16, 2023 at 08:10:20PM -0800, Richard Cochran wrote:
> Early on, around v1, there were about thirty configuration options,
> and these were grouped into functional areas in the man page.  At the
> time, that made some kind of sense.
> 
> Nowadays, the number of configuration options has grown to nearly 100,
> and, as a result, the ordering within the ptp4l man page is chaotic at
> best.  With so many options, the only sane ordering is alphabetical.
> 
> When alphabetizing, I did a sanity check that the context wasn't
> changed by doing:

s/context/content/

>sort ptp4l.8 > before
>(hack)
>sort ptp4l.8 > after
>diff -u before after

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH v5 03/11] Introduce the power profile.

2023-02-16 Thread Richard Cochran
On Wed, Feb 15, 2023 at 03:15:13PM +0100, Miroslav Lichvar wrote:
> On Tue, Feb 14, 2023 at 09:00:50PM -0800, Richard Cochran wrote:
> > @@ -300,6 +308,11 @@ 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_ENU("power_profile.version", IEEE_C37_238_VERSION_NONE, 
> > ieee_c37_238_enu),
> > +   PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
> > 0x, 0, INT_MAX),
> > +   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
> > INT_MAX),
> > +   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
> > INT_MAX),
> > +   PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
> 
> I'm sorry I didn't notice this earlier. Can you please add these to
> configs/default.cfg?

Sure, and the man page, too...


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


[Linuxptp-devel] [PATCH 6/6] man pages: Bump date.

2023-02-16 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 phc2sys.8 | 2 +-
 pmc.8 | 2 +-
 ptp4l.8   | 2 +-
 ts2phc.8  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/phc2sys.8 b/phc2sys.8
index 33c126e..6c6c7e8 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -1,4 +1,4 @@
-.TH PHC2SYS 8 "January 2021" "linuxptp"
+.TH PHC2SYS 8 "February 2023" "linuxptp"
 .SH NAME
 phc2sys \- synchronize two or more clocks
 
diff --git a/pmc.8 b/pmc.8
index f2b6ad7..629eadf 100644
--- a/pmc.8
+++ b/pmc.8
@@ -1,4 +1,4 @@
-.TH PMC 8 "October 2013" "linuxptp"
+.TH PMC 8 "February 2023" "linuxptp"
 .SH NAME
 pmc \- PTP management client
 
diff --git a/ptp4l.8 b/ptp4l.8
index 484793e..55070aa 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -1,4 +1,4 @@
-.TH PTP4l 8 "January 2021" "linuxptp"
+.TH PTP4l 8 "February 2023" "linuxptp"
 .SH NAME
 ptp4l - PTP Boundary/Ordinary/Transparent Clock
 
diff --git a/ts2phc.8 b/ts2phc.8
index 658457d..3c71d47 100644
--- a/ts2phc.8
+++ b/ts2phc.8
@@ -1,4 +1,4 @@
-.TH TS2PHC 8 "January 2021" "linuxptp"
+.TH TS2PHC 8 "February 2023" "linuxptp"
 .SH NAME
 ts2phc - Synchronizes one or more PTP Hardware Clocks using external time 
stamps.
 
-- 
2.30.2



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


[Linuxptp-devel] [PATCH 4/6] Alphabetize configuration options in the pmc man page.

2023-02-16 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 pmc.8 | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pmc.8 b/pmc.8
index 2659f3e..f2b6ad7 100644
--- a/pmc.8
+++ b/pmc.8
@@ -145,10 +145,6 @@ options. The name of the section is the name of the 
configured port (e.g.
 The domain attribute of the local clock. The default is 0.
 
 .SH PORT OPTIONS
-.TP
-.B transportSpecific
-The transport specific field. Must be in the range 0 to 255.
-The default is 0.
 
 .TP
 .B network_transport
@@ -159,6 +155,10 @@ is UDPv4.
 .B ptp_dst_mac
 The MAC address to which PTP management messages should be sent. Relevant only 
with L2 transport. The default is 01:1B:19:00:00:00.
 
+.TP
+.B transportSpecific
+The transport specific field. Must be in the range 0 to 255.
+The default is 0.
 
 .SH MANAGEMENT IDS
 
-- 
2.30.2



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


[Linuxptp-devel] [PATCH 1/6] Alphabetize configuration options in the ptp4l man page.

2023-02-16 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 ptp4l.8 | 1125 ++-
 1 file changed, 618 insertions(+), 507 deletions(-)

diff --git a/ptp4l.8 b/ptp4l.8
index 8b477f0..484793e 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -142,93 +142,68 @@ See UNICAST DISCOVERY OPTIONS, below.
 
 .SH PORT OPTIONS
 
+.TP
+.B announceReceiptTimeout
+The number of missed Announce messages before the last Announce messages
+expires.
+The default is 3.
+
+.TP
+.B boundary_clock_jbod
+When running as a boundary clock (that is, when more than one network
+interface is configured), ptp4l performs a sanity check to make sure
+that all of the ports share the same hardware clock device. This
+option allows ptp4l to work as a boundary clock using "just a bunch of
+devices" that are not synchronized to each other. For this mode, the
+collection of clocks must be synchronized by an external program, for
+example phc2sys(8) in "automatic" mode.
+The default is 0 (disabled).
+
 .TP
 .B delayAsymmetry
 The time difference in nanoseconds of the transmit and receive
 paths. This value should be positive when the server-to-client
 propagation time is longer and negative when the client-to-server time
 is longer. The default is 0 nanoseconds.
+
 .TP
-.B logAnnounceInterval
-The mean time interval between Announce messages. A shorter interval makes
-ptp4l react faster to the changes in the client/server hierarchy. The interval
-should be the same in the whole domain. It's specified as a power of two in
-seconds.
-The default is 1 (2 seconds).
-.TP
-.B logSyncInterval
-The mean time interval between Sync messages. A shorter interval may improve
-accuracy of the local clock. It's specified as a power of two in seconds.
-The default is 0 (1 second).
-.TP
-.B operLogSyncInterval
-The Sync message interval to be requested once the clock enters the
-SERVO_LOCKED_STABLE state.  If the 'msg_interval_request' option is
-set, then the local client port will request the remote server to
-switch to the given message rate via a signaling message containing a
-Message interval request TLV.  This option is specified as a power of
-two in seconds, and default value is 0 (1 second).
-.TP
-.B logMinDelayReqInterval
-The minimum permitted mean time interval between Delay_Req messages. A shorter
-interval makes ptp4l react faster to the changes in the path delay. It's
-specified as a power of two in seconds.
-The default is 0 (1 second).
-.TP
-.B logMinPdelayReqInterval
-The minimum permitted mean time interval between Pdelay_Req messages. It's
-specified as a power of two in seconds.
-The default is 0 (1 second).
-.TP
-.B operLogPdelayReqInterval
-The Pdelay Request messages interval to be used once the clock enters
-the SERVO_LOCKED_STABLE state.  If the 'msg_interval_request' option
-is set, then the local client port will adopt this rate when the local
-clock enters the "locked stable" state.  This option is specified as a
-power of two in seconds, and the default value is 0 (1 second).
-.TP
-.B inhibit_delay_req
-Don't send any delay requests. This will need the asCapable config option to be
-set to 'true'. This is useful when running as a designated server who does not
-need to calculate offset from client. The default is 0 (disabled).
+.B delay_filter
+Select the algorithm used to filter the measured delay and peer delay. Possible
+values are moving_average and moving_median.
+The default is moving_median.
+
 .TP
-.B announceReceiptTimeout
-The number of missed Announce messages before the last Announce messages
-expires.
-The default is 3.
+.B delay_filter_length
+The length of the delay filter in samples.
+The default is 10.
+
 .TP
-.B syncReceiptTimeout
-The number of sync/follow up messages that may go missing before
-triggering a Best Master Clock election. This option is used for
-running in gPTP mode according to the 802.1AS-2011 standard. Setting
-this option to zero will disable the sync message timeout.
-The default is 0 or disabled.
+.B delay_mechanism
+Select the delay mechanism. Possible values are E2E, P2P, NONE and Auto.
+The default is E2E.
+
 .TP
 .B delay_response_timeout
 The number of delay response messages that may go missing before
 triggering a synchronization fault. Setting this option to zero will
 disable the delay response timeout.
 The default is 0 or disabled.
+
 .TP
-.B transportSpecific
-The transport specific field. Must be in the range 0 to 255.
+.B egressLatency
+Specifies the difference in nanoseconds between the actual transmission
+time at the reference plane and the reported transmit time stamp. This
+value will be added to egress time stamps obtained from the hardware.
 The default is 0.
+
 .TP
-.B ignore_transport_specific
-By default, incoming messages are dropped if their transportSpecific
-field does not match the configured value.  However, many of
-transports specified in the 1588 standard mandate ignoring this field.
-Moreover, some equipment is 

[Linuxptp-devel] [PATCH 5/6] Alphabetize configuration options in the ts2phc man page.

2023-02-16 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 ts2phc.8 | 33 +++--
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/ts2phc.8 b/ts2phc.8
index c64a50b..658457d 100644
--- a/ts2phc.8
+++ b/ts2phc.8
@@ -124,12 +124,14 @@ changing the clock frequency (phase when using nullf 
servo) instead of stepping
 the clock. This is only applied on the first update. When set to 0.0, the servo
 will not step the clock on start.
 The default is 0.2 (20 microseconds).
+
 .TP
 .B free_running
 When set to 1, no PHC will be adjusted.
 This option can be useful in test scenarios, for example to determine
 how well synchronized a group of local clocks are to each other.
 The default is 0 (adjust the clocks).
+
 .TP
 .B leapfile
 The path to the current leap seconds definition file. In a Debian
@@ -138,37 +140,32 @@ system this file is provided by the tzdata package and 
can be found at
 will be reloaded if modified. The default is an empty string, which
 causes the program to use a hard coded table that reflects the known
 leap seconds on the date of the software's release.
+
 .TP
 .B logging_level
 The maximum logging level of messages which should be printed.
 The default is 6 (LOG_INFO).
+
 .TP
 .B max_frequency
 The maximum allowed frequency adjustment of the clock in parts per
 billion.  This is an additional limit to the maximum allowed by the
 hardware. When set to 0, the hardware limit will be used.
 The default is 9 (90%).
+
 .TP
 .B message_tag
 The tag which is added to all messages printed to the standard output
 or system log.  The default is an empty string (which cannot be set in
 the configuration file as the option requires an argument).
+
 .TP
 .B step_threshold
 The maximum offset, specified in seconds, that the servo will correct
 by changing the clock frequency instead of stepping the clock. When
 set to 0.0, the servo will never step the clock except on start.
 The default is 0.0.
-.TP
-.B ts2phc.tod_source
-Specifies the source of Time of Day (ToD) data.
-Use the key word "generic" for an external 1-PPS without ToD information.
-When using a PHC as the time source, the clock may be identified by its 
character
-device (like /dev/ptp0) or its associated network interface (like
-eth0).
-Use the key word "nmea" for an external 1-PPS from a GPS providing ToD
-information via the RMC NMEA sentence.
-The default is "generic"
+
 .TP
 .B ts2phc.nmea_remote_host, ts2phc.nmea_remote_port
 Specifies the remote host providing ToD information when using the
@@ -176,6 +173,7 @@ Specifies the remote host providing ToD information when 
using the
 specified, then the given remote connection will be used in preference
 to the configured serial port.
 These options default to the empty string, that is, not specified.
+
 .TP
 .B ts2phc.nmea_serialport, ts2phc.nmea_baudrate
 Specifies the serial port and baudrate in bps for character device
@@ -185,6 +183,7 @@ ts2phc.nmea_remote_port, are both specified, then the given 
remote
 connection will be used in preference to the configured serial port.
 The default serial port is "/dev/ttyS0".
 The default baudrate is 9600 bps.
+
 .TP
 .B ts2phc.perout_phase
 Configures the offset between the beginning of the second and the PPS
@@ -195,6 +194,7 @@ instead PPS will be requested to start at an absolute time 
equal to the
 nearest 2nd full second since the start of the program. This should yield
 the same effect, but may not work with drivers that do not support
 starting periodic output at an absolute time.
+
 .TP
 .B ts2phc.pulsewidth
 The pulse width of the external PPS signal in nanoseconds.
@@ -205,9 +205,22 @@ emit using this pulse width. If this fails, it is assumed 
that the specified
 pulse width is correct, and the value is used in the edge rejection algorithm.
 The supported range is 100 to 99000 nanoseconds.
 The default is 5 nanoseconds.
+
+.TP
+.B ts2phc.tod_source
+Specifies the source of Time of Day (ToD) data.
+Use the key word "generic" for an external 1-PPS without ToD information.
+When using a PHC as the time source, the clock may be identified by its 
character
+device (like /dev/ptp0) or its associated network interface (like
+eth0).
+Use the key word "nmea" for an external 1-PPS from a GPS providing ToD
+information via the RMC NMEA sentence.
+The default is "generic"
+
 .TP
 .B use_syslog
 Print messages to the system log if enabled.  The default is 1 (enabled).
+
 .TP
 .B verbose
 Print messages to the standard output if enabled.  The default is 0 (disabled).
-- 
2.30.2



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


[Linuxptp-devel] [PATCH 3/6] Alphabetize configuration options in the phc2sys man page.

2023-02-16 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 phc2sys.8 | 122 +++---
 1 file changed, 61 insertions(+), 61 deletions(-)

diff --git a/phc2sys.8 b/phc2sys.8
index b686d72..33c126e 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -262,12 +262,38 @@ sets the program options. This is the only used option.
 
 .SH FILE OPTIONS
 
+.TP
+.B clock_servo
+The servo which is used to synchronize the local clock. Valid values
+are "pi" for a PI controller, "linreg" for an adaptive controller using
+linear regression, "ntpshm" for the NTP SHM reference clock to allow
+another process to synchronize the local clock (the SHM segment number
+is set to the domain number), and "nullf" for a servo that always dials
+frequency offset zero (for use in SyncE nodes). The default is "pi."
+Same as option
+.B \-E
+(see above).
+
 .TP
 .B domainNumber
 Specify the domain number used by phc2sys. The default is 0. Same as option
 .B \-n
 (see above).
 
+.TP
+.B first_step_threshold
+Specify the step threshold applied only on the first update. It is the
+maximum offset that is corrected by adjusting clock. It's specified in
+seconds. The value of 0.0 disables stepping on start. The default is
+0.2 (20 microseconds).
+Same as option
+.B \-F
+(see above).
+
+.TP
+.B free-running
+Don't adjust the sink clock if enabled. The default is 0 (disabled).
+
 .TP
 .B kernel_leap
 When a leap second is announced, let the kernel apply it by stepping the
@@ -296,49 +322,17 @@ Same as option
 (see above).
 
 .TP
-.B sanity_freq_limit
-The maximum allowed frequency offset between uncorrected clock and the
-system monotonic clock in parts per billion (ppb). This is used as a
-sanity check of the synchronized clock. When a larger offset is measured,
-a warning message will be printed and the servo will be reset. When set
-to 0, the sanity check is disabled. The default is 2 (20%).
+.B ntpshm_segment
+The number of the SHM segment used by ntpshm servo.  The default is 0.
 Same as option
-.B \-L
+.B \-M
 (see above).
 
 .TP
-.B clock_servo
-The servo which is used to synchronize the local clock. Valid values
-are "pi" for a PI controller, "linreg" for an adaptive controller using
-linear regression, "ntpshm" for the NTP SHM reference clock to allow
-another process to synchronize the local clock (the SHM segment number
-is set to the domain number), and "nullf" for a servo that always dials
-frequency offset zero (for use in SyncE nodes). The default is "pi."
+.B pi_integral_const
+Specifies the integral constant of the PI controller.
 Same as option
-.B \-E
-(see above).
-
-.TP
-.B free-running
-Don't adjust the sink clock if enabled. The default is 0 (disabled).
-
-.TP
-.B transportSpecific
-The transport specific field. Must be in the range 0 to 255.
-The default is 0.
-
-.TP
-.B use_syslog
-Print messages to the system log if enabled.  The default is 1 (enabled).
-Related to option
-.B \-q
-(see above).
-
-.TP
-.B verbose
-Print messages to the standard output if enabled.  The default is 0 (disabled).
-Related to option
-.B \-m
+.B \-I
 (see above).
 
 .TP
@@ -349,10 +343,19 @@ Same as option
 (see above).
 
 .TP
-.B pi_integral_const
-Specifies the integral constant of the PI controller.
+.B refclock_sock_address
+The address of the UNIX domain socket to be used by the refclock_sock servo.
+The default is /var/run/refclock.ptp.sock.
+
+.TP
+.B sanity_freq_limit
+The maximum allowed frequency offset between uncorrected clock and the
+system monotonic clock in parts per billion (ppb). This is used as a
+sanity check of the synchronized clock. When a larger offset is measured,
+a warning message will be printed and the servo will be reset. When set
+to 0, the sanity check is disabled. The default is 2 (20%).
 Same as option
-.B \-I
+.B \-L
 (see above).
 
 .TP
@@ -368,26 +371,9 @@ Same as option
 (see above).
 
 .TP
-.B first_step_threshold
-Specify the step threshold applied only on the first update. It is the
-maximum offset that is corrected by adjusting clock. It's specified in
-seconds. The value of 0.0 disables stepping on start. The default is
-0.2 (20 microseconds).
-Same as option
-.B \-F
-(see above).
-
-.TP
-.B refclock_sock_address
-The address of the UNIX domain socket to be used by the refclock_sock servo.
-The default is /var/run/refclock.ptp.sock.
-
-.TP
-.B ntpshm_segment
-The number of the SHM segment used by ntpshm servo.  The default is 0.
-Same as option
-.B \-M
-(see above).
+.B transportSpecific
+The transport specific field. Must be in the range 0 to 255.
+The default is 0.
 
 .TP
 .B uds_address
@@ -397,6 +383,20 @@ Same as option
 .B \-z
 (see above).
 
+.TP
+.B use_syslog
+Print messages to the system log if enabled.  The default is 1 (enabled).
+Related to option
+.B \-q
+(see above).
+
+.TP
+.B verbose
+Print messages to the standard output if enabled.  The default is 0

[Linuxptp-devel] [PATCH 0/6] man pages: Spring Cleaning

2023-02-16 Thread Richard Cochran
Early on, around v1, there were about thirty configuration options,
and these were grouped into functional areas in the man page.  At the
time, that made some kind of sense.

Nowadays, the number of configuration options has grown to nearly 100,
and, as a result, the ordering within the ptp4l man page is chaotic at
best.  With so many options, the only sane ordering is alphabetical.

When alphabetizing, I did a sanity check that the context wasn't
changed by doing:

   sort ptp4l.8 > before
   (hack)
   sort ptp4l.8 > after
   diff -u before after


Richard Cochran (6):
  Alphabetize configuration options in the ptp4l man page.
  Remove stray copy/pasteo from the phc2sys man page.
  Alphabetize configuration options in the phc2sys man page.
  Alphabetize configuration options in the pmc man page.
  Alphabetize configuration options in the ts2phc man page.
  man pages: Bump date.

 phc2sys.8 |  129 +++---
 pmc.8 |   10 +-
 ptp4l.8   | 1127 +
 ts2phc.8  |   35 +-
 4 files changed, 710 insertions(+), 591 deletions(-)

-- 
2.30.2



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


[Linuxptp-devel] [PATCH 2/6] Remove stray copy/pasteo from the phc2sys man page.

2023-02-16 Thread Richard Cochran
---
 phc2sys.8 | 5 -
 1 file changed, 5 deletions(-)

diff --git a/phc2sys.8 b/phc2sys.8
index e6d9675..b686d72 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -279,11 +279,6 @@ stepping). Relevant only with software time stamping. The 
default is 1
 .B \-x
 (see above).
 
-The maximum logging level of messages which should be printed.
-The default is 6 (LOG_INFO). Same as option
-.B \-l
-(see above).
-
 .TP
 .B logging_level
 The maximum logging level of messages which should be printed.
-- 
2.30.2



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


Re: [Linuxptp-devel] [PATCH v2 1/4] clockadj: return error if failed to adjust clock

2023-02-14 Thread Richard Cochran
On Mon, Feb 13, 2023 at 01:24:27PM +, Wojtek Wasko via Linuxptp-devel wrote:
> Current clockadj code only prints a message in case the kernel returns
> an error for a clock adjustment and prevents the higher-level code from
> reacting to failure.
> 
> Signed-off-by: Wojciech Wasko 

Series applied.

Thanks,
Richard


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


[Linuxptp-devel] [PATCH v5 02/11] tlv: Encode and decode power profile TLVs.

2023-02-14 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 tlv.c | 36 
 tlv.h | 24 
 2 files changed, 60 insertions(+)

diff --git a/tlv.c b/tlv.c
index 7a2a4fa..fb807e8 100644
--- a/tlv.c
+++ b/tlv.c
@@ -35,6 +35,7 @@
(tlv->length < sizeof(struct type) - sizeof(struct TLV))
 
 uint8_t ieee8021_id[3] = { IEEE_802_1_COMMITTEE };
+uint8_t ieeec37_238_id[3] = { IEEE_C37_238_PROFILE };
 uint8_t itu_t_id[3] = { ITU_T_COMMITTEE };
 
 static TAILQ_HEAD(tlv_pool, tlv_extra) tlv_pool =
@@ -680,6 +681,7 @@ static void nsm_resp_pre_send(struct tlv_extra *extra)
 
 static int org_post_recv(struct organization_tlv *org)
 {
+   struct ieee_c37_238_2017_tlv *p;
struct follow_up_info_tlv *f;
struct msg_interface_rate_tlv *m;
 
@@ -718,6 +720,24 @@ static int org_post_recv(struct organization_tlv *org)
}
 
}
+   if (0 == memcmp(org->id, ieeec37_238_id, sizeof(ieeec37_238_id))) {
+   if (org->subtype[0] || org->subtype[1]) {
+   return 0;
+   }
+   switch (org->subtype[2]) {
+   case 1:
+   case 2:
+   /* Layout of 2011 and 2017 messages is compatible. */
+   if (org->length + sizeof(struct TLV) !=
+   sizeof(struct ieee_c37_238_2017_tlv))
+   goto bad_length;
+   p = (struct ieee_c37_238_2017_tlv *) org;
+   NTOHS(p->grandmasterID);
+   NTOHL(p->reserved1);
+   NTOHL(p->totalTimeInaccuracy);
+   break;
+   }
+   }
return 0;
 bad_length:
return -EBADMSG;
@@ -725,6 +745,7 @@ bad_length:
 
 static void org_pre_send(struct organization_tlv *org)
 {
+   struct ieee_c37_238_2017_tlv *p;
struct follow_up_info_tlv *f;
struct msg_interface_rate_tlv *m;
 
@@ -754,6 +775,21 @@ static void org_pre_send(struct organization_tlv *org)
break;
}
}
+   if (0 == memcmp(org->id, ieeec37_238_id, sizeof(ieeec37_238_id))) {
+   if (org->subtype[0] || org->subtype[1]) {
+   return;
+   }
+   switch (org->subtype[2]) {
+   case 1:
+   case 2:
+   /* Layout of 2011 and 2017 messages is compatible. */
+   p = (struct ieee_c37_238_2017_tlv *) org;
+   HTONS(p->grandmasterID);
+   HTONL(p->reserved1);
+   HTONL(p->totalTimeInaccuracy);
+   break;
+   }
+   }
 }
 
 static int slave_delay_timing_data_post_revc(struct tlv_extra *extra)
diff --git a/tlv.h b/tlv.h
index ec22e2f..3d838b7 100644
--- a/tlv.h
+++ b/tlv.h
@@ -213,6 +213,8 @@ struct nsm_resp_tlv_foot {
 /* Organizationally Unique Identifiers */
 #define IEEE_802_1_COMMITTEE 0x00, 0x80, 0xC2
 extern uint8_t ieee8021_id[3];
+#define IEEE_C37_238_PROFILE 0x1C, 0x12, 0x9D
+extern uint8_t ieeec37_238_id[3];
 
 struct organization_tlv {
Enumeration16 type;
@@ -300,6 +302,28 @@ struct follow_up_info_tlv {
Integer32 scaledLastGmPhaseChange;
 } PACKED;
 
+struct ieee_c37_238_2011_tlv {
+   Enumeration16 type;
+   UInteger16length;
+   Octet id[3];
+   Octet subtype[3];
+   UInteger16grandmasterID;
+   UInteger32grandmasterTimeInaccuracy;
+   UInteger32networkTimeInaccuracy;
+   Octet pad[2];
+} PACKED;
+
+struct ieee_c37_238_2017_tlv {
+   Enumeration16 type;
+   UInteger16length;
+   Octet id[3];
+   Octet subtype[3];
+   UInteger16grandmasterID;
+   UInteger32reserved1;
+   UInteger32totalTimeInaccuracy;
+   Octet pad[2];
+} PACKED;
+
 struct msg_interval_req_tlv {
Enumeration16 type;
UInteger16length;
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v5 08/11] Add the ALTERNATE_TIME_OFFSET_NAME management message.

2023-02-14 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 clock.c  | 21 +++-
 pmc.c|  9 +
 pmc_common.c | 56 +++-
 tlv.c| 11 +++
 tlv.h|  5 +
 5 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/clock.c b/clock.c
index e09bd18..91eb5a1 100644
--- a/clock.c
+++ b/clock.c
@@ -381,6 +381,7 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
  struct ptp_message *rsp, int id)
 {
struct alternate_time_offset_properties *atop;
+   struct alternate_time_offset_name *aton;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
@@ -461,6 +462,16 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
mtd->val = c->tds.flags & PTP_TIMESCALE;
datalen = sizeof(*mtd);
break;
+   case MID_ALTERNATE_TIME_OFFSET_NAME:
+   key = clock_alttime_offset_get_key(req);
+   if (key >= MAX_TIME_ZONES) {
+   break;
+   }
+   aton = (struct alternate_time_offset_name *) tlv->data;
+   aton->keyField = key;
+   ptp_text_copy(>displayName, >tz[key].display_name);
+   datalen = sizeof(*aton) + aton->displayName.length;
+   break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
key = clock_alttime_offset_get_key(req);
if (key >= MAX_TIME_ZONES) {
@@ -558,6 +569,7 @@ static int clock_management_set(struct clock *c, struct 
port *p,
int id, struct ptp_message *req, int *changed)
 {
struct alternate_time_offset_properties *atop;
+   struct alternate_time_offset_name *aton;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
@@ -579,6 +591,14 @@ static int clock_management_set(struct clock *c, struct 
port *p,
*changed = 1;
respond = 1;
break;
+   case MID_ALTERNATE_TIME_OFFSET_NAME:
+   aton = (struct alternate_time_offset_name *) tlv->data;
+   key = aton->keyField;
+   if (key < MAX_TIME_ZONES &&
+   !static_ptp_text_copy(>tz[key].display_name, 
>displayName)) {
+   respond = 1;
+   }
+   break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) tlv->data;
key = atop->keyField;
@@ -1594,7 +1614,6 @@ int clock_manage(struct clock *c, struct port *p, struct 
ptp_message *msg)
case MID_ACCEPTABLE_MASTER_TABLE:
case MID_ACCEPTABLE_MASTER_MAX_TABLE_SIZE:
case MID_ALTERNATE_TIME_OFFSET_ENABLE:
-   case MID_ALTERNATE_TIME_OFFSET_NAME:
case MID_ALTERNATE_TIME_OFFSET_MAX_KEY:
case MID_TRANSPARENT_CLOCK_DEFAULT_DATA_SET:
case MID_PRIMARY_DOMAIN:
diff --git a/pmc.c b/pmc.c
index fd8b978..35dddba 100644
--- a/pmc.c
+++ b/pmc.c
@@ -158,6 +158,7 @@ static void pmc_show_signaling(struct ptp_message *msg, 
FILE *fp)
 static void pmc_show(struct ptp_message *msg, FILE *fp)
 {
struct alternate_time_offset_properties *atop;
+   struct alternate_time_offset_name *aton;
struct ieee_c37_238_settings_np *pwr;
struct unicast_master_table_np *umtn;
struct grandmaster_settings_np *gsn;
@@ -361,6 +362,14 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
fprintf(fp, "TIMESCALE_PROPERTIES "
IFMT "ptpTimescale %d", mtd->val & PTP_TIMESCALE ? 1 : 
0);
break;
+   case MID_ALTERNATE_TIME_OFFSET_NAME:
+   aton = (struct alternate_time_offset_name *) mgt->data;
+   fprintf(fp, "ALTERNATE_TIME_OFFSET_NAME "
+   IFMT "keyField   %hhu"
+   IFMT "displayName%s",
+   aton->keyField,
+   text2str(>displayName));
+   break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
atop = (struct alternate_time_offset_properties *) mgt->data;
next_jump = atop->timeOfNextJump.seconds_msb;
diff --git a/pmc_common.c b/pmc_common.c
index 4ae9db0..1062c59 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -79,6 +79,7 @@ static void do_get_action(struct pmc *pmc, int action, int 
index, char *str);
 static void do_set_action(struct pmc *pmc, int action, int index, char *str);
 static void not_supported(struct pmc *pmc, int action, int index, char *str);
 static void null_management(struct pmc *pmc, int action, int index, char *str);
+stati

[Linuxptp-devel] [PATCH v5 11/11] Introduce a time zone helper program.

2023-02-14 Thread Richard Cochran
The ptp4l program supports up to four time zones via the
ALTERNATE_TIME_OFFSET_INDICATOR TLV.  Introduce a helper program that
leverages the local time zone database to monitor for changes in
daylight savings time and publishing them.

Signed-off-by: Richard Cochran 
---
 makefile |   7 +-
 tz2alt.8 | 126 ++
 tz2alt.c | 379 +++
 3 files changed, 510 insertions(+), 2 deletions(-)
 create mode 100644 tz2alt.8
 create mode 100644 tz2alt.c

diff --git a/makefile b/makefile
index 0f8f185..3e3b8b3 100644
--- a/makefile
+++ b/makefile
@@ -22,7 +22,7 @@ CC= $(CROSS_COMPILE)gcc
 VER = -DVER=$(version)
 CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
 LDLIBS = -lm -lrt -pthread $(EXTRA_LDFLAGS)
-PRG= ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster ts2phc
+PRG= ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster ts2phc tz2alt
 FILTERS= filter.o mave.o mmedian.o
 SERVOS = linreg.o ntpshm.o nullf.o pi.o refclock_sock.o servo.o
 TRANSP = raw.o transport.o udp.o udp6.o uds.o
@@ -35,7 +35,7 @@ OBJ   = bmc.o clock.o clockadj.o clockcheck.o config.o 
designated_fsm.o \
  unicast_fsm.o unicast_service.o util.o version.o
 
 OBJECTS= $(OBJ) hwstamp_ctl.o nsm.o phc2sys.o phc_ctl.o pmc.o 
pmc_agent.o \
- pmc_common.o sysoff.o timemaster.o $(TS2PHC)
+ pmc_common.o sysoff.o timemaster.o $(TS2PHC) tz2alt.o
 SRC= $(OBJECTS:.o=.c)
 DEPEND = $(OBJECTS:.o=.d)
 srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
@@ -72,6 +72,9 @@ ts2phc: config.o clockadj.o hash.o interface.o msg.o phc.o 
pmc_agent.o \
  pmc_common.o print.o $(SERVOS) sk.o $(TS2PHC) tlv.o transport.o raw.o \
  udp.o udp6.o uds.o util.o version.o
 
+tz2alt: config.o hash.o interface.o lstab.o msg.o phc.o pmc_common.o print.o \
+ sk.o tlv.o $(TRANSP) tz2alt.o util.o version.o
+
 version.o: .version version.sh $(filter-out version.d,$(DEPEND))
 
 .version: force
diff --git a/tz2alt.8 b/tz2alt.8
new file mode 100644
index 000..66a6605
--- /dev/null
+++ b/tz2alt.8
@@ -0,0 +1,126 @@
+.TH TS2ALT 8 "February 2023" "linuxptp"
+.SH NAME
+tz2alt - Monitors daylight savings time changes and publishes them to PTP 
stack.
+
+.SH SYNOPSIS
+.B ts2alt
+[
+.B \-hmqv
+] [
+.BI \-f " conf"
+] [
+.BI \-k " key"
+] [
+.BI \-p " period"
+] [
+.BI \-w " window"
+] [
+.BI \-z " timezone"
+] [
+.I long-options
+]
+.I .\|.\|.
+
+.SH DESCRIPTION
+.B tz2alt
+leverages the local time zone database to monitor for changes in
+daylight savings time and publishes the pending changes to the PTP
+stack.
+
+.SH OPTIONS
+.TP
+.BI \-f " config"
+Read configuration from the specified file.
+No configuration file is read by default.
+.TP
+.BI \-h
+Displays the command line help summary.
+.TP
+.BI \-l " print-level"
+Sets the maximum syslog level of messages which should be printed or
+sent to the system logger. The default is 6 (LOG_INFO).
+.TP
+.B \-m
+Prints log messages to the standard output.
+.TP
+.B \-q
+Prevents sending log messages to the system logger.
+.TP
+.B \-v
+Prints the software version and exits.
+
+.SH LONG OPTIONS
+
+Each and every configuration file option (see below) may also appear
+as a "long" style command line argument.  For example, the use_syslog
+option may be set using either of these two forms.
+
+.RS
+\f(CW\-\-use_syslog 1   \-\-use_syslog=1\fP
+.RE
+
+Option values given on the command line override values in the global
+section of the configuration file.
+
+.SH CONFIGURATION FILE
+
+The configuration file is divided into sections. Each section starts with a
+line containing its name enclosed in brackets and it follows with settings.
+Each setting is placed on a separate line, it contains the name of the
+option and the value separated by whitespace characters. Empty lines and lines
+starting with # are ignored.
+
+.SH GLOBAL OPTIONS
+
+.TP
+.B domainNumber
+The domain attribute of the local clock.
+The default is 0.
+
+.TP
+.B leapfile
+The path to the current leap seconds definition file. In a Debian
+system this file is provided by the tzdata package and can be found at
+/usr/share/zoneinfo/leap-seconds.list. If a leapfile is configured it
+will be reloaded if modified. The default is an empty string, which
+causes the program to use a hard coded table that reflects the known
+leap seconds on the date of the software's release.
+
+.TP
+.B logging_level
+The maximum logging level of messages which should be printed.
+The default is 6 (LOG_INFO).
+
+.TP
+.B message_tag
+The tag which is added to all messages printed to the standard output
+or system log.  The default is an empty string (which cannot be set in
+the configuration file as the option requires an argument).
+
+.TP
+.B transportSpecific
+The transport specific field. Must be in the range 0 to 255.
+The default is 0.
+
+.TP
+.B use_syslog
+Print messages to the system log if enabled.  The default is 

[Linuxptp-devel] [PATCH v5 03/11] Introduce the power profile.

2023-02-14 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 config.c| 15 +-
 port.c  | 53 +
 port_private.h  |  3 +++
 power_profile.h | 31 +
 tlv.h   |  8 
 5 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 power_profile.h

diff --git a/config.c b/config.c
index f028b88..cb4421f 100644
--- a/config.c
+++ b/config.c
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "ether.h"
 #include "hash.h"
+#include "power_profile.h"
 #include "print.h"
 #include "util.h"
 
@@ -66,7 +67,7 @@ typedef union {
char *s;
 } any_t;
 
-#define CONFIG_LABEL_SIZE 32
+#define CONFIG_LABEL_SIZE 64
 
 #define CFG_ITEM_STATIC (1 << 0) /* statically allocated, not to be freed */
 #define CFG_ITEM_LOCKED (1 << 1) /* command line value, may not be changed */
@@ -190,6 +191,13 @@ static struct config_enum hwts_filter_enu[] = {
{ NULL, 0 },
 };
 
+static struct config_enum ieee_c37_238_enu[] = {
+   { "none", IEEE_C37_238_VERSION_NONE },
+   { "2011", IEEE_C37_238_VERSION_2011 },
+   { "2017", IEEE_C37_238_VERSION_2017 },
+   { NULL, 0 },
+};
+
 static struct config_enum nw_trans_enu[] = {
{ "L2",TRANS_IEEE_802_3 },
{ "UDPv4", TRANS_UDP_IPV4   },
@@ -300,6 +308,11 @@ 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_ENU("power_profile.version", IEEE_C37_238_VERSION_NONE, 
ieee_c37_238_enu),
+   PORT_ITEM_INT("power_profile.2011.grandmasterTimeInaccuracy", 
0x, 0, INT_MAX),
+   PORT_ITEM_INT("power_profile.2011.networkTimeInaccuracy", 0, 0, 
INT_MAX),
+   PORT_ITEM_INT("power_profile.2017.totalTimeInaccuracy", 0x, 0, 
INT_MAX),
+   PORT_ITEM_INT("power_profile.grandmasterID", 0, 0, 0x),
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 92f3ee3..23697a5 100644
--- a/port.c
+++ b/port.c
@@ -453,6 +453,46 @@ static int follow_up_info_append(struct ptp_message *m)
return 0;
 }
 
+static int ieee_c37_238_append(struct port *p, struct ptp_message *m)
+{
+   struct ieee_c37_238_2017_tlv *p17;
+   struct ieee_c37_238_2011_tlv *p11;
+   struct tlv_extra *extra;
+
+   switch (p->pwr.version) {
+   case IEEE_C37_238_VERSION_NONE:
+   return 0;
+   case IEEE_C37_238_VERSION_2011:
+   extra = msg_tlv_append(m, sizeof(*p11));
+   if (!extra) {
+   return -1;
+   }
+   p11 = (struct ieee_c37_238_2011_tlv *) extra->tlv;
+   p11->type = TLV_ORGANIZATION_EXTENSION;
+   p11->length = sizeof(*p11) - sizeof(p11->type) - 
sizeof(p11->length);
+   memcpy(p11->id, ieeec37_238_id, sizeof(ieeec37_238_id));
+   p11->subtype[2] = 1;
+   p11->grandmasterID = p->pwr.grandmasterID;
+   p11->grandmasterTimeInaccuracy = 
p->pwr.grandmasterTimeInaccuracy;
+   p11->networkTimeInaccuracy = p->pwr.networkTimeInaccuracy;
+   break;
+   case IEEE_C37_238_VERSION_2017:
+   extra = msg_tlv_append(m, sizeof(*p17));
+   if (!extra) {
+   return -1;
+   }
+   p17 = (struct ieee_c37_238_2017_tlv *) extra->tlv;
+   p17->type = TLV_ORGANIZATION_EXTENSION;
+   p17->length = sizeof(*p17) - sizeof(p17->type) - 
sizeof(p17->length);
+   memcpy(p17->id, ieeec37_238_id, sizeof(ieeec37_238_id));
+   p17->subtype[2] = 2;
+   p17->grandmasterID = p->pwr.grandmasterID;
+   p17->totalTimeInaccuracy = p->pwr.totalTimeInaccuracy;
+   break;
+   }
+   return 0;
+}
+
 static int net_sync_resp_append(struct port *p, struct ptp_message *m)
 {
struct timePropertiesDS tp = clock_time_properties(p->clock);
@@ -1622,6 +1662,9 @@ int port_tx_announce(struct port *p, struct address *dst, 
uint16_t sequence_id)
if (p->path_trace_enabled && path_trace_append(p, msg, dad)) {
pr_err("%s: append path trace failed", p->log_name);
}
+   if (ieee_c37_238_append(p, msg)) {
+   pr_err("%s: append power profile failed", p->log_name);
+   }
 
err = port_prepare_and_send(p, msg,

[Linuxptp-devel] [PATCH v5 05/11] tlv: Encode and decode alternate time offset indicator TLVs.

2023-02-14 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 tlv.c | 58 ++
 tlv.h | 26 ++
 2 files changed, 84 insertions(+)

diff --git a/tlv.c b/tlv.c
index 66d797a..81982c6 100644
--- a/tlv.c
+++ b/tlv.c
@@ -78,6 +78,22 @@ static uint16_t flip16(void *p)
return v;
 }
 
+static void host2net32_unaligned(void *p)
+{
+   int32_t v;
+   memcpy(, p, sizeof(v));
+   v = htonl(v);
+   memcpy(p, , sizeof(v));
+}
+
+static void net2host32_unaligned(void *p)
+{
+   int32_t v;
+   memcpy(, p, sizeof(v));
+   v = ntohl(v);
+   memcpy(p, , sizeof(v));
+}
+
 static int64_t host2net64_unaligned(void *p)
 {
int64_t v;
@@ -112,6 +128,43 @@ static bool tlv_array_invalid(struct TLV *tlv, size_t 
base_size, size_t item_siz
return (tlv->length == expected_length) ? false : true;
 }
 
+static int alttime_offset_post_recv(struct tlv_extra *extra)
+{
+   struct TLV *tlv = extra->tlv;
+   struct alternate_time_offset_indicator_tlv *atoi =
+   (struct alternate_time_offset_indicator_tlv *) tlv;
+
+   if (tlv->length < sizeof(struct alternate_time_offset_indicator_tlv) +
+   atoi->displayName.length - sizeof(struct TLV)) {
+   return -EBADMSG;
+   }
+
+   NTOHS(atoi->type);
+   NTOHS(atoi->length);
+   /* Message alignment broken by design. */
+   net2host32_unaligned(>currentOffset);
+   net2host32_unaligned(>jumpSeconds);
+   flip16(>timeOfNextJump.seconds_msb);
+   net2host32_unaligned(>timeOfNextJump.seconds_lsb);
+
+   return 0;
+}
+
+static void alttime_offset_pre_send(struct tlv_extra *extra)
+{
+   struct alternate_time_offset_indicator_tlv *atoi;
+
+   atoi = (struct alternate_time_offset_indicator_tlv *) extra->tlv;
+
+   HTONS(atoi->type);
+   HTONS(atoi->length);
+   /* Message alignment broken by design. */
+   host2net32_unaligned(>currentOffset);
+   host2net32_unaligned(>jumpSeconds);
+   flip16(>timeOfNextJump.seconds_msb);
+   host2net32_unaligned(>timeOfNextJump.seconds_lsb);
+}
+
 static int mgt_post_recv(struct management_tlv *m, uint16_t data_len,
 struct tlv_extra *extra)
 {
@@ -1065,6 +1118,8 @@ int tlv_post_recv(struct tlv_extra *extra)
}
break;
case TLV_ALTERNATE_TIME_OFFSET_INDICATOR:
+   result = alttime_offset_post_recv(extra);
+   break;
case TLV_AUTHENTICATION_2008:
case TLV_AUTHENTICATION_CHALLENGE:
case TLV_SECURITY_ASSOCIATION_UPDATE:
@@ -1128,7 +1183,10 @@ void tlv_pre_send(struct TLV *tlv, struct tlv_extra 
*extra)
unicast_negotiation_pre_send(tlv);
break;
case TLV_PATH_TRACE:
+   break;
case TLV_ALTERNATE_TIME_OFFSET_INDICATOR:
+   alttime_offset_pre_send(extra);
+   break;
case TLV_AUTHENTICATION_2008:
case TLV_AUTHENTICATION_CHALLENGE:
case TLV_SECURITY_ASSOCIATION_UPDATE:
diff --git a/tlv.h b/tlv.h
index a08c74a..15df2bb 100644
--- a/tlv.h
+++ b/tlv.h
@@ -175,6 +175,32 @@ struct grant_unicast_xmit_tlv {
uint8_t flags;
 } PACKED;
 
+struct alternate_time_offset_indicator_tlv {
+   Enumeration16   type;
+   UInteger16  length;
+   UInteger8   keyField;
+   /* Message alignment broken by design. */
+   Integer32   currentOffset;
+   Integer32   jumpSeconds;
+   struct {
+   uint16_t   seconds_msb; /* 16 bits + */
+   uint32_t   seconds_lsb; /* 32 bits = 48 bits*/
+   } PACKED timeOfNextJump;
+   struct PTPText  displayName;
+} PACKED;
+
+struct alternate_time_offset_properties {
+   UInteger8   keyField;
+   /* Message alignment broken by design. */
+   Integer32   currentOffset;
+   Integer32   jumpSeconds;
+   struct {
+   uint16_t   seconds_msb; /* 16 bits + */
+   uint32_t   seconds_lsb; /* 32 bits = 48 bits*/
+   } PACKED timeOfNextJump;
+   uint8_t pad;
+} PACKED;
+
 struct management_tlv {
Enumeration16 type;
UInteger16length;
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v5 01/11] Accept the full range for domainNumber.

2023-02-14 Thread Richard Cochran
IEEE Std C37.238 invented its own rules with respect to the range of
values allowed for the domainNumber attribute.  The profile

"complies with IEEE Std 1588-2008 with the exception of the use of
the reserved domain 254. The value 254 is an exception granted to
this profile."

In addition, Table 2 of IEEE Std 1588-2019 presents an incoherent
Swiss cheese of allowed ranges, depending sdoId and network transport.

Avoid the standardized madness by allowing the user to simply choose
any domainNumber they want.

Signed-off-by: Richard Cochran 
---
 config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.c b/config.c
index 9b86b35..f028b88 100644
--- a/config.c
+++ b/config.c
@@ -248,7 +248,7 @@ struct config_item config_tab[] = {
PORT_ITEM_INT("delay_response_timeout", 0, 0, UINT8_MAX),
GLOB_ITEM_INT("dscp_event", 0, 0, 63),
GLOB_ITEM_INT("dscp_general", 0, 0, 63),
-   GLOB_ITEM_INT("domainNumber", 0, 0, 127),
+   GLOB_ITEM_INT("domainNumber", 0, 0, 255),
PORT_ITEM_INT("egressLatency", 0, INT_MIN, INT_MAX),
PORT_ITEM_INT("fault_badpeernet_interval", 16, INT32_MIN, INT32_MAX),
PORT_ITEM_INT("fault_reset_interval", 4, INT8_MIN, INT8_MAX),
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v5 10/11] pmc: Convert internal helper function into global method.

2023-02-14 Thread Richard Cochran
The function to set the alternate time offset name, a.k.a. time zone, will
be used by the time zone stand alone program.  Make the function into a
public PMC method.

Signed-off-by: Richard Cochran 
---
 pmc_common.c | 5 ++---
 pmc_common.h | 2 ++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/pmc_common.c b/pmc_common.c
index 6cab5e0..539e812 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -79,7 +79,6 @@ static void do_get_action(struct pmc *pmc, int action, int 
index, char *str);
 static void do_set_action(struct pmc *pmc, int action, int index, char *str);
 static void not_supported(struct pmc *pmc, int action, int index, char *str);
 static void null_management(struct pmc *pmc, int action, int index, char *str);
-static int send_set_aton(struct pmc *pmc, int id, uint8_t key, const char 
*name);
 
 static const char *action_string[] = {
"GET",
@@ -232,7 +231,7 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
idtab[index].name);
break;
}
-   send_set_aton(pmc, code, key, display_name);
+   pmc_send_set_aton(pmc, code, key, display_name);
break;
case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
memset(, 0, sizeof(atop));
@@ -759,7 +758,7 @@ int pmc_send_set_action(struct pmc *pmc, int id, void 
*data, int datasize)
return 0;
 }
 
-static int send_set_aton(struct pmc *pmc, int id, uint8_t key, const char 
*name)
+int pmc_send_set_aton(struct pmc *pmc, int id, uint8_t key, const char *name)
 {
struct alternate_time_offset_name *aton;
struct management_tlv *mgt;
diff --git a/pmc_common.h b/pmc_common.h
index 8bea2e0..6fb2fae 100644
--- a/pmc_common.h
+++ b/pmc_common.h
@@ -41,6 +41,8 @@ int pmc_send_get_action(struct pmc *pmc, int id);
 
 int pmc_send_set_action(struct pmc *pmc, int id, void *data, int datasize);
 
+int pmc_send_set_aton(struct pmc *pmc, int id, uint8_t key, const char *name);
+
 struct ptp_message *pmc_recv(struct pmc *pmc);
 
 int pmc_target(struct pmc *pmc, struct PortIdentity *pid);
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v5 06/11] Prepare clock based storage of up to four time zones.

2023-02-14 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 clock.c | 19 ---
 tz.h| 26 ++
 2 files changed, 42 insertions(+), 3 deletions(-)
 create mode 100644 tz.h

diff --git a/clock.c b/clock.c
index e9072ab..2c9e3f3 100644
--- a/clock.c
+++ b/clock.c
@@ -42,6 +42,7 @@
 #include "rtnl.h"
 #include "tlv.h"
 #include "tsproc.h"
+#include "tz.h"
 #include "uds.h"
 #include "util.h"
 
@@ -79,6 +80,15 @@ struct clock_subscriber {
time_t expiration;
 };
 
+struct time_zone {
+   bool enabled;
+   int32_t current_offset;
+   int32_t jump_seconds;
+   uint16_t next_jump_msb;
+   uint32_t next_jump_lsb;
+   struct static_ptp_text display_name;
+};
+
 struct clock {
enum clock_type type;
struct config *config;
@@ -137,6 +147,7 @@ struct clock {
struct monitor *slave_event_monitor;
int step_window_counter;
int step_window;
+   struct time_zone tz[MAX_TIME_ZONES];
 };
 
 struct clock the_clock;
@@ -896,19 +907,17 @@ int clock_required_modes(struct clock *c)
 struct clock *clock_create(enum clock_type type, struct config *config,
   const char *phc_device)
 {
+   int conf_phc_index, i, max_adj = 0, phc_index, required_modes = 0, sfl, 
sw_ts;
enum servo_type servo = config_get_int(config, NULL, "clock_servo");
char ts_label[IF_NAMESIZE], phc[32], *tmp;
enum timestamp_type timestamping;
-   int phc_index, conf_phc_index, required_modes = 0;
struct clock *c = _clock;
-   int max_adj = 0, sw_ts;
const char *uds_ifname;
double fadj = 0.0;
struct port *p;
unsigned char oui[OUI_LEN];
struct interface *iface;
struct timespec ts;
-   int sfl;
 
clock_gettime(CLOCK_REALTIME, );
srandom(ts.tv_sec ^ ts.tv_nsec);
@@ -1205,6 +1214,10 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
c->dad.pds.observedParentClockPhaseChangeRate= 0x7fff;
c->dad.ptl = c->ptl;
 
+   for (i = 0; i < MAX_TIME_ZONES; i++) {
+   c->tz[i].display_name.max_symbols = MAX_TZ_DISPLAY_NAME;
+   }
+
clock_sync_interval(c, 0);
 
LIST_INIT(>subscribers);
diff --git a/tz.h b/tz.h
new file mode 100644
index 000..986f976
--- /dev/null
+++ b/tz.h
@@ -0,0 +1,26 @@
+/**
+ * @file tz.h
+ * @brief Implements time zone constants.
+ * @note Copyright (C) 2021 Richard Cochran 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef HAVE_TZ_H
+#define HAVE_TZ_H
+
+#define MAX_TZ_DISPLAY_NAME10
+#define MAX_TIME_ZONES 4
+
+#endif
-- 
2.30.2



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


[Linuxptp-devel] [PATCH v5 07/11] Add the ALTERNATE_TIME_OFFSET_PROPERTIES management message.

2023-02-14 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 clock.c  | 70 +---
 pmc.c| 17 +
 pmc_common.c | 24 +-
 tlv.c| 21 
 util.h   |  7 ++
 5 files changed, 134 insertions(+), 5 deletions(-)

diff --git a/clock.c b/clock.c
index 2c9e3f3..e09bd18 100644
--- a/clock.c
+++ b/clock.c
@@ -157,6 +157,32 @@ static int clock_resize_pollfd(struct clock *c, int 
new_nports);
 static void clock_remove_port(struct clock *c, struct port *p);
 static void clock_stats_display(struct clock_stats *s);
 
+uint8_t clock_alttime_offset_get_key(struct ptp_message *req)
+{
+   struct management_tlv_datum *mtd;
+   struct management_tlv *mgt =
+   (struct management_tlv *) req->management.suffix;
+
+   /*
+* The data field of incoming management request messages is
+* normally ignored.  Indeed it can even be empty.  However
+* the ALTERNATE_TIME_OFFSET requests are exceptional because
+* the key field selects one of the configured time zones.
+*
+* Provide the first time zone for an empty GET, and validate
+* the length of the request when non-empty.
+*/
+   if (mgt->length == sizeof(mgt->id)) {
+   return 0;
+   }
+   if (mgt->length < sizeof(mgt->id) + sizeof(*mtd)) {
+   return MAX_TIME_ZONES;
+   }
+   mtd = (struct management_tlv_datum *) mgt->data;
+
+   return mtd->val;
+}
+
 static void remove_subscriber(struct clock_subscriber *s)
 {
LIST_REMOVE(s, list);
@@ -354,6 +380,7 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
  struct ptp_message *req,
  struct ptp_message *rsp, int id)
 {
+   struct alternate_time_offset_properties *atop;
struct grandmaster_settings_np *gsn;
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
@@ -363,6 +390,7 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
struct PTPText *text;
uint16_t duration;
int datalen = 0;
+   uint8_t key;
 
extra = tlv_extra_alloc();
if (!extra) {
@@ -433,6 +461,24 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
mtd->val = c->tds.flags & PTP_TIMESCALE;
datalen = sizeof(*mtd);
break;
+   case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
+   key = clock_alttime_offset_get_key(req);
+   if (key >= MAX_TIME_ZONES) {
+   break;
+   }
+   atop = (struct alternate_time_offset_properties *) tlv->data;
+   atop->keyField = key;
+   /* Message alignment broken by design. */
+   memcpy(>currentOffset, >tz[key].current_offset,
+  sizeof(atop->currentOffset));
+   memcpy(>jumpSeconds, >tz[key].jump_seconds,
+  sizeof(atop->jumpSeconds));
+   memcpy(>timeOfNextJump.seconds_lsb, 
>tz[key].next_jump_lsb,
+  sizeof(atop->timeOfNextJump.seconds_lsb));
+   memcpy(>timeOfNextJump.seconds_msb, 
>tz[key].next_jump_msb,
+  sizeof(atop->timeOfNextJump.seconds_msb));
+   datalen = sizeof(*atop);
+   break;
case MID_TIME_STATUS_NP:
tsn = (struct time_status_np *) tlv->data;
tsn->master_offset = tmv_to_nanoseconds(c->master_offset);
@@ -511,11 +557,12 @@ static int clock_management_get_response(struct clock *c, 
struct port *p,
 static int clock_management_set(struct clock *c, struct port *p,
int id, struct ptp_message *req, int *changed)
 {
-   int respond = 0;
-   struct management_tlv *tlv;
-   struct management_tlv_datum *mtd;
+   struct alternate_time_offset_properties *atop;
struct grandmaster_settings_np *gsn;
+   struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
+   struct management_tlv *tlv;
+   int key, respond = 0;
 
tlv = (struct management_tlv *) req->management.suffix;
 
@@ -532,6 +579,22 @@ static int clock_management_set(struct clock *c, struct 
port *p,
*changed = 1;
respond = 1;
break;
+   case MID_ALTERNATE_TIME_OFFSET_PROPERTIES:
+   atop = (struct alternate_time_offset_properties *) tlv->data;
+   key = atop->keyField;
+   if (key < MAX_TIME_ZONES) {
+   /* Message alignment broken by design. */
+   memcpy(>tz[key].current_offset, >currentOffset,
+  sizeof(c->tz[key].current_offset));
+ 

[Linuxptp-devel] [PATCH v5 09/11] Implement the ALTERNATE_TIME_OFFSET_ENABLE management message.

2023-02-14 Thread Richard Cochran
If the local PTP management client enables a time zone, append the
matching TLV to outgoing Announce messages.

Signed-off-by: Richard Cochran 
---
 clock.c  | 80 ++--
 clock.h  |  8 ++
 pmc.c|  8 ++
 pmc_common.c | 17 ++-
 port.c   |  3 ++
 5 files changed, 113 insertions(+), 3 deletions(-)

diff --git a/clock.c b/clock.c
index 91eb5a1..611d977 100644
--- a/clock.c
+++ b/clock.c
@@ -157,6 +157,43 @@ static int clock_resize_pollfd(struct clock *c, int 
new_nports);
 static void clock_remove_port(struct clock *c, struct port *p);
 static void clock_stats_display(struct clock_stats *s);
 
+static int clock_alttime_offset_append(struct clock *c, int key, struct 
ptp_message *m)
+{
+   struct alternate_time_offset_indicator_tlv *atoi;
+   struct tlv_extra *extra;
+   int tlv_len;
+
+   tlv_len = sizeof(*atoi) + c->tz[key].display_name.length;
+   if (tlv_len % 2) {
+   tlv_len++;
+   }
+   extra = msg_tlv_append(m, tlv_len);
+   if (!extra) {
+   return -1;
+   }
+   atoi = (struct alternate_time_offset_indicator_tlv *) extra->tlv;
+   atoi->type = TLV_ALTERNATE_TIME_OFFSET_INDICATOR;
+   atoi->length = tlv_len - sizeof(atoi->type) - sizeof(atoi->length);
+   atoi->keyField = key;
+
+   /* Message alignment broken by design. */
+   memcpy(>currentOffset, >tz[key].current_offset,
+  sizeof(atoi->currentOffset));
+
+   memcpy(>jumpSeconds, >tz[key].jump_seconds,
+  sizeof(atoi->jumpSeconds));
+
+   memcpy(>timeOfNextJump.seconds_lsb, >tz[key].next_jump_lsb,
+  sizeof(atoi->timeOfNextJump.seconds_lsb));
+
+   memcpy(>timeOfNextJump.seconds_msb, >tz[key].next_jump_msb,
+  sizeof(atoi->timeOfNextJump.seconds_msb));
+
+   ptp_text_copy(>displayName, >tz[key].display_name);
+
+   return 0;
+}
+
 uint8_t clock_alttime_offset_get_key(struct ptp_message *req)
 {
struct management_tlv_datum *mtd;
@@ -462,6 +499,16 @@ static int clock_management_fill_response(struct clock *c, 
struct port *p,
mtd->val = c->tds.flags & PTP_TIMESCALE;
datalen = sizeof(*mtd);
break;
+   case MID_ALTERNATE_TIME_OFFSET_ENABLE:
+   key = clock_alttime_offset_get_key(req);
+   if (key >= MAX_TIME_ZONES) {
+   break;
+   }
+   mtd = (struct management_tlv_datum *) tlv->data;
+   mtd->val = key;
+   mtd->reserved = c->tz[key].enabled ? 1 : 0;
+   datalen = sizeof(*mtd);
+   break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
key = clock_alttime_offset_get_key(req);
if (key >= MAX_TIME_ZONES) {
@@ -574,7 +621,7 @@ static int clock_management_set(struct clock *c, struct 
port *p,
struct management_tlv_datum *mtd;
struct subscribe_events_np *sen;
struct management_tlv *tlv;
-   int key, respond = 0;
+   int k, key, respond = 0;
 
tlv = (struct management_tlv *) req->management.suffix;
 
@@ -591,6 +638,20 @@ static int clock_management_set(struct clock *c, struct 
port *p,
*changed = 1;
respond = 1;
break;
+   case MID_ALTERNATE_TIME_OFFSET_ENABLE:
+   mtd = (struct management_tlv_datum *) tlv->data;
+   key = mtd->val;
+   if (key == 0xff) {
+   for (k = 0; k < MAX_TIME_ZONES; k++) {
+   c->tz[k].enabled = mtd->reserved & 1 ? true : 
false;
+   }
+   respond = 1;
+   }
+   if (key < MAX_TIME_ZONES) {
+   c->tz[key].enabled = mtd->reserved & 1 ? true : false;
+   respond = 1;
+   }
+   break;
case MID_ALTERNATE_TIME_OFFSET_NAME:
aton = (struct alternate_time_offset_name *) tlv->data;
key = aton->keyField;
@@ -896,6 +957,22 @@ static int forwarding(struct clock *c, struct port *p)
 
 /* public methods */
 
+int clock_append_timezones(struct clock *c, struct ptp_message *m)
+{
+   int err = 0, i;
+
+   for (i = 0; i < MAX_TIME_ZONES; i++) {
+   if (!c->tz[i].enabled) {
+   continue;
+   }
+   err = clock_alttime_offset_append(c, i, m);
+   if (err) {
+   break;
+   }
+   }
+   return err;
+}
+
 UInteger8 clock_class(struct clock *c)
 {
return c->dds.clockQuality.clockClass;
@@ -1613,7 +1690,6 @@ int clock_manage(struct clock *c, struct port *p, struct 
ptp_message *msg)
case MID_GRANDMASTER_CLUSTER_TABL

[Linuxptp-devel] [PATCH v5 04/11] Add a custom management message for power profile settings.

2023-02-14 Thread Richard Cochran
Signed-off-by: Richard Cochran 
---
 pmc.c| 15 +++
 pmc_common.c | 37 +
 port.c   | 20 +++-
 tlv.c| 20 
 tlv.h|  1 +
 5 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/pmc.c b/pmc.c
index e218ca4..793a790 100644
--- a/pmc.c
+++ b/pmc.c
@@ -157,6 +157,7 @@ static void pmc_show_signaling(struct ptp_message *msg, 
FILE *fp)
 
 static void pmc_show(struct ptp_message *msg, FILE *fp)
 {
+   struct ieee_c37_238_settings_np *pwr;
struct unicast_master_table_np *umtn;
struct grandmaster_settings_np *gsn;
struct port_service_stats_np *pssp;
@@ -572,6 +573,20 @@ static void pmc_show(struct ptp_message *msg, FILE *fp)
phn->phc_index,
phn->flags);
break;
+   case MID_POWER_PROFILE_SETTINGS_NP:
+   pwr = (struct ieee_c37_238_settings_np *) mgt->data;
+   fprintf(fp, "POWER_PROFILE_SETTINGS_NP "
+   IFMT "version   %hu"
+   IFMT "grandmasterID 0x%04hx"
+   IFMT "grandmasterTimeInaccuracy %u"
+   IFMT "networkTimeInaccuracy %u"
+   IFMT "totalTimeInaccuracy   %u",
+   pwr->version,
+   pwr->grandmasterID,
+   pwr->grandmasterTimeInaccuracy,
+   pwr->networkTimeInaccuracy,
+   pwr->totalTimeInaccuracy);
+   break;
case MID_LOG_ANNOUNCE_INTERVAL:
mtd = (struct management_tlv_datum *) mgt->data;
fprintf(fp, "LOG_ANNOUNCE_INTERVAL "
diff --git a/pmc_common.c b/pmc_common.c
index 1dd89f6..bb7d087 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -28,6 +28,7 @@
 #include "tlv.h"
 #include "transport.h"
 #include "pmc_common.h"
+#include "power_profile.h"
 
 #define BAD_ACTION   -1
 #define BAD_ID   -1
@@ -154,6 +155,7 @@ struct management_id idtab[] = {
{ "PORT_SERVICE_STATS_NP", MID_PORT_SERVICE_STATS_NP, do_get_action },
{ "UNICAST_MASTER_TABLE_NP", MID_UNICAST_MASTER_TABLE_NP, do_get_action 
},
{ "PORT_HWCLOCK_NP", MID_PORT_HWCLOCK_NP, do_get_action },
+   { "POWER_PROFILE_SETTINGS_NP", MID_POWER_PROFILE_SETTINGS_NP, 
do_set_action },
 };
 
 static void do_get_action(struct pmc *pmc, int action, int index, char *str)
@@ -168,6 +170,7 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
 {
int cnt, code = idtab[index].code, freq_traceable, leap_59, leap_61,
ptp_timescale, time_traceable, utc_off_valid;
+   struct ieee_c37_238_settings_np pwr;
struct grandmaster_settings_np gsn;
struct management_tlv_datum mtd;
struct subscribe_events_np sen;
@@ -302,6 +305,37 @@ static void do_set_action(struct pmc *pmc, int action, int 
index, char *str)
}
pmc_send_set_action(pmc, code, , sizeof(pnp));
break;
+   case MID_POWER_PROFILE_SETTINGS_NP:
+   cnt = sscanf(str, " %*s %*s "
+"version   %hu "
+"grandmasterID %hx "
+"grandmasterTimeInaccuracy %u "
+"networkTimeInaccuracy %u "
+"totalTimeInaccuracy   %u ",
+,
+,
+,
+,
+);
+   if (cnt != 5) {
+   fprintf(stderr, "%s SET needs 5 values\n",
+   idtab[index].name);
+   break;
+   }
+   switch (pwr.version) {
+   case IEEE_C37_238_VERSION_NONE:
+   case IEEE_C37_238_VERSION_2011:
+   case IEEE_C37_238_VERSION_2017:
+   pmc_send_set_action(pmc, code, , sizeof(pwr));
+   break;
+   default:
+   fprintf(stderr, "\nusage: set PROFILE_SETTINGS_NP 
version "
+   "%hu (none), %hu (2011), or %hu (2017)\n\n",
+   IEEE_C37_238_VERSION_NONE,
+   IEEE_C37_238_VERSION_2011,
+   IEEE_C37_238_VERSION_2017);
+   }
+   break;
}
 }
 
@@ -573,6 +607,9 @@ static int pmc_tlv_datalen(struct pmc *pmc, int id)
case MID_PORT_HWCLOCK_NP:
len += sizeof(struct 

[Linuxptp-devel] [PATCH v5 00/11] Profile support for IEEE C37.238-2011 and IEEE C37.238-2017

2023-02-14 Thread Richard Cochran
ChangeLog
~
v5:
 Rename tztool to tz2alt
 Provide man page for tz2alt
 Fix year 2106 bug
v4:
 Preserve all 48 bits of "next jump" (v3 review feedback from Erez Geva)
 Accept the full range for domainNumber (suggested by v.nosikov)
v3:
 Initial RFC
v2, v1:
 never published

The Power Profile specifies two new TLVs:

1. IEEE_C37_238 TLV

   - New configuration option to enable the TLV.

   - New configuration options for grandmasterID and default
 totalTimeInaccuracy.

   - New custom management message for changing totalTimeInaccuracy at
 run time. This message allows switching the TLV from the 2017
 format into the 2011 format by specifying grandmasterTimeInaccuracy
 and networkTimeInaccuracy.

2. ALTERNATE_TIME_OFFSET_INDICATOR TLV

   - New custom management message for enabling the TLV and setting
 the TLV values.

   - New helper program that computes the values from the local time
 and the Linux time zone data base and then sends the values to
 ptp4l. This method assumes that the local Linux system time and
 the PHC clock are synchronized.

Thanks,
Richard


Richard Cochran (11):
  Accept the full range for domainNumber.
  tlv: Encode and decode power profile TLVs.
  Introduce the power profile.
  Add a custom management message for power profile settings.
  tlv: Encode and decode alternate time offset indicator TLVs.
  Prepare clock based storage of up to four time zones.
  Add the ALTERNATE_TIME_OFFSET_PROPERTIES management message.
  Add the ALTERNATE_TIME_OFFSET_NAME management message.
  Implement the ALTERNATE_TIME_OFFSET_ENABLE management message.
  pmc: Convert internal helper function into global method.
  Introduce a time zone helper program.

 clock.c | 188 ++--
 clock.h |   8 +
 config.c|  17 ++-
 makefile|   7 +-
 pmc.c   |  49 +++
 pmc_common.c| 133 -
 pmc_common.h|   2 +
 port.c  |  76 +-
 port_private.h  |   3 +
 power_profile.h |  31 
 tlv.c   | 146 +++
 tlv.h   |  64 
 tz.h|  26 
 tz2alt.8| 126 
 tz2alt.c| 379 
 util.h  |   7 +
 16 files changed, 1245 insertions(+), 17 deletions(-)
 create mode 100644 power_profile.h
 create mode 100644 tz.h
 create mode 100644 tz2alt.8
 create mode 100644 tz2alt.c

-- 
2.30.2



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


Re: [Linuxptp-devel] [PATCH v4 11/11] Introduce a time zone helper program.

2023-02-14 Thread Richard Cochran
On Mon, Feb 13, 2023 at 12:11:08PM +0100, Miroslav Lichvar wrote:

> The lsb field of timeOfNextJump is unsigned, so it will overflow in
> year 2106 (in the TAI timescale).

Some of the power industry equipment lasts 30 or 40 years (except in
California where they make it out of sugar, and it melts at the first
rain).

So who knows?  Maybe someone will deploy the power profile today, and
it will be still running in 83 years?

I'll take care of it now, so our decendents have one less 2016 bug to fix...

Thanks,
Richard



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


Re: [Linuxptp-devel] [PATCH v4 00/11] Profile support for IEEE C37.238-2011 and IEEE C37.238-2017

2023-02-12 Thread Richard Cochran
On Sun, Feb 12, 2023 at 07:37:38PM -0800, Richard Cochran wrote:
> On Sat, Feb 11, 2023 at 08:04:27AM -0800, Richard Cochran wrote:
> > On Thu, Feb 02, 2023 at 11:52:09AM +0100, Miroslav Lichvar wrote:
> > > On Sat, Jan 28, 2023 at 02:43:41PM -0800, Richard Cochran wrote:
> > > > The Power Profile specifies two new TLVs:
> > > 
> > > It would be nice to have the new options documented in the ptp4l man
> > > page. Please consider renaming tztool to something more PTP-specific,
> > > (maybe tz2ptp4l?), to not confuse people that is does something with
> > > the system tz database.
> > 
> > How about "tz_alttime_tool" ?
> 
> I like "tz2alttime" ...

or even "tz2alt", short and sweet.

Thanks,
Richard



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


Re: [Linuxptp-devel] [PATCH v4 00/11] Profile support for IEEE C37.238-2011 and IEEE C37.238-2017

2023-02-12 Thread Richard Cochran
On Sat, Feb 11, 2023 at 08:04:27AM -0800, Richard Cochran wrote:
> On Thu, Feb 02, 2023 at 11:52:09AM +0100, Miroslav Lichvar wrote:
> > On Sat, Jan 28, 2023 at 02:43:41PM -0800, Richard Cochran wrote:
> > > The Power Profile specifies two new TLVs:
> > 
> > It would be nice to have the new options documented in the ptp4l man
> > page. Please consider renaming tztool to something more PTP-specific,
> > (maybe tz2ptp4l?), to not confuse people that is does something with
> > the system tz database.
> 
> How about "tz_alttime_tool" ?

I like "tz2alttime" ...

Thanks,
Richard


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


Re: [Linuxptp-devel] [PATCH] Handle error returned by kernel for clock adjustments

2023-02-12 Thread Richard Cochran
On Mon, Jan 30, 2023 at 03:39:45PM +, Wojtek Wasko via Linuxptp-devel wrote:
> Current code only prints a message in case the kernel returns an error
> for a clock adjustment. Failing to adjust clock leads to an inconsistent
> state in which a servo continues to report "locked" state while the
> underlying PHC's state is essentially undetermined.
> 
> This change resets the servo in case of failure to adjust the clock.

I like the error handling, but I'd like to have this one patch split
into a series of four patches:

1. Let methods in clockadj.[ch] return errors to caller.
2. Implement error handling in ptp4l.
3. Implement error handling in phc2sys.
4. Implement error handling in ts2phc.

That way, in the unlikely event of a regression, we can revert 2, 3, or 4.

Also, I have a few minor comments on coding style...

> diff --git a/clock.c b/clock.c
> index 134c7c3..ff1abbf 100644
> --- a/clock.c
> +++ b/clock.c
> @@ -1778,18 +1778,20 @@ static void clock_step_window(struct clock *c)
>   c->step_window_counter = c->step_window;
>  }
>  
> -static void clock_synchronize_locked(struct clock *c, double adj)
> +static int clock_synchronize_locked(struct clock *c, double adj)
>  {
>   if (c->sanity_check) {
>   clockcheck_freq(c->sanity_check, clockadj_get_freq(c->clkid));
>   }
> - clockadj_set_freq(c->clkid, -adj);
> + if (clockadj_set_freq(c->clkid, -adj) < 0)
> + return -1;

Please don't omit the braces, and drop the '< 0'

clockadj_set_freq returns either 0 or -1, so the test should be
simplified to  'if (clockadj_set_freq()) { ... }'

>   if (c->clkid == CLOCK_REALTIME) {
>   sysclk_set_sync();
>   }
>   if (c->sanity_check) {
>   clockcheck_set_freq(c->sanity_check, -adj);
>   }
> + return 0;
>  }
>  
>  enum servo_state clock_synchronize(struct clock *c, tmv_t ingress, tmv_t 
> origin)
> @@ -1841,8 +1843,10 @@ enum servo_state clock_synchronize(struct clock *c, 
> tmv_t ingress, tmv_t origin)
>   case SERVO_UNLOCKED:
>   break;
>   case SERVO_JUMP:
> - clockadj_set_freq(c->clkid, -adj);
> - clockadj_step(c->clkid, -tmv_to_nanoseconds(c->master_offset));
> + if (clockadj_set_freq(c->clkid, -adj) < 0)
> + goto servo_unlock;

Same here

> + if (clockadj_step(c->clkid, 
> -tmv_to_nanoseconds(c->master_offset)) < 0)
> + goto servo_unlock;

and here

>   c->ingress_ts = tmv_zero();
>   if (c->sanity_check) {
>   clockcheck_set_freq(c->sanity_check, -adj);
> @@ -1853,14 +1857,17 @@ enum servo_state clock_synchronize(struct clock *c, 
> tmv_t ingress, tmv_t origin)
>   clock_step_window(c);
>   break;
>   case SERVO_LOCKED:
> - clock_synchronize_locked(c, adj);
> + if (clock_synchronize_locked(c, adj) < 0)
> + goto servo_unlock;

ditto

>   break;
>   case SERVO_LOCKED_STABLE:
>   if (c->write_phase_mode) {
> - clockadj_set_phase(c->clkid, -offset);
> + if (clockadj_set_phase(c->clkid, -offset) < 0)
> + goto servo_unlock;

ditto

>   adj = 0;
>   } else {
> - clock_synchronize_locked(c, adj);
> + if (clock_synchronize_locked(c, adj) < 0)
> + goto servo_unlock;

ditto

>   }
>   break;
>   }
> @@ -1877,6 +1884,11 @@ enum servo_state clock_synchronize(struct clock *c, 
> tmv_t ingress, tmv_t origin)
>   clock_notify_event(c, NOTIFY_TIME_SYNC);
>  
>   return state;
> +
> +servo_unlock:
> + servo_reset(c->servo);
> + c->servo_state = SERVO_UNLOCKED;
> + return SERVO_UNLOCKED;
>  }
>  
>  void clock_sync_interval(struct clock *c, int n)
> diff --git a/clockadj.c b/clockadj.c
> index 4c920b9..1437ec0 100644
> --- a/clockadj.c
> +++ b/clockadj.c
> @@ -48,7 +48,7 @@ void clockadj_init(clockid_t clkid)
>  #endif
>  }
>  
> -void clockadj_set_freq(clockid_t clkid, double freq)
> +int clockadj_set_freq(clockid_t clkid, double freq)
>  {
>   struct timex tx;
>   memset(, 0, sizeof(tx));
> @@ -62,8 +62,11 @@ void clockadj_set_freq(clockid_t clkid, double freq)
>  
>   tx.modes |= ADJ_FREQUENCY;
>   tx.freq = (long) (freq * 65.536);
> - if (clock_adjtime(clkid, ) < 0)
> + if (clock_adjtime(clkid, ) < 0) {

FYI here the '< 0" makes sense, because clock_adjtime is the cousin of
adjtimex which can return both -1 and positive time code.

>   pr_err("failed to adjust the clock: %m");
> + return -1;
> + }
> + return 0;
>  }
>  
>  double clockadj_get_freq(clockid_t clkid)

Thanks,
Richard


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net

Re: [Linuxptp-devel] [PATCH] unicast: Avoid undefined integer shifts.

2023-02-12 Thread Richard Cochran
On Tue, Feb 07, 2023 at 03:16:15PM +0100, Miroslav Lichvar wrote:
> Deny client requests and ignore server responses that have
> logInterMessagePeriod outside of [-30..30] to avoid undefined
> integer shifts in calculation of the interval.
> 
> Signed-off-by: Miroslav Lichvar 

Applied.

Thanks,
Richard


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


  1   2   3   4   5   6   7   8   9   10   >