Blame SOURCES/0003-netlink-eeprom-Fallback-to-IOCTL-when-a-complete-hex.patch

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