hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/net/dummy.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* dummy.c: a dummy net driver
23
34 The purpose of this driver is to provide a device to point a
....@@ -32,6 +33,7 @@
3233 #include <linux/kernel.h>
3334 #include <linux/netdevice.h>
3435 #include <linux/etherdevice.h>
36
+#include <linux/ethtool.h>
3537 #include <linux/init.h>
3638 #include <linux/moduleparam.h>
3739 #include <linux/rtnetlink.h>
....@@ -40,7 +42,6 @@
4042 #include <linux/u64_stats_sync.h>
4143
4244 #define DRV_NAME "dummy"
43
-#define DRV_VERSION "1.0"
4445
4546 static int numdummies = 1;
4647
....@@ -49,41 +50,15 @@
4950 {
5051 }
5152
52
-struct pcpu_dstats {
53
- u64 tx_packets;
54
- u64 tx_bytes;
55
- struct u64_stats_sync syncp;
56
-};
57
-
5853 static void dummy_get_stats64(struct net_device *dev,
5954 struct rtnl_link_stats64 *stats)
6055 {
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);
7757 }
7858
7959 static netdev_tx_t dummy_xmit(struct sk_buff *skb, struct net_device *dev)
8060 {
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);
8762
8863 skb_tx_timestamp(skb);
8964 dev_kfree_skb(skb);
....@@ -92,8 +67,8 @@
9267
9368 static int dummy_dev_init(struct net_device *dev)
9469 {
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)
9772 return -ENOMEM;
9873
9974 return 0;
....@@ -101,7 +76,7 @@
10176
10277 static void dummy_dev_uninit(struct net_device *dev)
10378 {
104
- free_percpu(dev->dstats);
79
+ free_percpu(dev->lstats);
10580 }
10681
10782 static int dummy_change_carrier(struct net_device *dev, bool new_carrier)
....@@ -128,24 +103,11 @@
128103 struct ethtool_drvinfo *info)
129104 {
130105 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
131
- strlcpy(info->version, DRV_VERSION, sizeof(info->version));
132106 }
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
-};
145107
146108 static const struct ethtool_ops dummy_ethtool_ops = {
147109 .get_drvinfo = dummy_get_drvinfo,
148
- .get_ts_info = dummy_get_ts_info,
110
+ .get_ts_info = ethtool_op_get_ts_info,
149111 };
150112
151113 static void dummy_setup(struct net_device *dev)
....@@ -248,4 +210,3 @@
248210 module_exit(dummy_cleanup_module);
249211 MODULE_LICENSE("GPL");
250212 MODULE_ALIAS_RTNL_LINK(DRV_NAME);
251
-MODULE_VERSION(DRV_VERSION);