Commit Graph

997 Commits (5f9163af4bf6b54ea08f7fef112e9fcf4a669e56)

Author SHA1 Message Date
Miroslav Lichvar 17c9787b1d phc2sys: fix handling of multiple state changes.
When the master clock changed its state and then changed it back to the
original state before phc2sys could process the first change, e.g. SLAVE
-> UNCALIBRATED -> SLAVE after a clockcheck failure, the second change
was ignored because the new value was the same as the original state,
which wasn't updated for the first change yet. This caused phc2sys to be
stuck with a wrong state.

Fix phc2sys to check both the state and new_state variables of the clock.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-09-01 15:44:59 +02:00
Richard Cochran 14a97dc5da Remove redundant test on the UTC flags.
Now that we test the UTC flags in clock_update_slave(), the similar
code in clock_utc_correct() is redundant.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-08-23 20:36:56 +02:00
Richard Cochran fa575b60f6 Latch the UTC offset.
When acting as a slave, we accept the foreign master's advertised
TAI-UTC offset for as long as that master is present.  However, when
the master disappears, we fall back to the initial offset value.  As a
result of this behavior, when starting with an out of date initial
offset, losing a foreign master causes a sudden UTC offset error (in
phc2sys for example) in the range of whole seconds.

This patch fixes the issue by remembering the UTC offset when assuming
the slave role.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-08-23 20:36:56 +02:00
Richard Cochran 97e4242361 Simplify UTC tracking.
The clock code uses two different variables to store the TAI-UTC
offset.  One variable represents the compile time, configuration file,
or command line initial UTC offset, while the other is used when
taking on the GM role and is settable at run time.  However, making
this distinction makes no sense.  This patch simplifies and clarifies
the code by using a single variable for the offset.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-08-23 20:36:56 +02:00
Feras Daoud 7546434030 ptp4l: Add IPoIB interface support for ptp4l
The current implementation of ptp4l always assumes 6 octets MAC
address, which is correct for Ethernet interfaces but not for IPoIB
interfaces (that have 20 octets MAC), therefore running ptp4l over
IPoIB interface does not function correctly.

In Infiniband, every interface has three identifiers:
GUID, GID, and LID.
The GUID is similar in concept to a MAC address. From RFC4392:
The EUI-64 portion of a GID is referred to as the Global Unique
Identifier (GUID) and is the only persistent identifier of a port.

Therefore, to support IPoIB interfaces, the GUID of the port should
be used instead of the MAC.
This patch checks the interface type before creating the clock identity,
for Infiniband ports, it retrieves the GUID of the port using sysfs
and use it to create the clock identity.

sysfs method was chosen since the GUID is the 6 lsb bytes of
the 20 byte device address, and SIOCGIFHWADDR ioctl call returns
the 14 msb bytes of the device address, so it is not possible to
get the GUID using SIOCGIFHWADDR ioctl call.

[ RC: fixed trivial coding style error, space after switch keyword. ]

Signed-off-by: Feras Daoud <ferasda@mellanox.com>
Reviewed-by: Alex Vesker <valex@mellanox.com>
2017-08-10 10:42:16 +02:00
Hangbin Liu 7c3f9579f0 clock: remove hash table index2port
Remove index2port since we don't need it now.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-07-13 07:19:57 +02:00
Hangbin Liu 25ec8a3b4e clock: remove rtnl fd on clock
Remove rtnl fd on clock since we track the link status per port now.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-07-13 07:19:57 +02:00
Hangbin Liu c149a3dbc1 port: add FD_RTNL event to track per-port status
With rtnl socket we can track link status per port(except UDS port).

We can make sure we get the correct interface and latest status with function
port_link_status().

At the same time we need to set clock sde after link down. But we return
EV_FAULT_DETECTED in port_event(), which will not set clock sde. So we need
to set it in port_link_status().

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-07-13 07:19:57 +02:00
Hangbin Liu 17aa750a49 rtnl: replace obsolete RTMGRP_LINK with RTNLGRP_LINK for nl groups
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-07-13 07:19:57 +02:00
Hangbin Liu 46cc187e82 phc2sys: free clock device when exit
Since we called strdup() for clock device, we need free the memory
before exit.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-06-23 07:31:43 +02:00
Cliff Spradlin via Linuxptp-devel 6b18e12b9b phc2sys: Add described device to stats output
When phc2sys synced more than one ethernet interface, such as in a JBOD
boundary clock arrangement, it was unclear which interface a line of statistics
referred to.

