Commit Graph

243 Commits (f848a30a3e36dbbc0b32901f6819194ac7887842)

Author SHA1 Message Date
Richard Cochran a8d0eb92c6 telecom: Introduce the local priority attribute into the data set.
The Telecom Profiles G.8275.1 and G.8275.2 have invented a new
per-port and per-clock attribute, not in 1588, called "localPriority".
The use of this attribute is a distinguishing feature of the telecom
data set comparison algorithm.

This patch adds the attribute, hard coded to its default value.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:13 -07:00
Richard Cochran 6f96ebb7b8 Refactor the data set comparison function variable.
There is no need to keep two copies of the data set comparison
function.  This patch adds a method that allows the port code to
obtain the function from the clock code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-24 21:39:10 -07:00
Richard Cochran a1c5e3f2ed transport: Fix callers to pass a proper enumeration value.
The majority of the callers of transport_send() 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-04-13 22:29:05 -07:00
Anders Selhammer b36142cb51 port: Fix coding style
Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-04-12 19:47:51 -07:00
Miroslav Lichvar 73c4d9a3c7 port: fix buffer overflow in net_sync_resp_append()
The PortAddress structure has no space for the actual address and should
be used only as a pointer to a larger buffer.

The issue was reported by gcc with enabled source fortification.

[ RC: Replace magic number with sizeof() macro. ]

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-06 18:41:10 -07:00
Richard Cochran 46acbcee42 port: share init code, peer delay code, and helpers
This patch makes a number of subroutines into global functions in order
to share code with the TC implementations to come.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran d87bb60712 port: export a private interface.
This patch places the internal port data structure into a common header
for use by the original BC and the new TC code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran 866da1044c port: Provide a common method for updating the port state.
When computing the next port state based on a FSM event, much of the logic
will stay the same for OC, BC, and TC nodes.

- handling a fault ASAP
- INITIALIZING state handling
- showing the transition in the log
- sending notifications

This patch moves this common code into a global port method, making it
available to future TC implementations.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran c170405822 port: make the dispatch and event methods variable based on clock type.
This paves the way to allow different implementations for the upcoming
Transparent Clock code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran ec33010f56 port: Make the data set comparison algorithm into a function variable.
This will allow adding alternative algorithms as defined in PTP profiles.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-03 09:28:22 -07:00
Richard Cochran 4842d2c7ec Introduce peer to peer one step.
The 1588 standard defines one step operation for both Sync and
PDelay_Resp messages.  Up until now, hardware with P2P one step has
been rare, and kernel support was lacking.  This patch adds support of
the mode in anticipation of new kernel and hardware developments.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-27 22:26:32 -07:00
Richard Cochran 510777deca msg: Move the check for missing HW time stamps into caller.
On the transmit path, the port-level code calls msg_sots_missing()
directly, but on receive this check is buried in the message layer.
With the coming addition of peer to peer one step, the ingress check
will need knowledge of the configured time stamping option.  This
patch moves the check in order to accommodate the exceptional case.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-27 22:26:32 -07:00
Anders Selhammer f9db6855fd port: Added TAILQ for sent delay_req
In a ptp unaware network (like the telecom profile for frequency sync
G.8265.1), both the RTD and the PDV can be substantially higher than
in a ptp aware network. To achieve more accurate measurements, the
rate may need to be configured higher to get more data and increase
the chance of lucky packets.
In a combination of a high configured rate of delay_req and high
RTD/PDV in network, the risk that the response from the previously
sent delay_req have not been received before a new delay_req is sent
also become high. In that case, the need of storing more than the
latest sent delay_req arise.

