Skip to content

net: add NETDEV_TX_STAMP capability flag and SIOCGIFTSCAPS query ioctl - #20346

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

daniel-p-carvalho wants to merge 3 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 SIOCGIFTSCAPS nuttx-apps#3800) currently detects hardware TX timestamp support by trial and error (three consecutive failures, then a silent switch to software timestamps). The Linux equivalent solves this by having the driver statically declare the capability (SOF_TIMESTAMPING_TX_HARDWARE, read once via ethtool/SIOCETHTOOL); this PR adds the NuttX equivalent.
  • NETDEV_TX_STAMP (1 << 4) added to include/nuttx/net/netdev.h, next to the existing NETDEV_RX_STAMP. A driver sets it in d_features to declare that it delivers hardware TX timestamps.
  • New SIOCGIFTSCAPS ioctl (net/netdev/netdev_ioctl.c), returning the RX/TX timestamping bits of d_features for a named interface via struct ifreq, following the same pattern already used by SIOCGIFFLAGS.
  • STM32H7 Ethernet driver (arch/arm/src/stm32h7/stm32_ethernet.c) declares NETDEV_TX_STAMP when CONFIG_STM32_ETH_TIMESTAMP_TX is enabled, mirroring the existing NETDEV_RX_STAMP declaration right above it.
  • STM32F1/F3/F4 Ethernet driver (arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c) declares NETDEV_TX_STAMP the same way.
  • 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 SIOCGIFTSCAPS ioctl; no existing behavior changes for drivers that do not opt in.
  • Impact on user (will user need to adapt to change)? NO for existing users; enables netutils/ptpd: query timestamping capabilities via SIOCGIFTSCAPS 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/SIOCGIFTSCAPS follow the exact naming and usage pattern of the existing NETDEV_RX_STAMP/SIOCGIFFLAGS, self-documented by that symmetry.
  • Impact on security (any sort of implications)? NO.
  • Impact on compatibility (backward/forward/interoperability)? NO.

Testing

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

  • Build Host(s): Linux (Ubuntu), x86_64, GCC (arm-none-eabi-gcc toolchain).
  • Target(s): arm, two real boards, both against a physical IEEE 1588 PTP Grandmaster over Ethernet, exercised end-to-end through the companion netutils/ptpd: query timestamping capabilities via SIOCGIFTSCAPS nuttx-apps#3800 change:
    • STM32H7 board (CONFIG_STM32_ETH_TIMESTAMP_TX=y).
    • STM32F1/F3/F4 board (CONFIG_STM32_ETH_TIMESTAMP_TX=y).

Build log (STM32H7 board):

Memory region         Used Size  Region Size  %age Used
            itcm:           0 B        64 KB      0.00%
           flash:      390924 B         2 MB     18.64%
           dtcm1:           0 B        64 KB      0.00%
           dtcm2:           0 B        64 KB      0.00%
            sram:       50104 B       512 KB      9.56%
           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, ptpd -s -2 -H -B -P -i eth0 -p /dev/ptp0 status query on the STM32H7 board: SIOCGIFTSCAPS correctly reports NETDEV_TX_STAMP, hardware TX timestamp active from the first packet:

PTPD (PID 8) status:
- clock_source_valid: 1
- last_delta_ns: 539
- drift_ppb: 16265
- path_delay_ns: 9386
- last_received_announce: 1 s ago
- last_received_sync: 1 s ago

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

ptp_update_local_clock: Local time: 1790260023.503704646, remote time 1790260023.503692546
ptp_update_local_clock: Delta: -2788 ns, adjustment -80060 ns, drift rate -79662 ppb
ptp_record_path_delay: Path delay: 9304 ns (avg: 9312 ns)

10-minute soak against the Grandmaster (STM32H7 board): 0 ping failures over 19 samples at 30s intervals, clock_source_valid stayed 1 throughout, path_delay_ns stable between 9381-9395 ns.

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
daniel-p-carvalho and others added 3 commits September 24, 2026 17:38
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.

Introduce SIOCGIFTSCAPS (_SIOC(0x0046)) socket ioctl to allow userspace
applications (such as ptpd) to query network interface hardware
timestamping capabilities (NETDEV_RX_STAMP and NETDEV_TX_STAMP) from
dev->d_features via struct ifreq.

Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Assisted-by: Gemini:gemini-3.8-pro
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRmWhQ8CrfkRzuw5WMUXwH
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.

Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Assisted-by: Gemini:gemini-3.8-pro
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRmWhQ8CrfkRzuw5WMUXwH
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.

Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
Assisted-by: Gemini:gemini-3.8-pro
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRmWhQ8CrfkRzuw5WMUXwH
@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
Comment thread net/netdev/netdev_ioctl.c
break;

case SIOCGIFTSCAPS: /* Gets timestamping capabilities */
req->ifr_flags = dev->d_features & (NETDEV_RX_STAMP |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but show we expose these flags through SIOCETHTOOL

Comment thread include/nuttx/net/ioctl.h

#define SIOCSIFFLAGS _SIOC(0x001a) /* Sets the interface flags */
#define SIOCGIFFLAGS _SIOC(0x001b) /* Gets the interface flags */
#define SIOCGIFTSCAPS _SIOC(0x0046) /* Gets timestamping capabilities */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we return all feature bits

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: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants