All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivien Didelot <vivien.didelot@gmail.com>
To: netdev@vger.kernel.org
Cc: Chris Healy <cphealy@gmail.com>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	"John W . Linville" <linville@tuxdriver.com>,
	f.fainelli@gmail.com, andrew@lunn.ch
Subject: [PATCH 2/7] ethtool: dsa: mv88e6xxx: add pretty dump
Date: Fri, 14 Dec 2018 21:50:30 -0500	[thread overview]
Message-ID: <20181215025035.26977-3-vivien.didelot@gmail.com> (raw)
In-Reply-To: <20181215025035.26977-1-vivien.didelot@gmail.com>

The mv88e6xxx DSA driver supports many Marvell devices all using 32
registers of 16 bits. However each devices have a slightly different
register definition.

This patch adds the boilerplate for providing an optional function
per mv88e6xxx switch.

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 dsa.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/dsa.c b/dsa.c
index 83396b5..e747c1f 100644
--- a/dsa.c
+++ b/dsa.c
@@ -3,9 +3,86 @@
 
 #include "internal.h"
 
+/* Macros and dump functions for the 16-bit mv88e6xxx per-port registers */
+
+#define REG(_reg, _name, _val) \
+	printf("%.02u: %-38.38s 0x%.4x\n", _reg, _name, _val)
+
+#define FIELD(_name, _fmt, ...) \
+	printf("      %-36.36s " _fmt "\n", _name, ##__VA_ARGS__)
+
+#define FIELD_BITMAP(_name, _val) \
+	FIELD(_name, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", \
+	      ((_val) & 0x0001) ? "0 " : "", \
+	      ((_val) & 0x0002) ? "1 " : "", \
+	      ((_val) & 0x0004) ? "2 " : "", \
+	      ((_val) & 0x0008) ? "3 " : "", \
+	      ((_val) & 0x0010) ? "4 " : "", \
+	      ((_val) & 0x0020) ? "5 " : "", \
+	      ((_val) & 0x0040) ? "6 " : "", \
+	      ((_val) & 0x0080) ? "7 " : "", \
+	      ((_val) & 0x0100) ? "8 " : "", \
+	      ((_val) & 0x0200) ? "9 " : "", \
+	      ((_val) & 0x0400) ? "10 " : "", \
+	      ((_val) & 0x0800) ? "11 " : "", \
+	      ((_val) & 0x1000) ? "12 " : "", \
+	      ((_val) & 0x2000) ? "13 " : "", \
+	      ((_val) & 0x4000) ? "14 " : "", \
+	      ((_val) & 0x8000) ? "15 " : "")
+
+struct dsa_mv88e6xxx_switch {
+	void (*dump)(int reg, u16 val);
+	const char *name;
+	u16 id;
+};
+
+static const struct dsa_mv88e6xxx_switch dsa_mv88e6xxx_switches[] = {
+};
+
+static int dsa_mv88e6xxx_dump_regs(struct ethtool_regs *regs)
+{
+	const struct dsa_mv88e6xxx_switch *sw = NULL;
+	const u16 *data = (u16 *)regs->data;
+	u16 id;
+	int i;
+
+	/* Marvell chips have 32 per-port 16-bit registers */
+	if (regs->len < 32 * 2)
+		return 1;
+
+	id = data[3] & 0xfff0;
+
+	for (i = 0; i < ARRAY_SIZE(dsa_mv88e6xxx_switches); i++) {
+		if (id == dsa_mv88e6xxx_switches[i].id) {
+			sw = &dsa_mv88e6xxx_switches[i];
+			break;
+		}
+	}
+
+	if (!sw)
+		return 1;
+
+	printf("%s Switch Port Registers\n", sw->name);
+	printf("------------------------------\n");
+
+	for (i = 0; i < 32; i++)
+		if (sw->dump)
+			sw->dump(i, data[i]);
+		else
+			REG(i, "", data[i]);
+
+	return 0;
+}
+
+#undef FIELD_BITMAP
+#undef FIELD
+#undef REG
+
 int dsa_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs)
 {
 	/* DSA per-driver register dump */
+	if (!dsa_mv88e6xxx_dump_regs(regs))
+		return 0;
 
 	/* Fallback to hexdump */
 	return 1;
-- 
2.19.2

  parent reply	other threads:[~2018-12-15  2:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-15  2:50 [PATCH 0/7] ethtool: add pretty dump for DSA mv88e6xxx drivers Vivien Didelot
2018-12-15  2:50 ` [PATCH 1/7] ethtool: dsa: add pretty dump Vivien Didelot
2018-12-15  2:50 ` Vivien Didelot [this message]
2018-12-15  2:50 ` [PATCH 3/7] ethtool: dsa: mv88e6xxx: add pretty dump for 88E6185 Vivien Didelot
2018-12-15  2:50 ` [PATCH 4/7] ethtool: dsa: mv88e6xxx: add pretty dump for 88E6161 Vivien Didelot
2018-12-15  2:50 ` [PATCH 5/7] ethtool: dsa: mv88e6xxx: add pretty dump for 88E6352 Vivien Didelot
2018-12-15  2:50 ` [PATCH 6/7] ethtool: dsa: mv88e6xxx: add pretty dump for 88E6390 Vivien Didelot
2018-12-15  2:50 ` [PATCH 7/7] ethtool: dsa: mv88e6xxx: pretty dump others Vivien Didelot
2018-12-15 17:28 ` [PATCH 0/7] ethtool: add pretty dump for DSA mv88e6xxx drivers Florian Fainelli
2018-12-15 17:48   ` Andrew Lunn
2018-12-16 18:02     ` Florian Fainelli
2018-12-16 20:00       ` Andrew Lunn
2018-12-16 18:03     ` Vivien Didelot
2018-12-16 17:57   ` Vivien Didelot

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=20181215025035.26977-3-vivien.didelot@gmail.com \
    --to=vivien.didelot@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=cphealy@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=linville@tuxdriver.com \
    --cc=netdev@vger.kernel.org \
    /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.