diff mbox series

[ethtool,3/5] netlink: eeprom: Fallback to IOCTL when a complete hex/raw dump is requested

Message ID 20210914112738.358627-4-idosch@idosch.org (mailing list archive)
State Accepted
Commit 2ddb1a1f06e2892efb8a7c75739092dac8582a37
Delegated to: Michal Kubecek
Headers show
Series ethtool: Module EEPROM fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ido Schimmel Sept. 14, 2021, 11:27 a.m. UTC
From: Ido Schimmel <idosch@nvidia.com>

The IOCTL backend provides a complete hex/raw dump of the module EEPROM
contents:

 # ethtool -m swp11 hex on | wc -l
 34

 # ethtool -m swp11 raw on | wc -c
 512

With the netlink backend, only the first 128 bytes from I2C address 0x50
are dumped:

 # ethtool -m swp11 hex on | wc -l
 10

 # ethtool -m swp11 raw on | wc -c
 128

The presence of optional / banked pages is unknown without parsing the
EEPROM contents which is unavailable when pretty printing is disabled
(i.e., configure --disable-pretty-dump). With the IOCTL backend, this
parsing happens inside the kernel.

Therefore, when a complete hex/raw dump is requested, fallback to the
IOCTL backend.

After the patch:

 # ethtool -m swp11 hex on | wc -l
 34

 # ethtool -m swp11 raw on | wc -c
 512

This avoids breaking users that are relying on current behavior.

If users want a hex/raw dump of optional/banked pages that are not
returned with the IOCTL backend, they will be required to request these
explicitly via the netlink backend. For example:

 # ethtool -m swp11 hex on page 0x2

This is desirable as that way there is no ambiguity regarding the
location of optional/banked pages in the dump.

Another way to implement the above would be to use the 'nlchk' callback
added in commit 67a9ef551661 ("ethtool: add nlchk for redirecting to
netlink"). However, it is called before the netlink instance is
initialized and before the command line parameters are parsed via
nl_parser().

Fixes: 25b64c66f58d ("ethtool: Add netlink handler for getmodule (-m)")
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 netlink/module-eeprom.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/netlink/module-eeprom.c b/netlink/module-eeprom.c
index 38e7d2cd6cf3..e9a122df3259 100644
--- a/netlink/module-eeprom.c
+++ b/netlink/module-eeprom.c
@@ -365,6 +365,16 @@  int nl_getmodule(struct cmd_context *ctx)
 		return -EINVAL;
 	}
 
+	/* When complete hex/raw dump of the EEPROM is requested, fallback to
+	 * ioctl. Netlink can only request specific pages.
+	 */
+	if ((getmodule_cmd_params.dump_hex || getmodule_cmd_params.dump_raw) &&
+	    !getmodule_cmd_params.page && !getmodule_cmd_params.bank &&
+	    !getmodule_cmd_params.i2c_address) {
+		nlctx->ioctl_fallback = true;
+		return -EOPNOTSUPP;
+	}
+
 	request.i2c_address = ETH_I2C_ADDRESS_LOW;
 	request.length = 128;
 	ret = page_fetch(nlctx, &request);