Previous output:

phc2sys[583.098]: sys offset       -32 s2 freq +131974 delay   3871
phc2sys[583.098]: sys offset        33 s2 freq +125746 delay   4095
phc2sys[583.098]: sys offset       -73 s2 freq +125720 delay   4128
phc2sys[583.098]: sys offset       -19 s2 freq +133265 delay   3888
phc2sys[583.098]: sys offset         2 s2 freq +131986 delay   3920

Now:

phc2sys[583.098]: eth9 sys offset       -32 s2 freq +131974 delay   3871
phc2sys[583.098]: eth8 sys offset        33 s2 freq +125746 delay   4095
phc2sys[583.098]: eth7 sys offset       -73 s2 freq +125720 delay   4128
phc2sys[583.098]: eth6 sys offset       -19 s2 freq +133265 delay   3888
phc2sys[583.098]: eth1 sys offset         2 s2 freq +131986 delay   3920

Signed-off-by: Cliff Spradlin <cspradlin@google.com>
2017-06-19 08:14:40 +02:00
Brian Olson 7c6a9862fd added workaround for ticks being returned as zero from 2.6.32 kernel.
Signed-off-by: Brian Olson <brian@amergint.com>
2017-06-19 08:14:40 +02:00
Brian Olson ae28f5295f fixed include order to work around issue on RHEL 6.6
[ RC: Added comment explaining the ordering requirements. ]

Signed-off-by: Brian Olson <brian@amergint.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-06-19 08:13:40 +02:00
Richard Cochran 97c351cafd Fix build when using uClinux.
Unfortunately uClinux is rather inconsistent with respect to
clock_nanosleep().  Older versions of uclibc lack that function, while
newer versions may include the declaration but still lack the
definition, depending on whether pthreads are selected in the
configuration.

This patch works around uClinux shortcomings by using the library call
when available at compile time, otherwise falling back to syscall().

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-05-30 08:42:27 +02:00
Hangbin Liu 95b5a13cb2 pmc: goto out when get unknown management tlv
If handle unknown management tlv. The management message id and format are
also unknown, thus we may crash due to access unknown area.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-05-25 13:44:07 +02:00
Petr Kulhavy a216b11ce5 pmc: optimize duplicated code in do_set_action()
TLV_PRIORITY1 and TLV_PRIORITY2 cases in do_set_action() use the same repeated
piece of generic code for setting one-value parameter. Remove the duplicated
code and let both cases use the same code.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
2017-05-21 21:37:10 +02:00
Richard Cochran 78d2a32a94 clock: Fix poor snprintf() handling.
The calls to snprintf() to format /dev/phc%d use the wrong pattern.
That function always properly terminates the string with null.
However, the code passes a hard coded length of 31 to static arrays of
length 32.  While this is not a bug, there are two issues here.

First, any (improbable) future increase in the array lengths would
have to also remember to fix up the snprintf() call site as well.
Secondly, the pattern of using buf[N] and then length=N-1 is
appropriate for strncpy(), but is useless for snprintf().

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Petr Kulhavy <brain@jikos.cz>
2017-05-21 21:17:03 +02:00
Richard Cochran 6558bade7c Merge 'tsproc' branch allowing clock synch. after jump.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-05-21 19:20:36 +02:00
Petr Kulhavy 0efc3a97f5 Fix detection of clock_adjtime
On some platforms clock_adjtime is defined in timex.h instead of time.h
Due to this fact the detection in incdefs.h was failing.
Add timex.h into the list of searched files.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
2017-05-15 23:18:27 +02:00
Petr Kulhavy c7837b9a29 Remove conflicting netinet/ether.h
On some platforms like br-arm-cortex-a9-musl struct ethhdr was defined twice
due to including of both linux/if_ether.h and netinet/ether.h. Which lead
to a compilation error.

Remove netinet/ether.h as the official header for struct ethhdr is
linux/if_ether.h

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
2017-05-15 23:18:19 +02:00
Stephen Walker 159eb5ff11 util: Fix unknown time_t types with musl-libc builds
Fixes the following build errors seen with musl-libc:

In file included from print.h:25:0,
                     from linreg.c:24:
util.h:364:32: error: unknown type name 'time_t'
int rate_limited(int interval, time_t *last);

Signed-off-by: Stephen Walker <stephendwalker+github@gmail.com>
[florian: extract patch from OpenWrt, add commit message]
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2017-05-15 23:05:57 +02:00
Hangbin Liu 43b2f5d120 msg: use last_tlv if there is not enough room for another tlv
If the len is not enought for another tlv process. e.g. one more bytes
padding at the end of message. And we set extra to NULL instead of
msg->last_tlv in tlv_post_recv(). Then the msg->last_tlv will not be
initialised. And program will crash if we read msg->last_tlv. e.g. in
function pmc_show().

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-05-12 16:18:45 +02:00
Florian Fainelli 8b61aa2c3f udp: Avoid including netdb.h
netdb.h pulls in a large chain of include files:
rpc/netdb.h
rpc/types.h

rpc/types.h re-defines TRUE/FALSE and does it in this way:

 #ifndef FALSE
 #      define  FALSE   (0)
 #endif

 #ifndef TRUE
 #      define  TRUE    (1)
 #endif

And this later causes build problems that appear in this way:

mipsel-linux-gnu-gcc -Wall -DVER=1.8  -D_GNU_SOURCE -DHAVE_CLOCK_ADJTIME
-DHAVE_POSIX_SPAWN -DHAVE_ONESTEP_SYNC  -Os -pipe -mno-branch-likely
-mips32r2 -mtune=24kc -fno-caller-saves -Wno-unused-result
-D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro
-I/home/florian/dev/openwrt/trunk/staging_dir/target-mipsel-unknown-linux-gnu_glibc/usr/include
-I/home/florian/dev/openwrt/trunk/staging_dir/target-mipsel-unknown-linux-gnu_glibc/include
-I/home/florian/dev/toolchains/stbgcc-4.8-1.5/usr/include
-I/home/florian/dev/toolchains/stbgcc-4.8-1.5/include
-DHAVE_CLOCK_ADJTIME -DHAVE_POSIX_SPAWN -DHAVE_ONESTEP_SYNC   -c -o
udp.o udp.c
In file included from
/home/florian/dev/openwrt/trunk/staging_dir/target-mipsel-unknown-linux-gnu_glibc/usr/include/rpc/netdb.h:45:0,
                 from
/home/florian/dev/toolchains/stbgcc-4.8-1.5/mipsel-linux-gnu/sys-root/usr/include/netdb.h:32,
                 from udp.c:23:
pdt.h:25:7: error: expected identifier before '(' token
 enum {FALSE, TRUE};
       ^
<builtin>: recipe for target 'udp.o' failed

Upon inspection, it does not appear that netdb.h is providing any useful
definition or declaration, so let's just remove its inclusion.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
2017-05-07 23:22:50 +02:00
Richard Cochran 2d5d8a0395 tsproc: Allow clock synchronization immediately after jump.
After a servo jump, the call to tsproc_reset() clears tsp->t3.  This
causes the next call to tsproc_update_offset() to fail.  However the
offset calculation does not necessarily depend on t3, i.e. when
filtered_delay is available and neither raw nor weighting is used.

This patch fixes the issue by allowing the stored filtered delay to be
used when appropriate.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Burkhard Ilsen <burkhardilsen@gmail.com>
2017-04-08 21:17:01 +02:00
Richard Cochran a0cbeb7367 tsproc: Clarify the internal mode handling.
The time stamp processor features four modes resulting from the
combination of two independent Boolean options.  Even though we have a
proper enumerated type to represent the mode, still the code coverts
the mode into two variables.

