This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 28402b9b35aacc2b0661527cfca64d59148a5dcd Author: OceanfromXiaomi <[email protected]> AuthorDate: Tue Nov 25 17:14:35 2025 +0800 net: add NETDEV_RX_STAMP flag in d_features Replace compile-time CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP with a runtime NETDEV_RX_STAMP bit in net_driver_s.d_features. Drivers providing hardware RX timestamps set the flag at probe time; the stack checks it at runtime. Signed-off-by: OceanfromXiaomi <[email protected]> --- arch/arm/src/common/stm32/Kconfig.eth | 1 - arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c | 4 ++++ include/nuttx/mm/iob.h | 8 ++++---- include/nuttx/net/netdev.h | 1 + net/Kconfig | 4 ---- net/can/can_input.c | 13 +++++++++---- net/devif/ipv4_input.c | 13 +++++++++---- net/devif/ipv6_input.c | 13 +++++++++---- net/netdev/netdev_input.c | 7 +++++-- net/pkt/pkt_input.c | 13 ++++++++----- 10 files changed, 49 insertions(+), 28 deletions(-) diff --git a/arch/arm/src/common/stm32/Kconfig.eth b/arch/arm/src/common/stm32/Kconfig.eth index d682b5d3459..7a028c19fd8 100644 --- a/arch/arm/src/common/stm32/Kconfig.eth +++ b/arch/arm/src/common/stm32/Kconfig.eth @@ -188,7 +188,6 @@ config STM32_ETH_PTP_RTC_HIRES config STM32_ETH_TIMESTAMP_RX bool "Hardware timestamping of received packets" depends on STM32_COMMON_LEGACY && STM32_ETH_PTP && NET_TIMESTAMP && STM32_ETH_ENHANCEDDESC - select ARCH_HAVE_NETDEV_TIMESTAMP default n ---help--- Timestamp all received Ethernet packets. diff --git a/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c b/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c index a33b15a6bc7..b151bf6e9ce 100644 --- a/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c +++ b/arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c @@ -4234,6 +4234,10 @@ int stm32_ethinitialize(int intf) return ret; } +#ifdef CONFIG_STM32_ETH_TIMESTAMP_RX + priv->dev.d_features |= NETDEV_RX_STAMP; +#endif + /* Register the device with the OS so that socket IOCTLs can be performed */ netdev_register(&priv->dev, NET_LL_ETHERNET); diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h index a32c5090bca..6985cc3dcf2 100644 --- a/include/nuttx/mm/iob.h +++ b/include/nuttx/mm/iob.h @@ -132,10 +132,10 @@ struct iob_s #ifdef CONFIG_NET_TIMESTAMP /* timestamp of the packet. - * If CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP is true, the timestamp is provided - * by hardware driver. Otherwise it is filled in by kernel when the packet - * is passed into respective protocol layer. The timestamp is in - * CLOCK_REALTIME. + * d_features is the member of net_driver_s struct, if the NETDEV_RX_STAMP + * bit of d_features is set, the timestamp is provided by hardware driver. + * Otherwise it is filled in by kernel when the packet is passed into + * respective protocol layer. The timestamp is in CLOCK_REALTIME. */ struct timespec io_time; diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index ca68c30eaaf..c5395ba67cd 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -84,6 +84,7 @@ #define NETDEV_TX_CSUM (1 << 1) /* Netdev support hardware tx checksum */ #define NETDEV_RX_CSUM (1 << 2) /* Netdev support hardware rx checksum */ +#define NETDEV_RX_STAMP (1 << 3) /* Netdev support hardware timestamp */ /* Determine the largest possible address */ diff --git a/net/Kconfig b/net/Kconfig index 26d55b7a87e..7ca3c467637 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -23,10 +23,6 @@ config ARCH_HAVE_NETDEV_STATISTICS bool default n -config ARCH_HAVE_NETDEV_TIMESTAMP - bool - default n - config NET_WRITE_BUFFERS bool default n diff --git a/net/can/can_input.c b/net/can/can_input.c index f1cd561df66..d84f4b247c7 100644 --- a/net/can/can_input.c +++ b/net/can/can_input.c @@ -229,11 +229,16 @@ static int can_in(FAR struct net_driver_s *dev) return OK; } - /* Store reception timestamp if enabled and not provided by hardware. */ + /* Storing reception timestamp provided by realtime + * if timestamp no provided by hardware. + */ -#if defined(CONFIG_NET_TIMESTAMP) && !defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) - clock_gettime(CLOCK_REALTIME, &dev->d_iob->io_time); -#endif +#ifdef CONFIG_NET_TIMESTAMP + if ((dev->d_features & NETDEV_RX_STAMP) == 0) + { + clock_gettime(CLOCK_REALTIME, &dev->d_iob->io_time); + } +#endif /* CONFIG_NET_TIMESTAMP */ can_conn_list_lock(); diff --git a/net/devif/ipv4_input.c b/net/devif/ipv4_input.c index b94c4c53ba4..233e3105fce 100644 --- a/net/devif/ipv4_input.c +++ b/net/devif/ipv4_input.c @@ -231,11 +231,16 @@ static int ipv4_in(FAR struct net_driver_s *dev) bool isfrag; int ret = OK; - /* Store reception timestamp if enabled and not provided by hardware. */ + /* Storing reception timestamp provided by realtime + * if timestamp no provided by hardware. + */ -#if defined(CONFIG_NET_TIMESTAMP) && !defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) - clock_gettime(CLOCK_REALTIME, &dev->d_iob->io_time); -#endif +#ifdef CONFIG_NET_TIMESTAMP + if ((dev->d_features & NETDEV_RX_STAMP) == 0) + { + clock_gettime(CLOCK_REALTIME, &dev->d_iob->io_time); + } +#endif /* CONFIG_NET_TIMESTAMP */ /* Handle ARP on input then give the IPv4 packet to the network layer */ diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c index 065c5873341..87067bcf367 100644 --- a/net/devif/ipv6_input.c +++ b/net/devif/ipv6_input.c @@ -229,11 +229,16 @@ static int ipv6_in(FAR struct net_driver_s *dev) bool isfrag = false; #endif - /* Store reception timestamp if enabled and not provided by hardware. */ + /* Storing reception timestamp provided by realtime + * if timestamp no provided by hardware. + */ -#if defined(CONFIG_NET_TIMESTAMP) && !defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) - clock_gettime(CLOCK_REALTIME, &dev->d_iob->io_time); -#endif +#ifdef CONFIG_NET_TIMESTAMP + if ((dev->d_features & NETDEV_RX_STAMP) == 0) + { + clock_gettime(CLOCK_REALTIME, &dev->d_iob->io_time); + } +#endif /* CONFIG_NET_TIMESTAMP */ /* This is where the input processing starts. */ diff --git a/net/netdev/netdev_input.c b/net/netdev/netdev_input.c index 05882f5d9d7..36333d27bc8 100644 --- a/net/netdev/netdev_input.c +++ b/net/netdev/netdev_input.c @@ -80,8 +80,11 @@ int netdev_input(FAR struct net_driver_s *dev, return ret; } -#if defined(CONFIG_NET_TIMESTAMP) && defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) - dev->d_iob->io_time = dev->d_rxtime; +#if defined(CONFIG_NET_TIMESTAMP) + if ((dev->d_features & NETDEV_RX_STAMP) != 0) + { + dev->d_iob->io_time = dev->d_rxtime; + } #endif /* Copy data to iob entry */ diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c index a517f04a69d..fa3b88e0e2d 100644 --- a/net/pkt/pkt_input.c +++ b/net/pkt/pkt_input.c @@ -157,12 +157,15 @@ static int pkt_in(FAR struct net_driver_s *dev) return OK; } -#if defined(CONFIG_NET_TIMESTAMP) && !defined(CONFIG_ARCH_HAVE_NETDEV_TIMESTAMP) - /* Get system as timestamp if no hardware timestamp */ - - if (_SO_GETOPT(conn->sconn.s_options, SO_TIMESTAMP) || - _SO_GETOPT(conn->sconn.s_options, SO_TIMESTAMPNS)) +#ifdef CONFIG_NET_TIMESTAMP + if ((dev->d_features & NETDEV_RX_STAMP) == 0 && + (_SO_GETOPT(conn->sconn.s_options, SO_TIMESTAMP) || + _SO_GETOPT(conn->sconn.s_options, SO_TIMESTAMPNS))) { + /* Storing reception timestamp provided by realtime + * if timestamp no provided by hardware. + */ + clock_gettime(CLOCK_REALTIME, &dev->d_iob->io_time); } #endif /* CONFIG_NET_TIMESTAMP */
