Blame SOURCES/0035-sff-8079-8472-Fix-missing-sff-8472-output-in-netlink.patch

89ea86
From 206cd00caf9b71ae20f897075b4bd261e923e563 Mon Sep 17 00:00:00 2001
89ea86
From: Ivan Vecera <ivecera@redhat.com>
89ea86
Date: Tue, 31 May 2022 20:55:03 +0200
89ea86
Subject: [PATCH 35/35] sff-8079/8472: Fix missing sff-8472 output in netlink
89ea86
 path
89ea86
89ea86
Commit 25b64c66f58d ("ethtool: Add netlink handler for
89ea86
getmodule (-m)") provided a netlink variant for getmodule
89ea86
but also introduced a regression as netlink output is different
89ea86
from ioctl output that provides information from A2h page
89ea86
via sff8472_show_all().
89ea86
89ea86
To fix this the netlink path should check a presence of A2h page
89ea86
by value of bit 6 in byte 92 of page A0h and if it is set then
89ea86
get A2h page and call sff8472_show_all().
89ea86
89ea86
Fixes: 25b64c66f58d ("ethtool: Add netlink handler for getmodule (-m)")
89ea86
Tested-by: Daniel Juarez <djuarezg@cern.ch>
89ea86
Tested-by: Ido Schimmel <idosch@nvidia.com>
89ea86
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
89ea86
Co-authored-by: Ido Schimmel <idosch@nvidia.com>
89ea86
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
89ea86
---
89ea86
 sfpid.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++--------
89ea86
 1 file changed, 46 insertions(+), 8 deletions(-)
89ea86
89ea86
diff --git a/sfpid.c b/sfpid.c
89ea86
index 621d1e86c278..1bc45c183770 100644
89ea86
--- a/sfpid.c
89ea86
+++ b/sfpid.c
89ea86
@@ -13,8 +13,9 @@
89ea86
 #include "sff-common.h"
89ea86
 #include "netlink/extapi.h"
89ea86
 
89ea86
-#define SFF8079_PAGE_SIZE	0x80
89ea86
-#define SFF8079_I2C_ADDRESS_LOW	0x50
89ea86
+#define SFF8079_PAGE_SIZE		0x80
89ea86
+#define SFF8079_I2C_ADDRESS_LOW		0x50
89ea86
+#define SFF8079_I2C_ADDRESS_HIGH	0x51
89ea86
 
89ea86
 static void sff8079_show_identifier(const __u8 *id)
89ea86
 {
89ea86
@@ -450,18 +451,55 @@ void sff8079_show_all_ioctl(const __u8 *id)
89ea86
 	sff8079_show_all_common(id);
89ea86
 }
89ea86
 
89ea86
-int sff8079_show_all_nl(struct cmd_context *ctx)
89ea86
+static int sff8079_get_eeprom_page(struct cmd_context *ctx, u8 i2c_address,
89ea86
+				   __u8 *buf)
89ea86
 {
89ea86
 	struct ethtool_module_eeprom request = {
89ea86
 		.length = SFF8079_PAGE_SIZE,
89ea86
-		.i2c_address = SFF8079_I2C_ADDRESS_LOW,
89ea86
+		.i2c_address = i2c_address,
89ea86
 	};
89ea86
 	int ret;
89ea86
 
89ea86
 	ret = nl_get_eeprom_page(ctx, &request);
89ea86
-	if (ret < 0)
89ea86
-		return ret;
89ea86
-	sff8079_show_all_common(request.data);
89ea86
+	if (!ret)
89ea86
+		memcpy(buf, request.data, SFF8079_PAGE_SIZE);
89ea86
+
89ea86
+	return ret;
89ea86
+}
89ea86
+
89ea86
+int sff8079_show_all_nl(struct cmd_context *ctx)
89ea86
+{
89ea86
+	u8 *buf;
89ea86
+	int ret;
89ea86
+
89ea86
+	/* The SFF-8472 parser expects a single buffer that contains the
89ea86
+	 * concatenation of the first 256 bytes from addresses A0h and A2h,
89ea86
+	 * respectively.
89ea86
+	 */
89ea86
+	buf = calloc(1, ETH_MODULE_SFF_8472_LEN);
89ea86
+	if (!buf)
89ea86
+		return -ENOMEM;
89ea86
+
89ea86
+	/* Read A0h page */
89ea86
+	ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_LOW, buf);
89ea86
+	if (ret)
89ea86
+		goto out;
89ea86
+
89ea86
+	sff8079_show_all_common(buf);
89ea86
+
89ea86
+	/* Finish if A2h page is not present */
89ea86
+	if (!(buf[92] & (1 << 6)))
89ea86
+		goto out;
89ea86
+
89ea86
+	/* Read A2h page */
89ea86
+	ret = sff8079_get_eeprom_page(ctx, SFF8079_I2C_ADDRESS_HIGH,
89ea86
+				      buf + ETH_MODULE_SFF_8079_LEN);
89ea86
+	if (ret)
89ea86
+		goto out;
89ea86
+
89ea86
+	sff8472_show_all(buf);
89ea86
+out:
89ea86
+	free(buf);
89ea86
 
89ea86
-	return 0;
89ea86
+	return ret;
89ea86
 }
89ea86
-- 
89ea86
2.35.1
89ea86