This patch adds a queue for sent delay requests so several request can
be ongoing in parallel. When a delay response is received, a matching
request will be searched for in the queue and after processed removed
from the queue.
The stored delay_req will be removed if older than 5 seconds. Check is
made before a new delay_req is sent or announce receipt tmo expires.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-03-24 14:40:35 -07:00
Anders Selhammer 9320f768e2 port: Fix coding style
We always but braces around 'if' blocks.

Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-03-24 14:40:35 -07:00
Michael Brown 1e19ce204a port: Remove unnecessary conversions from tmv_t to int64_t
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 73c59e83d9 port: Remove unnecessary ts_to_Timestamp() wrapper
The function ts_to_Timestamp() is now just a wrapper around
tmv_to_Timestamp().  Simplify code by using tmv_to_Timestamp()
directly.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 7f59858d08 msg: Represent hw_timestamp "sw" field as tmv_t
Convert a software timestamp to the internal tmv_t representation at
the earliest possible opportunity, to match the behaviour for hardware
timestamps.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 29a99ad513 msg: Represent hw_timestamp "ts" field as tmv_t
Convert a hardware timestamp to the internal tmv_t representation at
the earliest possible opportunity.  This allows us to:

- eliminate multiple redundant calls to timespec_to_tmv()

- use tmv_add() instead of open-coded manipulation of a struct
  timespec in ts_add()

- use tmv_to_Timestamp() instead of open-coded manipulation of a
  struct timespec and struct Timestamp in ts_to_Timestamp()

- use tmv_is_zero() instead of open-coded manipulation of a struct
  timespec in msg_sots_valid()

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown 5a23ccddf6 port: Match calling convention for tmv_to_Timestamp()
The function ts_to_timestamp() currently performs open-coded
manipulation of a struct timespec and struct Timestamp instead of
using the tmv_t abstractions.

Prepare for the removal of this code by matching the calling
convention for tmv_to_Timestamp(): returning a struct Timestamp rather
than accepting a pointer to a struct Timestamp.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown cdceec59fa port: Treat ingressLatency and egressLatency as corrections
The function ts_add() currently performs open-coded manipulation of a
struct timespec instead of using the tmv_t abstractions.

Prepare for the removal of this code by storing ingressLatency and
egressLatency as corrections (matching the behaviour for
delayAsymmetry).

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Michael Brown c9f3fad780 clock: Remove open-coded conversion of struct timespec
The function clock_check_ts() performs open-coded manipulation of a
struct timespec instead of using the tmv_t abstractions.

Use the existing tmv_t abstractions to convert from struct timespec to
nanoseconds, and modify the prototype of clock_check_ts() to match
that of the underlying clockcheck_sample().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-17 19:04:28 -07:00
Richard Cochran d89d26d618 Add a configuration file option to enable the NetSync Monitor protocol.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-08 07:20:42 -08:00
Richard Cochran 61e57e9fca port: Implement the NetSync Monitor protocol.
When NSM is enabled on a given port, that port always replies to a NSM
delay request with a delay response, sync, and follow up, regardless
of the current state of the port.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-08 07:20:42 -08:00
Richard Cochran b0d9c9600a port: Introduce unicast sync messages.
The port will need to send unicast Sync messages in order to support
the NSM protocol.  Besides that, we will need this ability anyhow if
we ever want to implement unicast operation.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-08 07:20:42 -08:00
Richard Cochran a003b4c36e port: Accept multiple TLVs on receive.
Path trace TLVs and Follow-Up info TLVs might be mixed in among other
random TLVs.  This patch fixes the parsing code to find these TLVs even
when multiple other TLVs are present.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-07 19:28:25 -08:00
Richard Cochran e0005dac94 port: Convert to the API for appending TLVs on the transmit path.
The current code uses an ad hoc method of appending TLVs.  When
constructing a message, the code computes the total PDU length by adding
the message size to the TLV size.  By using the new API, this patch
simplifies message construction, letting each TLV add its own length
to the total.

As a result of the this change, the return value for the helper
functions, follow_up_info_append() and path_trace_append(), has
changed meaning.  Instead of returning the TLV length, these functions
now provide an error code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-07 19:28:25 -08:00
Richard Cochran 7fe69e7ba0 msg: Populate the TLV list on receive.
This patch changes the receive message parsing code to place each TLV
into the list.  A method is introduced that allows attaching TLVs to
the end of the list.

In addition, msg.last_tlv is converted into a pointer to the last item
in the list.  Because of this change, the transmit code that uses this
field now allocates a TLV before using it.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-07 19:28:25 -08:00
Michael Brown 1b7ff890be tmv: Generalise tmv_eq() to tmv_cmp()
Time values are compared using an inequality test in mmedian.c
Generalise tmv_eq() to tmv_cmp() (by analogy with memcmp()) and
replace existing uses of tmv_eq().

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-07 07:55:51 -08:00
Michael Brown 5df2779ef0 tmv: Add missing uses of tmv_is_zero()
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
2018-03-07 07:55:51 -08:00
Richard Cochran d34d253fb4 port: Fix coding style.
We always but braces around 'if' blocks.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-06 06:37:54 -08:00
Richard Cochran 2d25209993 port: Simplify management response logic.
The code uses a local variable for program flow control in a silly way.
This patch simplifies the logic by using the common switch/case/default
pattern instead.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-06 06:37:54 -08:00
Richard Cochran 0a726b4390 port: Clean up coding style.
Re-arrange local variables into a more legible reverse Christmas tree.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-03-06 06:31:46 -08:00
Richard Cochran 99fd084253 Introduce an option to ignore the transport specific field.
Up until now the transportSpecific field has been treated according to
802.1AS, namely as a field that must match exactly on receive.
However, 1588 mandates ignoring this field for some transports, and
there is equipment in the wild that does in fact set the reserved
bits.

This patch adds an option to ignore the field on receive completely.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Petr Kulhavy <brain@jikos.cz>
2018-03-06 06:31:04 -08:00
Miroslav Lichvar 16e9abceee port: update timeout after changing logMinDelayReqInterval.
When the minimum delay request interval is changed after processing a
delay response, update the current timeout to immediately follow the new
interval.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2018-02-19 09:47:13 -08:00
Hangbin Liu 7092db3030 port: return timestamping iface in port properties
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Hangbin Liu 8923bcdf64 transport: pass struct interface to transport_open
Pass struct interface so we can use ts_iface in HW filter.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Hangbin Liu 536a71031d ptp4l: use ts label to get ts info
Now the ts label will be either the bond active slave or the interface
name, which is the exactly interface we need to get ts info.

When the link down/up or there is a fail over and ts_label changed, the
phc index may also changed. So we need to check get new ts info and check
clock_required_modes. We will set the link to LINK_DOWN by force if
the new ts_label's timestamp do not support required mode.

If all good, then we set phc index to new one. Also sync clock interval
after switch phc.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Hangbin Liu b65b1d5f3b port: update port link_status to enum
Besides link up and down, we may also receive other rtnl messages, like
bond slave changed info, which link state keeps the same.

So we should return EV_FAULT_CLEARED only when both LINK_UP and
LINK_STATE_CHANGED.

When the link state keep the same, we should return EV_NONE.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Hangbin Liu 80bc4d4c2f rtnl: update function rtnl_link_status to get bond slave info
Update function rtnl_link_status to get bond slave info. Pass the slave index
to call back functions. i.e. port_link_status.

Also check the interface index of rtnl message in function rtnl_link_status.
Then we don't need to check it in port_link_status.

Add ifndef IFLA_BOND_MAX in case we build linuxptp on kernel before v3.13-rc1.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Hangbin Liu 05bba46198 rtnl: update rtgenmsg to ifinfomsg when request link info
The previous function use general message and will dump all interfaces'
information. Now update with ifinfomsg so we could get specific interface's
information.

We still could get all interfaces' info if set device to NULL.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Hangbin Liu 7e294a4d04 port: track interface info in port
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07: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
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
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
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