The tests on the variables are currently simple enough, but soon we
will want to add some more complexity.  In the interest of clarity,
this patch converts the paired Boolean tests into a switch/case
pattern.

No functional change.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-04-08 21:17:01 +02:00
Richard Cochran 74ab3b3728 tsproc: Track the validity of the filtered delay explicitly.
We will want to test whether a valid filtered delay value has been
calculated or not.  However, we cannot simply test for zero since that is
a legitimate possible delay value.  This patch adds a flag that reflects
the state of the filtered delay field.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-04-08 21:13:36 +02:00
Burkhard Ilsen d1bb9ecbd5 port: sequence of nrate and peer_delay calculation
The sequence of port_nrate_calculate() and tsproc_update_delay()
in port_peer_delay() is mixed up.
The peer delay depends on the nrate ratio so the nrate ratio
shall be updated before peer delay is calculated.

Signed-off-by: Burkhard Ilsen <burkhardilsen@gmail.com>
2017-04-08 21:04:50 +02:00
Burkhard Ilsen 7e1ccac8f8 servo: NULL pointer check for servo constructors
The servo constructors might return a NULL pointer.
The function servo_create() uses servo without checks.

Signed-off-by: Burkhard Ilsen <burkhardilsen@gmail.com>
2017-04-06 06:25:34 +02:00
Miroslav Lichvar ac92a71161 phc2sys: don't synchronize clock to itself.
When ptp4l is using multiple interfaces sharing the same clock, phc2sys
in the automatic mode should not try to synchronize them to each other.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reported-by: Stefan Lange <s.lange@gateware.de>
2017-03-29 13:10:52 +02:00
Miroslav Lichvar 8deb52a849 Fix leaks of sockets on errors.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-14 09:05:04 +01:00
Richard Cochran 73318c5b99 clock: Force a BMC election when a port link goes down.
Having one fewer port may affect the result of the BMCA.  This patch
changes the main loop so that a link down event also causes a state
decision event.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Henry Jesuiter <Henry.Jesuiter@alcnetworx.de>
2017-02-05 18:31:27 +01:00
Richard Cochran 6b471d45ed port: Change port_dispatch() into a void function.
This global function used to return an error code, but now it always
returns zero.  This patch converts the function signature to return void
and simplifies the main clock loop by removing the useless test.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-02-05 18:25:18 +01:00
Miroslav Lichvar 117ed5c2d0 timemaster: check support for SW time stamping.
When an interface doesn't support HW time stamping, before falling back
to SW time stamping, check if it's actually supported and exit with an
error message if not.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-05 16:44:48 +01:00
Miroslav Lichvar e54158195b timemaster: tag ptp4l and phc2sys messages.
Use the new options of ptp4l and phc2sys to tag their log messages with
the PTP domain number and name(s) of interface(s) in the domain.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-05 16:44:48 +01:00
Miroslav Lichvar 0f6c6972c7 Add options to tag ptp4l and phc2sys log messages.
When running multiple instances of ptp4l or phc2sys, it's difficult to
tell which log message belongs to which instance. Add new options to
ptp4l and phc2sys which can specify a tag for all messages printed to
the standard output or system log, so messages from different instances
can have different tags.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-05 16:44:48 +01:00
Viliam Lejcik 33e62f9925 ptp4l: Make UTC offset configurable.
Currently UTC offset is defined as a constant - CURRENT_UTC_OFFSET, and if
a leap second is added, that constant is no longer valid. Ptp4l was
updated to read the UTC offset from configuration instead.

Signed-off-by: Viliam Lejcik <viliam.lejcik@kistler.com>
2017-02-05 16:41:58 +01:00
Richard Cochran b738afb604 fsm: Make the transition out of INITIALIZING part of the FSM code.
The state machines in 1588 do not specify an event that causes a transition
out of the initializing state.  This was left as a local issue.  For this
transition, the current code assigns the next state outside of the FSM.  But
doing so prevents an alternative FSM to handle this transition differently.

