Skip to content

Commit 8491000

Browse files
IronShendavem330
authored andcommitted
net: hns3: Add packet statistics of netdev
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 <[email protected]> Signed-off-by: Peng Li <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b59f558 commit 8491000

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,41 @@ static const struct hns3_stats hns3_rxq_stats[] = {
5959

6060
#define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
6161

62+
/* netdev stats */
63+
#define HNS3_NETDEV_STAT(_string, _member) { \
64+
.stats_string = _string, \
65+
.stats_offset = offsetof(struct rtnl_link_stats64, _member) \
66+
}
67+
68+
static const struct hns3_stats hns3_netdev_stats[] = {
69+
/* Rx per-queue statistics */
70+
HNS3_NETDEV_STAT("rx_packets", rx_packets),
71+
HNS3_NETDEV_STAT("tx_packets", tx_packets),
72+
HNS3_NETDEV_STAT("rx_bytes", rx_bytes),
73+
HNS3_NETDEV_STAT("tx_bytes", tx_bytes),
74+
HNS3_NETDEV_STAT("rx_errors", rx_errors),
75+
HNS3_NETDEV_STAT("tx_errors", tx_errors),
76+
HNS3_NETDEV_STAT("rx_dropped", rx_dropped),
77+
HNS3_NETDEV_STAT("tx_dropped", tx_dropped),
78+
HNS3_NETDEV_STAT("multicast", multicast),
79+
HNS3_NETDEV_STAT("collisions", collisions),
80+
HNS3_NETDEV_STAT("rx_length_errors", rx_length_errors),
81+
HNS3_NETDEV_STAT("rx_over_errors", rx_over_errors),
82+
HNS3_NETDEV_STAT("rx_crc_errors", rx_crc_errors),
83+
HNS3_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
84+
HNS3_NETDEV_STAT("rx_fifo_errors", rx_fifo_errors),
85+
HNS3_NETDEV_STAT("rx_missed_errors", rx_missed_errors),
86+
HNS3_NETDEV_STAT("tx_aborted_errors", tx_aborted_errors),
87+
HNS3_NETDEV_STAT("tx_carrier_errors", tx_carrier_errors),
88+
HNS3_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
89+
HNS3_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
90+
HNS3_NETDEV_STAT("tx_window_errors", tx_window_errors),
91+
HNS3_NETDEV_STAT("rx_compressed", rx_compressed),
92+
HNS3_NETDEV_STAT("tx_compressed", tx_compressed),
93+
};
94+
95+
#define HNS3_NETDEV_STATS_COUNT ARRAY_SIZE(hns3_netdev_stats)
96+
6297
#define HNS3_SELF_TEST_TPYE_NUM 1
6398
#define HNS3_NIC_LB_TEST_PKT_NUM 1
6499
#define HNS3_NIC_LB_TEST_RING_ID 0
@@ -431,6 +466,27 @@ static u8 *hns3_get_strings_tqps(struct hnae3_handle *handle, u8 *data)
431466
return data;
432467
}
433468

469+
static u8 *hns3_netdev_stats_get_strings(u8 *data)
470+
{
471+
int i;
472+
473+
/* get strings for netdev */
474+
for (i = 0; i < HNS3_NETDEV_STATS_COUNT; i++) {
475+
snprintf(data, ETH_GSTRING_LEN,
476+
hns3_netdev_stats[i].stats_string);
477+
data += ETH_GSTRING_LEN;
478+
}
479+
480+
snprintf(data, ETH_GSTRING_LEN, "netdev_rx_dropped");
481+
data += ETH_GSTRING_LEN;
482+
snprintf(data, ETH_GSTRING_LEN, "netdev_tx_dropped");
483+
data += ETH_GSTRING_LEN;
484+
snprintf(data, ETH_GSTRING_LEN, "netdev_tx_timeout");
485+
data += ETH_GSTRING_LEN;
486+
487+
return data;
488+
}
489+
434490
static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
435491
{
436492
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)
442498

443499
switch (stringset) {
444500
case ETH_SS_STATS:
501+
buff = hns3_netdev_stats_get_strings(buff);
445502
buff = hns3_get_strings_tqps(h, buff);
446503
h->ae_algo->ops->get_strings(h, stringset, (u8 *)buff);
447504
break;
@@ -480,6 +537,27 @@ static u64 *hns3_get_stats_tqps(struct hnae3_handle *handle, u64 *data)
480537
return data;
481538
}
482539

540+
static u64 *hns3_get_netdev_stats(struct net_device *netdev, u64 *data)
541+
{
542+
struct hns3_nic_priv *priv = netdev_priv(netdev);
543+
const struct rtnl_link_stats64 *net_stats;
544+
struct rtnl_link_stats64 temp;
545+
u8 *stat;
546+
int i;
547+
548+
net_stats = dev_get_stats(netdev, &temp);
549+
for (i = 0; i < HNS3_NETDEV_STATS_COUNT; i++) {
550+
stat = (u8 *)net_stats + hns3_netdev_stats[i].stats_offset;
551+
*data++ = *(u64 *)stat;
552+
}
553+
554+
*data++ = netdev->rx_dropped.counter;
555+
*data++ = netdev->tx_dropped.counter;
556+
*data++ = priv->tx_timeout_count;
557+
558+
return data;
559+
}
560+
483561
/* hns3_get_stats - get detail statistics.
484562
* @netdev: net device
485563
* @stats: statistics info.
@@ -496,7 +574,7 @@ static void hns3_get_stats(struct net_device *netdev,
496574
return;
497575
}
498576

499-
h->ae_algo->ops->update_stats(h, &netdev->stats);
577+
p = hns3_get_netdev_stats(netdev, p);
500578

501579
/* get per-queue stats */
502580
p = hns3_get_stats_tqps(h, p);

0 commit comments

Comments
 (0)