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

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