Commit Graph

305 Commits (278d9f45ab2e89e6887b27768d2a69ebdd54a9ce)

Author SHA1 Message Date
Vladimir Oltean bf0a644b99 port: print sync/follow-up mismatch events
ptp4l is too silent when receiving, for whatever reason, out of order
messages. If the reordering is persistent (which is either a broken
network, or a broken kernel), the behavior looks like a complete
synchronization stall, since the application is designed to never
attempt to recover from such a condition.

At least save some people some debugging hours and print when the
application reaches this code path. Since it's a debugging tool, we
don't want to create false alarms when the occasional packet gets
reordered in a production system, but have this information readily
available when the program's log level is set to debug, instead of
having users fish for it with code instrumentation.

[ RC - corrected printf format for sequence id. ]

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-06-24 10:09:13 -07:00
Richard Cochran 271a6d53f6 port: Support slave event monitoring of delay timing data.
After a successful message exchange, the delay measurement values are
processed by the port code.  This patch makes the values available to a
monitor by calling the appropriate method.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 18bd3054ff port: Support slave event monitoring of Sync timing data.
The monitoring module accepts Sync timing events.  This patch hooks up the
port receive path to call into the monitor.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 19:46:31 -07:00
Richard Cochran 5aa19dd3f4 port: Convey targeted forwarding errors to the caller.
The port_forward_to() method clobbers the specific error code returned
by the transport layer with -1.  This patch lets the code preserve the
specific error in question.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -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
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 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 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 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 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 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 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 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
Miroslav Lichvar ee6930a884 unicast: Enable sharing master tables between ports.
Don't require each port to have its own master table specified in the
config. Instead of ports claming configured tables, clone the table in
each port, so different ports don't interfere with each other.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2020-02-09 04:20:08 -08:00
Richard Cochran 581a6bd59b Accept external PHC devices from the command line.
A single, external PTP Hardware Clock device may be wired to one or more
MAC devices, providing the MACs with an input clock.  This patch adds
support for such a hardware architecture by letting the command line PHC
override the one discovered via the ethtool ioctl.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-02-08 07:31:14 -08:00
Miroslav Lichvar e20d8228f9 port: Avoid calling freed servo after switching PHC.
In port_synchronize(), when the clock returned SERVO_UNLOCKED and
port_dispatch() triggered a switch of the PHC, the variable "s" would
point to a servo which was already freed and the following call of
servo_offset_threshold() would read invalid memory.

Don't save the servo before dispatching the port.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 3f5f5653d7 ("port: Add interval update mechanism.")
2019-10-12 20:42:58 -07:00
Miroslav Lichvar f9e84e69bf port: Don't leak transport when unicast initialization fails.
[RC: Fix two more bad goto labels. ]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-10-12 20:40:44 -07:00
Petr Machata 2b5bec8d27 pmc: Add a new TLV to obtain per-port statistics
Add an ability of pmc to query per-port stats added in the previous patch.

Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-09-10 20:56:30 -07:00
Petr Machata e3f0891996 port: Introduce per-port stats for received and transmitted messages
Add struct PortStats to keep per-port number of messages sent and received,
split by message type. Bump TX counters after messages are sent
successfully, and RX counters after a message is received. To keep things
simple, reserve one counter for each theoretically possible message type,
including the reserved ones.

Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-09-10 20:56:30 -07:00
Vedang Patel 450b1ed844 port: Add inhibit_delay_req.
Add provision to disable delay requests. Designated masters who do not
need to calculate pdelay can use this option. This is required by
Automotive Profile to reduce network load.

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2019-05-08 21:29:48 -07:00
Vedang Patel 3f5f5653d7 port: Add interval update mechanism.
This commit adds functionality to increase the sync and pdelay request
intervals once gptp synchronization has been achieved. This is useful
while running Automotive Profile where the network is usually static.

Here, we are assuming that the gPTP synchronization is achieved whenever
the last 'n' offsets calculated using the Sync messages are below a
certain threshold. Both, the number of offsets to consider and the offset
threshold are configurable.

In order to support the interval update, a new clock servo state
CLOCK_SERVO_STABLE has been added. The clock will transition to this
state whenever the above condition is satisfied. When this transition
occurs, the slave will send an "interval request" signaling message
asking the master to change the sync interval. It will also update the
pdelay request interval locally.

Four new config options have been added to provide this functionality:

- servo_offset_threshold: All the offset values being considered should
  be below this value.
- servo_num_offset_values: number of previously received offset values
  to consider.
- operLogSyncInterval: slave will ask the master to switch to this
  interval for sending sync messages when the offset stabilizes.
- operLogPdelayReqInterval: the slave will set this interval for pdelay
  request messages when the offset stabilizes.

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2019-05-08 21:29:48 -07:00
Vedang Patel 630ce719fc port: implement message interval request processing
This implements transmission and receipt of message interval requests.
Using this mechanism, a time-aware device can request change in sync,
link delay and announce intervals on the device connected on the other
end.

