netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ethtool] ethtool: dump nested registers
@ 2019-08-02 19:34 Vivien Didelot
  2019-08-02 19:34 ` [PATCH net-next] net: dsa: dump CPU port regs through master Vivien Didelot
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Vivien Didelot @ 2019-08-02 19:34 UTC (permalink / raw)
  To: netdev; +Cc: f.fainelli, andrew, davem, linville, cphealy, Vivien Didelot

Usually kernel drivers set the regs->len value to the same length as
info->regdump_len, which was used for the allocation. In case where
regs->len is smaller than the allocated info->regdump_len length,
we may assume that the dump contains a nested set of registers.

This becomes handy for kernel drivers to expose registers of an
underlying network conduit unfortunately not exposed to userspace,
as found in network switching equipment for example.

This patch adds support for recursing into the dump operation if there
is enough room for a nested ethtool_drvinfo structure containing a
valid driver name, followed by a ethtool_regs structure like this:

    0      regs->len                        info->regdump_len
    v              v                                        v
    +--------------+-----------------+--------------+-- - --+
    | ethtool_regs | ethtool_drvinfo | ethtool_regs |       |
    +--------------+-----------------+--------------+-- - --+

Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com>
---
 ethtool.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 05fe05a08..c0e2903c5 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -1245,7 +1245,7 @@ static int dump_regs(int gregs_dump_raw, int gregs_dump_hex,
 
 	if (gregs_dump_raw) {
 		fwrite(regs->data, regs->len, 1, stdout);
-		return 0;
+		goto nested;
 	}
 
 	if (!gregs_dump_hex)
@@ -1253,7 +1253,7 @@ static int dump_regs(int gregs_dump_raw, int gregs_dump_hex,
 			if (!strncmp(driver_list[i].name, info->driver,
 				     ETHTOOL_BUSINFO_LEN)) {
 				if (driver_list[i].func(info, regs) == 0)
-					return 0;
+					goto nested;
 				/* This version (or some other
 				 * variation in the dump format) is
 				 * not handled; fall back to hex
@@ -1263,6 +1263,15 @@ static int dump_regs(int gregs_dump_raw, int gregs_dump_hex,
 
 	dump_hex(stdout, regs->data, regs->len, 0);
 
+nested:
+	/* Recurse dump if some drvinfo and regs structures are nested */
+	if (info->regdump_len > regs->len + sizeof(*info) + sizeof(*regs)) {
+		info = (struct ethtool_drvinfo *)(&regs->data[0] + regs->len);
+		regs = (struct ethtool_regs *)(&regs->data[0] + regs->len + sizeof(*info));
+
+		return dump_regs(gregs_dump_raw, gregs_dump_hex, info, regs);
+	}
+
 	return 0;
 }
 
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-08-09 17:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-02 19:34 [PATCH ethtool] ethtool: dump nested registers Vivien Didelot
2019-08-02 19:34 ` [PATCH net-next] net: dsa: dump CPU port regs through master Vivien Didelot
2019-08-06 21:08   ` David Miller
2019-08-05  8:04 ` [PATCH ethtool] ethtool: dump nested registers Michal Kubecek
2019-08-05 14:52   ` Vivien Didelot
2019-08-06  5:20     ` Michal Kubecek
2019-08-06 17:24       ` Vivien Didelot
2019-08-07  6:34       ` Jiri Pirko
2019-08-09 16:23 ` John W. Linville
2019-08-09 17:21   ` Michal Kubecek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).