Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2826301pxb; Mon, 18 Oct 2021 02:44:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0zUK6w2OMdXPrqW5nIFRE072Mrxk3ZVfm7VeFue86cdVtnWQOofA2QpeRzWuP429/ZRxX X-Received: by 2002:a05:6402:35d1:: with SMTP id z17mr43115958edc.174.1634550241323; Mon, 18 Oct 2021 02:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634550241; cv=none; d=google.com; s=arc-20160816; b=b6nK6i8lxUJYFWpA2QHvbrRUDQrLp9vKGRB2uskH/DC4IUO5Uc53ZpugatJtf645Oi 6SOGotNvvWHTgcI1CiDVl6w9KXbx5A77FmPpSYG8v0d5pymW3vw0NfqHTD/lZomMTmo4 9MB36ffLb+KaWv3at9ToBEMuCSAKma4ZCP2HD4Ly+LmDljJ+aqOPmt0nGtmROaG1Ihd7 56LNENQbBqSTIGUryRSeBHbvbuusGB6rBbHDwPVFVfSNCEwivlzONEX/wPRG3Kc2osyH D0wXM0y870/vzuB44WD3+i73FNvwVP2HwZkxBfvJ7THe163U3dhMy4vGmdRfAxP0yCXd AIjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SYW9s3lVZC5aslSNOtbi0Ys8bvQWIz/CC1qr0VatBQ8=; b=LWKf5KxxxtREHq0t2idX7Jl0whGw13iRTbMNRfrf85XQuEyiwnlBlZYKUUOtgJCAMs qpFlRN7ejna3pR9vAbUj3AHC/+Old1O3j+u5YXGzTPpu8w7M8/IS4kD57Hcl5Xj5/fHK G/jyoRNdSNQIOnxYQdTLC1L6pPXiS2wz6qaeEifgZN+R8WpKUlrqSKg0wbowuevm0hq8 JDAXLt35xHD3kMNBnu+OtXnFfq27Ow1majOxTZro5PtMbgYo339KpusaPmKH1+5y58zX jHAVrUuDT1xzGq6Fsvwgx7qoN699l8qed55Q5x2jsMdSncKwILggsj+7Njss8expbd6c YpIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@pqrs.dk header.s=google header.b="K/82oRz+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l18si29308797ejo.688.2021.10.18.02.43.37; Mon, 18 Oct 2021 02:44:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@pqrs.dk header.s=google header.b="K/82oRz+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231521AbhJRJmx (ORCPT + 99 others); Mon, 18 Oct 2021 05:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231519AbhJRJmo (ORCPT ); Mon, 18 Oct 2021 05:42:44 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38882C061768 for ; Mon, 18 Oct 2021 02:40:32 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id w14so68282817edv.11 for ; Mon, 18 Oct 2021 02:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SYW9s3lVZC5aslSNOtbi0Ys8bvQWIz/CC1qr0VatBQ8=; b=K/82oRz+IhhAG5QFa/4yLJrsdh50lrTFay7dQvzxHBqF0tOcpUznQS19WaAYvP+5/W JFBusAse6+hlhZgjn9jKCQ7NP8C4HLVxzdhIH015eHPVx3ZVJ2XIsWtyK+HBWuJKzfKH ShaioUGFdMYt3nGnmD+e1RAg4vtfCnJA1VAV4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SYW9s3lVZC5aslSNOtbi0Ys8bvQWIz/CC1qr0VatBQ8=; b=j1RDhFFYXopvHZigq9zBPkDh6i6u9eHhmFKTnBID9ejJr+blSIM7mTMjc0jofuUPkZ xD2IOGuxzQIvRVOf3xSwaulrpE78lNZuIVbUBk2Fd5hz9ZLYCbFjceBBkjjN3tF5l9xJ yVx9V2eBBzKYuUg5aqdwpYZvDayyVlcHZlo7jTkWMtA0586J/SHQmdLwvTbCW3RcnqLd 6cI+E2xM3UbIg2eKQR7Rgv1NQGhI5H6ez+NXnNGi6g8Ef0KpBIr03p8oThhmtxp1d0TC AEzGCULrbkn4D4aludyDwdX0rR9y7znFEAs+mVIPLYcvhxHkvDXz1iE3OZIK/Ci999L7 mqyg== X-Gm-Message-State: AOAM532Qaj+wQLwWlTBuoAPEPOjzi24sQfAKSQ7auMdsLPYDwDajiuLW /it0A39ekSNA0vdFxTJuwmKEGw== X-Received: by 2002:a50:e041:: with SMTP id g1mr43184238edl.4.1634550030783; Mon, 18 Oct 2021 02:40:30 -0700 (PDT) Received: from capella.. ([80.208.66.147]) by smtp.gmail.com with ESMTPSA id z1sm10134566edc.68.2021.10.18.02.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 02:40:30 -0700 (PDT) From: =?UTF-8?q?Alvin=20=C5=A0ipraga?= To: Linus Walleij , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Rob Herring , Heiner Kallweit , Russell King Cc: arinc.unal@arinc9.com, =?UTF-8?q?Alvin=20=C5=A0ipraga?= , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 net-next 2/7] net: dsa: allow reporting of standard ethtool stats for slave devices Date: Mon, 18 Oct 2021 11:37:57 +0200 Message-Id: <20211018093804.3115191-3-alvin@pqrs.dk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211018093804.3115191-1-alvin@pqrs.dk> References: <20211018093804.3115191-1-alvin@pqrs.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alvin Šipraga Jakub pointed out that we have a new ethtool API for reporting device statistics in a standardized way, via .get_eth_{phy,mac,ctrl}_stats. Add a small amount of plumbing to allow DSA drivers to take advantage of this when exposing statistics. Suggested-by: Jakub Kicinski Signed-off-by: Alvin Šipraga --- v3 -> v4: no change v2 -> v3: this patch is new include/net/dsa.h | 6 ++++++ net/dsa/slave.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index d784e76113b8..8fefd58ced8f 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -645,6 +645,12 @@ struct dsa_switch_ops { int (*get_sset_count)(struct dsa_switch *ds, int port, int sset); void (*get_ethtool_phy_stats)(struct dsa_switch *ds, int port, uint64_t *data); + void (*get_eth_phy_stats)(struct dsa_switch *ds, int port, + struct ethtool_eth_phy_stats *phy_stats); + void (*get_eth_mac_stats)(struct dsa_switch *ds, int port, + struct ethtool_eth_mac_stats *mac_stats); + void (*get_eth_ctrl_stats)(struct dsa_switch *ds, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats); void (*get_stats64)(struct dsa_switch *ds, int port, struct rtnl_link_stats64 *s); void (*self_test)(struct dsa_switch *ds, int port, diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 11ec9e689589..499f8d18c76d 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -789,6 +789,37 @@ static int dsa_slave_get_sset_count(struct net_device *dev, int sset) return -EOPNOTSUPP; } +static void dsa_slave_get_eth_phy_stats(struct net_device *dev, + struct ethtool_eth_phy_stats *phy_stats) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + + if (ds->ops->get_eth_phy_stats) + ds->ops->get_eth_phy_stats(ds, dp->index, phy_stats); +} + +static void dsa_slave_get_eth_mac_stats(struct net_device *dev, + struct ethtool_eth_mac_stats *mac_stats) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + + if (ds->ops->get_eth_mac_stats) + ds->ops->get_eth_mac_stats(ds, dp->index, mac_stats); +} + +static void +dsa_slave_get_eth_ctrl_stats(struct net_device *dev, + struct ethtool_eth_ctrl_stats *ctrl_stats) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + + if (ds->ops->get_eth_ctrl_stats) + ds->ops->get_eth_ctrl_stats(ds, dp->index, ctrl_stats); +} + static void dsa_slave_net_selftest(struct net_device *ndev, struct ethtool_test *etest, u64 *buf) { @@ -1695,6 +1726,9 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = { .get_strings = dsa_slave_get_strings, .get_ethtool_stats = dsa_slave_get_ethtool_stats, .get_sset_count = dsa_slave_get_sset_count, + .get_eth_phy_stats = dsa_slave_get_eth_phy_stats, + .get_eth_mac_stats = dsa_slave_get_eth_mac_stats, + .get_eth_ctrl_stats = dsa_slave_get_eth_ctrl_stats, .set_wol = dsa_slave_set_wol, .get_wol = dsa_slave_get_wol, .set_eee = dsa_slave_set_eee, -- 2.32.0