As part of the commit, we are also saving the initial values of Announce
and Sync Interval.

For more information look at sections 10.2.4.4, 10.3.9.5, 10.3.14, 10.4,
10.5.4 and 11.2.17 of 802.1AS standard

Please note that this commit does not implement logic related to
computeNeighborRateRatio and computeNeighborPropDelay flags mentioned in
Section 10.5.4.3.9 of 802.1AS Standard.

[ RC - memset the targetPortIdentity to all ones. ]

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-05-08 21:29:29 -07:00
Vedang Patel 888afcdbae port: Add logPdelayReqInterval.
It will be used to store the current value of Pdelay Request Interval.
It will be represented as power of two in seconds.

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2019-05-08 21:29:29 -07:00
Vedang Patel 705e5a32fa port: Make port_capable() accessible outside port.c
Make sure port_capable() can be accessed by the signaling construct in
port_signaling.c

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2019-05-08 21:21:30 -07:00
Hangbin Liu 51d76bdfb7 port: should check the new phc_index before switching
In logic, when we want to switch phc, we should check if the new phc
index is valid instead of checking the previous one.

In reality, if we use linux team interface with activebackup mode. As
teamd is a userspace tool, it sets the new slave as active port after
receiving link change message. If we set current active port down and
another slave up. There is a race that we receive the new slave's link
up message while active port(ts_index) is still the old one. This means
we may use a link down interface as ts_index and get phc_index with -1.

If we update the p->phc_index to -1, there will be no possibility to
change it back to other value as we swith phc only when p->phc_index >= 0.

With this fix, we will not switch phc_index until receiving the real
active port(p->iface->ts_info.phc_index >= 0) update message.

Reported-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 536a71031d ("ptp4l: use ts label to get ts info")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2019-03-25 06:25:07 -07:00
David Mirabito via Linuxptp-devel 6b61ba29c7 Avoid fault when receiving zero length packets
The manpage for recvmsg says -1 will be returned on error, Zero indicates an
"orderly shutdown", presumably only in case of stream sockets.
Further, UNIX Network Programming, Vol 1 says ".. a return value of 0 from
recvfrom is acceptable for a datagram protocol"

Such packets have been observed in the wild, aimed at PTP's multicast
address and port, possibly related to malformed management queries.

Patch to properly check return from recvmesg and not trigger the fault
codepath. Instead, such packets are treated as "Bad Message" the same as
non-zero but still too-short UDP payloads.

Signed-off-by: David Mirabito <davidjm@arista.com>
2019-03-25 06:25:07 -07:00
Miroslav Lichvar 6d50817dc0 port: Prevent undefined shift operations in msg_current().
Adjust checks of logMessageInterval in received packet to prevent 1 of
type int being shifted by values >= 31.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2019-01-28 20:55:30 -08:00
Vedang Patel d1ce07d5cb port: Fix for inhibit_announce.
When inhibit_announce is set, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES event is
still sent once every state change. Avoid this by explicitly sending
EV_NONE instead.

