Commit 09401ae2 authored by Jacob Keller's avatar Jacob Keller Committed by Jeff Kirsher

fm10k: add helper functions to set strings and data for ethtool stats

Reduce duplicate code and the amount of indentation by adding
fm10k_add_stat_strings and fm10k_add_ethtool_stats functions which help
add fm10k_stat structures to the ethtool stats callbacks. This helps
increase ease of use for future stat additions, and increases code
readability.
Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Tested-by: default avatarKrishneil Singh <Krishneil.k.singh@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 10c9ead9
...@@ -121,13 +121,22 @@ static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = { ...@@ -121,13 +121,22 @@ static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = {
FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed), FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed),
}; };
#define FM10K_QUEUE_STAT(_name, _stat) { \
.stat_string = _name, \
.sizeof_stat = FIELD_SIZEOF(struct fm10k_ring, _stat), \
.stat_offset = offsetof(struct fm10k_ring, _stat) \
}
static const struct fm10k_stats fm10k_gstrings_queue_stats[] = {
FM10K_QUEUE_STAT("packets", stats.packets),
FM10K_QUEUE_STAT("bytes", stats.bytes),
};
#define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats) #define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
#define FM10K_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_stats) #define FM10K_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_stats)
#define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats) #define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
#define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats) #define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats)
#define FM10K_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_queue_stats)
#define FM10K_QUEUE_STATS_LEN(_n) \
((_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
#define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \ #define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
FM10K_NETDEV_STATS_LEN + \ FM10K_NETDEV_STATS_LEN + \
...@@ -202,14 +211,17 @@ static void fm10k_get_stat_strings(struct net_device *dev, u8 *data) ...@@ -202,14 +211,17 @@ static void fm10k_get_stat_strings(struct net_device *dev, u8 *data)
} }
for (i = 0; i < interface->hw.mac.max_queues; i++) { for (i = 0; i < interface->hw.mac.max_queues; i++) {
snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_packets", i); char prefix[ETH_GSTRING_LEN];
p += ETH_GSTRING_LEN;
snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i); snprintf(prefix, ETH_GSTRING_LEN, "tx_queue_%u_", i);
p += ETH_GSTRING_LEN; fm10k_add_stat_strings(&p, prefix,
snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_packets", i); fm10k_gstrings_queue_stats,
p += ETH_GSTRING_LEN; FM10K_QUEUE_STATS_LEN);
snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
p += ETH_GSTRING_LEN; snprintf(prefix, ETH_GSTRING_LEN, "rx_queue_%u_", i);
fm10k_add_stat_strings(&p, prefix,
fm10k_gstrings_queue_stats,
FM10K_QUEUE_STATS_LEN);
} }
} }
...@@ -244,7 +256,7 @@ static int fm10k_get_sset_count(struct net_device *dev, int sset) ...@@ -244,7 +256,7 @@ static int fm10k_get_sset_count(struct net_device *dev, int sset)
case ETH_SS_TEST: case ETH_SS_TEST:
return FM10K_TEST_LEN; return FM10K_TEST_LEN;
case ETH_SS_STATS: case ETH_SS_STATS:
stats_len += FM10K_QUEUE_STATS_LEN(hw->mac.max_queues); stats_len += hw->mac.max_queues * 2 * FM10K_QUEUE_STATS_LEN;
if (hw->mac.type != fm10k_mac_vf) if (hw->mac.type != fm10k_mac_vf)
stats_len += FM10K_PF_STATS_LEN; stats_len += FM10K_PF_STATS_LEN;
...@@ -272,9 +284,10 @@ static void fm10k_add_ethtool_stats(u64 **data, void *pointer, ...@@ -272,9 +284,10 @@ static void fm10k_add_ethtool_stats(u64 **data, void *pointer,
unsigned int i; unsigned int i;
char *p; char *p;
/* simply skip forward if we were not given a valid pointer */
if (!pointer) { if (!pointer) {
*data += size; /* memory is not zero allocated so we have to clear it */
for (i = 0; i < size; i++)
*((*data)++) = 0;
return; return;
} }
...@@ -304,11 +317,10 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev, ...@@ -304,11 +317,10 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,
struct ethtool_stats __always_unused *stats, struct ethtool_stats __always_unused *stats,
u64 *data) u64 *data)
{ {
const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64);
struct fm10k_intfc *interface = netdev_priv(netdev); struct fm10k_intfc *interface = netdev_priv(netdev);
struct fm10k_iov_data *iov_data = interface->iov_data; struct fm10k_iov_data *iov_data = interface->iov_data;
struct net_device_stats *net_stats = &netdev->stats; struct net_device_stats *net_stats = &netdev->stats;
int i, j; int i;
fm10k_update_stats(interface); fm10k_update_stats(interface);
...@@ -347,19 +359,16 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev, ...@@ -347,19 +359,16 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,
for (i = 0; i < interface->hw.mac.max_queues; i++) { for (i = 0; i < interface->hw.mac.max_queues; i++) {
struct fm10k_ring *ring; struct fm10k_ring *ring;
u64 *queue_stat;
ring = interface->tx_ring[i]; ring = interface->tx_ring[i];
if (ring) fm10k_add_ethtool_stats(&data, ring,
queue_stat = (u64 *)&ring->stats; fm10k_gstrings_queue_stats,
for (j = 0; j < stat_count; j++) FM10K_QUEUE_STATS_LEN);
*(data++) = ring ? queue_stat[j] : 0;
ring = interface->rx_ring[i]; ring = interface->rx_ring[i];
if (ring) fm10k_add_ethtool_stats(&data, ring,
queue_stat = (u64 *)&ring->stats; fm10k_gstrings_queue_stats,
for (j = 0; j < stat_count; j++) FM10K_QUEUE_STATS_LEN);
*(data++) = ring ? queue_stat[j] : 0;
} }
} }
......
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