Article View: linux.kernel.netdev
Article #11046[PATCH net-next v10 0/8] hsr: Allow to send packets on specific port and pass the timestamp
From: Sebastian Andrzej Siewior
Date: Wed, 04 Nov 2026 15:10
Date: Wed, 04 Nov 2026 15:10
197 lines
19195 bytes
19195 bytes
I am trying to extend linuxptp to support PTP over a HSR network.
This is the kernel side of the changes. In short PTP over HSR sends its
packets to a multicast address and every node needs to forward the PTP
packet (SYNC and FOLLOW-UP for instance) within the HSR ring.
In order to achieve this, the HSR stack must not duplicate and forward
the PTP packets as it would do with other packets. The delay caused by
the duplication and forwarding adds overhead which in turn makes the
timing information within the PTP packet inaccurate.
The PTP stack needs to forward the packets so it is aware of the delay
and can update the PTP packet (the FOLLOW-UP) accordingly to the delay.
My current approach is to open the slave devices (eth0/ eth1) from
userland in order to receive the PTP packets. Sending happens from the
hsr0 device. The actual packet has an inline header prepended of type
struct hsr_inline_header. The size of the header is equivalent to
ethhdr. The header has a type (h_proto) at the same position as ethhdr
and expects it to be ETH_P_1588 as this extra meta information is only
relevant for PTP packets. It makes no sense to send PTP packets via the
HSR interface because it gets duplicated and the timestamp information
is lost so this should not break anything. As an additional safe guard
there is a magic value at h_source position. The value has '0xaf' at the
most significant byte which makes the address a locally administered
multicast address.
The header passes two information from userland: On which slave port
the packet has to be sent and does the HSR stack need to prepend a
header or not.
hsr_inline_header::{has_hsr_header = 1, req_tx_port = HSR_INLINE_HDR_PORT_A]
will send the packet on port PORT_A and it carries already a HSR tag.
hsr_inline_header::{has_hsr_header = 0, req_tx_port = HSR_INLINE_HDR_PORT_B]
will send the packet on port PORT_B and add system's HSR tag.
The header is skipped so that the remaining stack sees the actual data
and can send it as requested.
The PRP packets are sent directly via the SLAVE interface. The standard
mandates not add a PRP trailer (PRP, redundancy control trailer) to PTP
packets. There is not really a reason to use hsr interface.
HSR hardware offloading is optional. The driver needs to know if the
operating mode is HSR or PRP. In PRP mode it needs to check the ether
type and for ETH_P_1588 it must not perform any offloading.
In HSR mode, for ether-type ETH_P_1588 there must be no offloading. If
the ether-type is ETH_P_HSR there must be no offloading if the
encapsulated protocol is ETH_P_1588.
Driver with offloading support enabled need to be updated to handle
these cases correctly. Also their firmware may need to be updated if
cut-through forwarding is supported. This is not part of the series.
This has been tested in a pure software environment and in an HW-assisted
environment where the HW is able to duplicate and deduplicate packets
but does not do it for PTP packets.
It has not been tested within an environment where the HW is able to
forward the PTP packet and correctly update the timing information.
---
v9…v10: https://patch.msgid.link/20261014-hsr_ptp-v9-0-2d20a2a0f816@linutronix.de
- A few patches got their commit description updated/ corrected as
suggested by Daniel Machon.
- A few variables (local and uAPI) have been renamed to get alligned:
- tx_port -> req_tx_port
- hsr_hdr has_header has_foreign_header -> has_hsr_header
Suggested by Daniel Machon.
- hsr_forward_do() got two comments updated to be more clear what it
does. Suggested by Daniel Machon.
- sashiko
- noticed that skb_cow_head() needs also be adjusted by the size of
skb_metadata_len()
- hsr_dev_xmit() verifies that __pad0 and __pad1 of the supplied
hsr_inline_header is 0.
- hsr_dev_xmit() does skb_reset_mac_header() if the MAC header was not
yet set.
- Earlier sashiko pointed out that #4 does not consider VLAN headers
in hsr_handle_frame() while checking for PTP packets. I updated the
commit message saying that I don't check/ ignore VLAN because I have
no working setup and can't validate that the whole chain is working.
Now sashiko pointed out that this is not true (not checking VLAN)
because __netif_receive_skb_core() "unpacks" the VLAN header via
skb_vlan_untag(). This looks correct so I removed that part from the
commit message since it should the right thing here. However it is
still not verified.
- The selftest has been updated to verify that SRC-MAC and the HSR
sequence number is the supplied one if the HSR header was supplied.
v8…v9: https://patch.msgid.link/20261002-hsr_ptp-v8-0-60dabc07e554@linutronix.de
- Use skb_postpush_data_move() for the data move
- A few patches got their description updated so that the bot does
hopefully not complain about a few things that are meant to be (such
as skipping PRP).
v7…v8: https://patch.msgid.link/20260928-hsr_ptp-v7-0-d55d304d9a7e@linutronix.de
- Use __u8 instead of uint8_t, add header file for in hsr_ptp.h
- Add header file to if_hsr.h for struct ethhdr
- Remove the inline keyword from hsr_ptp_test.c
v6…v7: https://patch.msgid.link/20260923-hsr_ptp-v6-0-6ea07b3fb8a8@linutronix.de
- Change the logic in hsr_create_tagged_frame():
- Don't update ->csum_start (the cloning takes care of this)
- pskb_may_pull() does not need to include HSR_HLEN (it only copies
'movelen')
- Set network header to 'movelen' which takes VLAN into account
- Drop also PTP packets which were received on HSR_PT_INTERLINK (not
just HSR A/B).
- Move include HSR header to include/uapi/linux/hsr_ptp.h, so it is also
available in userland.
- selftests:
- Add hsr_ptp.sh alphabetically ordered to the Makefile
- Use "$0" in hsr_ptp.sh
- Drop unnused arguments in open_socket()
v5…v6: https://lore.kernel.org/r/20260527-hsr_ptp-v5-0-158a7633eac0@linutronix.de
- hsr_ptp_test: Let it wait up to 100ms for a packet. Otherwise it will
complain if the recevied packet is not already in socket.
- Use TEST_GEN_PROGS instead TEST_GEN_FILES, the test can not run
without additional arguments.
- Make the inline header mandatory for sending ETH_P_1588 packets via
the HSR device.
- Use kfree_skb() instead kfree() for the skb.
- Rephrase the commit message saying that skb_clone() shares
skb_shared_info and does not copy it.
v4…v5: https://lore.kernel.org/r/20260508-hsr_ptp-v4-1-aa19aa7c6a71@linutronix.de
- Split the patch into smaller pieces
- Added a test for the added inline header (which signals the port while
sending packets).
- Replaced __pskb_copy() with skb_clone() + skb_cow_head() in
hsr_create_tagged_frame() to preserve timestamp request.
v3…v4: https://lore.kernel.org/r/20260429-hsr_ptp-v3-1-afbf8f200f48@linutronix.de
- Removed skb extention. The information within HSR is passed via
struct hsr_frame_info. Driver with HSR-offloading capabilities need to
know the HSR mode (HSR or PRP) and parse the skb to decide what needs
to be done (whether to send on both ports and if adding a header is
needed).
v2…v3: https://patch.msgid.link/20260309-hsr_ptp-v2-0-798262aad3a4@linutronix.de
- Remove af_packet changes entirely.
- Add an internal header to pass additional information for HSR-PTP
packets.
- Remove PRP, userland will use slave devices directly.
- Drop all received PTP packets. Userland needs to use the slave device
for RX.
v1…v2: https://patch.msgid.link/20260204-hsr_ptp-v1-0-b421c69a77da@linutronix.de
- Added PRP support
- skb extention is used instead of extending struct skb_shared_info
- in af_packet
- packet_sendmsg_spkt() is no longer extended
- jump labels are used to avoid the overhead if there no socket that
is using this HSR extension.
---
Sebastian Andrzej Siewior (8):
hsr: Add header_ops::parse_protocol
hsr: Use skb_clone() while adding the HSR header
hsr: Add a magic header for sending PTP packets
hsr: Drop received PTP packets
hsr: Use the port and header information in hsr_forward_skb()
hsr: Assign a socket for cloned skbs
hsr: Move struct hsr_ethhdr to a global header
selftests: hsr: Add test for the inline PTP header on HSR
MAINTAINERS | 1 +
include/linux/if_hsr.h | 7 +
include/uapi/linux/hsr_ptp.h | 20 +
net/hsr/hsr_device.c | 72 +++-
net/hsr/hsr_forward.c | 84 +++--
net/hsr/hsr_forward.h | 3 +-
net/hsr/hsr_framereg.h | 2 +
net/hsr/hsr_main.h | 5 -
net/hsr/hsr_slave.c | 34 +-
tools/include/uapi/linux/hsr_ptp.h | 20 +
tools/testing/selftests/net/hsr/.gitignore | 1 +
tools/testing/selftests/net/hsr/Makefile | 5 +
tools/testing/selftests/net/hsr/hsr_ptp.sh | 109 ++++++
tools/testing/selftests/net/hsr/hsr_ptp_test.c | 496 +++++++++++++++++++++++++
14 files changed, 811 insertions(+), 48 deletions(-)
---
base-commit: bc71431221f5ba8bb33918399552636e059c2c45
change-id: 20260204-hsr_ptp-1f6380f1d35f
Best regards,
--
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Technical Details
Message-ID:
<20261104-hsr_ptp-v10-0-2c4a38ad973c@linutronix.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356534-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356534-linux-kernel-netdev=dewy.ru From: bigeasy@linutronix.de (Sebastian Andrzej Siewior) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v10 0/8] hsr: Allow to send packets on specific port and pass the timestamp Date: Wed, 4 Nov 2026 16:10:36 +0100 Organization: Usenet Network Message-ID: <20261104-hsr_ptp-v10-0-2c4a38ad973c@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="3419556"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:fgEvmmv552gNNZ4BR9TcCUAITXc= sha256:+g+H/3k5ZEd1RmJoq99KR5Fznwn1PpLI/MkAos6iUpo= sha1:lvtg2fLNH14dIhJ9/g1aIA973DI= sha256:Quh9a6Fe17UnAH3/I63wW0fHjeAADqtmblptHkUi8yc= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 385F3112C1E; Wed, 4 Nov 2026 18:29:03 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=linutronix.de header.b=wFvGD6an; dkim=neutral reason="invalid (unsupported algorithm ed25519-sha256)" header.d=linutronix.de header.b=xI4sWFBO X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z2ILl-fp_Lwx; Wed, 4 Nov 2026 18:28:58 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-356534-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linutronix.de X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id BB379112BC2; Wed, 4 Nov 2026 18:28:44 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 06CA22BEF7; Wed, 4 Nov 2026 15:11:09 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793805059; b=1t9ao0A9Ssget81dknJZUCoJlqPAdEOju3bSRzcCUFraQLFE0UP9i636DRPv2P4gpu7H kdq85R+VychR/onxAi508YWIWKA/3F+zp03igblhjqAjsx5KKQYuQq2BvutpUJ3lStpGj YzWR899GCAb9pNnjG8sAXqhm764SPse+F/JZjAzItEGB8Cu9BdYGaha14xblNz7fovP+o HmOvHvDGn147ddrh4s7uq9pofXtLf7zgW6kvgvYNEmouzQPkMtyS+4NGxfzMicJkOsjBU 9GIVc4pJA1lYILvAqB4FiHRidkakkhXFq3knW9j8OKABdzoCVy9D17wwNUTApfsF9Fg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793805059; h=X-Original-To:Received:DMARC-Filter:From:DKIM-Signature: DKIM-Signature:To:Cc:Subject:Date:Message-ID:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:X-Change-ID: Content-Transfer-Encoding; bh=zmgmwcpv007AVMhaY7C4b3XqDQc1jijG7lDzSdI6gHE=; b=l0PbcsE5RRHUHvUTOUIvG+OM5E1zR+T/2fWX0mtr6EaS/4JHZ4+5r5UokWIp20kOw46e Jgrhh/mYscqnCScSFFJqtrrbz2QEyjxrtueCBiD/+Xq00D/IiUCFofmstFOaEY6SzgJmx XqMYpsi5Fz3y72w8EzZxyI2x3ySJO4+aQ4TSotgjWwDFJJzf9CimCnimia9uyoZ9Brpss bvsQJAxZUCDDR+c0nGmLbv3OYJogrsSJXmkyjYMyILxpkx7HdasAy0RyAv32F9kVy0vGv jaZh9yJNf1quw5XtiuLHw72m9DYDNKWyEE/QmY/zjj6JTGUcc5fl06+6HHTqJhqmP2Q== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=wFvGD6an; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=xI4sWFBO; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78DF5606D81A; Wed, 4 Nov 2026 15:10:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=wFvGD6an; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=xI4sWFBO X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793805053; b=Kl+Pl1vTttAcaTXBfkgq1h/E6vIo7MZ9i+2p/XozFQ3Veuvmq7xbzgOo53o+hutK5gbu CO/mdgaz/Hws097Q8gXY/oLygQ2z7uXrR2sbtH6rD9lzp2RR89zYbBtcx6RBwJwWXp8vH 7dFgF09kvbDarWRClM0ozajwi9FPWZbAwGMIXtieJozw995eoYwZ8H56AigD8qrj6iN73 1YyxiRJ15r7l7dRK/Y00dRZWXSsuZ8F/TERAH3xMKpnBRaob6zrV4sRt7L7cjcc79FrHf uIpzNNEvo0WqFVU1qKOSaSfthgbrqdk3a3XwW8nOj0mmDt28Bta0iSMn4i3QccbeHTA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793805053; h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:To:Cc:Subject:Date: Message-ID:MIME-Version:Content-Type:X-Change-ID: Content-Transfer-Encoding; bh=zmgmwcpv007AVMhaY7C4b3XqDQc1jijG7lDzSdI6gHE=; b=avejIEN5reZBhVfLTqb9SaqbzAgJc/JU2O144lU28dxWAAFsTHfsKMcIwwSTnykaFImR Nadr1ahf1nKP45bdbdbYpTuprr5dLIfG69IKMeWXpgUGfozxiRwHM3Hj4yNQ9xeLUXMl3 Fqk1V1OngI2zeUQVnymfxdEgc41fnso4vpwVO8rqEz/0GF99fyccjPrExosaML1yWBjB9 dhbnjrwvtlGeWApwGJHGQOXav3lBy0yUkAxaEibbb94TiuiWy/RhNC0ONL+Eb63jsL/hj 9IPvxcMIZ+W1/WAfaFp3q1NKUnX36utRzyVLmt3amlsU5oWIsWBQNgacOROszCuSHLw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=wFvGD6an; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=xI4sWFBO; arc=none smtp.remote-ip=193.142.43.55 X-Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A67C606A32F for <netdev@vger.kernel.org>; Wed, 4 Nov 2026 15:10:52 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6A67C606A32F X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1793805050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zmgmwcpv007AVMhaY7C4b3XqDQc1jijG7lDzSdI6gHE=; b=wFvGD6an6OW8Ktchu1u2TZlV+jg+02qLYutf1zUryYZSff6Nl388e3DRjIZ9hHCjrN77W4 q9VnSoAvxEcXLcQ/ovVs/nJC6ZKaKlmmQGDcwZUwtEbY10cy480Ky4i5gWckdLuuoHCocW 2kTyncOZNwncSK7YQgHs+wuZqckCECjEKMbxDAhWr7Cz664xhf6hShe00kjtxEbX1SO8hD iaR2JsA62bL3a7ylPOUX1lgYPrM8pj9lbOZmUOCLwcKo1LK79Tns685xWBK7DjUhOsAXdL I1jjGP7S4rGMPuOvbSNBn3tpSW32RW1k9b0bdnBFx8sYbBPwttR7qPqYEBSCAA== X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1793805050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zmgmwcpv007AVMhaY7C4b3XqDQc1jijG7lDzSdI6gHE=; b=xI4sWFBOkWv88AYgXA6R4+lCXRQdZL3czeFV/5HIr4j6Y1DeCtN9Y3vkBti6TKWMGHv0Ap vEPryQiKYLPNhyBQ== X-Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>, "(JC), Jayachandran" <j-rameshbabu@ti.com>, Andrew Lunn <andrew+netdev@lunn.ch>, Chintan Vankar <c-vankar@ti.com>, Danish Anwar <danishanwar@ti.com>, Daolin Qiu <d-qiu@ti.com>, "David S. Miller" <davem@davemloft.net>, Felix Maurer <fmaurer@redhat.com>, Jakub Kicinski <kuba@kernel.org>, Neelima Muralidharan <neelima@ti.com>, Paolo Abeni <pabeni@redhat.com>, Praneeth Bajjuri <praneeth@ti.com>, Pratheesh Gangadhar TK <pratheesh@ti.com>, Richard Cochran <richardcochran@gmail.com>, Simon Horman <horms@kernel.org>, Vignesh Raghavendra <vigneshr@ti.com>, Willem de Bruijn <willemdebruijn.kernel@gmail.com>, Daniel Machon <daniel.machon@microchip.com>, Eric Dumazet <edumazet@kernel.org> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Change-ID: 20260204-hsr_ptp-1f6380f1d35f