@@ -401,6 +401,10 @@ static inline bool netif_is_bridge_port(const struct net_device *dev)
#endif
#if LINUX_VERSION_IS_LESS(5,10,0)
+#define dev_fetch_sw_netstats LINUX_BACKPORT(dev_fetch_sw_netstats)
+void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
+ const struct pcpu_sw_netstats __percpu *netstats);
+
#define netif_rx_any_context LINUX_BACKPORT(netif_rx_any_context)
int netif_rx_any_context(struct sk_buff *skb);
#endif /* < 5.10 */
@@ -4,6 +4,40 @@
#include <linux/kernel.h>
#include <linux/netdevice.h>
+/**
+ * dev_fetch_sw_netstats - get per-cpu network device statistics
+ * @s: place to store stats
+ * @netstats: per-cpu network stats to read from
+ *
+ * Read per-cpu network statistics and populate the related fields in @s.
+ */
+void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
+ const struct pcpu_sw_netstats __percpu *netstats)
+{
+ int cpu;
+
+ for_each_possible_cpu(cpu) {
+ const struct pcpu_sw_netstats *stats;
+ struct pcpu_sw_netstats tmp;
+ unsigned int start;
+
+ stats = per_cpu_ptr(netstats, cpu);
+ do {
+ start = u64_stats_fetch_begin_irq(&stats->syncp);
+ tmp.rx_packets = stats->rx_packets;
+ tmp.rx_bytes = stats->rx_bytes;
+ tmp.tx_packets = stats->tx_packets;
+ tmp.tx_bytes = stats->tx_bytes;
+ } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
+
+ s->rx_packets += tmp.rx_packets;
+ s->rx_bytes += tmp.rx_bytes;
+ s->tx_packets += tmp.tx_packets;
+ s->tx_bytes += tmp.tx_bytes;
+ }
+}
+EXPORT_SYMBOL_GPL(dev_fetch_sw_netstats);
+
int netif_rx_any_context(struct sk_buff *skb)
{
/*
Add the dev_fetch_sw_netstats which was added in commit 44fa32f008ab ("net: add function dev_fetch_sw_netstats for fetching pcpu_sw_netstats") in kernel 5.10. This is used by qmi_wwan, usbnet, qtnfmac and mac80211. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> --- backport/backport-include/linux/netdevice.h | 4 +++ backport/compat/backport-5.10.c | 34 +++++++++++++++++++++ 2 files changed, 38 insertions(+)