netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peng Li <lipeng321@huawei.com>
To: <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linuxarm@huawei.com>, <salil.mehta@huawei.com>,
	<lipeng321@huawei.com>
Subject: [PATCH net-next 12/20] net: hns3: Add packet statistics of netdev
Date: Fri, 5 Jan 2018 18:18:16 +0800	[thread overview]
Message-ID: <1515147504-86802-13-git-send-email-lipeng321@huawei.com> (raw)
In-Reply-To: <1515147504-86802-1-git-send-email-lipeng321@huawei.com>

From: Jian Shen <shenjian15@huawei.com>

Add packet statistics of netdev for ethtool -S, in
order to show the statistics data for current net
device.

Remove update_stats() calling because it has been
completed in hns3_get_netdev_stats().

Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 80 +++++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index d3cb3ec..1e8fac3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -59,6 +59,41 @@ struct hns3_stats {
 
 #define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
 
+/* netdev stats */
+#define HNS3_NETDEV_STAT(_string, _member)	{			\
+	.stats_string = _string,					\
+	.stats_offset = offsetof(struct rtnl_link_stats64, _member)	\
+}
+
+static const struct hns3_stats hns3_netdev_stats[] = {
+	/* Rx per-queue statistics */
+	HNS3_NETDEV_STAT("rx_packets", rx_packets),
+	HNS3_NETDEV_STAT("tx_packets", tx_packets),
+	HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
+	HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
+	HNS3_NETDEV_STAT("rx_errors", rx_errors),
+	HNS3_NETDEV_STAT("tx_errors", tx_errors),
+	HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
+	HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
+	HNS3_NETDEV_STAT("multicast", multicast),
+	HNS3_NETDEV_STAT("collisions", collisions),
+	HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
+	HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
+	HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
+	HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
+	HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
+	HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
+	HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
+	HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
+	HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
+	HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
+	HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
+	HNS3_NETDEV_STAT("rx_compressed", rx_compressed),
+	HNS3_NETDEV_STAT("tx_compressed", tx_compressed),
+};
+
+#define HNS3_NETDEV_STATS_COUNT ARRAY_SIZE(hns3_netdev_stats)
+
 #define HNS3_SELF_TEST_TPYE_NUM		1
 #define HNS3_NIC_LB_TEST_PKT_NUM	1
 #define HNS3_NIC_LB_TEST_RING_ID	0
@@ -431,6 +466,27 @@ static u8 *hns3_get_strings_tqps(struct hnae3_handle *handle, u8 *data)
 	return data;
 }
 
+static u8 *hns3_netdev_stats_get_strings(u8 *data)
+{
+	int i;
+
+	/* get strings for netdev */
+	for (i = 0; i < HNS3_NETDEV_STATS_COUNT; i++) {
+		snprintf(data, ETH_GSTRING_LEN,
+			 hns3_netdev_stats[i].stats_string);
+		data += ETH_GSTRING_LEN;
+	}
+
+	snprintf(data, ETH_GSTRING_LEN, "netdev_rx_dropped");
+	data += ETH_GSTRING_LEN;
+	snprintf(data, ETH_GSTRING_LEN, "netdev_tx_dropped");
+	data += ETH_GSTRING_LEN;
+	snprintf(data, ETH_GSTRING_LEN, "netdev_tx_timeout");
+	data += ETH_GSTRING_LEN;
+
+	return data;
+}
+
 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 {
 	struct hnae3_handle *h = hns3_get_handle(netdev);
@@ -442,6 +498,7 @@ static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 
 	switch (stringset) {
 	case ETH_SS_STATS:
+		buff = hns3_netdev_stats_get_strings(buff);
 		buff = hns3_get_strings_tqps(h, buff);
 		h->ae_algo->ops->get_strings(h, stringset, (u8 *)buff);
 		break;
@@ -480,6 +537,27 @@ static u64 *hns3_get_stats_tqps(struct hnae3_handle *handle, u64 *data)
 	return data;
 }
 
+static u64 *hns3_get_netdev_stats(struct net_device *netdev, u64 *data)
+{
+	struct hns3_nic_priv *priv = netdev_priv(netdev);
+	const struct rtnl_link_stats64 *net_stats;
+	struct rtnl_link_stats64 temp;
+	u8 *stat;
+	int i;
+
+	net_stats = dev_get_stats(netdev, &temp);
+	for (i = 0; i < HNS3_NETDEV_STATS_COUNT; i++) {
+		stat = (u8 *)net_stats + hns3_netdev_stats[i].stats_offset;
+		*data++ = *(u64 *)stat;
+	}
+
+	*data++ = netdev->rx_dropped.counter;
+	*data++ = netdev->tx_dropped.counter;
+	*data++ = priv->tx_timeout_count;
+
+	return data;
+}
+
 /* hns3_get_stats - get detail statistics.
  * @netdev: net device
  * @stats: statistics info.
@@ -496,7 +574,7 @@ static void hns3_get_stats(struct net_device *netdev,
 		return;
 	}
 
-	h->ae_algo->ops->update_stats(h, &netdev->stats);
+	p = hns3_get_netdev_stats(netdev, p);
 
 	/* get per-queue stats */
 	p = hns3_get_stats_tqps(h, p);
-- 
1.9.1

  parent reply	other threads:[~2018-01-05 10:18 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-05 10:18 [PATCH net-next 00/20] add some new features and fix some bugs for HNS3 driver Peng Li
2018-01-05 10:18 ` [PATCH net-next 01/20] net: hns3: Add ethtool interface for vlan filter Peng Li
2018-01-05 10:18 ` [PATCH net-next 02/20] net: hns3: Disable VFs change rxvlan offload status Peng Li
2018-01-05 10:18 ` [PATCH net-next 03/20] net: hns3: Unify the strings display of packet statistics Peng Li
2018-01-05 10:18 ` [PATCH net-next 04/20] net: hns3: Fix spelling errors Peng Li
2018-01-05 10:18 ` [PATCH net-next 05/20] net: hns3: Remove repeat statistic of rx_errors Peng Li
2018-01-05 10:18 ` [PATCH net-next 06/20] net: hns3: Modify the update period of packet statistics Peng Li
2018-01-05 14:54   ` Andrew Lunn
2018-01-06  6:23     ` lipeng (Y)
2018-01-06 15:49       ` Andrew Lunn
2018-01-05 10:18 ` [PATCH net-next 07/20] net: hns3: Mask the packet statistics query when NIC is down Peng Li
2018-01-05 10:18 ` [PATCH net-next 08/20] net: hns3: Fix an error of total drop packet statistics Peng Li
2018-01-05 10:18 ` [PATCH net-next 09/20] net: hns3: Fix a loop index error of tqp statistics query Peng Li
2018-01-05 10:18 ` [PATCH net-next 10/20] net: hns3: Fix an error macro definition of HNS3_TQP_STAT Peng Li
2018-01-05 10:18 ` [PATCH net-next 11/20] net: hns3: Remove a useless member of struct hns3_stats Peng Li
2018-01-05 10:18 ` Peng Li [this message]
2018-01-08 20:04   ` [PATCH net-next 12/20] net: hns3: Add packet statistics of netdev Jakub Kicinski
2018-01-09  1:39     ` David Miller
2018-01-09  1:46       ` Jakub Kicinski
2018-01-09  1:50         ` Jakub Kicinski
2018-01-09  1:54           ` David Miller
2018-01-09  2:48             ` lipeng (Y)
2018-01-09  3:06               ` David Miller
2018-01-09  3:27                 ` lipeng (Y)
2018-01-05 10:18 ` [PATCH net-next 13/20] net: hns3: Fix a response data read error of tqp statistics query Peng Li
2018-01-05 10:18 ` [PATCH net-next 14/20] net: hns3: fix for updating fc_mode_last_time Peng Li
2018-01-05 10:18 ` [PATCH net-next 15/20] net: hns3: fix for setting MTU Peng Li
2018-01-05 10:18 ` [PATCH net-next 16/20] net: hns3: fix for changing MTU Peng Li
2018-01-05 10:18 ` [PATCH net-next 17/20] net: hns3: add MTU initialization for hardware Peng Li
2018-01-05 10:18 ` [PATCH net-next 18/20] net: hns3: fix for not setting pause parameters Peng Li
2018-01-05 10:18 ` [PATCH net-next 19/20] net: hns3: remove redundant semicolon Peng Li
2018-01-05 10:18 ` [PATCH net-next 20/20] net: hns3: Add more packet size statisctics Peng Li
2018-01-08 19:08 ` [PATCH net-next 00/20] add some new features and fix some bugs for HNS3 driver 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=1515147504-86802-13-git-send-email-lipeng321@huawei.com \
    --to=lipeng321@huawei.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.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).