Skip to content

Commit 6df014c

Browse files
Ezequiel Lara Gomezdavem330
authored andcommitted
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: Ezequiel Lara Gomez <ezegomez@amazon.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 406910a commit 6df014c

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎drivers/net/dummy.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/init.h>
3636
#include <linux/moduleparam.h>
3737
#include <linux/rtnetlink.h>
38+
#include <linux/net_tstamp.h>
3839
#include <net/rtnetlink.h>
3940
#include <linux/u64_stats_sync.h>
4041

@@ -125,6 +126,7 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)
125126
dstats->tx_bytes += skb->len;
126127
u64_stats_update_end(&dstats->syncp);
127128

129+
skb_tx_timestamp(skb);
128130
dev_kfree_skb(skb);
129131
return NETDEV_TX_OK;
130132
}
@@ -304,8 +306,21 @@ static void dummy_get_drvinfo(struct net_device *dev,
304306
strlcpy(info->version, DRV_VERSION, sizeof(info->version));
305307
}
306308

309+
static int dummy_get_ts_info(struct net_device *dev,
310+
struct ethtool_ts_info *ts_info)
311+
{
312+
ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
313+
SOF_TIMESTAMPING_RX_SOFTWARE |
314+
SOF_TIMESTAMPING_SOFTWARE;
315+
316+
ts_info->phc_index = -1;
317+
318+
return 0;
319+
};
320+
307321
static const struct ethtool_ops dummy_ethtool_ops = {
308322
.get_drvinfo = dummy_get_drvinfo,
323+
.get_ts_info = dummy_get_ts_info,
309324
};
310325

311326
static void dummy_free_netdev(struct net_device *dev)

‎drivers/net/loopback.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <linux/ip.h>
5656
#include <linux/tcp.h>
5757
#include <linux/percpu.h>
58+
#include <linux/net_tstamp.h>
5859
#include <net/net_namespace.h>
5960
#include <linux/u64_stats_sync.h>
6061

@@ -74,6 +75,7 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
7475
struct pcpu_lstats *lb_stats;
7576
int len;
7677

78+
skb_tx_timestamp(skb);
7779
skb_orphan(skb);
7880

7981
/* Before queueing this packet to netif_rx(),
@@ -129,8 +131,21 @@ static u32 always_on(struct net_device *dev)
129131
return 1;
130132
}
131133

134+
static int loopback_get_ts_info(struct net_device *netdev,
135+
struct ethtool_ts_info *ts_info)
136+
{
137+
ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
138+
SOF_TIMESTAMPING_RX_SOFTWARE |
139+
SOF_TIMESTAMPING_SOFTWARE;
140+
141+
ts_info->phc_index = -1;
142+
143+
return 0;
144+
};
145+
132146
static const struct ethtool_ops loopback_ethtool_ops = {
133147
.get_link = always_on,
148+
.get_ts_info = loopback_get_ts_info,
134149
};
135150

136151
static int loopback_dev_init(struct net_device *dev)

0 commit comments

Comments
 (0)