By introducing a new event, this patch places this transition where it
belongs, namely under the control of the FSM code,

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:54 +01:00
Richard Cochran 01ee947457 Disentangle initialization from fault clearing.
Although leaving the INITIALIZING state and clearing the FAULTY state
ASAP both result in a port entering the LISTENING state, still there
is no benefit from conflating the two.  In the FAULTY case, the
current code actually skips the INITIALIZING state altogether.

This patch separates the two cases resulting in two benefits.  First,
the check for ASAP fault status is only made when a fault is actually
present, unlike the present unconditional check.  Second, this change
will allow us to cleanly support alternative state machines later on.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Richard Cochran 1f66948d38 Make the fault handling code more readable.
The code that decides whether a fault qualifies for ASAP treatment is
a tangle of logical operators.  This patch replaces the open coded
logic with a helper function whose name makes the intent clear.  This
is a cosmetic change only.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Richard Cochran 80a28a9dc3 Change a misleading fault handling function signature.
Looking at the fault logic in port_dispatch(), you might think that
the function, fault_interval(), checks whether a fault is active, but
you would be wrong, since that function always returns zero.

This patch removes the superfluous input error checking inside of
fault_interval() and changes the return type to void, making the
actual behavior explicit.  Dropping the input check is safe because
that function has exactly two callers, both of whom always provide
valid inputs.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Richard Cochran 10d4e7f8b0 port: Make the finite state machine into a function variable.
This allows adding new FSM flavors in the future.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Miroslav Lichvar 0309a880fb Update TAI-UTC offset
A leap second was applied to UTC on 2016-12-31 and the offset between
TAI and UTC is now 37 seconds.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-01-08 21:28:40 +01:00
Richard Cochran 4e966536c6 ptp4l: Document the "long" command line options in the man page.
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
2016-12-13 20:52:45 +01:00
Richard Cochran e658982624 config: Fix bitwise copy-and-pasto for command line items.
The recent change allowing every configuration option to appear on the
command line wrongly used bitwise AND to set a flag.  This patch fixes
the bug by using the proper bitwise OR idiom.

Signed-off-by: Richard Cochran <rcochran@linutronix.de>
Reported-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 4e8dbd8 ("ptp4l: Accept any configuration option as a command line argument.")
2016-12-13 19:57:07 +01:00
Richard Cochran 81d97657bf Add an acknowledgment in the readme for Exablaze.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-12-09 19:41:08 +01:00
Richard Cochran 356eb81d4d makefile: Make the 'clean' target conform to standard practice.
This patch makes the build system less surprising by removing the
executable binaries in the 'clean' target.  This behavior is more in
line with the GNU makefile guidelines.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Suggested-by: Manuel Traut <manut@linutronix.de>
2016-12-06 19:48:39 +01:00
Richard Cochran 4e8dbd8492 ptp4l: Accept any configuration option as a command line argument.
This patch provides a way to use the entire table of configuration options
as "long" command line switches.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-12-06 19:40:36 +01:00
Richard Cochran 891d56e429 Version 1.8
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-11-04 19:38:56 +01:00
Richard Cochran 3b82f227ce clock: Monitor the link status using a RT netlink socket.
Poll for link up/down events.  When a link goes down, the port becomes
faulty until the link goes up again.  We keep the fault timer from the
existing fault detection, but a downed link prevents clear the fault.

The new state machine is depicted in this ascii art diagram:

          +--------+    Fault    +---------+
          |        |------------>|         |
          |   UP   |             |  FAULT  |
          |        |<------------|         |
          +--------+   Timeout   +---------+
             A  |                   /
             |  |                  /
   Link-Up   |  | Link-Down       /
             |  |                /
             |  V               /
          +--------+           /  Link-Down
          |        |          /
          |  DOWN  |<--------/
          |        |
          +--------+

If the fault timer occurs in the DOWN state, we simply ignore it.
After all, without the link the port is useless.

There is one case where the new code changes the existing behavior.
If the link quickly does down and then up again while another fault
(and its timer) are active, then we will enter the UP state without
waiting for the fault timer expiration.  However, this behavior is
acceptable because when a link goes up, you are starting with a clean
slate.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-19 21:48:07 +02:00
Richard Cochran 5e3156da15 port: Provide methods to set and get the link status.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00