[ RC - Simplify and keep all of the timer's state maintenance. ]

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-01-06 17:35:37 -08:00
Richard Cochran 563c52b833 Allow ignoring source port identity in end to end mode.
The "inhibit_announce" and "ignore_source_id" options were introduced
in order to support the automotive profile.  That profile happens to
specify using the peer to peer delay mechanism, but there is no reason
to restrict them to that mechanism.  As it now stands, enabling these
two options prevents E2E slaves from synchronizing.  This patch fixes
the issue by checking the "ignore_source_id" option when accepting E2E
delay response messages.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2019-01-06 17:34:31 -08:00
Anders Selhammer 8f2f9bbcab port: correction of port name used port_open
Correction of fault introduced in "Add BMCA config option."

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
Reviewed-by: Vedang Patel <vedang.patel@intel.com>
2018-11-01 20:07:55 -07:00
Vedang Patel d58b1080bc Add ignore_source_id config option.
This config option will skip the source port identity verification in
the Sync and Follow_up messages. This option is needed when the announce
messages are disabled because the slave cannot know the identity of
master without announce messages.

This is required by Automotive Profile as part of skipping the Best
Master Clock Algorithm (BMCA).

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2018-10-04 19:38:19 -07:00
Vedang Patel 1cbeec80cd Add inhibit_announce config option.
This option will accomplish 2 things. On the master, it will stop the
announce messages being sent (by disabling FD_MANNO_TIMER timer). On
slave, it will not configure announce message timeouts (by disabling
FD_ANNOUNCE_TIMEOUT timer).

This config option is needed for the Automotive profile as part of
skipping the Best Master Clock Algorithm (BMCA).

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2018-10-04 19:38:19 -07:00
Vedang Patel 83be05256b Add BMCA config option.
This adds config option to specify static roles for master and slave
in the Best Master Clock Algorithm. This is the case for Automotive
Profile where networks are mostly static and role for each device is
known in advance.

masterOnly and slaveOnly will be used to determine the roles for the
devices. Since masterOnly is a per-port config and slaveOnly is a global
config option, role assignment will be slightly odd in case of bridges.
If slaveOnly is set to 1, all the ports will be in slave roles except
for the ones where masterOnly is set to 1. These ports will assume the
master role.

Two new FSMs which will be used for master and slave roles for this
config option have also been added.

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2018-10-04 19:38:19 -07:00
Vedang Patel 3f764aec6a port: Add configurable option to set asCapable.
If set to 'true', this unconditionally sets the asCapable variable. The
usual checks will be applied to asCapable if it is set to 'auto'. The
default value is 'auto'.

This config option is needed by the Automotive Profile. The master will
be able to send out Sync Message as soon as the daemon is started.

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2018-10-04 19:38:19 -07:00
Vedang Patel 4910055bd7 port: Add condition to check fc.
If foreign clock is NULL, both the clocks are obviously not equal. So,
return 0 in that case.

The above condition (fc == NULL) is not currently encountered. It will
be encoutered in the next few patches which implement static roles for
master and slave.

Signed-off-by: Vedang Patel <vedang.patel@intel.com>
2018-10-04 19:38:19 -07:00
Anders Selhammer 1173e774dd Introduce the maxStepsRemoved attribute
Add attribute maxStepsRemoved which is included in IEEE1588-2017 (v2.1)
It is an optional attribute which can decide if an Announce message is
considered in the operation of the BMCA or not.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-09-30 18:39:39 -07:00
Miroslav Lichvar 47971bdd50 port: Fix memory leaks.
In port_management_fill_response() the TLV descriptor leaked when
not responding.

In port_open() the port would leak with the unsupported management clock
type.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2018-08-12 13:33:06 -07:00
Richard Cochran a2740768b6 Apply ingress and egress latency corrections in P2P one step mode.
When using peer to peer one step mode, the normal time stamp handling
of peer delay request messages is bypassed.  The hardware subtracts
the ingress time stamp from the correction field and then adds the
egress time into the correction of the response.  The configured
latency values are never applied since the hardware has no knowledge
of them.  This patch adds in the correction values in this special
case.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-08-05 21:15:59 -07:00
Richard Cochran b1ce06206f port: Introduce an option to disable mutlicast service.
Some profiles forbid multicast altogther.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:07 -07:00
Richard Cochran b9b18268cd port: Hook into the unicast service logic.
Now that all the pieces are in place, hook the port logic into the
unicast service code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:07 -07:00
Richard Cochran dfa9e65785 fd: Introduce a unicast service timer.
This patch adds a new timer to be used by the server side unicast
negotiation logic.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran f71caedc57 port: Hook into the unicast client logic.
Now that all the pieces are in place, hook the port logic into the unicast
client code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran e8e2be017a Support unicast peer to peer delay mechanism.
There are two aspects.  First, on the receive path, we reply to
unicast peer delay requests in kind.  That is, if the peer sends a
unicast delay request, then reply with unicast, too, since this is
obviously what the peer expects.

Second, if configured, we transmit peer delay requests to the
specified unicast peer address.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 22:10:06 -07:00
Richard Cochran ffdb3f7192 fd: Introduce a unicast request timer.
This patch adds a new timer to be used by the client side unicast
negotiation logic.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:48 -07:00
Richard Cochran f94df4f625 port: Make the sync and announce transmit functions public.
These functions will be needed by the new unicast mode.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:48 -07:00
Richard Cochran 05dce31d81 port: Allow transmission of unicast announce messages.
This will be needed by unicast mode.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:27:47 -07:00
Richard Cochran ffbafa557b transport: Fix even more callers to pass a proper enumeration value.
All of the callers of transport_peer() use hard coded magic numbers.
This patch fixes them to use the corresponding enumerated values instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-07-01 06:25:34 -07:00
Rafaël Carré ee2a9d4ac9 follow_up_info_append: port argument is unused
Signed-off-by: Rafaël Carré <funman@videolan.org>
2018-06-25 07:24:17 -07:00
Rafaël Carré 3c7fa5dd42 clock_send_notification: msg_len is unused
message length is already included in the msg structure

Signed-off-by: Rafaël Carré <funman@videolan.org>
2018-06-25 07:24:17 -07:00
Michael Walle 6bc77ccf4b Replace memcmp() with pid_eq() and cid_eq()
Consistenly use the pid_eq() and cid_eq() helper functions. Move the
functions into utils.h (making them inline functions) because they are
used in multiple source files.

Signed-off-by: Michael Walle <michael@walle.cc>
2018-06-21 07:18:24 -07:00