net: ptp: add IEEE 802.3 transport, timestamping fixes, and regression coverage#106464
Open
DBS06 wants to merge 22 commits intozephyrproject-rtos:mainfrom
Open
net: ptp: add IEEE 802.3 transport, timestamping fixes, and regression coverage#106464DBS06 wants to merge 22 commits intozephyrproject-rtos:mainfrom
DBS06 wants to merge 22 commits intozephyrproject-rtos:mainfrom
Conversation
Store the first foreign Announce and compare it against the previous entry. Fix the BTCA receiver-port tie-break to avoid false role decisions. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
RM0481 Rev 4 documents the Ethernet PTP timestamp clock as a dedicated
reference clock (`clk_ptp_ref_i`), not the `eth_hclk` bus clock.
Table 115 ("Kernel clock distribution overview", p. 470/3154) lists
`ETH (ptp)` on `pll1_q_ck`, and the IEEE 1588 section states that the
64-bit PTP time is updated from `clk_ptp_ref_i`.
Add an explicit `mac-clk-ptp` clock for STM32H5 sourced from
`STM32_SRC_PLL1_Q`, use that clock rate for PTP addend programming, and
remove the previous `stm-eth / 2` workaround.
Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
run clang format to satisfy compliance test Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
run clang format to satisfy compliance test Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Implement AF_PACKET recvmsg() support and deliver ancillary SO_TIMESTAMPING data to packet socket users. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Use NET_CMSG_SPACE() when checking ancillary buffer capacity and account for aligned cmsg storage in msg_controllen. This keeps recvmsg() control-data handling consistent with cmsghdr layout and avoids under-reporting consumed control-buffer space. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Add Layer-2 (EtherType 0x88F7) transport support and the PTP stack updates needed for L2 operation. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
run clang format to satisfy compliance test Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Enable SO_TIMESTAMPING on IEEE 802.3 PTP sockets and read RX timestamps from recvmsg() control data. If recvmsg() is unavailable or fails at runtime, fall back to recvfrom() to keep L2 reception working. Register the Delay_Req TX timestamp callback for both UDP and L2 paths, and suppress expected UDP parse warnings when running in L2 mode. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Add a new `net ptp` shell command to inspect PTP runtime state from the Zephyr shell. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Replace printk with LOG_INF and adapt sample config Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Improve the PTP sample documentation by clarifying requirements and providing a complete Linux host + native_sim run guide. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Document IEEE 802.3 transport support and describe timestamping behavior for both UDP and Layer-2 operation. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
run clang format to satisfy compliance test Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
native_tap only queued TX timestamp callbacks for gPTP packets, which left PTP SO_TIMESTAMPING socket traffic without TX timestamps. Add host-clock packet timestamp updates in native_tap TX/RX paths, queue TX timestamp callbacks when net_pkt_is_tx_timestamping() is set (while preserving gPTP behavior without double-queueing), and propagate SO_TIMESTAMPING TX/RX flags for AF_PACKET packets in net_context. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Add regression coverage for BTCA and PTP state-machine transitions. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Add regression tests for foreign master discovery and update handling. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Add a full state transition matrix test for BTCA event handling. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Add regression coverage for clock decision and BMCA edge cases. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Add a focused unit test suite for ptp_msg_post_recv(). Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Enable timestamping in the UDP socket test config and add a recvmsg() regression that verifies SO_TIMESTAMPING ancillary data updates msg_controllen with NET_CMSG_SPACE(sizeof(struct net_ptp_time)). Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Enable packet timestamping in the AF_PACKET socket test config and add recvmsg() regression coverage for SO_TIMESTAMPING ancillary data. Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
3d92658 to
3270c3a
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Motivation
I started this work while trying to run the Zephyr PTP sample on a Nucleo-H563ZI with a GPS clock and a PTP-capable switch. That exposed a mix of correctness, timestamping, and usability issues: some paths did not work reliably on hardware, IEEE 802.3 / Layer-2 transport support was missing, and the native_sim/native_tap path was not a good enough stand-in for development and regression testing.
What began as a small hardware bring-up fix turned into a broader hardening pass of the PTP stack. Along the way I fixed several bugs in transport handling, timestamp propagation, foreign-master selection, and BTCA/state handling, and I added documentation, shell diagnostics, and regression coverage so the current behavior is easier to validate and maintain.
Key Features
EtherType 0x88f7).net ptpshell diagnostics and improve sample/documentation usability.Why These Changes Were Needed
recvmsg()first to collectSO_TIMESTAMPINGcontrol data, then falls back torecvfrom()plus a PHC read when ancillary RX timestamps are unavailable.ptp_clock_synchronize()now also guards against missing or out-of-range ingress timestamps instead of blindly using bad data.eth_native_tap.cneeded to change because native_tap only queued TX timestamp callbacks for gPTP traffic. PTP socket traffic usingSO_TIMESTAMPINGtherefore missed TX timestamps on native_sim. This PR fixes that by queueing TX callbacks for timestamped packets in general, updating packet timestamps on TX/RX, propagating timestamping flags throughnet_context, and adding AF_PACKETrecvmsg()timestamp support with correct ancillary buffer accounting.eth_stm32_hal_ptp.cneeded a separate fix for STM32H5. In "RM0481 Rev 4" the Ethernet chapter documents the timestamp engine as running from a dedicated PTP reference clock (clk_ptp_ref_i) separate frometh_hclk, and RCC Table 115 ("Kernel clock distribution overview") listsETH (ptp)onpll1_q_ck. This PR therefore models an explicitmac-clk-ptpsource for STM32H5 and uses that clock rate for PTP addend programming. On Nucleo-H563ZI, that corrected the large, repeating delay and offset errors seen when the addend was derived from the wrong clock (see below). This took me quite a lot of time to find out ;-)LOG_INFstatus prints, run-forever sample behavior, expanded README guidance, explicit PTP shell support, and documentation for transport/timestamping behavior.Testing
net.ptp.btca_state_machine,net.ptp.clock_decision,net.ptp.foreign_master,net.ptp.msg_post_recv, andnet.ptp.state_matrix.recvmsg()ancillary-data handling,msg_controllenaccounting, andMSG_CTRUNCbehavior.ptp4l, a GPS clock (direct link), a PTP-capable switch, and a GPS clock through a PTP-capable switch. The exercised transports were UDP/IPv4, UDP/IPv6, and IEEE 802.3 / Layer-2.net ptpshell transcripts, so the excerpts below use the actual sample output from those runs.The last excerpt is the reason for the STM32H5 PTP reference-clock fix: without it, the measured delay is off by roughly 170 ms and the clock keeps bouncing by about 500 ms instead of converging. RM0481 Rev 4 backs the final approach here: the IEEE 1588 section says the 64-bit PTP time is updated from
clk_ptp_ref_i, and the RCC clock distribution tables listETH (ptp)onpll1_q_ck.If this PR is merged and the maintainers think it would be useful, would it be possible if I can add me as a maintainer for the PTP area? I plan to keep working on this part of the networking stack.