Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751656AbdH1TVs (ORCPT ); Mon, 28 Aug 2017 15:21:48 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:36378 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236AbdH1TVk (ORCPT ); Mon, 28 Aug 2017 15:21:40 -0400 From: Vivien Didelot To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Florian Fainelli , Andrew Lunn , Egil Hjelmeland , John Crispin , Woojung Huh , Sean Wang , Nikita Yushchenko , Chris Healy , Vivien Didelot Subject: [PATCH net-next v2 06/10] net: dsa: debugfs: add port fdb Date: Mon, 28 Aug 2017 15:17:44 -0400 Message-Id: <20170828191748.19492-7-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: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2097 Lines: 74 Add a debug filesystem "fdb" entry to query a port's hardware FDB entries through the .port_fdb_dump switch operation. This is really convenient to query directly the hardware or inspect DSA or CPU links, since these ports are not exposed to userspace. # cat port1/fdb vid 0 12:34:56:78:90:ab unicast static Signed-off-by: Vivien Didelot Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn --- net/dsa/debugfs.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/net/dsa/debugfs.c b/net/dsa/debugfs.c index 7b299c9d9892..59c09a67bc23 100644 --- a/net/dsa/debugfs.c +++ b/net/dsa/debugfs.c @@ -10,6 +10,7 @@ */ #include +#include #include #include "dsa_priv.h" @@ -109,6 +110,31 @@ static int dsa_debugfs_create_file(struct dsa_switch *ds, struct dentry *dir, return 0; } +static int dsa_debugfs_fdb_dump_cb(const unsigned char *addr, u16 vid, + bool is_static, void *data) +{ + struct seq_file *seq = data; + + seq_printf(seq, "vid %d %pM %s %s\n", vid, addr, + is_unicast_ether_addr(addr) ? "unicast" : "multicast", + is_static ? "static" : "dynamic"); + + return 0; +} + +static int dsa_debugfs_fdb_read(struct dsa_switch *ds, int id, + struct seq_file *seq) +{ + if (!ds->ops->port_fdb_dump) + return -EOPNOTSUPP; + + return ds->ops->port_fdb_dump(ds, id, dsa_debugfs_fdb_dump_cb, seq); +} + +static const struct dsa_debugfs_ops dsa_debugfs_fdb_ops = { + .read = dsa_debugfs_fdb_read, +}; + static void dsa_debugfs_regs_read_count(struct dsa_switch *ds, int id, struct seq_file *seq, int count) { @@ -222,6 +248,11 @@ static int dsa_debugfs_create_port(struct dsa_switch *ds, int port) if (IS_ERR_OR_NULL(dir)) return -EFAULT; + err = dsa_debugfs_create_file(ds, dir, "fdb", port, + &dsa_debugfs_fdb_ops); + if (err) + return err; + err = dsa_debugfs_create_file(ds, dir, "regs", port, &dsa_debugfs_regs_ops); if (err) -- 2.14.1