/*
* Old network device statistics. Fields are native words
* (unsigned long) so they can be read and written atomically.
- * Each field is padded to 64 bits for compatibility with
- * rtnl_link_stats64.
*/
-#if BITS_PER_LONG == 64
-#define NET_DEVICE_STATS_DEFINE(name) unsigned long name
-#elif defined(__LITTLE_ENDIAN)
-#define NET_DEVICE_STATS_DEFINE(name) unsigned long name, pad_ ## name
-#else
-#define NET_DEVICE_STATS_DEFINE(name) unsigned long pad_ ## name, name
-#endif
-
struct net_device_stats {
- NET_DEVICE_STATS_DEFINE(rx_packets);
- NET_DEVICE_STATS_DEFINE(tx_packets);
- NET_DEVICE_STATS_DEFINE(rx_bytes);
- NET_DEVICE_STATS_DEFINE(tx_bytes);
- NET_DEVICE_STATS_DEFINE(rx_errors);
- NET_DEVICE_STATS_DEFINE(tx_errors);
- NET_DEVICE_STATS_DEFINE(rx_dropped);
- NET_DEVICE_STATS_DEFINE(tx_dropped);
- NET_DEVICE_STATS_DEFINE(multicast);
- NET_DEVICE_STATS_DEFINE(collisions);
- NET_DEVICE_STATS_DEFINE(rx_length_errors);
- NET_DEVICE_STATS_DEFINE(rx_over_errors);
- NET_DEVICE_STATS_DEFINE(rx_crc_errors);
- NET_DEVICE_STATS_DEFINE(rx_frame_errors);
- NET_DEVICE_STATS_DEFINE(rx_fifo_errors);
- NET_DEVICE_STATS_DEFINE(rx_missed_errors);
- NET_DEVICE_STATS_DEFINE(tx_aborted_errors);
- NET_DEVICE_STATS_DEFINE(tx_carrier_errors);
- NET_DEVICE_STATS_DEFINE(tx_fifo_errors);
- NET_DEVICE_STATS_DEFINE(tx_heartbeat_errors);
- NET_DEVICE_STATS_DEFINE(tx_window_errors);
- NET_DEVICE_STATS_DEFINE(rx_compressed);
- NET_DEVICE_STATS_DEFINE(tx_compressed);
+ unsigned long rx_packets;
+ unsigned long tx_packets;
+ unsigned long rx_bytes;
+ unsigned long tx_bytes;
+ unsigned long rx_errors;
+ unsigned long tx_errors;
+ unsigned long rx_dropped;
+ unsigned long tx_dropped;
+ unsigned long multicast;
+ unsigned long collisions;
+ unsigned long rx_length_errors;
+ unsigned long rx_over_errors;
+ unsigned long rx_crc_errors;
+ unsigned long rx_frame_errors;
+ unsigned long rx_fifo_errors;
+ unsigned long rx_missed_errors;
+ unsigned long tx_aborted_errors;
+ unsigned long tx_carrier_errors;
+ unsigned long tx_fifo_errors;
+ unsigned long tx_heartbeat_errors;
+ unsigned long tx_window_errors;
+ unsigned long rx_compressed;
+ unsigned long tx_compressed;
};
#endif /* __KERNEL__ */
* Callback uses when the transmitter has not made any progress
* for dev->watchdog ticks.
*
- * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev
+ * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
* struct rtnl_link_stats64 *storage);
* struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
* Called when a user wants to get the network device usage
* statistics. Drivers must do one of the following:
- * 1. Define @ndo_get_stats64 to update a rtnl_link_stats64 structure
- * (which should normally be dev->stats64) and return a ponter to
- * it. The structure must not be changed asynchronously.
+ * 1. Define @ndo_get_stats64 to fill in a zero-initialised
+ * rtnl_link_stats64 structure passed by the caller.
* 2. Define @ndo_get_stats to update a net_device_stats structure
* (which should normally be dev->stats) and return a pointer to
* it. The structure may be changed asynchronously only if each
int ifindex;
int iflink;
- union {
- struct rtnl_link_stats64 stats64;
- struct net_device_stats stats;
- };
+ struct net_device_stats stats;
#ifdef CONFIG_WIRELESS_EXT
/* List of functions to handle Wireless Extensions (instead of ioctl).
extern const struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
struct rtnl_link_stats64 *storage);
extern void dev_txq_stats_fold(const struct net_device *dev,
- struct net_device_stats *stats);
+ struct rtnl_link_stats64 *stats);
extern int netdev_max_backlog;
extern int netdev_tstamp_prequeue;
/**
* dev_txq_stats_fold - fold tx_queues stats
* @dev: device to get statistics from
- * @stats: struct net_device_stats to hold results
+ * @stats: struct rtnl_link_stats64 to hold results
*/
void dev_txq_stats_fold(const struct net_device *dev,
- struct net_device_stats *stats)
+ struct rtnl_link_stats64 *stats)
{
unsigned long tx_bytes = 0, tx_packets = 0, tx_dropped = 0;
unsigned int i;
}
EXPORT_SYMBOL(dev_txq_stats_fold);
+/* Convert net_device_stats to rtnl_link_stats64. They have the same
+ * fields in the same order, with only the type differing.
+ */
+static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
+ const struct net_device_stats *netdev_stats)
+{
+#if BITS_PER_LONG == 64
+ BUILD_BUG_ON(sizeof(*stats64) != sizeof(*netdev_stats));
+ memcpy(stats64, netdev_stats, sizeof(*stats64));
+#else
+ size_t i, n = sizeof(*stats64) / sizeof(u64);
+ const unsigned long *src = (const unsigned long *)netdev_stats;
+ u64 *dst = (u64 *)stats64;
+
+ BUILD_BUG_ON(sizeof(*netdev_stats) / sizeof(unsigned long) !=
+ sizeof(*stats64) / sizeof(u64));
+ for (i = 0; i < n; i++)
+ dst[i] = src[i];
+#endif
+}
+
/**
* dev_get_stats - get network device statistics
* @dev: device to get statistics from
return ops->ndo_get_stats64(dev, storage);
}
if (ops->ndo_get_stats) {
- memcpy(storage, ops->ndo_get_stats(dev), sizeof(*storage));
+ netdev_stats_to_stats64(storage, ops->ndo_get_stats(dev));
return storage;
}
- memcpy(storage, &dev->stats, sizeof(*storage));
- dev_txq_stats_fold(dev, (struct net_device_stats *)storage);
+ netdev_stats_to_stats64(storage, &dev->stats);
+ dev_txq_stats_fold(dev, storage);
return storage;
}
EXPORT_SYMBOL(dev_get_stats);