Skip to content

net/netdev: add NETDEV_TX_STAMP and SIOCETHTOOL ETHTOOL_GET_TS_INFO - #20346

Open
daniel-p-carvalho wants to merge 4 commits into
apache:masterfrom
daniel-p-carvalho:feat/netdev-txtstamp-caps
Open

daniel-p-carvalho wants to merge 4 commits into
apache:masterfrom
daniel-p-carvalho:feat/netdev-txtstamp-caps

Conversation

@daniel-p-carvalho

@daniel-p-carvalho daniel-p-carvalho commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Follow-up to the discussion in netutils/ptpd: hardware TX timestamps via MSG_ERRQUEUE and egress latency compensation nuttx-apps#3791.
  • 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/ptp4l instead reads the interface's timestamping capabilities once through SIOCETHTOOL with ETHTOOL_GET_TS_INFO; this PR adds the NuttX side of that query.
  • include/sys/socket.h: the SOF_TIMESTAMPING_* flags all aliased 1 << SO_TIMESTAMPING, so they could not tell hardware from software or RX from TX. They now have their distinct Linux values, and SOF_TIMESTAMPING_RX_HARDWARE, SOF_TIMESTAMPING_RX_SOFTWARE and SOF_TIMESTAMPING_SYS_HARDWARE are added. Behaviour does not change: setsockopt(SO_TIMESTAMPING) only checks for a non-zero value and getsockopt() returns 0 or 1, so existing users and binaries keep working.
  • include/nuttx/net/netdev.h: NETDEV_TX_STAMP (1 << 4) added to d_features, next to the existing NETDEV_RX_STAMP. A driver sets it to declare that it delivers hardware TX timestamps.
  • include/nuttx/ethtool.h, net/netdev/netdev_ioctl.c: SIOCETHTOOL and ETHTOOL_GET_TS_INFO were already defined but not implemented. Add struct ethtool_ts_info (same layout as Linux) and handle SIOCETHTOOL: ETHTOOL_GET_TS_INFO fills so_timestamping from d_features (RX_HARDWARE | RAW_HARDWARE with NETDEV_RX_STAMP, otherwise RX_SOFTWARE | SOFTWARE, since the stack stamps received packets with CLOCK_REALTIME; TX_HARDWARE | RAW_HARDWARE with NETDEV_TX_STAMP), with phc_index set to -1 and tx_types/rx_filters zero. Any other ethtool command is passed to the driver's d_ioctl when CONFIG_NETDEV_IOCTL is enabled, otherwise -ENOTTY is returned.
  • STM32H7 (arch/arm/src/stm32h7/stm32_ethernet.c) and STM32F1/F3/F4 (arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c) Ethernet drivers declare NETDEV_TX_STAMP when CONFIG_STM32_ETH_TIMESTAMP_TX is enabled, mirroring the existing NETDEV_RX_STAMP declaration.
  • Related NuttX Apps Pull Request: ptpd queries this capability once at startup instead of detecting it by trial and error.

Impact

  • Is new feature added? Is existing feature changed? YES - new NETDEV_TX_STAMP capability flag and SIOCETHTOOL/ETHTOOL_GET_TS_INFO support; the SOF_TIMESTAMPING_* values change but no existing behavior does, and drivers that do not opt in are unaffected.
  • Impact on user (will user need to adapt to change)? NO for existing users; enables netutils/ptpd: query timestamping capabilities via ETHTOOL_GET_TS_INFO nuttx-apps#3800 to remove its runtime detection.
  • Impact on build (will build process change)? NO.
  • Impact on hardware (will arch(s) / board(s) / driver(s) change)? YES - STM32H7 and STM32F1/F3/F4 Ethernet drivers now declare NETDEV_TX_STAMP in d_features when CONFIG_STM32_ETH_TIMESTAMP_TX is set. Both already deliver hardware TX timestamps today; this only makes that capability queryable, it does not change the timestamping behavior itself.
  • Impact on documentation (is update required / provided)? NO - NETDEV_TX_STAMP follows the existing NETDEV_RX_STAMP pattern, and SIOCETHTOOL/ETHTOOL_GET_TS_INFO the Linux interface of the same name.
  • Impact on security (any sort of implications)? NO.
  • Impact on compatibility (backward/forward/interoperability)? YES, minor - the numeric values of the SOF_TIMESTAMPING_* macros change to match Linux. In-tree users (ptpd, candump, nettest) use the macros symbolically, the individual flags are still not honoured by SO_TIMESTAMPING, and binaries built with the old values keep working.

