summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEzequiel Lara Gomez <ezegomez@amazon.com>2017-03-11 15:06:54 -0500
committerDavid S. Miller <davem@davemloft.net>2017-03-21 17:40:01 -0400
commit6df014cffbe335ea7f41ee5324d8ba2047d3f0d0 (patch)
tree6848b5e2947b95b8100ea21a64542730a22340c5
parent406910a8ba0f0d4d36d1106f3106c47d6c86a33d (diff)
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>
-rw-r--r--drivers/net/dummy.c15
-rw-r--r--drivers/net/loopback.c15
2 files changed, 30 insertions, 0 deletions
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 2c80611b94ae..149244aac20a 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/moduleparam.h> 36#include <linux/moduleparam.h>
37#include <linux/rtnetlink.h> 37#include <linux/rtnetlink.h>
38#include <linux/net_tstamp.h>
38#include <net/rtnetlink.h> 39#include <net/rtnetlink.h>
39#include <linux/u64_stats_sync.h> 40#include <linux/u64_stats_sync.h>
40 41
@@ -125,6 +126,7 @@ static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)
125 dstats->tx_bytes += skb->len; 126 dstats->tx_bytes += skb->len;
126 u64_stats_update_end(&dstats->syncp); 127 u64_stats_update_end(&dstats->syncp);
127 128
129 skb_tx_timestamp(skb);
128 dev_kfree_skb(skb); 130 dev_kfree_skb(skb);
129 return NETDEV_TX_OK; 131 return NETDEV_TX_OK;
130} 132}
@@ -304,8 +306,21 @@ static void dummy_get_drvinfo(struct net_device *dev,
304 strlcpy(info->version, DRV_VERSION, sizeof(info->version)); 306 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
305} 307}
306 308
309static 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
307static const struct ethtool_ops dummy_ethtool_ops = { 321static const struct ethtool_ops dummy_ethtool_ops = {
308 .get_drvinfo = dummy_get_drvinfo, 322 .get_drvinfo = dummy_get_drvinfo,
323 .get_ts_info = dummy_get_ts_info,
309}; 324};
310 325
311static void dummy_free_netdev(struct net_device *dev) 326static void dummy_free_netdev(struct net_device *dev)
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index b23b71981fd5..8d179d616993 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -55,6 +55,7 @@
55#include <linux/ip.h> 55#include <linux/ip.h>
56#include <linux/tcp.h> 56#include <linux/tcp.h>
57#include <linux/percpu.h> 57#include <linux/percpu.h>
58#include <linux/net_tstamp.h>
58#include <net/net_namespace.h> 59#include <net/net_namespace.h>
59#include <linux/u64_stats_sync.h> 60#include <linux/u64_stats_sync.h>
60 61
@@ -74,6 +75,7 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
74 struct pcpu_lstats *lb_stats; 75 struct pcpu_lstats *lb_stats;
75 int len; 76 int len;
76 77
78 skb_tx_timestamp(skb);
77 skb_orphan(skb); 79 skb_orphan(skb);
78 80
79 /* Before queueing this packet to netif_rx(), 81 /* Before queueing this packet to netif_rx(),
@@ -129,8 +131,21 @@ static u32 always_on(struct net_device *dev)
129 return 1; 131 return 1;
130} 132}
131 133
134static 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
132static const struct ethtool_ops loopback_ethtool_ops = { 146static const struct ethtool_ops loopback_ethtool_ops = {
133 .get_link = always_on, 147 .get_link = always_on,
148 .get_ts_info = loopback_get_ts_info,
134}; 149};
135 150
136static int loopback_dev_init(struct net_device *dev) 151static int loopback_dev_init(struct net_device *dev)