Commit d72d6c19 authored by Emil Tantilov's avatar Emil Tantilov Committed by Jeff Kirsher

ixgbevf: refactor ethtool stats handling

This brings the logic closer to how we handle the stats in ixgbe and it
sets us up for introducing per-queue stats.

Use IXGBEVF_STAT and IXGBEVF_NETDEV_STAT for accessing the driver and
netdev stats respectively. This way we don't have to calculate the
stats based on register values which could lead to the counters not
being initialized properly when the interface is down.

IXGBEVF_QUEUE_STATS_LEN is set to include the number of queues.

Also some defines were renamed to use the IXGBEVF prefix.
Signed-off-by: default avatarEmil Tantilov <emil.s.tantilov@intel.com>
Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 2f2219be
...@@ -42,65 +42,62 @@ ...@@ -42,65 +42,62 @@
#define IXGBE_ALL_RAR_ENTRIES 16 #define IXGBE_ALL_RAR_ENTRIES 16
enum {NETDEV_STATS, IXGBEVF_STATS};
struct ixgbe_stats { struct ixgbe_stats {
char stat_string[ETH_GSTRING_LEN]; char stat_string[ETH_GSTRING_LEN];
struct { int type;
int sizeof_stat; int sizeof_stat;
int stat_offset; int stat_offset;
int base_stat_offset;
int saved_reset_offset;
};
}; };
#define IXGBEVF_STAT(m, b, r) { \ #define IXGBEVF_STAT(_name, _stat) { \
.sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, m), \ .stat_string = _name, \
.stat_offset = offsetof(struct ixgbevf_adapter, m), \ .type = IXGBEVF_STATS, \
.base_stat_offset = offsetof(struct ixgbevf_adapter, b), \ .sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, _stat), \
.saved_reset_offset = offsetof(struct ixgbevf_adapter, r) \ .stat_offset = offsetof(struct ixgbevf_adapter, _stat) \
} }
#define IXGBEVF_ZSTAT(m) { \ #define IXGBEVF_NETDEV_STAT(_net_stat) { \
.sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, m), \ .stat_string = #_net_stat, \
.stat_offset = offsetof(struct ixgbevf_adapter, m), \ .type = NETDEV_STATS, \
.base_stat_offset = -1, \ .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
.saved_reset_offset = -1 \ .stat_offset = offsetof(struct net_device_stats, _net_stat) \
} }
static const struct ixgbe_stats ixgbe_gstrings_stats[] = { static struct ixgbe_stats ixgbevf_gstrings_stats[] = {
{"rx_packets", IXGBEVF_STAT(stats.vfgprc, stats.base_vfgprc, IXGBEVF_NETDEV_STAT(rx_packets),
stats.saved_reset_vfgprc)}, IXGBEVF_NETDEV_STAT(tx_packets),
{"tx_packets", IXGBEVF_STAT(stats.vfgptc, stats.base_vfgptc, IXGBEVF_NETDEV_STAT(rx_bytes),
stats.saved_reset_vfgptc)}, IXGBEVF_NETDEV_STAT(tx_bytes),
{"rx_bytes", IXGBEVF_STAT(stats.vfgorc, stats.base_vfgorc, IXGBEVF_STAT("tx_busy", tx_busy),
stats.saved_reset_vfgorc)}, IXGBEVF_STAT("tx_restart_queue", restart_queue),
{"tx_bytes", IXGBEVF_STAT(stats.vfgotc, stats.base_vfgotc, IXGBEVF_STAT("tx_timeout_count", tx_timeout_count),
stats.saved_reset_vfgotc)}, IXGBEVF_NETDEV_STAT(multicast),
{"tx_busy", IXGBEVF_ZSTAT(tx_busy)}, IXGBEVF_STAT("rx_csum_offload_errors", hw_csum_rx_error),
{"tx_restart_queue", IXGBEVF_ZSTAT(restart_queue)},
{"tx_timeout_count", IXGBEVF_ZSTAT(tx_timeout_count)},
{"multicast", IXGBEVF_STAT(stats.vfmprc, stats.base_vfmprc,
stats.saved_reset_vfmprc)},
{"rx_csum_offload_errors", IXGBEVF_ZSTAT(hw_csum_rx_error)},
#ifdef BP_EXTENDED_STATS #ifdef BP_EXTENDED_STATS
{"rx_bp_poll_yield", IXGBEVF_ZSTAT(bp_rx_yields)}, IXGBEVF_STAT("rx_bp_poll_yield", bp_rx_yields),
{"rx_bp_cleaned", IXGBEVF_ZSTAT(bp_rx_cleaned)}, IXGBEVF_STAT("rx_bp_cleaned", bp_rx_cleaned),
{"rx_bp_misses", IXGBEVF_ZSTAT(bp_rx_missed)}, IXGBEVF_STAT("rx_bp_misses", bp_rx_missed),
{"tx_bp_napi_yield", IXGBEVF_ZSTAT(bp_tx_yields)}, IXGBEVF_STAT("tx_bp_napi_yield", bp_tx_yields),
{"tx_bp_cleaned", IXGBEVF_ZSTAT(bp_tx_cleaned)}, IXGBEVF_STAT("tx_bp_cleaned", bp_tx_cleaned),
{"tx_bp_misses", IXGBEVF_ZSTAT(bp_tx_missed)}, IXGBEVF_STAT("tx_bp_misses", bp_tx_missed),
#endif #endif
}; };
#define IXGBE_QUEUE_STATS_LEN 0 #define IXGBEVF_QUEUE_STATS_LEN ( \
#define IXGBE_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbe_gstrings_stats) (((struct ixgbevf_adapter *)netdev_priv(netdev))->num_tx_queues + \
((struct ixgbevf_adapter *)netdev_priv(netdev))->num_rx_queues) * \
(sizeof(struct ixgbe_stats) / sizeof(u64)))
#define IXGBEVF_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbevf_gstrings_stats)
#define IXGBEVF_STATS_LEN (IXGBE_GLOBAL_STATS_LEN + IXGBE_QUEUE_STATS_LEN) #define IXGBEVF_STATS_LEN (IXGBEVF_GLOBAL_STATS_LEN + IXGBEVF_QUEUE_STATS_LEN)
static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = { static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
"Register test (offline)", "Register test (offline)",
"Link test (on/offline)" "Link test (on/offline)"
}; };
#define IXGBE_TEST_LEN (sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN) #define IXGBEVF_TEST_LEN (sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN)
static int ixgbevf_get_settings(struct net_device *netdev, static int ixgbevf_get_settings(struct net_device *netdev,
struct ethtool_cmd *ecmd) struct ethtool_cmd *ecmd)
...@@ -396,9 +393,9 @@ static int ixgbevf_get_sset_count(struct net_device *dev, int stringset) ...@@ -396,9 +393,9 @@ static int ixgbevf_get_sset_count(struct net_device *dev, int stringset)
{ {
switch (stringset) { switch (stringset) {
case ETH_SS_TEST: case ETH_SS_TEST:
return IXGBE_TEST_LEN; return IXGBEVF_TEST_LEN;
case ETH_SS_STATS: case ETH_SS_STATS:
return IXGBE_GLOBAL_STATS_LEN; return IXGBEVF_GLOBAL_STATS_LEN;
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -408,8 +405,11 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev, ...@@ -408,8 +405,11 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev,
struct ethtool_stats *stats, u64 *data) struct ethtool_stats *stats, u64 *data)
{ {
struct ixgbevf_adapter *adapter = netdev_priv(netdev); struct ixgbevf_adapter *adapter = netdev_priv(netdev);
char *base = (char *)adapter; struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *net_stats;
int i; int i;
char *p;
#ifdef BP_EXTENDED_STATS #ifdef BP_EXTENDED_STATS
u64 rx_yields = 0, rx_cleaned = 0, rx_missed = 0, u64 rx_yields = 0, rx_cleaned = 0, rx_missed = 0,
tx_yields = 0, tx_cleaned = 0, tx_missed = 0; tx_yields = 0, tx_cleaned = 0, tx_missed = 0;
...@@ -436,22 +436,24 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev, ...@@ -436,22 +436,24 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev,
#endif #endif
ixgbevf_update_stats(adapter); ixgbevf_update_stats(adapter);
for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { net_stats = dev_get_stats(netdev, &temp);
char *p = base + ixgbe_gstrings_stats[i].stat_offset; for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) {
char *b = base + ixgbe_gstrings_stats[i].base_stat_offset; switch (ixgbevf_gstrings_stats[i].type) {
char *r = base + ixgbe_gstrings_stats[i].saved_reset_offset; case NETDEV_STATS:
p = (char *)net_stats +
if (ixgbe_gstrings_stats[i].sizeof_stat == sizeof(u64)) { ixgbevf_gstrings_stats[i].stat_offset;
if (ixgbe_gstrings_stats[i].base_stat_offset >= 0) break;
data[i] = *(u64 *)p - *(u64 *)b + *(u64 *)r; case IXGBEVF_STATS:
else p = (char *)adapter +
data[i] = *(u64 *)p; ixgbevf_gstrings_stats[i].stat_offset;
} else { break;
if (ixgbe_gstrings_stats[i].base_stat_offset >= 0) default:
data[i] = *(u32 *)p - *(u32 *)b + *(u32 *)r; data[i] = 0;
else continue;
data[i] = *(u32 *)p;
} }
data[i] = (ixgbevf_gstrings_stats[i].sizeof_stat ==
sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
} }
} }
...@@ -464,11 +466,11 @@ static void ixgbevf_get_strings(struct net_device *netdev, u32 stringset, ...@@ -464,11 +466,11 @@ static void ixgbevf_get_strings(struct net_device *netdev, u32 stringset,
switch (stringset) { switch (stringset) {
case ETH_SS_TEST: case ETH_SS_TEST:
memcpy(data, *ixgbe_gstrings_test, memcpy(data, *ixgbe_gstrings_test,
IXGBE_TEST_LEN * ETH_GSTRING_LEN); IXGBEVF_TEST_LEN * ETH_GSTRING_LEN);
break; break;
case ETH_SS_STATS: case ETH_SS_STATS:
for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) {
memcpy(p, ixgbe_gstrings_stats[i].stat_string, memcpy(p, ixgbevf_gstrings_stats[i].stat_string,
ETH_GSTRING_LEN); ETH_GSTRING_LEN);
p += ETH_GSTRING_LEN; p += ETH_GSTRING_LEN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment