{"id":806739,"url":"http://patchwork.ozlabs.org/api/1.0/patches/806739/?format=json","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.0/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20170828191748.19492-5-vivien.didelot@savoirfairelinux.com>","date":"2017-08-28T19:17:42","name":"[net-next,v2,04/10] net: dsa: debugfs: add port stats","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":true,"hash":"4303b0771a12ba4efd634ca85c2c1d2aa715ae75","submitter":{"id":15889,"url":"http://patchwork.ozlabs.org/api/1.0/people/15889/?format=json","name":"Vivien Didelot","email":"vivien.didelot@savoirfairelinux.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/1.0/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170828191748.19492-5-vivien.didelot@savoirfairelinux.com/mbox/","series":[{"id":246,"url":"http://patchwork.ozlabs.org/api/1.0/series/246/?format=json","date":"2017-08-28T19:17:41","name":"net: dsa: add generic debugfs interface","version":2,"mbox":"http://patchwork.ozlabs.org/series/246/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/806739/checks/","tags":{},"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xh1zv2sqFz9sNq\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 29 Aug 2017 05:29:31 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751429AbdH1TVo (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 28 Aug 2017 15:21:44 -0400","from mail.savoirfairelinux.com ([208.88.110.44]:36334 \"EHLO\n\tmail.savoirfairelinux.com\" rhost-flags-OK-OK-OK-OK) by\n\tvger.kernel.org with ESMTP id S1751194AbdH1TVk (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Mon, 28 Aug 2017 15:21:40 -0400","from localhost (localhost [127.0.0.1])\n\tby mail.savoirfairelinux.com (Postfix) with ESMTP id 5E7839C27C0;\n\tMon, 28 Aug 2017 15:21:39 -0400 (EDT)","from mail.savoirfairelinux.com ([127.0.0.1])\n\tby localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new,\n\tport 10032)\n\twith ESMTP id zFGR7Tf6Cb2s; Mon, 28 Aug 2017 15:21:38 -0400 (EDT)","from localhost (localhost [127.0.0.1])\n\tby mail.savoirfairelinux.com (Postfix) with ESMTP id DB7379C24B3;\n\tMon, 28 Aug 2017 15:21:37 -0400 (EDT)","from mail.savoirfairelinux.com ([127.0.0.1])\n\tby localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new,\n\tport 10026)\n\twith ESMTP id x4KKdgU3ZtrZ; Mon, 28 Aug 2017 15:21:37 -0400 (EDT)","from weeman.mtl.sfl (unknown [192.168.50.91])\n\tby mail.savoirfairelinux.com (Postfix) with ESMTPSA id 8930E9C1C7E;\n\tMon, 28 Aug 2017 15:21:37 -0400 (EDT)"],"X-Virus-Scanned":"amavisd-new at mail.savoirfairelinux.com","From":"Vivien Didelot <vivien.didelot@savoirfairelinux.com>","To":"netdev@vger.kernel.org","Cc":"linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com,\n\t\"David S. Miller\" <davem@davemloft.net>,\n\tFlorian Fainelli <f.fainelli@gmail.com>, Andrew Lunn <andrew@lunn.ch>,\n\tEgil Hjelmeland <privat@egil-hjelmeland.no>,\n\tJohn Crispin <john@phrozen.org>, Woojung Huh <Woojung.Huh@microchip.com>,\n\tSean Wang <sean.wang@mediatek.com>,\n\tNikita Yushchenko <nikita.yoush@cogentembedded.com>,\n\tChris Healy <cphealy@gmail.com>,\n\tVivien Didelot <vivien.didelot@savoirfairelinux.com>","Subject":"[PATCH net-next v2 04/10] net: dsa: debugfs: add port stats","Date":"Mon, 28 Aug 2017 15:17:42 -0400","Message-Id":"<20170828191748.19492-5-vivien.didelot@savoirfairelinux.com>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":"<20170828191748.19492-1-vivien.didelot@savoirfairelinux.com>","References":"<20170828191748.19492-1-vivien.didelot@savoirfairelinux.com>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"Add a debug filesystem \"stats\" entry to query a port's hardware\nstatistics through the DSA switch .get_sset_count, .get_strings and\n.get_ethtool_stats operations.\n\nThis allows one to get statistics about DSA links interconnecting\nswitches, which is very convenient because this kind of port is not\nexposed to userspace.\n\nHere are the stats of a zii-rev-b DSA and CPU ports:\n\n    # pr -mt switch0/port{5,6}/stats\n    in_good_octets      : 0             in_good_octets      : 13824\n    in_bad_octets       : 0             in_bad_octets       : 0\n    in_unicast          : 0             in_unicast          : 0\n    in_broadcasts       : 0             in_broadcasts       : 216\n    in_multicasts       : 0             in_multicasts       : 0\n    in_pause            : 0             in_pause            : 0\n    in_undersize        : 0             in_undersize        : 0\n    in_fragments        : 0             in_fragments        : 0\n    in_oversize         : 0             in_oversize         : 0\n    in_jabber           : 0             in_jabber           : 0\n    in_rx_error         : 0             in_rx_error         : 0\n    in_fcs_error        : 0             in_fcs_error        : 0\n    out_octets          : 9216          out_octets          : 0\n    out_unicast         : 0             out_unicast         : 0\n    out_broadcasts      : 144           out_broadcasts      : 0\n    out_multicasts      : 0             out_multicasts      : 0\n    out_pause           : 0             out_pause           : 0\n    excessive           : 0             excessive           : 0\n    collisions          : 0             collisions          : 0\n    deferred            : 0             deferred            : 0\n    single              : 0             single              : 0\n    multiple            : 0             multiple            : 0\n    out_fcs_error       : 0             out_fcs_error       : 0\n    late                : 0             late                : 0\n    hist_64bytes        : 0             hist_64bytes        : 0\n    hist_65_127bytes    : 0             hist_65_127bytes    : 0\n    hist_128_255bytes   : 0             hist_128_255bytes   : 0\n    hist_256_511bytes   : 0             hist_256_511bytes   : 0\n    hist_512_1023bytes  : 0             hist_512_1023bytes  : 0\n    hist_1024_max_bytes : 0             hist_1024_max_bytes : 0\n    sw_in_discards      : 0             sw_in_discards      : 0\n    sw_in_filtered      : 0             sw_in_filtered      : 0\n    sw_out_filtered     : 0             sw_out_filtered     : 216\n\nSigned-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>\nReviewed-by: Florian Fainelli <f.fainelli@gmail.com>\nReviewed-by: Andrew Lunn <andrew@lunn.ch>\n---\n net/dsa/debugfs.c | 43 +++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 43 insertions(+)","diff":"diff --git a/net/dsa/debugfs.c b/net/dsa/debugfs.c\nindex 8a0e4311ff8c..997bbc8eb502 100644\n--- a/net/dsa/debugfs.c\n+++ b/net/dsa/debugfs.c\n@@ -109,6 +109,43 @@ static int dsa_debugfs_create_file(struct dsa_switch *ds, struct dentry *dir,\n \treturn 0;\n }\n \n+static void dsa_debugfs_stats_read_count(struct dsa_switch *ds, int id,\n+\t\t\t\t\t struct seq_file *seq, int count)\n+{\n+\tu8 strings[count * ETH_GSTRING_LEN];\n+\tu64 stats[count];\n+\tint i;\n+\n+\tds->ops->get_strings(ds, id, strings);\n+\tds->ops->get_ethtool_stats(ds, id, stats);\n+\n+\tfor (i = 0; i < count; i++)\n+\t\tseq_printf(seq, \"%-20s: %lld\\n\", strings + i * ETH_GSTRING_LEN,\n+\t\t\t   stats[i]);\n+}\n+\n+static int dsa_debugfs_stats_read(struct dsa_switch *ds, int id,\n+\t\t\t\t  struct seq_file *seq)\n+{\n+\tint count;\n+\n+\tif (!ds->ops->get_sset_count || !ds->ops->get_strings ||\n+\t    !ds->ops->get_ethtool_stats)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tcount = ds->ops->get_sset_count(ds);\n+\tif (count < 0)\n+\t\treturn count;\n+\n+\tdsa_debugfs_stats_read_count(ds, id, seq, count);\n+\n+\treturn 0;\n+}\n+\n+static const struct dsa_debugfs_ops dsa_debugfs_stats_ops = {\n+\t.read = dsa_debugfs_stats_read,\n+};\n+\n static int dsa_debugfs_tag_protocol_read(struct dsa_switch *ds, int id,\n \t\t\t\t\t struct seq_file *seq)\n {\n@@ -143,6 +180,7 @@ static int dsa_debugfs_create_port(struct dsa_switch *ds, int port)\n {\n \tstruct dentry *dir;\n \tchar name[32];\n+\tint err;\n \n \tsnprintf(name, sizeof(name), DSA_PORT_FMT, port);\n \n@@ -150,6 +188,11 @@ static int dsa_debugfs_create_port(struct dsa_switch *ds, int port)\n \tif (IS_ERR_OR_NULL(dir))\n \t\treturn -EFAULT;\n \n+\terr = dsa_debugfs_create_file(ds, dir, \"stats\", port,\n+\t\t\t\t      &dsa_debugfs_stats_ops);\n+\tif (err)\n+\t\treturn err;\n+\n \treturn 0;\n }\n \n","prefixes":["net-next","v2","04/10"]}