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