All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com,
	"David S. Miller" <davem@davemloft.net>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Egil Hjelmeland <privat@egil-hjelmeland.no>,
	John Crispin <john@phrozen.org>,
	Woojung Huh <Woojung.Huh@microchip.com>,
	Sean Wang <sean.wang@mediatek.com>,
	Nikita Yushchenko <nikita.yoush@cogentembedded.com>,
	Chris Healy <cphealy@gmail.com>,
	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Subject: [PATCH net-next v2 05/10] net: dsa: debugfs: add port regs
Date: Mon, 28 Aug 2017 15:17:43 -0400	[thread overview]
Message-ID: <20170828191748.19492-6-vivien.didelot@savoirfairelinux.com> (raw)
In-Reply-To: <20170828191748.19492-1-vivien.didelot@savoirfairelinux.com>

Add a debug filesystem "regs" entry to query a port's hardware registers
through the .get_regs_len and .get_regs_len switch operations.

This is very convenient because it allows one to dump the registers of
DSA links, which are not exposed to userspace.

Here are the registers of a zii-rev-b CPU and DSA ports:

    # pr -mt switch0/port{5,6}/regs
     0: 4e07			     0: 4d04
     1: 403e			     1: 003d
     2: 0000			     2: 0000
     3: 3521			     3: 3521
     4: 0533			     4: 373f
     5: 8000			     5: 0000
     6: 005f			     6: 003f
     7: 002a			     7: 002a
     8: 2080			     8: 2080
     9: 0001			     9: 0001
    10: 0000			    10: 0000
    11: 0020			    11: 0000
    12: 0000			    12: 0000
    13: 0000			    13: 0000
    14: 0000			    14: 0000
    15: 9100			    15: dada
    16: 0000			    16: 0000
    17: 0000			    17: 0000
    18: 0000			    18: 0000
    19: 0000			    19: 00d8
    20: 0000			    20: 0000
    21: 0000			    21: 0000
    22: 0022			    22: 0000
    23: 0000			    23: 0000
    24: 3210			    24: 3210
    25: 7654			    25: 7654
    26: 0000			    26: 0000
    27: 8000			    27: 8000
    28: 0000			    28: 0000
    29: 0000			    29: 0000
    30: 0000			    30: 0000
    31: 0000			    31: 0000

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/debugfs.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/net/dsa/debugfs.c b/net/dsa/debugfs.c
index 997bbc8eb502..7b299c9d9892 100644
--- a/net/dsa/debugfs.c
+++ b/net/dsa/debugfs.c
@@ -109,6 +109,40 @@ static int dsa_debugfs_create_file(struct dsa_switch *ds, struct dentry *dir,
 	return 0;
 }
 
+static void dsa_debugfs_regs_read_count(struct dsa_switch *ds, int id,
+					struct seq_file *seq, int count)
+{
+	u16 data[count * ETH_GSTRING_LEN];
+	struct ethtool_regs regs;
+	int i;
+
+	ds->ops->get_regs(ds, id, &regs, data);
+
+	for (i = 0; i < count / 2; i++)
+		seq_printf(seq, "%2d: %04x\n", i, data[i]);
+}
+
+static int dsa_debugfs_regs_read(struct dsa_switch *ds, int id,
+				 struct seq_file *seq)
+{
+	int count;
+
+	if (!ds->ops->get_regs_len || !ds->ops->get_regs)
+		return -EOPNOTSUPP;
+
+	count = ds->ops->get_regs_len(ds, id);
+	if (count < 0)
+		return count;
+
+	dsa_debugfs_regs_read_count(ds, id, seq, count);
+
+	return 0;
+}
+
+static const struct dsa_debugfs_ops dsa_debugfs_regs_ops = {
+	.read = dsa_debugfs_regs_read,
+};
+
 static void dsa_debugfs_stats_read_count(struct dsa_switch *ds, int id,
 					 struct seq_file *seq, int count)
 {
@@ -188,6 +222,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, "regs", port,
+				      &dsa_debugfs_regs_ops);
+	if (err)
+		return err;
+
 	err = dsa_debugfs_create_file(ds, dir, "stats", port,
 				      &dsa_debugfs_stats_ops);
 	if (err)
-- 
2.14.1

  parent reply	other threads:[~2017-08-28 19:21 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-28 19:17 [PATCH net-next v2 00/10] net: dsa: add generic debugfs interface Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 01/10] net: dsa: add " Vivien Didelot
2017-08-28 19:50   ` Jiri Pirko
2017-08-28 19:58     ` Florian Fainelli
2017-08-28 20:05       ` Jiri Pirko
2017-08-28 20:19   ` Andrew Lunn
2017-09-07 19:34   ` Greg KH
2017-09-08 13:58     ` Vivien Didelot
2017-09-14 19:59       ` Maxim Uvarov
2017-09-14 20:12         ` Alexander Duyck
2017-09-14 21:01           ` Andrew Lunn
2017-09-15  5:51             ` Jiri Pirko
2017-09-15  7:35               ` Egil Hjelmeland
2017-09-15 14:08               ` Andrew Lunn
2017-09-15 14:26                 ` Jiri Pirko
2017-09-15 15:19                   ` Andrew Lunn
2017-08-28 19:17 ` [PATCH net-next v2 02/10] net: dsa: debugfs: add tree Vivien Didelot
2017-09-08 14:18   ` Vivien Didelot
2017-09-08 14:40     ` Greg Kroah-Hartman
2017-09-08 14:57   ` Vivien Didelot
2017-09-08 15:03     ` David Laight
2017-09-08 15:29     ` Greg Kroah-Hartman
2017-08-28 19:17 ` [PATCH net-next v2 03/10] net: dsa: debugfs: add tag_protocol Vivien Didelot
2017-08-28 20:16   ` Andrew Lunn
2017-08-28 19:17 ` [PATCH net-next v2 04/10] net: dsa: debugfs: add port stats Vivien Didelot
2017-08-28 19:17 ` Vivien Didelot [this message]
2017-08-28 19:17 ` [PATCH net-next v2 06/10] net: dsa: debugfs: add port fdb Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 07/10] net: dsa: restore mdb dump Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 08/10] net: dsa: debugfs: add port mdb Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 09/10] net: dsa: restore VLAN dump Vivien Didelot
2017-08-28 19:17 ` [PATCH net-next v2 10/10] net: dsa: debugfs: add port vlan Vivien Didelot
2017-08-28 19:53 ` [PATCH net-next v2 00/10] net: dsa: add generic debugfs interface Jiri Pirko
2017-08-28 20:08   ` Andrew Lunn
2017-08-29  6:25     ` Jiri Pirko
2017-08-29 12:50       ` Andrew Lunn
2017-08-29 19:05         ` Arkadi Sharshevsky
2017-08-29 19:19           ` Florian Fainelli
2017-08-29 20:27             ` Andrew Lunn
2017-08-30  7:43         ` Jiri Pirko
2017-08-29  4:38 ` David Miller
2017-08-29  6:29   ` Jiri Pirko
2017-08-29 15:57     ` Vivien Didelot
2017-08-30  7:40       ` Jiri Pirko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170828191748.19492-6-vivien.didelot@savoirfairelinux.com \
    --to=vivien.didelot@savoirfairelinux.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=cphealy@gmail.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=john@phrozen.org \
    --cc=kernel@savoirfairelinux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nikita.yoush@cogentembedded.com \
    --cc=privat@egil-hjelmeland.no \
    --cc=sean.wang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.