Testing

I confirm that changes are verified on local setup and works as intended:

Build log (STM32H7 board):

Memory region         Used Size  Region Size  %age Used
            itcm:           0 B        64 KB      0.00%
           flash:      333508 B         2 MB     15.90%
           dtcm1:           0 B        64 KB      0.00%
           dtcm2:           0 B        64 KB      0.00%
            sram:       49200 B       512 KB      9.38%
           sram1:           0 B       128 KB      0.00%
           sram2:           0 B       128 KB      0.00%
           sram3:           0 B        32 KB      0.00%
           sram4:           0 B        64 KB      0.00%
           bbram:           0 B         4 KB      0.00%
CP: nuttx.hex
CP: nuttx.bin

Runtime log, STM32H7 board, ptpd status query 135 s after start: ETHTOOL_GET_TS_INFO reports both hardware capabilities (otherwise ptpd would refuse to start) and the clock is synchronized to the Grandmaster:

PTPD (PID 8) status:
- clock_source_valid: 1
|- gm_id: 00 14 2d ff fe 61 2b b5
- last_delta_ns: 445
- drift_ppb: 16614
- path_delay_ns: 9398
- last_received_announce: 1 s ago
- last_received_sync: 1 s ago

Build log (STM32F1/F3/F4 board):

Memory region         Used Size  Region Size  %age Used
           flash:      186332 B         1 MB     17.77%
CP: nuttx.bin

Same test on the STM32F1/F3/F4 board (dmesg excerpt, full PTP P2P exchange, hardware timestamps used throughout):

ptp_update_local_clock: Local time: 1790369881.590090526, remote time 1790369881.590078683
ptp_update_local_clock: Delta: -2544 ns, adjustment -80315 ns, drift rate -80177 ppb
ptp_record_path_delay: Path delay: 9372 ns (avg: 9299 ns)

sim (virtual eth0, neither NETDEV_RX_STAMP nor NETDEV_TX_STAMP set): ETHTOOL_GET_TS_INFO reports no hardware timestamping, so ptpd -2 -H -i eth0 refuses to start:

nsh> ptpd -2 -H -i eth0
[    6.021917] ptp_initialize_state: Interface eth0 does not support hardware RX TX timestamping, use -S for software timestamps
[    6.022007] ptpd_start: Failed to initialize PTP state, exiting
ERROR: ptpd_start() failed: -1

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is still work in progress (not ready for review).
  • My PR is ready for review and can be safely merged into a codebase.

@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Area: Memory Management Memory Management issues Size: M The size of the change in this PR is medium labels Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

acassis
acassis previously approved these changes Sep 24, 2026
@daniel-p-carvalho
daniel-p-carvalho marked this pull request as draft September 24, 2026 17:21
@github-actions github-actions Bot added Area: Networking Effects networking subsystem Size: S The size of the change in this PR is small and removed Area: Memory Management Memory Management issues Size: M The size of the change in this PR is medium labels Sep 24, 2026
@daniel-p-carvalho
daniel-p-carvalho marked this pull request as ready for review September 24, 2026 21:26
acassis
acassis previously approved these changes Sep 25, 2026
Comment thread net/netdev/netdev_ioctl.c Outdated
Comment thread include/nuttx/net/ioctl.h Outdated
claude and others added 4 commits September 25, 2026 16:35
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>
@github-actions github-actions Bot added Size: M The size of the change in this PR is medium and removed Size: S The size of the change in this PR is small labels Sep 25, 2026
@daniel-p-carvalho daniel-p-carvalho changed the title net: add NETDEV_TX_STAMP capability flag and SIOCGIFTSCAPS query ioctl net/netdev: add NETDEV_TX_STAMP and SIOCETHTOOL ETHTOOL_GET_TS_INFO Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Networking Effects networking subsystem Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants