Commit d2e0721b 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. Skip handling of the per-queue stats as these will be
reworked in a following patch.
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 c8ed563b
...@@ -153,57 +153,51 @@ static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = { ...@@ -153,57 +153,51 @@ static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = {
"debug-statistics", "debug-statistics",
}; };
static void fm10k_add_stat_strings(char **p, const char *prefix,
const struct fm10k_stats stats[],
const unsigned int size)
{
unsigned int i;
for (i = 0; i < size; i++) {
snprintf(*p, ETH_GSTRING_LEN, "%s%s",
prefix, stats[i].stat_string);
*p += ETH_GSTRING_LEN;
}
}
static void fm10k_get_stat_strings(struct net_device *dev, u8 *data) static void fm10k_get_stat_strings(struct net_device *dev, u8 *data)
{ {
struct fm10k_intfc *interface = netdev_priv(dev); struct fm10k_intfc *interface = netdev_priv(dev);
struct fm10k_iov_data *iov_data = interface->iov_data; struct fm10k_iov_data *iov_data = interface->iov_data;
char *p = (char *)data; char *p = (char *)data;
unsigned int i; unsigned int i;
unsigned int j;
for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) { fm10k_add_stat_strings(&p, "", fm10k_gstrings_net_stats,
memcpy(p, fm10k_gstrings_net_stats[i].stat_string, FM10K_NETDEV_STATS_LEN);
ETH_GSTRING_LEN);
p += ETH_GSTRING_LEN;
}
for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) { fm10k_add_stat_strings(&p, "", fm10k_gstrings_global_stats,
memcpy(p, fm10k_gstrings_global_stats[i].stat_string, FM10K_GLOBAL_STATS_LEN);
ETH_GSTRING_LEN);
p += ETH_GSTRING_LEN;
}
if (interface->flags & FM10K_FLAG_DEBUG_STATS) { if (interface->flags & FM10K_FLAG_DEBUG_STATS)
for (i = 0; i < FM10K_DEBUG_STATS_LEN; i++) { fm10k_add_stat_strings(&p, "", fm10k_gstrings_debug_stats,
memcpy(p, fm10k_gstrings_debug_stats[i].stat_string, FM10K_DEBUG_STATS_LEN);
ETH_GSTRING_LEN);
p += ETH_GSTRING_LEN;
}
}
for (i = 0; i < FM10K_MBX_STATS_LEN; i++) { fm10k_add_stat_strings(&p, "", fm10k_gstrings_mbx_stats,
memcpy(p, fm10k_gstrings_mbx_stats[i].stat_string, FM10K_MBX_STATS_LEN);
ETH_GSTRING_LEN);
p += ETH_GSTRING_LEN;
}
if (interface->hw.mac.type != fm10k_mac_vf) { if (interface->hw.mac.type != fm10k_mac_vf)
for (i = 0; i < FM10K_PF_STATS_LEN; i++) { fm10k_add_stat_strings(&p, "", fm10k_gstrings_pf_stats,
memcpy(p, fm10k_gstrings_pf_stats[i].stat_string, FM10K_PF_STATS_LEN);
ETH_GSTRING_LEN);
p += ETH_GSTRING_LEN;
}
}
if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) { if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) {
for (i = 0; i < iov_data->num_vfs; i++) { for (i = 0; i < iov_data->num_vfs; i++) {
for (j = 0; j < FM10K_MBX_STATS_LEN; j++) { char prefix[ETH_GSTRING_LEN];
snprintf(p,
ETH_GSTRING_LEN, snprintf(prefix, ETH_GSTRING_LEN, "vf_%u_", i);
"vf_%u_%s", i, fm10k_add_stat_strings(&p, prefix,
fm10k_gstrings_mbx_stats[j].stat_string); fm10k_gstrings_mbx_stats,
p += ETH_GSTRING_LEN; FM10K_MBX_STATS_LEN);
}
} }
} }
...@@ -271,6 +265,41 @@ static int fm10k_get_sset_count(struct net_device *dev, int sset) ...@@ -271,6 +265,41 @@ static int fm10k_get_sset_count(struct net_device *dev, int sset)
} }
} }
static void fm10k_add_ethtool_stats(u64 **data, void *pointer,
const struct fm10k_stats stats[],
const unsigned int size)
{
unsigned int i;
char *p;
/* simply skip forward if we were not given a valid pointer */
if (!pointer) {
*data += size;
return;
}
for (i = 0; i < size; i++) {
p = (char *)pointer + stats[i].stat_offset;
switch (stats[i].sizeof_stat) {
case sizeof(u64):
*((*data)++) = *(u64 *)p;
break;
case sizeof(u32):
*((*data)++) = *(u32 *)p;
break;
case sizeof(u16):
*((*data)++) = *(u16 *)p;
break;
case sizeof(u8):
*((*data)++) = *(u8 *)p;
break;
default:
*((*data)++) = 0;
}
}
}
static void fm10k_get_ethtool_stats(struct net_device *netdev, 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)
...@@ -279,47 +308,29 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev, ...@@ -279,47 +308,29 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,
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;
char *p;
int i, j; int i, j;
fm10k_update_stats(interface); fm10k_update_stats(interface);
for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) { fm10k_add_ethtool_stats(&data, net_stats, fm10k_gstrings_net_stats,
p = (char *)net_stats + fm10k_gstrings_net_stats[i].stat_offset; FM10K_NETDEV_STATS_LEN);
*(data++) = (fm10k_gstrings_net_stats[i].sizeof_stat ==
sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
}
for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) { fm10k_add_ethtool_stats(&data, interface, fm10k_gstrings_global_stats,
p = (char *)interface + FM10K_GLOBAL_STATS_LEN);
fm10k_gstrings_global_stats[i].stat_offset;
*(data++) = (fm10k_gstrings_global_stats[i].sizeof_stat ==
sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
}
if (interface->flags & FM10K_FLAG_DEBUG_STATS) { if (interface->flags & FM10K_FLAG_DEBUG_STATS)
for (i = 0; i < FM10K_DEBUG_STATS_LEN; i++) { fm10k_add_ethtool_stats(&data, interface,
p = (char *)interface + fm10k_gstrings_debug_stats,
fm10k_gstrings_debug_stats[i].stat_offset; FM10K_DEBUG_STATS_LEN);
*(data++) = (fm10k_gstrings_debug_stats[i].sizeof_stat ==
sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
}
}
for (i = 0; i < FM10K_MBX_STATS_LEN; i++) { fm10k_add_ethtool_stats(&data, &interface->hw.mbx,
p = (char *)&interface->hw.mbx + fm10k_gstrings_mbx_stats,
fm10k_gstrings_mbx_stats[i].stat_offset; FM10K_MBX_STATS_LEN);
*(data++) = (fm10k_gstrings_mbx_stats[i].sizeof_stat ==
sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
}
if (interface->hw.mac.type != fm10k_mac_vf) { if (interface->hw.mac.type != fm10k_mac_vf) {
for (i = 0; i < FM10K_PF_STATS_LEN; i++) { fm10k_add_ethtool_stats(&data, interface,
p = (char *)interface + fm10k_gstrings_pf_stats,
fm10k_gstrings_pf_stats[i].stat_offset; FM10K_PF_STATS_LEN);
*(data++) = (fm10k_gstrings_pf_stats[i].sizeof_stat ==
sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
}
} }
if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) { if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) {
...@@ -328,18 +339,9 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev, ...@@ -328,18 +339,9 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,
vf_info = &iov_data->vf_info[i]; vf_info = &iov_data->vf_info[i];
/* skip stats if we don't have a vf info */ fm10k_add_ethtool_stats(&data, &vf_info->mbx,
if (!vf_info) { fm10k_gstrings_mbx_stats,
data += FM10K_MBX_STATS_LEN; FM10K_MBX_STATS_LEN);
continue;
}
for (j = 0; j < FM10K_MBX_STATS_LEN; j++) {
p = (char *)&vf_info->mbx +
fm10k_gstrings_mbx_stats[j].stat_offset;
*(data++) = (fm10k_gstrings_mbx_stats[j].sizeof_stat ==
sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
}
} }
} }
......
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