net/netdev: add NETDEV_TX_STAMP and SIOCETHTOOL ETHTOOL_GET_TS_INFO - #20346
Open
daniel-p-carvalho wants to merge 4 commits into
Open
daniel-p-carvalho wants to merge 4 commits into
daniel-p-carvalho wants to merge 4 commits into
Conversation
daniel-p-carvalho
requested review from
antmerlino,
davids5,
fjpanag,
jerpelea and
xiaoxiang781216
as code owners
September 24, 2026 13:56
5 tasks
acassis
previously approved these changes
Sep 24, 2026
daniel-p-carvalho
marked this pull request as draft
September 24, 2026 17:21
daniel-p-carvalho
force-pushed
the
feat/netdev-txtstamp-caps
branch
from
September 24, 2026 17:38
8f8fef1 to
0bfa471
Compare
daniel-p-carvalho
marked this pull request as ready for review
September 24, 2026 21:26
acassis
previously approved these changes
Sep 25, 2026
All SOF_TIMESTAMPING_* flags currently alias 1 << SO_TIMESTAMPING, so they cannot tell hardware from software or RX from TX. Give them their distinct Linux values, and add SOF_TIMESTAMPING_RX_HARDWARE, SOF_TIMESTAMPING_RX_SOFTWARE and SOF_TIMESTAMPING_SYS_HARDWARE, so that they can also describe the timestamping capabilities of an interface (so_timestamping of ETHTOOL_GET_TS_INFO). This does not change behaviour: setsockopt(SO_TIMESTAMPING) only checks for a non-zero value and getsockopt() returns 0 or 1, so existing users and binaries built with the previous values keep working. The individual flags are still not honoured. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
…_INFO Add the NETDEV_TX_STAMP capability flag to d_features, next to the existing NETDEV_RX_STAMP, so a driver can declare that it delivers hardware TX timestamps. SIOCETHTOOL and ETHTOOL_GET_TS_INFO were already defined but not implemented. Add struct ethtool_ts_info, with the same layout as Linux, and handle SIOCETHTOOL in netdev_ioctl.c so that userspace (such as ptpd) can query the timestamping capabilities of an interface the same way linuxptp/ptp4l does on Linux: - ETHTOOL_GET_TS_INFO fills so_timestamping from d_features: RX_HARDWARE | RAW_HARDWARE with NETDEV_RX_STAMP, otherwise RX_SOFTWARE | SOFTWARE (the stack stamps received packets with CLOCK_REALTIME), and TX_HARDWARE | RAW_HARDWARE with NETDEV_TX_STAMP. phc_index is -1, tx_types and rx_filters are zero. - Any other ethtool command is passed to the driver's d_ioctl when CONFIG_NETDEV_IOCTL is enabled, otherwise -ENOTTY is returned. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Advertise the NETDEV_TX_STAMP capability flag in stm32_ethinitialize() when CONFIG_STM32_ETH_TIMESTAMP_TX is enabled, indicating that the driver provides hardware TX timestamping. Assisted-by: Gemini:gemini-3.8-pro Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Advertise NETDEV_TX_STAMP in dev.d_features during stm32_ethinitialize() when CONFIG_STM32_ETH_TIMESTAMP_TX is enabled, indicating that the STM32H7 Ethernet driver provides hardware TX timestamping. Assisted-by: Gemini:gemini-3.8-pro Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
daniel-p-carvalho
force-pushed
the
feat/netdev-txtstamp-caps
branch
from
September 25, 2026 19:10
0bfa471 to
540206b
Compare
daniel-p-carvalho
force-pushed
the
feat/netdev-txtstamp-caps
branch
from
September 25, 2026 19:12
540206b to
fe274c6
Compare
xiaoxiang781216
approved these changes
Sep 25, 2026
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.
Summary
ptpd(companion PR netutils/ptpd: query timestamping capabilities via ETHTOOL_GET_TS_INFO nuttx-apps#3800) currently detects hardware TX timestamp support by trial and error (three consecutive failures, then a silent switch to software timestamps). On Linux,linuxptp/ptp4linstead reads the interface's timestamping capabilities once throughSIOCETHTOOLwithETHTOOL_GET_TS_INFO; this PR adds the NuttX side of that query.include/sys/socket.h: theSOF_TIMESTAMPING_*flags all aliased1 << SO_TIMESTAMPING, so they could not tell hardware from software or RX from TX. They now have their distinct Linux values, andSOF_TIMESTAMPING_RX_HARDWARE,SOF_TIMESTAMPING_RX_SOFTWAREandSOF_TIMESTAMPING_SYS_HARDWAREare added. Behaviour does not change:setsockopt(SO_TIMESTAMPING)only checks for a non-zero value andgetsockopt()returns 0 or 1, so existing users and binaries keep working.include/nuttx/net/netdev.h:NETDEV_TX_STAMP(1 << 4) added tod_features, next to the existingNETDEV_RX_STAMP. A driver sets it to declare that it delivers hardware TX timestamps.include/nuttx/ethtool.h,net/netdev/netdev_ioctl.c:SIOCETHTOOLandETHTOOL_GET_TS_INFOwere already defined but not implemented. Addstruct ethtool_ts_info(same layout as Linux) and handleSIOCETHTOOL:ETHTOOL_GET_TS_INFOfillsso_timestampingfromd_features(RX_HARDWARE | RAW_HARDWAREwithNETDEV_RX_STAMP, otherwiseRX_SOFTWARE | SOFTWARE, since the stack stamps received packets withCLOCK_REALTIME;TX_HARDWARE | RAW_HARDWAREwithNETDEV_TX_STAMP), withphc_indexset to -1 andtx_types/rx_filterszero. Any other ethtool command is passed to the driver'sd_ioctlwhenCONFIG_NETDEV_IOCTLis enabled, otherwise-ENOTTYis returned.arch/arm/src/stm32h7/stm32_ethernet.c) and STM32F1/F3/F4 (arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c) Ethernet drivers declareNETDEV_TX_STAMPwhenCONFIG_STM32_ETH_TIMESTAMP_TXis enabled, mirroring the existingNETDEV_RX_STAMPdeclaration.ptpdqueries this capability once at startup instead of detecting it by trial and error.Impact
NETDEV_TX_STAMPcapability flag andSIOCETHTOOL/ETHTOOL_GET_TS_INFOsupport; theSOF_TIMESTAMPING_*values change but no existing behavior does, and drivers that do not opt in are unaffected.NETDEV_TX_STAMPind_featureswhenCONFIG_STM32_ETH_TIMESTAMP_TXis set. Both already deliver hardware TX timestamps today; this only makes that capability queryable, it does not change the timestamping behavior itself.NETDEV_TX_STAMPfollows the existingNETDEV_RX_STAMPpattern, andSIOCETHTOOL/ETHTOOL_GET_TS_INFOthe Linux interface of the same name.SOF_TIMESTAMPING_*macros change to match Linux. In-tree users (ptpd,candump,nettest) use the macros symbolically, the individual flags are still not honoured bySO_TIMESTAMPING, and binaries built with the old values keep working.Testing
I confirm that changes are verified on local setup and works as intended:
sim).ptpd -s -2 -H -B -P -i eth0 -p /dev/ptp0); plussimfor the case of a driver that reports no hardware timestamping. All tests use the head of this PR together with the head of netutils/ptpd: query timestamping capabilities via ETHTOOL_GET_TS_INFO nuttx-apps#3800.CONFIG_STM32_ETH_TIMESTAMP_RX=y,CONFIG_STM32_ETH_TIMESTAMP_TX=y).CONFIG_STM32_ETH_TIMESTAMP_RX=y,CONFIG_STM32_ETH_TIMESTAMP_TX=y).Build log (STM32H7 board):
Runtime log, STM32H7 board,
ptpdstatus query 135 s after start:ETHTOOL_GET_TS_INFOreports both hardware capabilities (otherwiseptpdwould refuse to start) and the clock is synchronized to the Grandmaster:Build log (STM32F1/F3/F4 board):
Same test on the STM32F1/F3/F4 board (
dmesgexcerpt, full PTP P2P exchange, hardware timestamps used throughout):sim(virtualeth0, neitherNETDEV_RX_STAMPnorNETDEV_TX_STAMPset):ETHTOOL_GET_TS_INFOreports no hardware timestamping, soptpd -2 -H -i eth0refuses to start:PR verification Self-Check