mv643xx_eth: kill private unused instance of struct net_device_stats

The per-port mv643xx_eth_private struct had a private instance
of struct net_device_stats that was never ever written to, only
read (via the ethtool statistics interface).  This patch gets
rid of the private instance, and tweaks the ethtool statistics
code in mv643xx_eth to use the statistics in struct net_device
instead.

Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Acked-by: Dale Farnsworth <dale@farnsworth.org>
This commit is contained in:
Lennert Buytenhek 2008-06-01 11:40:29 +02:00
parent 03ae1aac4a
commit 1682005477

View file

@ -325,7 +325,6 @@ struct mv643xx_eth_private {
struct net_device *dev; struct net_device *dev;
struct napi_struct napi; struct napi_struct napi;
struct net_device_stats stats;
struct mib_counters mib_counters; struct mib_counters mib_counters;
spinlock_t lock; spinlock_t lock;
/* Size of Tx Ring per queue */ /* Size of Tx Ring per queue */
@ -885,55 +884,59 @@ static void update_mib_counters(struct mv643xx_eth_private *mp)
struct mv643xx_eth_stats { struct mv643xx_eth_stats {
char stat_string[ETH_GSTRING_LEN]; char stat_string[ETH_GSTRING_LEN];
int sizeof_stat; int sizeof_stat;
int stat_offset; int netdev_off;
int mp_off;
}; };
#define MV643XX_ETH_STAT(m) FIELD_SIZEOF(struct mv643xx_eth_private, m), \ #define SSTAT(m) \
offsetof(struct mv643xx_eth_private, m) { #m, FIELD_SIZEOF(struct net_device_stats, m), \
offsetof(struct net_device, stats.m), -1 }
static const struct mv643xx_eth_stats mv643xx_eth_gstrings_stats[] = { #define MIBSTAT(m) \
{ "rx_packets", MV643XX_ETH_STAT(stats.rx_packets) }, { #m, FIELD_SIZEOF(struct mib_counters, m), \
{ "tx_packets", MV643XX_ETH_STAT(stats.tx_packets) }, -1, offsetof(struct mv643xx_eth_private, mib_counters.m) }
{ "rx_bytes", MV643XX_ETH_STAT(stats.rx_bytes) },
{ "tx_bytes", MV643XX_ETH_STAT(stats.tx_bytes) }, static const struct mv643xx_eth_stats mv643xx_eth_stats[] = {
{ "rx_errors", MV643XX_ETH_STAT(stats.rx_errors) }, SSTAT(rx_packets),
{ "tx_errors", MV643XX_ETH_STAT(stats.tx_errors) }, SSTAT(tx_packets),
{ "rx_dropped", MV643XX_ETH_STAT(stats.rx_dropped) }, SSTAT(rx_bytes),
{ "tx_dropped", MV643XX_ETH_STAT(stats.tx_dropped) }, SSTAT(tx_bytes),
{ "good_octets_received", MV643XX_ETH_STAT(mib_counters.good_octets_received) }, SSTAT(rx_errors),
{ "bad_octets_received", MV643XX_ETH_STAT(mib_counters.bad_octets_received) }, SSTAT(tx_errors),
{ "internal_mac_transmit_err", MV643XX_ETH_STAT(mib_counters.internal_mac_transmit_err) }, SSTAT(rx_dropped),
{ "good_frames_received", MV643XX_ETH_STAT(mib_counters.good_frames_received) }, SSTAT(tx_dropped),
{ "bad_frames_received", MV643XX_ETH_STAT(mib_counters.bad_frames_received) }, MIBSTAT(good_octets_received),
{ "broadcast_frames_received", MV643XX_ETH_STAT(mib_counters.broadcast_frames_received) }, MIBSTAT(bad_octets_received),
{ "multicast_frames_received", MV643XX_ETH_STAT(mib_counters.multicast_frames_received) }, MIBSTAT(internal_mac_transmit_err),
{ "frames_64_octets", MV643XX_ETH_STAT(mib_counters.frames_64_octets) }, MIBSTAT(good_frames_received),
{ "frames_65_to_127_octets", MV643XX_ETH_STAT(mib_counters.frames_65_to_127_octets) }, MIBSTAT(bad_frames_received),
{ "frames_128_to_255_octets", MV643XX_ETH_STAT(mib_counters.frames_128_to_255_octets) }, MIBSTAT(broadcast_frames_received),
{ "frames_256_to_511_octets", MV643XX_ETH_STAT(mib_counters.frames_256_to_511_octets) }, MIBSTAT(multicast_frames_received),
{ "frames_512_to_1023_octets", MV643XX_ETH_STAT(mib_counters.frames_512_to_1023_octets) }, MIBSTAT(frames_64_octets),
{ "frames_1024_to_max_octets", MV643XX_ETH_STAT(mib_counters.frames_1024_to_max_octets) }, MIBSTAT(frames_65_to_127_octets),
{ "good_octets_sent", MV643XX_ETH_STAT(mib_counters.good_octets_sent) }, MIBSTAT(frames_128_to_255_octets),
{ "good_frames_sent", MV643XX_ETH_STAT(mib_counters.good_frames_sent) }, MIBSTAT(frames_256_to_511_octets),
{ "excessive_collision", MV643XX_ETH_STAT(mib_counters.excessive_collision) }, MIBSTAT(frames_512_to_1023_octets),
{ "multicast_frames_sent", MV643XX_ETH_STAT(mib_counters.multicast_frames_sent) }, MIBSTAT(frames_1024_to_max_octets),
{ "broadcast_frames_sent", MV643XX_ETH_STAT(mib_counters.broadcast_frames_sent) }, MIBSTAT(good_octets_sent),
{ "unrec_mac_control_received", MV643XX_ETH_STAT(mib_counters.unrec_mac_control_received) }, MIBSTAT(good_frames_sent),
{ "fc_sent", MV643XX_ETH_STAT(mib_counters.fc_sent) }, MIBSTAT(excessive_collision),
{ "good_fc_received", MV643XX_ETH_STAT(mib_counters.good_fc_received) }, MIBSTAT(multicast_frames_sent),
{ "bad_fc_received", MV643XX_ETH_STAT(mib_counters.bad_fc_received) }, MIBSTAT(broadcast_frames_sent),
{ "undersize_received", MV643XX_ETH_STAT(mib_counters.undersize_received) }, MIBSTAT(unrec_mac_control_received),
{ "fragments_received", MV643XX_ETH_STAT(mib_counters.fragments_received) }, MIBSTAT(fc_sent),
{ "oversize_received", MV643XX_ETH_STAT(mib_counters.oversize_received) }, MIBSTAT(good_fc_received),
{ "jabber_received", MV643XX_ETH_STAT(mib_counters.jabber_received) }, MIBSTAT(bad_fc_received),
{ "mac_receive_error", MV643XX_ETH_STAT(mib_counters.mac_receive_error) }, MIBSTAT(undersize_received),
{ "bad_crc_event", MV643XX_ETH_STAT(mib_counters.bad_crc_event) }, MIBSTAT(fragments_received),
{ "collision", MV643XX_ETH_STAT(mib_counters.collision) }, MIBSTAT(oversize_received),
{ "late_collision", MV643XX_ETH_STAT(mib_counters.late_collision) }, MIBSTAT(jabber_received),
MIBSTAT(mac_receive_error),
MIBSTAT(bad_crc_event),
MIBSTAT(collision),
MIBSTAT(late_collision),
}; };
#define MV643XX_ETH_STATS_LEN ARRAY_SIZE(mv643xx_eth_gstrings_stats)
static int mv643xx_eth_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) static int mv643xx_eth_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
{ {
struct mv643xx_eth_private *mp = netdev_priv(dev); struct mv643xx_eth_private *mp = netdev_priv(dev);
@ -969,7 +972,7 @@ static void mv643xx_eth_get_drvinfo(struct net_device *netdev,
strncpy(drvinfo->version, mv643xx_eth_driver_version, 32); strncpy(drvinfo->version, mv643xx_eth_driver_version, 32);
strncpy(drvinfo->fw_version, "N/A", 32); strncpy(drvinfo->fw_version, "N/A", 32);
strncpy(drvinfo->bus_info, "mv643xx", 32); strncpy(drvinfo->bus_info, "mv643xx", 32);
drvinfo->n_stats = MV643XX_ETH_STATS_LEN; drvinfo->n_stats = ARRAY_SIZE(mv643xx_eth_stats);
} }
static int mv643xx_eth_nway_restart(struct net_device *dev) static int mv643xx_eth_nway_restart(struct net_device *dev)
@ -993,9 +996,9 @@ static void mv643xx_eth_get_strings(struct net_device *netdev, uint32_t stringse
switch(stringset) { switch(stringset) {
case ETH_SS_STATS: case ETH_SS_STATS:
for (i=0; i < MV643XX_ETH_STATS_LEN; i++) { for (i=0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) {
memcpy(data + i * ETH_GSTRING_LEN, memcpy(data + i * ETH_GSTRING_LEN,
mv643xx_eth_gstrings_stats[i].stat_string, mv643xx_eth_stats[i].stat_string,
ETH_GSTRING_LEN); ETH_GSTRING_LEN);
} }
break; break;
@ -1010,10 +1013,19 @@ static void mv643xx_eth_get_ethtool_stats(struct net_device *netdev,
update_mib_counters(mp); update_mib_counters(mp);
for (i = 0; i < MV643XX_ETH_STATS_LEN; i++) { for (i = 0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) {
char *p = (char *)mp+mv643xx_eth_gstrings_stats[i].stat_offset; const struct mv643xx_eth_stats *stat;
data[i] = (mv643xx_eth_gstrings_stats[i].sizeof_stat == void *p;
sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
stat = mv643xx_eth_stats + i;
if (stat->netdev_off >= 0)
p = ((void *)mp->dev) + stat->netdev_off;
else
p = ((void *)mp) + stat->mp_off;
data[i] = (stat->sizeof_stat == 8) ?
*(uint64_t *)p : *(uint32_t *)p;
} }
} }
@ -1021,7 +1033,7 @@ static int mv643xx_eth_get_sset_count(struct net_device *netdev, int sset)
{ {
switch (sset) { switch (sset) {
case ETH_SS_STATS: case ETH_SS_STATS:
return MV643XX_ETH_STATS_LEN; return ARRAY_SIZE(mv643xx_eth_stats);
default: default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }