Thread (6 messages) 6 messages, 1 author, 5d ago
DORMANTno replies REVIEWED: 3 (3M)
Revisions (2)
  1. v2 [diff vs current]
  2. v3 current

[PATCH ethtool-next v3 4/5] netlink: module-eeprom: Add 'hex on pages on' option for page-organized hex dump

From: Danielle Ratson <hidden>
Date: 2026-05-25 11:58:20
Subsystem: the rest · Maintainer: Linus Torvalds

Add 'pages on|off' sub-option to 'hex on|off' for 'ethtool -m'.
When 'hex on pages on' is specified, eeprom_parse() dispatches to the
appropriate per-type function with dump_pages=true, producing a hex dump
of all relevant EEPROM pages with a per-page header showing the page
number and optional bank number.

eeprom_parse() is extended with a bool dump_pages parameter to select
between pretty-print and hex dump output, avoiding duplication of the
module-type dispatch logic.

Unlike plain 'hex on', 'hex on pages on' does not fall back to the ioctl
path, as page selection is handled internally by the per-type functions.

Unknown module types fall back to dumping the lower 128 bytes.

'pages' and 'hex' are both parsed as independent flat options, since the
parameter parser does not support context-dependent argument recognition.
The requirement for 'hex on' when using 'pages on' is enforced by an
explicit validation check.

SFF-8636 Output example (values zeroed to omit vendor-specific
identifiers):

$ ethtool -m swp61 hex on pages on
Page: 0x0

Offset          Values
------          ------
0x0000:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0010:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0020:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0030:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0040:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0050:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0060:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0070:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Page: 0x0

Offset          Values
------          ------
0x0080:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0090:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00a0:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00b0:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00c0:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00d0:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00e0:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00f0:         00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Note: 'Page: 0x0' appears twice in the output. The first block is the
lower memory (bytes 0x00-0x7f), which is always accessible. The second
block is upper memory page 00h (bytes 0x80-0xff). Both carry the same
page label but are distinguished by their offset range in the hex dump.

Assisted-by: Claude:claude-sonnet-4.6
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Danielle Ratson <redacted>
---
 ethtool.c               |  1 +
 netlink/module-eeprom.c | 43 ++++++++++++++++++++++++++++++++++-------
 2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/ethtool.c b/ethtool.c
index 2444d85..8869c06 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -6165,6 +6165,7 @@ static const struct option args[] = {
 		.help	= "Query/Decode Module EEPROM information and optical diagnostics if available",
 		.xhelp	= "		[ raw on|off ]\n"
 			  "		[ hex on|off ]\n"
+			  "		[ pages on|off ]\n"
 			  "		[ offset N ]\n"
 			  "		[ length N ]\n"
 			  "		[ page N ]\n"
diff --git a/netlink/module-eeprom.c b/netlink/module-eeprom.c
index 7e4e6ac..ce88475 100644
--- a/netlink/module-eeprom.c
+++ b/netlink/module-eeprom.c
@@ -25,6 +25,7 @@ struct cmd_params {
 	unsigned long present;
 	u8 dump_hex;
 	u8 dump_raw;
+	u8 dump_pages;
 	u32 offset;
 	u32 length;
 	u32 page;
@@ -83,6 +84,12 @@ static const struct param_parser getmodule_params[] = {
 		.dest_offset	= offsetof(struct cmd_params, i2c_address),
 		.min_argc	= 1,
 	},
+	{
+		.arg		= "pages",
+		.handler	= nl_parse_u8bool,
+		.dest_offset	= offsetof(struct cmd_params, dump_pages),
+		.min_argc	= 1,
+	},
 	{}
 };
 
@@ -207,7 +214,7 @@ static int eeprom_dump_hex(struct cmd_context *ctx)
 	return 0;
 }
 
-static int eeprom_parse(struct cmd_context *ctx)
+static int eeprom_parse(struct cmd_context *ctx, bool dump_pages)
 {
 	struct ethtool_module_eeprom request = {
 		.length = 1,
@@ -228,18 +235,18 @@ static int eeprom_parse(struct cmd_context *ctx)
 	case MODULE_ID_GBIC:
 	case MODULE_ID_SOLDERED_MODULE:
 	case MODULE_ID_SFP:
-		return sff8079_show_all_nl(ctx, false);
+		return sff8079_show_all_nl(ctx, dump_pages);
 	case MODULE_ID_QSFP:
 	case MODULE_ID_QSFP28:
 	case MODULE_ID_QSFP_PLUS:
-		return sff8636_show_all_nl(ctx, false);
+		return sff8636_show_all_nl(ctx, dump_pages);
 	case MODULE_ID_QSFP_DD:
 	case MODULE_ID_OSFP:
 	case MODULE_ID_DSFP:
 	case MODULE_ID_QSFP_PLUS_CMIS:
 	case MODULE_ID_SFP_DD_CMIS:
 	case MODULE_ID_SFP_PLUS_CMIS:
-		return cmis_show_all_nl(ctx, false);
+		return cmis_show_all_nl(ctx, dump_pages);
 #endif
 	default:
 		/* If we cannot recognize the memory map, default to dumping
@@ -272,10 +279,28 @@ int nl_getmodule(struct cmd_context *ctx)
 		return -EINVAL;
 	}
 
+	if (getmodule_cmd_params.dump_pages && !getmodule_cmd_params.dump_hex) {
+		fprintf(stderr, "Pages dump requires hex on\n");
+		return -EINVAL;
+	}
+
+	if (getmodule_cmd_params.dump_pages &&
+	    (getmodule_cmd_params.present & (1 << PARAM_PAGE |
+					     1 << PARAM_BANK |
+					     1 << PARAM_OFFSET |
+					     1 << PARAM_LENGTH |
+					     1 << PARAM_I2C))) {
+		fprintf(stderr,
+			"Pages dump cannot be combined with offset, length, page, bank or i2c\n");
+		return -EINVAL;
+	}
+
 	/* When complete hex/raw dump of the EEPROM is requested, fallback to
-	 * ioctl. Netlink can only request specific pages.
+	 * ioctl. Netlink can only request specific pages. Skip fallback when
+	 * pages dump is requested, as it handles page selection internally.
 	 */
 	if ((getmodule_cmd_params.dump_hex || getmodule_cmd_params.dump_raw) &&
+	    !getmodule_cmd_params.dump_pages &&
 	    !(getmodule_cmd_params.present & (1 << PARAM_PAGE |
 					      1 << PARAM_BANK |
 					      1 << PARAM_I2C))) {
@@ -300,7 +325,11 @@ int nl_getmodule(struct cmd_context *ctx)
 	if (request.page && !request.offset)
 		request.offset = 128;
 
-	if (getmodule_cmd_params.dump_hex || getmodule_cmd_params.dump_raw) {
+	if (getmodule_cmd_params.dump_pages) {
+		ret = eeprom_parse(ctx, true);
+		if (ret < 0)
+			goto cleanup;
+	} else if (getmodule_cmd_params.dump_hex || getmodule_cmd_params.dump_raw) {
 		ret = nl_get_eeprom_page(ctx, &request);
 		if (ret < 0)
 			goto cleanup;
@@ -311,7 +340,7 @@ int nl_getmodule(struct cmd_context *ctx)
 			dump_hex(stdout, request.data, request.length,
 				 request.offset);
 	} else {
-		ret = eeprom_parse(ctx);
+		ret = eeprom_parse(ctx, false);
 		if (ret < 0)
 			goto cleanup;
 	}
-- 
2.51.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help