mirror of
https://github.com/apache/nuttx.git
synced 2026-10-03 04:07:55 +00:00
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 <zhaohaiyang1@xiaomi.com>
This commit is contained in:
parent
c6878db031
commit
28402b9b35
10 changed files with 49 additions and 28 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue