Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions arch/arm/src/common/stm32/stm32_eth_m3m4_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4604,6 +4604,9 @@ int stm32_ethinitialize(int intf)
#ifdef CONFIG_STM32_ETH_TIMESTAMP_RX
priv->dev.d_features |= NETDEV_RX_STAMP;
#endif
#ifdef CONFIG_STM32_ETH_TIMESTAMP_TX
priv->dev.d_features |= NETDEV_TX_STAMP;
#endif

/* Register the device with the OS so that socket IOCTLs can be performed */

Expand Down
4 changes: 4 additions & 0 deletions arch/arm/src/stm32h7/stm32_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -5161,6 +5161,10 @@ static inline int stm32_ethinitialize(int intf)
priv->dev.d_features |= NETDEV_RX_STAMP;
#endif

#ifdef CONFIG_STM32_ETH_TIMESTAMP_TX
priv->dev.d_features |= NETDEV_TX_STAMP;
#endif

/* Register the device with the OS so that socket IOCTLs can be performed */

netdev_register(&priv->dev, NET_LL_ETHERNET);
Expand Down
31 changes: 31 additions & 0 deletions include/nuttx/ethtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#ifndef __INCLUDE_NUTTX_ETHTOOL_H
#define __INCLUDE_NUTTX_ETHTOOL_H

/****************************************************************************
* Included Files
****************************************************************************/

#include <stdint.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand Down Expand Up @@ -221,4 +227,29 @@ struct ethtool_cmd
uint32_t reserved[2];
};

/* struct ethtool_ts_info - holds a device's timestamping and PHC
* association (ETHTOOL_GET_TS_INFO), same layout as Linux.
* @cmd: command number = %ETHTOOL_GET_TS_INFO
* @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING
* flags (SOF_TIMESTAMPING_*)
* @phc_index: device index of the associated PHC, or -1 if there is none
* @tx_types: bit mask of the supported hwtstamp_tx_types values; zero,
* NuttX has no SIOCSHWTSTAMP to select them
* @tx_reserved: reserved for future use, zero
* @rx_filters: bit mask of the supported hwtstamp_rx_filters values; zero,
* NuttX has no SIOCSHWTSTAMP to select them
* @rx_reserved: reserved for future use, zero
*/

struct ethtool_ts_info
{
uint32_t cmd;
uint32_t so_timestamping;
int32_t phc_index;
uint32_t tx_types;
uint32_t tx_reserved[3];
uint32_t rx_filters;
uint32_t rx_reserved[3];
};

#endif
1 change: 1 addition & 0 deletions include/nuttx/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 */
#define NETDEV_TX_STAMP (1 << 4) /* Netdev provides hardware TX timestamps */

/* Determine the largest possible address */

Expand Down
17 changes: 13 additions & 4 deletions include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,24 @@

#define __SO_PROTOCOL 16

/* SO_TIMESTAMPING flags, with the same values as Linux so that they can
* also describe the capabilities of an interface (ETHTOOL_GET_TS_INFO).
* setsockopt(SO_TIMESTAMPING) currently treats any non-zero value as
* "enabled" and does not honour the individual flags.
*/

/* Timestamp generation */

#define SOF_TIMESTAMPING_TX_HARDWARE (1 << SO_TIMESTAMPING)
#define SOF_TIMESTAMPING_TX_SOFTWARE SOF_TIMESTAMPING_TX_HARDWARE
#define SOF_TIMESTAMPING_TX_HARDWARE (1 << 0)
#define SOF_TIMESTAMPING_TX_SOFTWARE (1 << 1)
#define SOF_TIMESTAMPING_RX_HARDWARE (1 << 2)
#define SOF_TIMESTAMPING_RX_SOFTWARE (1 << 3)

/* Timestamp reporting */

#define SOF_TIMESTAMPING_SOFTWARE SOF_TIMESTAMPING_TX_SOFTWARE
#define SOF_TIMESTAMPING_RAW_HARDWARE SOF_TIMESTAMPING_TX_HARDWARE
#define SOF_TIMESTAMPING_SOFTWARE (1 << 4)
#define SOF_TIMESTAMPING_SYS_HARDWARE (1 << 5)
#define SOF_TIMESTAMPING_RAW_HARDWARE (1 << 6)

/* The options are unsupported but included for compatibility
* and portability
Expand Down
85 changes: 85 additions & 0 deletions net/netdev/netdev_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <net/ethernet.h>
#include <netinet/in.h>

#include <nuttx/ethtool.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/radiodev.h>
#include <nuttx/net/vlan.h>
Expand Down Expand Up @@ -767,6 +768,7 @@ static ssize_t net_ioctl_ifreq_arglen(uint8_t domain, int cmd)
case SIOCGIFCOUNT:
case SIOCSIFFLAGS:
case SIOCGIFFLAGS:
case SIOCETHTOOL:
case SIOCMIINOTIFY:
case SIOCGMIIPHY:
case SIOCGMIIREG:
Expand Down Expand Up @@ -809,6 +811,85 @@ static ssize_t net_ioctl_ifreq_arglen(uint8_t domain, int cmd)
return -ENOTTY;
}

/****************************************************************************
* Name: netdev_ethtool_ioctl
*
* Description:
* Handle the SIOCETHTOOL command. req->ifr_data points to an ethtool
* command structure whose first field is the ETHTOOL_* command.
* ETHTOOL_GET_TS_INFO is answered from the device features; any other
* command is passed to the driver.
*
* Input Parameters:
* dev The network device
* req The argument of the ioctl cmd
*
* Returned Value:
* >=0 on success (positive non-zero values are cmd-specific)
* Negated errno returned on failure.
*
****************************************************************************/

static int netdev_ethtool_ioctl(FAR struct net_driver_s *dev,
FAR struct ifreq *req)
{
FAR uint32_t *ethcmd = req->ifr_data;

if (ethcmd == NULL)
{
return -EINVAL;
}

switch (*ethcmd)
{
case ETHTOOL_GET_TS_INFO: /* Get time stamping and PHC info */
{
FAR struct ethtool_ts_info *info = req->ifr_data;

memset(info, 0, sizeof(*info));
info->cmd = ETHTOOL_GET_TS_INFO;
info->phc_index = -1;

#ifdef CONFIG_NET_TIMESTAMP
/* Received packets carry the hardware timestamp when the driver
* provides one, and are stamped by the stack with CLOCK_REALTIME
* otherwise.
*/

if ((dev->d_features & NETDEV_RX_STAMP) != 0)
{
info->so_timestamping |= SOF_TIMESTAMPING_RX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE;
}
else
{
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE;
}

if ((dev->d_features & NETDEV_TX_STAMP) != 0)
{
info->so_timestamping |= SOF_TIMESTAMPING_TX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE;
}
#endif

return OK;
}

default:
#ifdef CONFIG_NETDEV_IOCTL
if (dev->d_ioctl != NULL)
{
return dev->d_ioctl(dev, SIOCETHTOOL,
(unsigned long)(uintptr_t)req->ifr_data);
}
#endif

return -ENOTTY;
}
}

/****************************************************************************
* Name: netdev_ifr_ioctl
*
Expand Down Expand Up @@ -1088,6 +1169,10 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
req->ifr_flags = dev->d_flags;
break;

case SIOCETHTOOL: /* Ethtool interface */
ret = netdev_ethtool_ioctl(dev, req);
break;

/* MAC address operations only make sense if Ethernet or 6LoWPAN are
* supported.
*/
Expand Down
Loading