From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: Jacob Keller <jacob.e.keller@intel.com>,
netdev@vger.kernel.org, nhorman@redhat.com, sassmann@redhat.com,
jogreene@redhat.com, Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [net-next 01/17] fm10k: add helper functions to set strings and data for ethtool stats
Date: Wed, 20 Apr 2016 23:09:13 -0700 [thread overview]
Message-ID: <1461218969-68578-2-git-send-email-jeffrey.t.kirsher@intel.com> (raw)
In-Reply-To: <1461218969-68578-1-git-send-email-jeffrey.t.kirsher@intel.com>
From: Jacob Keller <jacob.e.keller@intel.com>
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: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Krishneil Singh <Krishneil.k.singh@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 59 ++++++++++++++----------
1 file changed, 34 insertions(+), 25 deletions(-)
diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
index a237487..f331966 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c
@@ -121,13 +121,22 @@ static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = {
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_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_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_QUEUE_STATS_LEN(_n) \
- ((_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
+#define FM10K_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_queue_stats)
#define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
FM10K_NETDEV_STATS_LEN + \
@@ -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++) {
- snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_packets", i);
- p += ETH_GSTRING_LEN;
- snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
- p += ETH_GSTRING_LEN;
- snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_packets", i);
- p += ETH_GSTRING_LEN;
- snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
- p += ETH_GSTRING_LEN;
+ char prefix[ETH_GSTRING_LEN];
+
+ snprintf(prefix, ETH_GSTRING_LEN, "tx_queue_%u_", i);
+ fm10k_add_stat_strings(&p, prefix,
+ fm10k_gstrings_queue_stats,
+ FM10K_QUEUE_STATS_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)
case ETH_SS_TEST:
return FM10K_TEST_LEN;
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)
stats_len += FM10K_PF_STATS_LEN;
@@ -272,9 +284,10 @@ static void fm10k_add_ethtool_stats(u64 **data, void *pointer,
unsigned int i;
char *p;
- /* simply skip forward if we were not given a valid 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;
}
@@ -304,11 +317,10 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,
struct ethtool_stats __always_unused *stats,
u64 *data)
{
- const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64);
struct fm10k_intfc *interface = netdev_priv(netdev);
struct fm10k_iov_data *iov_data = interface->iov_data;
struct net_device_stats *net_stats = &netdev->stats;
- int i, j;
+ int i;
fm10k_update_stats(interface);
@@ -347,19 +359,16 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,
for (i = 0; i < interface->hw.mac.max_queues; i++) {
struct fm10k_ring *ring;
- u64 *queue_stat;
ring = interface->tx_ring[i];
- if (ring)
- queue_stat = (u64 *)&ring->stats;
- for (j = 0; j < stat_count; j++)
- *(data++) = ring ? queue_stat[j] : 0;
+ fm10k_add_ethtool_stats(&data, ring,
+ fm10k_gstrings_queue_stats,
+ FM10K_QUEUE_STATS_LEN);
ring = interface->rx_ring[i];
- if (ring)
- queue_stat = (u64 *)&ring->stats;
- for (j = 0; j < stat_count; j++)
- *(data++) = ring ? queue_stat[j] : 0;
+ fm10k_add_ethtool_stats(&data, ring,
+ fm10k_gstrings_queue_stats,
+ FM10K_QUEUE_STATS_LEN);
}
}
--
2.5.5
next prev parent reply other threads:[~2016-04-21 6:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-21 6:09 [net-next 00/17][pull request] 100GbE Intel Wired LAN Driver Updates 2016-04-20 Jeff Kirsher
2016-04-21 6:09 ` Jeff Kirsher [this message]
2016-04-21 6:09 ` [net-next 02/17] fm10k: remove debug-statistics support Jeff Kirsher
2016-04-21 6:09 ` [net-next 03/17] fm10k: Add support for bulk Tx cleanup & cleanup boolean logic Jeff Kirsher
2016-04-21 6:09 ` [net-next 04/17] fm10k: use DRV_SUMMARY to reduce code duplication Jeff Kirsher
2016-04-21 6:09 ` [net-next 05/17] fm10k: prevent RCU issues during AER events Jeff Kirsher
2016-04-21 6:09 ` [net-next 06/17] fm10k: drop 1588 support Jeff Kirsher
2016-04-21 6:09 ` [net-next 07/17] fm10k: Fix multicast mode sync issues Jeff Kirsher
2016-04-21 6:09 ` [net-next 08/17] fm10k: correctly handle LPORT_MAP error Jeff Kirsher
2016-04-21 6:09 ` [net-next 09/17] fm10k: do not disable PCI device in fm10k_io_error_detected Jeff Kirsher
2016-04-21 6:09 ` [net-next 10/17] fm10k: fix documentation of fm10k_tlv_parse_attr Jeff Kirsher
2016-04-21 6:09 ` [net-next 11/17] fm10k: use 8bit notation instead of 10bit notation for diagram Jeff Kirsher
2016-04-21 6:09 ` [net-next 12/17] fm10k: use different name than FM10K_VLAN_CLEAR for override bit Jeff Kirsher
2016-04-21 6:09 ` [net-next 13/17] fm10k: update comment regarding reserved bits check Jeff Kirsher
2016-04-21 6:09 ` [net-next 14/17] fm10k: Reset multicast mode when deleting lport Jeff Kirsher
2016-04-21 6:09 ` [net-next 15/17] fm10k: fix possible null pointer deref after kcalloc Jeff Kirsher
2016-04-21 19:44 ` Keller, Jacob E
2016-04-21 19:47 ` David Miller
2016-04-21 19:48 ` Jeff Kirsher
2016-04-21 20:09 ` Keller, Jacob E
2016-04-21 6:09 ` [net-next 16/17] fm10k: consistently use Intel(R) for driver names Jeff Kirsher
2016-04-21 6:09 ` [net-next 17/17] fm10k: fix incorrect IPv6 extended header checksum Jeff Kirsher
2016-04-21 16:21 ` [net-next 00/17][pull request] 100GbE Intel Wired LAN Driver Updates 2016-04-20 David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461218969-68578-2-git-send-email-jeffrey.t.kirsher@intel.com \
--to=jeffrey.t.kirsher@intel.com \
--cc=davem@davemloft.net \
--cc=jacob.e.keller@intel.com \
--cc=jogreene@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=nhorman@redhat.com \
--cc=sassmann@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).