| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* dummy.c: a dummy net driver |
|---|
| 2 | 3 | |
|---|
| 3 | 4 | The purpose of this driver is to provide a device to point a |
|---|
| .. | .. |
|---|
| 32 | 33 | #include <linux/kernel.h> |
|---|
| 33 | 34 | #include <linux/netdevice.h> |
|---|
| 34 | 35 | #include <linux/etherdevice.h> |
|---|
| 36 | +#include <linux/ethtool.h> |
|---|
| 35 | 37 | #include <linux/init.h> |
|---|
| 36 | 38 | #include <linux/moduleparam.h> |
|---|
| 37 | 39 | #include <linux/rtnetlink.h> |
|---|
| .. | .. |
|---|
| 40 | 42 | #include <linux/u64_stats_sync.h> |
|---|
| 41 | 43 | |
|---|
| 42 | 44 | #define DRV_NAME "dummy" |
|---|
| 43 | | -#define DRV_VERSION "1.0" |
|---|
| 44 | 45 | |
|---|
| 45 | 46 | static int numdummies = 1; |
|---|
| 46 | 47 | |
|---|
| .. | .. |
|---|
| 49 | 50 | { |
|---|
| 50 | 51 | } |
|---|
| 51 | 52 | |
|---|
| 52 | | -struct pcpu_dstats { |
|---|
| 53 | | - u64 tx_packets; |
|---|
| 54 | | - u64 tx_bytes; |
|---|
| 55 | | - struct u64_stats_sync syncp; |
|---|
| 56 | | -}; |
|---|
| 57 | | - |
|---|
| 58 | 53 | static void dummy_get_stats64(struct net_device *dev, |
|---|
| 59 | 54 | struct rtnl_link_stats64 *stats) |
|---|
| 60 | 55 | { |
|---|
| 61 | | - int i; |
|---|
| 62 | | - |
|---|
| 63 | | - for_each_possible_cpu(i) { |
|---|
| 64 | | - const struct pcpu_dstats *dstats; |
|---|
| 65 | | - u64 tbytes, tpackets; |
|---|
| 66 | | - unsigned int start; |
|---|
| 67 | | - |
|---|
| 68 | | - dstats = per_cpu_ptr(dev->dstats, i); |
|---|
| 69 | | - do { |
|---|
| 70 | | - start = u64_stats_fetch_begin_irq(&dstats->syncp); |
|---|
| 71 | | - tbytes = dstats->tx_bytes; |
|---|
| 72 | | - tpackets = dstats->tx_packets; |
|---|
| 73 | | - } while (u64_stats_fetch_retry_irq(&dstats->syncp, start)); |
|---|
| 74 | | - stats->tx_bytes += tbytes; |
|---|
| 75 | | - stats->tx_packets += tpackets; |
|---|
| 76 | | - } |
|---|
| 56 | + dev_lstats_read(dev, &stats->tx_packets, &stats->tx_bytes); |
|---|
| 77 | 57 | } |
|---|
| 78 | 58 | |
|---|
| 79 | 59 | static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev) |
|---|
| 80 | 60 | { |
|---|
| 81 | | - struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats); |
|---|
| 82 | | - |
|---|
| 83 | | - u64_stats_update_begin(&dstats->syncp); |
|---|
| 84 | | - dstats->tx_packets++; |
|---|
| 85 | | - dstats->tx_bytes += skb->len; |
|---|
| 86 | | - u64_stats_update_end(&dstats->syncp); |
|---|
| 61 | + dev_lstats_add(dev, skb->len); |
|---|
| 87 | 62 | |
|---|
| 88 | 63 | skb_tx_timestamp(skb); |
|---|
| 89 | 64 | dev_kfree_skb(skb); |
|---|
| .. | .. |
|---|
| 92 | 67 | |
|---|
| 93 | 68 | static int dummy_dev_init(struct net_device *dev) |
|---|
| 94 | 69 | { |
|---|
| 95 | | - dev->dstats = netdev_alloc_pcpu_stats(struct pcpu_dstats); |
|---|
| 96 | | - if (!dev->dstats) |
|---|
| 70 | + dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats); |
|---|
| 71 | + if (!dev->lstats) |
|---|
| 97 | 72 | return -ENOMEM; |
|---|
| 98 | 73 | |
|---|
| 99 | 74 | return 0; |
|---|
| .. | .. |
|---|
| 101 | 76 | |
|---|
| 102 | 77 | static void dummy_dev_uninit(struct net_device *dev) |
|---|
| 103 | 78 | { |
|---|
| 104 | | - free_percpu(dev->dstats); |
|---|
| 79 | + free_percpu(dev->lstats); |
|---|
| 105 | 80 | } |
|---|
| 106 | 81 | |
|---|
| 107 | 82 | static int dummy_change_carrier(struct net_device *dev, bool new_carrier) |
|---|
| .. | .. |
|---|
| 128 | 103 | struct ethtool_drvinfo *info) |
|---|
| 129 | 104 | { |
|---|
| 130 | 105 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
|---|
| 131 | | - strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
|---|
| 132 | 106 | } |
|---|
| 133 | | - |
|---|
| 134 | | -static int dummy_get_ts_info(struct net_device *dev, |
|---|
| 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 | 107 | |
|---|
| 146 | 108 | static const struct ethtool_ops dummy_ethtool_ops = { |
|---|
| 147 | 109 | .get_drvinfo = dummy_get_drvinfo, |
|---|
| 148 | | - .get_ts_info = dummy_get_ts_info, |
|---|
| 110 | + .get_ts_info = ethtool_op_get_ts_info, |
|---|
| 149 | 111 | }; |
|---|
| 150 | 112 | |
|---|
| 151 | 113 | static void dummy_setup(struct net_device *dev) |
|---|
| .. | .. |
|---|
| 248 | 210 | module_exit(dummy_cleanup_module); |
|---|
| 249 | 211 | MODULE_LICENSE("GPL"); |
|---|
| 250 | 212 | MODULE_ALIAS_RTNL_LINK(DRV_NAME); |
|---|
| 251 | | -MODULE_VERSION(DRV_VERSION); |
|---|