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