89ea86
From 04d36d7c373db7069554a6d21ece628e2cf6b21c Mon Sep 17 00:00:00 2001
89ea86
From: Ido Schimmel <idosch@nvidia.com>
89ea86
Date: Tue, 14 Sep 2021 14:27:36 +0300
89ea86
Subject: [PATCH 03/35] netlink: eeprom: Fallback to IOCTL when a complete
89ea86
 hex/raw dump is requested
89ea86
89ea86
The IOCTL backend provides a complete hex/raw dump of the module EEPROM
89ea86
contents:
89ea86
89ea86
 # ethtool -m swp11 hex on | wc -l
89ea86
 34
89ea86
89ea86
 # ethtool -m swp11 raw on | wc -c
89ea86
 512
89ea86
89ea86
With the netlink backend, only the first 128 bytes from I2C address 0x50
89ea86
are dumped:
89ea86
89ea86
 # ethtool -m swp11 hex on | wc -l
89ea86
 10
89ea86
89ea86
 # ethtool -m swp11 raw on | wc -c
89ea86
 128
89ea86
89ea86
The presence of optional / banked pages is unknown without parsing the
89ea86
EEPROM contents which is unavailable when pretty printing is disabled
89ea86
(i.e., configure --disable-pretty-dump). With the IOCTL backend, this
89ea86
parsing happens inside the kernel.
89ea86
89ea86
Therefore, when a complete hex/raw dump is requested, fallback to the
89ea86
IOCTL backend.
89ea86
89ea86
After the patch:
89ea86
89ea86
 # ethtool -m swp11 hex on | wc -l
89ea86
 34
89ea86
89ea86
 # ethtool -m swp11 raw on | wc -c
89ea86
 512
89ea86
89ea86
This avoids breaking users that are relying on current behavior.
89ea86
89ea86
If users want a hex/raw dump of optional/banked pages that are not
89ea86
returned with the IOCTL backend, they will be required to request these
89ea86
explicitly via the netlink backend. For example:
89ea86
89ea86
 # ethtool -m swp11 hex on page 0x2
89ea86
89ea86
This is desirable as that way there is no ambiguity regarding the
89ea86
location of optional/banked pages in the dump.
89ea86
89ea86
Another way to implement the above would be to use the 'nlchk' callback
89ea86
added in commit 67a9ef551661 ("ethtool: add nlchk for redirecting to
89ea86
netlink"). However, it is called before the netlink instance is
89ea86
initialized and before the command line parameters are parsed via
89ea86
nl_parser().
89ea86
89ea86
Fixes: 25b64c66f58d ("ethtool: Add netlink handler for getmodule (-m)")
89ea86
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
89ea86
---
89ea86
 netlink/module-eeprom.c | 10 ++++++++++
89ea86
 1 file changed, 10 insertions(+)
89ea86
89ea86
diff --git a/netlink/module-eeprom.c b/netlink/module-eeprom.c
89ea86
index 38e7d2cd6cf3..e9a122df3259 100644
89ea86
--- a/netlink/module-eeprom.c
89ea86
+++ b/netlink/module-eeprom.c
89ea86
@@ -365,6 +365,16 @@ int nl_getmodule(struct cmd_context *ctx)
89ea86
 		return -EINVAL;
89ea86
 	}
89ea86
 
89ea86
+	/* When complete hex/raw dump of the EEPROM is requested, fallback to
89ea86
+	 * ioctl. Netlink can only request specific pages.
89ea86
+	 */
89ea86
+	if ((getmodule_cmd_params.dump_hex || getmodule_cmd_params.dump_raw) &&
89ea86
+	    !getmodule_cmd_params.page && !getmodule_cmd_params.bank &&
89ea86
+	    !getmodule_cmd_params.i2c_address) {
89ea86
+		nlctx->ioctl_fallback = true;
89ea86
+		return -EOPNOTSUPP;
89ea86
+	}
89ea86
+
89ea86
 	request.i2c_address = ETH_I2C_ADDRESS_LOW;
89ea86
 	request.length = 128;
89ea86
 	ret = page_fetch(nlctx, &request);
89ea86
-- 
89ea86
2.35.1
89ea86