From patchwork Fri Apr 15 10:17:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Westgaard Ry X-Patchwork-Id: 8846931 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6551BC0553 for ; Fri, 15 Apr 2016 10:18:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6F5EC20204 for ; Fri, 15 Apr 2016 10:18:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65FEB202E9 for ; Fri, 15 Apr 2016 10:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751415AbcDOKSd (ORCPT ); Fri, 15 Apr 2016 06:18:33 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:42309 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750920AbcDOKSb (ORCPT ); Fri, 15 Apr 2016 06:18:31 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u3FAIHKw001165 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Apr 2016 10:18:17 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u3FAIHhs005414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Apr 2016 10:18:17 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u3FAIGoS020856; Fri, 15 Apr 2016 10:18:16 GMT Received: from lab07.no.oracle.com (/10.172.144.17) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Apr 2016 03:18:15 -0700 From: Hans Westgaard Ry Cc: Hans Westgaard Ry , Doug Ledford , Sean Hefty , Hal Rosenstock , Or Gerlitz , Santosh Shilimkar , Yuval Shaia , linux-rdma@vger.kernel.org (open list:INFINIBAND SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] IB/ipoib: Add readout of statistics using ethtool Date: Fri, 15 Apr 2016 12:17:48 +0200 Message-Id: <1460715468-16235-1-git-send-email-hans.westgaard.ry@oracle.com> X-Mailer: git-send-email 2.4.3 X-Source-IP: userv0021.oracle.com [156.151.31.71] To: unlisted-recipients:; (no To-header on input) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP IPoIB collects statistics of traffic including number of packets sent/received, number of bytes transferred, and certain errors. This patch makes these statistics available to be queried by ethtool. Signed-off-by: Hans Westgaard Ry Reviewed-by: Yuval Shaia Reviewed-by: Santosh Shilimkar Tested-by: Yuval Shaia Acked-by: Erez Shitrit --- drivers/infiniband/ulp/ipoib/ipoib_ethtool.c | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c b/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c index a53fa5f..52a1f30 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c @@ -36,6 +36,31 @@ #include "ipoib.h" +struct ipoib_stats { + char stat_string[ETH_GSTRING_LEN]; + int stat_offset; +}; + + +#define IPOIB_NETDEV_STAT(str, m) { \ + .stat_string = str, \ + .stat_offset = offsetof(struct rtnl_link_stats64, m) } + + + +static const struct ipoib_stats ipoib_gstrings_stats[] = { + IPOIB_NETDEV_STAT("rx_packets", rx_packets), + IPOIB_NETDEV_STAT("tx_packets", tx_packets), + IPOIB_NETDEV_STAT("rx_bytes", rx_bytes), + IPOIB_NETDEV_STAT("tx_bytes", tx_bytes), + IPOIB_NETDEV_STAT("tx_errors", tx_errors), + IPOIB_NETDEV_STAT("rx_dropped", rx_dropped), + IPOIB_NETDEV_STAT("tx_dropped", tx_dropped) +}; + +#define IPOIB_GLOBAL_STATS_LEN ARRAY_SIZE(ipoib_gstrings_stats) + + static void ipoib_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) { @@ -92,11 +117,56 @@ static int ipoib_set_coalesce(struct net_device *dev, return 0; } +static void ipoib_get_ethtool_stats(struct net_device *dev, + struct ethtool_stats __always_unused *stats, + u64 *data) +{ + int i; + struct net_device_stats *net_stats = &dev->stats; + u8 *p = (u8 *)net_stats; + + for (i = 0; i < IPOIB_GLOBAL_STATS_LEN; i++) + data[i] = *(u64 *)(p + ipoib_gstrings_stats[i].stat_offset); + +} +static void ipoib_get_strings(struct net_device __always_unused *dev, + u32 stringset, u8 *data) +{ + u8 *p = data; + int i; + + switch (stringset) { + case ETH_SS_TEST: + break; + case ETH_SS_STATS: + for (i = 0; i < IPOIB_GLOBAL_STATS_LEN; i++) { + memcpy(p, ipoib_gstrings_stats[i].stat_string, + ETH_GSTRING_LEN); + p += ETH_GSTRING_LEN; + } + break; + } +} +static int ipoib_get_sset_count(struct net_device __always_unused *dev, + int sset) +{ + switch (sset) { + case ETH_SS_TEST: + return -EOPNOTSUPP; + case ETH_SS_STATS: + return IPOIB_GLOBAL_STATS_LEN; + default: + return -EOPNOTSUPP; + } +} static const struct ethtool_ops ipoib_ethtool_ops = { .get_drvinfo = ipoib_get_drvinfo, .get_coalesce = ipoib_get_coalesce, .set_coalesce = ipoib_set_coalesce, + .get_strings = ipoib_get_strings, + .get_ethtool_stats = ipoib_get_ethtool_stats, + .get_sset_count = ipoib_get_sset_count, }; void ipoib_set_ethtool_ops(struct net_device *dev)