diff mbox series

[02/47] backports: Add dev_get_tstats64() and bp_dev_get_tstats64()

Message ID 20211019214320.2035704-3-hauke@hauke-m.de (mailing list archive)
State New, archived
Headers show
Series backports: Update to kernel 5.15-rc6 | expand

Commit Message

Hauke Mehrtens Oct. 19, 2021, 9:42 p.m. UTC
dev_get_tstats64() was added as a generic function for .ndo_get_stats64.
The signature of this callback function changed with kernel 4.11, add
the bp_dev_get_tstats64() function on such older kernel version.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 backport/backport-include/linux/netdevice.h | 10 ++++++++++
 backport/compat/Makefile                    |  2 ++
 backport/compat/backport-4.11.c             | 12 ++++++++++++
 backport/compat/backport-5.11.c             | 19 +++++++++++++++++++
 4 files changed, 43 insertions(+)
 create mode 100644 backport/compat/backport-4.11.c
 create mode 100644 backport/compat/backport-5.11.c
diff mbox series

Patch

diff --git a/backport/backport-include/linux/netdevice.h b/backport/backport-include/linux/netdevice.h
index e9c07a91..d854faef 100644
--- a/backport/backport-include/linux/netdevice.h
+++ b/backport/backport-include/linux/netdevice.h
@@ -113,4 +113,14 @@  void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
 int netif_rx_any_context(struct sk_buff *skb);
 #endif /* < 5.10 */
 
+#if LINUX_VERSION_IS_LESS(5,11,0)
+#define dev_get_tstats64 LINUX_BACKPORT(dev_get_tstats64)
+void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
+#endif /* < 5.11 */
+
+#if LINUX_VERSION_IS_LESS(4,11,0)
+struct rtnl_link_stats64 *
+bp_dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
+#endif /* < 4.11 */
+
 #endif /* __BACKPORT_NETDEVICE_H */
diff --git a/backport/compat/Makefile b/backport/compat/Makefile
index bbedd49c..e927a0c8 100644
--- a/backport/compat/Makefile
+++ b/backport/compat/Makefile
@@ -12,11 +12,13 @@  compat-$(CPTCFG_KERNEL_4_6) += backport-4.6.o
 compat-$(CPTCFG_KERNEL_4_7) += backport-4.7.o
 compat-$(CPTCFG_KERNEL_4_8) += backport-4.8.o
 compat-$(CPTCFG_KERNEL_4_10) += backport-4.10.o
+compat-$(CPTCFG_KERNEL_4_11) += backport-4.11.o
 compat-$(CPTCFG_KERNEL_4_18) += backport-4.18.o
 compat-$(CPTCFG_KERNEL_5_2) += backport-5.2.o backport-genetlink.o
 compat-$(CPTCFG_KERNEL_5_3) += backport-5.3.o
 compat-$(CPTCFG_KERNEL_5_5) += backport-5.5.o
 compat-$(CPTCFG_KERNEL_5_10) += backport-5.10.o
+compat-$(CPTCFG_KERNEL_5_11) += backport-5.11.o
 
 compat-$(CPTCFG_BPAUTO_BUILD_SYSTEM_DATA_VERIFICATION) += verification/verify.o
 compat-$(CPTCFG_BPAUTO_BUILD_SYSTEM_DATA_VERIFICATION) += verification/pkcs7.asn1.o
diff --git a/backport/compat/backport-4.11.c b/backport/compat/backport-4.11.c
new file mode 100644
index 00000000..83445856
--- /dev/null
+++ b/backport/compat/backport-4.11.c
@@ -0,0 +1,12 @@ 
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/export.h>
+#include <linux/netdevice.h>
+
+struct rtnl_link_stats64 *
+bp_dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s)
+{
+	dev_get_tstats64(dev, s);
+	return s;
+}
+EXPORT_SYMBOL_GPL(bp_dev_get_tstats64);
diff --git a/backport/compat/backport-5.11.c b/backport/compat/backport-5.11.c
new file mode 100644
index 00000000..e60f35cf
--- /dev/null
+++ b/backport/compat/backport-5.11.c
@@ -0,0 +1,19 @@ 
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/export.h>
+#include <linux/netdevice.h>
+
+/**
+ *	dev_get_tstats64 - ndo_get_stats64 implementation
+ *	@dev: device to get statistics from
+ *	@s: place to store stats
+ *
+ *	Populate @s from dev->stats and dev->tstats. Can be used as
+ *	ndo_get_stats64() callback.
+ */
+void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s)
+{
+	netdev_stats_to_stats64(s, &dev->stats);
+	dev_fetch_sw_netstats(s, dev->tstats);
+}
+EXPORT_SYMBOL_GPL(dev_get_tstats64);