提交 6df014cf 编写于 作者: E Ezequiel Lara Gomez 提交者: David S. Miller

Enable tx timestamping on loopback and dummy

This enables developing code that uses SOF_TIMESTAMPING_TX_SOFTWARE
by using localhost addresses (without needing to send packets outside),
as well as enabling unit and functional testing of TX timestamping code
without needing hardware support or network access.

It also fulfills the expectation of software network devices supporting
software-based timestamping.

Tested on qemu using txtimestamping.c from the kernel selftests, and
ethtool -T.
Signed-off-by: NEzequiel Lara Gomez <ezegomez@amazon.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 406910a8
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/net_tstamp.h>
#include <net/rtnetlink.h> #include <net/rtnetlink.h>
#include <linux/u64_stats_sync.h> #include <linux/u64_stats_sync.h>
...@@ -125,6 +126,7 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -125,6 +126,7 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)
dstats->tx_bytes += skb->len; dstats->tx_bytes += skb->len;
u64_stats_update_end(&dstats->syncp); u64_stats_update_end(&dstats->syncp);
skb_tx_timestamp(skb);
dev_kfree_skb(skb); dev_kfree_skb(skb);
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
...@@ -304,8 +306,21 @@ static void dummy_get_drvinfo(struct net_device *dev, ...@@ -304,8 +306,21 @@ static void dummy_get_drvinfo(struct net_device *dev,
strlcpy(info->version, DRV_VERSION, sizeof(info->version)); strlcpy(info->version, DRV_VERSION, sizeof(info->version));
} }
static int dummy_get_ts_info(struct net_device *dev,
struct ethtool_ts_info *ts_info)
{
ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE;
ts_info->phc_index = -1;
return 0;
};
static const struct ethtool_ops dummy_ethtool_ops = { static const struct ethtool_ops dummy_ethtool_ops = {
.get_drvinfo = dummy_get_drvinfo, .get_drvinfo = dummy_get_drvinfo,
.get_ts_info = dummy_get_ts_info,
}; };
static void dummy_free_netdev(struct net_device *dev) static void dummy_free_netdev(struct net_device *dev)
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/net_tstamp.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <linux/u64_stats_sync.h> #include <linux/u64_stats_sync.h>
...@@ -74,6 +75,7 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb, ...@@ -74,6 +75,7 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
struct pcpu_lstats *lb_stats; struct pcpu_lstats *lb_stats;
int len; int len;
skb_tx_timestamp(skb);
skb_orphan(skb); skb_orphan(skb);
/* Before queueing this packet to netif_rx(), /* Before queueing this packet to netif_rx(),
...@@ -129,8 +131,21 @@ static u32 always_on(struct net_device *dev) ...@@ -129,8 +131,21 @@ static u32 always_on(struct net_device *dev)
return 1; return 1;
} }
static int loopback_get_ts_info(struct net_device *netdev,
struct ethtool_ts_info *ts_info)
{
ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE;
ts_info->phc_index = -1;
return 0;
};
static const struct ethtool_ops loopback_ethtool_ops = { static const struct ethtool_ops loopback_ethtool_ops = {
.get_link = always_on, .get_link = always_on,
.get_ts_info = loopback_get_ts_info,
}; };
static int loopback_dev_init(struct net_device *dev) static int loopback_dev_init(struct net_device *dev)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册