Commit Graph

1218 Commits (d4fbb0701d70e27cdc02037cf31ae2c438867ab9)

Author SHA1 Message Date
Richard Cochran d4fbb0701d udp: Convey transmit path errors to the caller.
The transport layer's functional interface foresees having error codes
percolate back up to the caller.  However, up until now, the udp module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran 306ac67460 transport: Correct grammar in the doxygen comments.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran f8078f00f7 Let the free running port state reflect the synchronization uncertain flag.
When using the "free running" option, a slaved port remains in the
UNCALIBRATED state.  If the actual servo resides in and external program,
for example when following the 802.1AS recommendations, that program can
signal the synchronization state using the "synchronization uncertain"
management message. This patch lets the port state transitions from
UNCALIBRATED to SLAVE based on that message.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:02:49 -07:00
Richard Cochran 6c5b61a64c pmc: Support getting and setting the local synchronization uncertain flag.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:02:49 -07:00
Richard Cochran b8194a177a Implement the synchronization uncertain flag.
IEEE 1588 v2.1 and ITU G.8275.1/2 call for an optional "synchronization
uncertain" flag passed in Announce messages along with the other flags
from the time properties data set.  The value of the flag depends is a
logical OR function of the inputs from the remote master and the local
process.  This patch adds background support for handling the flag.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:02:49 -07:00
Richard Cochran 7df88afab9 Add support for write phase mode.
Recently the Linux kernel's PTP Hardware Clock interface was expanded
to include a "write phase" mode where the clock servo in implemented
in hardware.  This mode hearkens back to the tradition ntp_adjtime
interface, passing a measured offset into the kernel's servo.

This patch adds a new configuration option and logic to support the
write phase mode.

Because the hardware's adjustment bandwidth may be limited, this mode
is only activated when the servo reaches SERVO_LOCKED_STABLE state, in
order to achieve reasonably fast locking times.  Users may control the
SERVO_LOCKED_STABLE state by configuring 'servo_offset_threshold' and
'servo_num_offset_values' accordingly.

Example configuration file highlights:

  unicast_listen          1
  logSyncInterval         0
  logMinDelayReqInterval  0
  first_step_threshold    0.001000000
  step_threshold          0
  clock_servo             pi

  write_phase_mode        1
  servo_offset_threshold  50
  servo_num_offset_values 10
  tsproc_mode             raw

Signed-off-by: Vincent Cheng <vincent.cheng.xh@renesas.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 11:43:51 -07:00
Vincent Cheng d4b97f497c Decouple servo state from automotive profile.
The logic for the Automotive Profile added a message interval update
mechanism that triggers whenever the servo enters the "stable locked"
state.  This SERVO_LOCKED_STABLE state is active when the
configuration option servo_offset_threshold is non-zero and
servo_offset_threshold criteria is satisfied.

However, in general, the state of the servo can and should be
independent of any profile specific optional behavior.  In particular,
the "stable locked" state will be used in the future to trigger other
kinds useful logic.  For example, an upcoming write phase mode feature
would like to take advantage of the SERVO_LOCKED_STABLE state to
trigger its activation.

This patch introduces a proper configuration option to enable
transmission of the message interval request that is specific to the
Automotive Profile.

Signed-off-by: Vincent Cheng <vincent.cheng.xh@renesas.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 11:42:49 -07:00
Richard Cochran acd1429645 Add documentation for the ts2phc program.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 7486e6e4e1 ts2phc: Support using a GPS radio as the master clock.
Many GPS radios provide both a 1-PPS and time of day information via
NMEA sentences.  This patch introduces a ts2phc master that decodes
the "recommended minimum data" sentence, RMC, which provides UTC time
and a validity flag.  Together with the file based leap second table,
this sentence provides adequate time of day for determining the time
of the PPS edge.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 43c51cf144 Introduce a leap second table.
There are several issues surrounding leap seconds that emerge when a clock
takes on the Grand Master role.  One of them is the fact that GPS radios
provide time of day in the UTC time scale and not in TAI, and they do not,
in general, provide any conversion information.  Another issue is the
expectation that the GM provide correct leap second status flags to the
network.  Although both NTP and GPS do, in theory, provide on-line leap
second status, in practice the information is not reliable due to poor
implementations.

In order to provide correct leap second status and TAI - UTC offsets,
this patch introduces a leap second table based on the information
published by the IETF and NIST.  The hard coded default table can be
updated at run time by reading the standard leap seconds file from the
commonly used tzdata package.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 9c6e0f57b3 ts2phc: Support using a PHC as the master clock.
This patch introduces a new ts2phc source using a PHC device.  There
are multiple use cases for such a master.  By connecting pins of two
or more separate PHC devices together, one may act as the source, and
the others may be synchronized to it in hardware.  In this way, "just
a bunch of devices" together forms a Transparent Clock.  If the master
clock is synchronized to a global time source (like a PPS from a GPS),
then the system becomes a mutli-port Grand Master or a Boundary Clock
with GM capability.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 1bdc9143aa Introduce the ts2phc program.
Some PTP Hardware Clocks have input pins that can generate time stamps
on the edges of external signals.  This functionality can be used in
various ways.  For example, one can synchronize a PHC device to a
global time source by taking a Pulse Per Second signal from the source
into the PHC.  This patch adds support for synchronizing one or more
PHC slaves to a given master clock.

The implementation follows a modular design that allows adding
different kinds of master clocks in the future.  This patch starts off
with a single "generic" PPS master, meaning a PPS signal that lacks
and time or date information.  The generic master assumes that the
Linux system time is approximately correct (by NTP or RTC for example)
in order to calculate the time of the incoming PPS edges.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: Balint Ferencz <fernya@gmail.com>
2020-05-07 14:57:47 -07:00
Richard Cochran 2f0bfb2837 pmc: Allow multiple local subscribers.
If more than one local UDS client subscribes to push notifications,
only the last one receives data from the ptp4l service.  This happens
because ptp4l uses the PortIdentity as a unique key to track client
subscriptions.  As a result, it is not possible for both phc2sys and
pmc to receive push notifications at the same time, for example.

This patch sets the PortIdentity.portNumber attribute of UDS clients
to the local process ID, making each such client subscription unique.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-04-03 07:11:42 -07:00
Richard Cochran 1044268e85 pmc: Subscribe to port state push notification events when requested.
Allow interactive input like

    set SUBSCRIBE_EVENTS_NP duration 60 NOTIFY_PORT_STATE on

to request push notifications from the ptp4l service.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-04-03 07:04:31 -07:00
Richard Cochran e6d52c54e9 pmc: Allow printing of the SUBSCRIBE_EVENTS_NP tlv.
While we are at it, reformat the pmc_show() function into reverse
Christmas tree order.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-31 15:03:41 -07:00
Richard Cochran aed79c38d4 pmc: Move private macros back into their source files.
The header file, pmc_common.h, makes some private macros public.  The
intent was to use those macros in SNMP code, but that development never
materialized into production code.  This patch removes the private macros
from public view.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-31 15:03:41 -07:00
Richard Cochran 467552d1cb clock: Reply with correct payload length for SUBSCRIBE_EVENTS_NP queries.
The clock layer indeed replies to management GET actions for this item,
but it sends an empty management message by mistake.  This patch fixes the
issue by replying with a payload of the correct length.

While we are at it, correct overly zealous line breaking according to our
coding style.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-31 15:03:41 -07:00
Richard Cochran b829580a33 Provide a method to convert a tmv_t into a timespec.
Currently there is a method to convert a timespec into a tmv_t, but
not the other way round.  This patch adds the missing function in
anticipation of a new feature that will need this conversion.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-21 04:48:16 -07:00
Richard Cochran 43d49a21d0 Add PHC methods for querying and configuring the pin functionality.
In anticipation of support for external time stamping in PHC devices, this
patch adds wrapper functions around the pin functionality.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-21 04:48:16 -07:00
Richard Cochran 9850ce0e51 Add definitions for PTP pin ioctls for backwards kernel compatibility.
Upcoming functionality will need to configure the input and output pins of
PHC devices.  However, this requires fairly recent kernel support.  This
patch adds the needed definitions for compiling with older kernel headers.

In addition, kernel v5.4 introduced a second set of ioctls for the
ancillary PTP Hardware Clock functionality.  The original ioctls
failed to enforce the various flags and reversed fields, but the
second version has fixed the issues.  Going forward, our user space
PTP stack ought to use the newer ioctls (if available) from day one.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-21 04:45:07 -07:00
Richard Cochran dde0bf2e28 Balance the posix clock open function with a close method.
The one user of the function, posix_clock_open(), simply open codes
the closing call to phc_close().  This patch provides a method to
balance closing and opening of a posix clock.  In addition, the
phc_ctl program never explicitly closed the opened clock, and so this
patch adds the missing call.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-21 04:36:10 -07:00
Richard Cochran 01db4c8849 Remove the unfinished SNMP code.
Unfortunately the SNMP code still has issues like not passing the
valgrind test, and no one is able to finish this up right now.  This
patch removes the SNMP program so that the upcoming release does not
contain unfinished work, potentially misleading end users about the
scope and completeness of the features.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-21 04:35:51 -07:00
Richard Cochran 45aa981e4a clock: Safely remove event subscribers from list.
When updating and potentially removing event subscribers, the code uses
the simple list traversal macro.  As a result, the list will become
corrupted whenever a subscriber is removed.  This patch fixes the issue
by using the appropriate macro.

Fixes: 5104e3e56b ("Event subscribing")
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Michael Walle <michael@walle.cc>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-21 04:34:43 -07:00
Richard Cochran 25d4e4fbdd Revert "phc2sys: Notify kernel if clock is not in sync"
This novel use of the STA_UNSYNC flag breaks with the established,
traditional meaning of that flag, which is:

   The clock has is believed to have an error larger than 16 seconds.

This reverts commit 944f5f7ac6.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-06 10:13:50 -08:00
Ville Heikkinen 944f5f7ac6 phc2sys: Notify kernel if clock is not in sync
In case there is no connection to the server, notify the kernel
that the clock is currently unsynchronized.

Signed-off-by: Ville Heikkinen <ville.heikkinen@nokia.com>
2020-03-04 10:01:27 -08:00
Richard Cochran 0a4d85c2ed interface: Remove obsolete method.
Now that all call sites have been converted to interface_create(), there
is no longer any needed for a way to set the interface's name.  This patch
removes the useless method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:41 -08:00
Richard Cochran b878dd99fa interface: Silence warning from gcc version 8.
When compiling with gcc8 and -O2, the clever compiler complains:

   interface.c: In function ‘interface_ensure_tslabel’:
   interface.c:38:3: error: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 108 [-Werror=stringop-truncation]

Even though this is a false positive, this patch silences the warning
by using memcpy instead of strncpy.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:41 -08:00
Richard Cochran a8f742528e interface: Hide the implementation details.
Now that a complete functional API is in place, there is no need to expose
the inner workings of the network interface data type.  This patch converts
it into an opaque type while leaving the list marker visible to users
through a simple form of "friendly exposition".

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:41 -08:00
Richard Cochran 66dc3167e3 pmc: Use the proper create/destroy API for network interfaces.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:38 -08:00
Richard Cochran 812e0df4b8 config: Use the proper create/destroy API for network interfaces.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:34 -08:00
Richard Cochran 52482e0969 clock: Use the proper create/destroy API for network interfaces.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:30 -08:00
Richard Cochran 5316a36422 interface: Introduce methods to create and destroy instances.
In order to eventually hide the implementation details of the interface,
users will need to be able to create and destroy instances thereof.  This
patch adds the needed methods.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:26 -08:00
Richard Cochran 21141a44e6 Convert call sites to the proper method for testing time stamping modes.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:22 -08:00
Richard Cochran 720c9fa08d interface: Introduce a method to test supported time stamping modes.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:19 -08:00
Richard Cochran 605abc45dd Convert call sites to the proper method for testing time stamp info validity.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:15 -08:00
Richard Cochran 3d388e1992 interface: Introduce a method to test the time stamping information validity.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:10 -08:00
Richard Cochran 02bbf36c2a Convert call sites to the proper method for getting the PHC index.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:04 -08:00
Richard Cochran a228de7dff interface: Introduce a method to get the PHC index.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:46:00 -08:00
Richard Cochran e43a76cbe6 Convert call sites to the proper method for setting the time stamping label.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:46:00 -08:00
Richard Cochran 5f9d36c76a interface: Introduce a method to set the time stamping label.
The ts_label field of the interface is set in different ways by different
callers.  In order to prevent users from open coding the logic that sets
the label, this patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:56 -08:00
Richard Cochran d471a57aa8 Convert call sites to the proper method for setting the name.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:51 -08:00
Richard Cochran 47982fb8c8 interface: Introduce a method to set the name.
The name field of the interface is set in different ways by different
callers.  In order to prevent users from open coding the logic that sets
the name, this patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:47 -08:00
Richard Cochran a8df585e04 Convert call sites to the proper method for initializing the time stamping label.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:43 -08:00
Richard Cochran b802e3b784 interface: Introduce a method to initialize the time stamping label.
In many cases, the time stamping label will be the same as the name of
the interface.  In order to prevent users from open coding the logic that
initializes the label from the interface name, this patch add an
appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:38 -08:00
Richard Cochran 6d73e755c3 Convert call sites to the proper method for getting time stamp information.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:33 -08:00
Richard Cochran cca19dab99 interface: Introduce a method to get the time stamping information.
In order to prevent users from open coding this logic, this patch
provides a method that populates the time stamping information from
the interface label.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:28 -08:00
Richard Cochran e752cac7b1 Convert call sites to the proper method for getting interface labels.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:24 -08:00
Richard Cochran a3c0a88b82 interface: Introduce an access method for the time stamping label.
Many of the users only require a read only reference to the time
stamping label of the interface.  This patch adds an appropriate
method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:10 -08:00
Richard Cochran 34945679fe Convert call sites to the proper method for getting interface names.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:45:10 -08:00
Richard Cochran 380ee349f6 interface: Introduce an access method for the name field.
Many of the users only require a read only reference to the interface name.
This patch adds an appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:45:10 -08:00