Skip to contentSkip to conversation

Extend module EEPROM API

PATCH Superseded Moshe Shemesh 3 participants 12 messages Apr 23, 2021 – May 4, 2021

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Extend module EEPROM API

Ethtool supports module EEPROM dumps via the ethtool -m <dev> command. But in current state its functionality is limited - offset and length parameters, which are used to specify a linear desired region of EEPROM data to dump, is not enough, considering emergence of complex module EEPROM layouts such as CMIS 4.0.

Moreover, CMIS 4.0 extends the amount of pages that may be accessible by introducing another parameter for page addressing - banks. Besides, currently module EEPROM is represented as a chunk of concatenated pages, where lower 128 bytes of all pages, except page 00h, are omitted. Offset and length are used to address parts of this fake linear memory. But in practice drivers, which implement get_module_info() and get_module_eeprom() ethtool ops still calculate page number and set I2C address on their own.

This series adds support in ethtool -m of dumping an arbitrary page specified by page number, bank number and I2C address. Implement netlink handler for ethtool -m in order to make such requests to the kernel
and extend CLI by adding corresponding parameters.
New command line format:
ethtool -m <dev> [hex on|off] [raw on|off] [offset N] [length N] [page N] [bank N] [i2c N]

Netlink infrastructure works on per-page basis and allows dumps of a single page at once. But in case user requests human-readable output, which currently may require more than one page, userspace can make such additional calls to kernel on demand and place pages in a linked list. It allows to get pages from cache on demand and pass them to refactored SFF decoders.

Vladyslav Tarasiuk (4):
ethtool: Add netlink handler for getmodule (-m)
ethtool: Refactor human-readable module EEPROM output for new API
ethtool: Rename QSFP-DD identifiers to use CMIS 4.0
ethtool: Update manpages to reflect changes to getmodule (-m) command

 Makefile.am             |   3 +-
 qsfp-dd.c => cmis4.c    | 220 +++++++++++---------
 cmis4.h                 | 128 ++++++++++++
 ethtool.8.in            |  14 ++
 ethtool.c               |   4 +
 internal.h              |  12 ++
 list.h                  |  34 ++++
 netlink/desc-ethtool.c  |  13 ++
 netlink/extapi.h        |   2 +
 netlink/module-eeprom.c | 438 ++++++++++++++++++++++++++++++++++++++++
 qsfp-dd.h               | 125 ------------
 qsfp.c                  | 129 +++++++-----
 qsfp.h                  |  52 ++---
 sff-common.c            |   3 +
 sff-common.h            |   3 +-
 15 files changed, 876 insertions(+), 304 deletions(-)
 rename qsfp-dd.c => cmis4.c (55%)
 create mode 100644 cmis4.h
 create mode 100644 list.h
 create mode 100644 netlink/module-eeprom.c
 delete mode 100644 qsfp-dd.h
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/4 ethtool: Add netlink handler for getmodule (-m)

From: Vladyslav Tarasiuk <[email protected]>

Implement "ethtool -m <dev>" subcommand using netlink and extend the interface for new module EEPROM standards. Currently, ethtool supports module EEPROM dumps of continuous memory regions, which are specified using a pair of parameters - offset and length. But due to emergence of new standards such as CMIS 4.0, which further extends possible addressed memory, this approach shows its limitations.

Extend command line interface in order to support dumps of arbitrary pages including CMIS 4.0-specific banked pages:
ethtool -m <dev> [page N] [bank N] [i2c N]

Command example:

 # ethtool -m eth2 page 1 offset 0x80 length 0x20
 Offset          Values
 ------          ------
 0x0080:         11 00 23 80 00 00 00 00 00 00 00 08 ff 00 00 00
 0x0090:         00 00 01 a0 4d 65 6c 6c 61 6e 6f 78 20 20 20 20
---
 Makefile.am             |   1 +
 ethtool.c               |   4 +
 internal.h              |  10 +
 list.h                  |  34 ++++
 netlink/desc-ethtool.c  |  13 ++
 netlink/extapi.h        |   2 +
 netlink/module-eeprom.c | 425 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 489 insertions(+)
 create mode 100644 list.h
 create mode 100644 netlink/module-eeprom.c
Makefile.am +1 -0
index e3e311d..9734bde 100644
@@ -37,6 +37,7 @@ ethtool_SOURCES += \
 		  netlink/channels.c netlink/coalesce.c netlink/pause.c \
 		  netlink/eee.c netlink/tsinfo.c \
 		  netlink/desc-ethtool.c netlink/desc-genlctrl.c \
+		  netlink/module-eeprom.c \
 		  netlink/desc-rtnl.c netlink/cable_test.c netlink/tunnels.c \
 		  uapi/linux/ethtool_netlink.h \
 		  uapi/linux/netlink.h uapi/linux/genetlink.h \
ethtool.c +4 -0
index a8339c8..f7e8d28 100644
@@ -5881,11 +5881,15 @@ static const struct option args[] = {
 	{
 		.opts	= "-m|--dump-module-eeprom|--module-info",
 		.func	= do_getmodule,
+		.nlfunc = nl_getmodule,
 		.help	= "Query/Decode Module EEPROM information and optical diagnostics if available",
 		.xhelp	= "		[ raw on|off ]\n"
 			  "		[ hex on|off ]\n"
 			  "		[ offset N ]\n"
 			  "		[ length N ]\n"
+			  "		[ page N ]\n"
+			  "		[ bank N ]\n"
+			  "		[ i2c N ]\n"
 	},
 	{
 		.opts	= "--show-eee",
internal.h +10 -0
index 27da8ea..2affebe 100644
@@ -216,6 +216,16 @@ static inline int ethtool_link_mode_set_bit(unsigned int nr, u32 *mask)
 	return 0;
 }
 
+/* Struct for managing module EEPROM pages */
+struct ethtool_module_eeprom {
+	u32	offset;
+	u32	length;
+	u8	page;
+	u8	bank;
+	u8	i2c_address;
+	u8	*data;
+};
+
 /* Context for sub-commands */
 struct cmd_context {
 	const char *devname;	/* net device name */
list.h new file +34 -0
new file mode 100644
index 0000000..aa97fdd
@@ -0,0 +1,34 @@
+#ifndef ETHTOOL_LIST_H__
+#define ETHTOOL_LIST_H__
+
+#include <unistd.h>
+
+/* Generic list utilities */
+
+struct list_head {
+	struct list_head *next, *prev;
+};
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+static inline void list_add(struct list_head *new, struct list_head *head)
+{
+	head->next->prev = new;
+	new->next = head->next;
+	new->prev = head;
+	head->next = new;
+}
+
+static inline void list_del(struct list_head *entry)
+{
+	entry->next->prev = entry->prev;
+	entry->prev->next = entry->next;
+	entry->next = NULL;
+	entry->prev = NULL;
+}
+
+#define list_for_each_safe(pos, n, head) \
+	for (pos = (head)->next, n = pos->next; pos != (head); \
+		pos = n, n = pos->next)
+
+#endif
netlink/desc-ethtool.c +13 -0
index fe5d7ba..3aacf05 100644
@@ -318,6 +318,17 @@ const struct pretty_nla_desc __tunnel_info_desc[] = {
 	NLATTR_DESC_NESTED(ETHTOOL_A_TUNNEL_INFO_UDP_PORTS, tunnel_udp),
 };
 
+const struct pretty_nla_desc __module_eeprom_desc[] = {
+	NLATTR_DESC_INVALID(ETHTOOL_A_MODULE_EEPROM_UNSPEC),
+	NLATTR_DESC_NESTED(ETHTOOL_A_MODULE_EEPROM_HEADER, header),
+	NLATTR_DESC_U32(ETHTOOL_A_MODULE_EEPROM_OFFSET),
+	NLATTR_DESC_U32(ETHTOOL_A_MODULE_EEPROM_LENGTH),
+	NLATTR_DESC_U8(ETHTOOL_A_MODULE_EEPROM_PAGE),
+	NLATTR_DESC_U8(ETHTOOL_A_MODULE_EEPROM_BANK),
+	NLATTR_DESC_U8(ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS),
+	NLATTR_DESC_BINARY(ETHTOOL_A_MODULE_EEPROM_DATA)
+};
+
 const struct pretty_nlmsg_desc ethnl_umsg_desc[] = {
 	NLMSG_DESC_INVALID(ETHTOOL_MSG_USER_NONE),
 	NLMSG_DESC(ETHTOOL_MSG_STRSET_GET, strset),
@@ -348,6 +359,7 @@ const struct pretty_nlmsg_desc ethnl_umsg_desc[] = {
 	NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_ACT, cable_test),
 	NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_TDR_ACT, cable_test_tdr),
 	NLMSG_DESC(ETHTOOL_MSG_TUNNEL_INFO_GET, tunnel_info),
+	NLMSG_DESC(ETHTOOL_MSG_MODULE_EEPROM_GET, module_eeprom),
 };
 
 const unsigned int ethnl_umsg_n_desc = ARRAY_SIZE(ethnl_umsg_desc);
@@ -383,6 +395,7 @@ const struct pretty_nlmsg_desc ethnl_kmsg_desc[] = {
 	NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_NTF, cable_test_ntf),
 	NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_TDR_NTF, cable_test_tdr_ntf),
 	NLMSG_DESC(ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY, tunnel_info),
+	NLMSG_DESC(ETHTOOL_MSG_MODULE_EEPROM_GET_REPLY, module_eeprom),
 };
 
 const unsigned int ethnl_kmsg_n_desc = ARRAY_SIZE(ethnl_kmsg_desc);
netlink/extapi.h +2 -0
index 761cafb..72308e2 100644
@@ -39,6 +39,7 @@ int nl_cable_test(struct cmd_context *ctx);
 int nl_cable_test_tdr(struct cmd_context *ctx);
 int nl_gtunnels(struct cmd_context *ctx);
 int nl_monitor(struct cmd_context *ctx);
+int nl_getmodule(struct cmd_context *ctx);
 
 void nl_monitor_usage(void);
 
@@ -87,6 +88,7 @@ static inline void nl_monitor_usage(void)
 #define nl_cable_test		NULL
 #define nl_cable_test_tdr	NULL
 #define nl_gtunnels		NULL
+#define nl_getmodule		NULL
 
 #endif /* ETHTOOL_ENABLE_NETLINK */
 
netlink/module-eeprom.c new file +425 -0

425 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/4 ethtool: Refactor human-readable module EEPROM output

In reply to Moshe Shemesh

From: Vladyslav Tarasiuk <[email protected]>

Reuse existing SFF8636 and QSFP-DD infrastructures to implement EEPROM decoders, which work with paged memory. Add support for human-readable output for QSFP, QSFP28, QSFP Plus, QSFP-DD and DSFP transreceivers from netlink 'ethtool -m' handler.

---
 internal.h              |   2 +
 netlink/module-eeprom.c |  13 ++++
 qsfp-dd.c               |  44 +++++++++++---
 qsfp-dd.h               |  29 +++++----
 qsfp.c                  | 127 +++++++++++++++++++++++-----------------
 qsfp.h                  |  52 ++++++++--------
 sff-common.c            |   3 +
 sff-common.h            |   3 +-
 8 files changed, 171 insertions(+), 102 deletions(-)
internal.h +2 -0
index 2affebe..33e619b 100644
@@ -391,6 +391,8 @@ void sff8472_show_all(const __u8 *id);
 
 /* QSFP Optics diagnostics */
 void sff8636_show_all(const __u8 *id, __u32 eeprom_len);
+void sff8636_show_all_paged(const struct ethtool_module_eeprom *page_zero,
+			    const struct ethtool_module_eeprom *page_three);
 
 /* FUJITSU Extended Socket network device */
 int fjes_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs);
netlink/module-eeprom.c +13 -0
index 7298087..768a261 100644
@@ -291,6 +291,7 @@ static bool page_available(struct ethtool_module_eeprom *which)
 	case SFF8024_ID_QSFP_PLUS:
 		return (!which->bank && which->page <= 3);
 	case SFF8024_ID_QSFP_DD:
+	case SFF8024_ID_DSFP:
 		return !(flat_mem && which->page);
 	default:
 		return true;
@@ -323,6 +324,7 @@ static int decoder_prefetch(struct nl_context *nlctx)
 		request.page = 3;
 		break;
 	case SFF8024_ID_QSFP_DD:
+	case SFF8024_ID_DSFP:
 		memset(&request, 0, sizeof(request));
 		request.i2c_address = ETH_I2C_ADDRESS_LOW;
 		request.offset = 128;
@@ -336,13 +338,24 @@ static int decoder_prefetch(struct nl_context *nlctx)
 
 static void decoder_print(void)
 {
+	struct ethtool_module_eeprom *page_three = cache_get(3, 0, ETH_I2C_ADDRESS_LOW);
 	struct ethtool_module_eeprom *page_zero = cache_get(0, 0, ETH_I2C_ADDRESS_LOW);
+	struct ethtool_module_eeprom *page_one = cache_get(1, 0, ETH_I2C_ADDRESS_LOW);
 	u8 module_id = page_zero->data[SFF8636_ID_OFFSET];
 
 	switch (module_id) {
 	case SFF8024_ID_SFP:
 		sff8079_show_all(page_zero->data);
 		break;
+	case SFF8024_ID_QSFP:
+	case SFF8024_ID_QSFP28:
+	case SFF8024_ID_QSFP_PLUS:
+		sff8636_show_all_paged(page_zero, page_three);
+		break;
+	case SFF8024_ID_QSFP_DD:
+	case SFF8024_ID_DSFP:
+		cmis4_show_all(page_zero, page_one);
+		break;
 	default:
 		dump_hex(stdout, page_zero->data, page_zero->length, page_zero->offset);
 		break;
qsfp-dd.c +35 -9

59 lines not on this page · raw message

qsfp-dd.h +16 -13
index f589c4e..fddb188 100644
@@ -96,30 +96,33 @@
 /*-----------------------------------------------------------------------
  * Upper Memory Page 0x01: contains advertising fields that define properties
  * that are unique to active modules and cable assemblies.
- * RealOffset = 1 * 0x80 + LocalOffset
+ * GlobalOffset = 2 * 0x80 + LocalOffset
  */
-#define PAG01H_UPPER_OFFSET			(0x01 * 0x80)
+#define PAG01H_UPPER_OFFSET			(0x02 * 0x80)
 
 /* Supported Link Length (Page 1) */
-#define QSFP_DD_SMF_LEN_OFFSET			(PAG01H_UPPER_OFFSET + 0x84)
-#define QSFP_DD_OM5_LEN_OFFSET			(PAG01H_UPPER_OFFSET + 0x85)
-#define QSFP_DD_OM4_LEN_OFFSET			(PAG01H_UPPER_OFFSET + 0x86)
-#define QSFP_DD_OM3_LEN_OFFSET			(PAG01H_UPPER_OFFSET + 0x87)
-#define QSFP_DD_OM2_LEN_OFFSET			(PAG01H_UPPER_OFFSET + 0x88)
+#define QSFP_DD_SMF_LEN_OFFSET			0x4
+#define QSFP_DD_OM5_LEN_OFFSET			0x5
+#define QSFP_DD_OM4_LEN_OFFSET			0x6
+#define QSFP_DD_OM3_LEN_OFFSET			0x7
+#define QSFP_DD_OM2_LEN_OFFSET			0x8
 
 /* Wavelength (Page 1) */
-#define QSFP_DD_NOM_WAVELENGTH_MSB		(PAG01H_UPPER_OFFSET + 0x8A)
-#define QSFP_DD_NOM_WAVELENGTH_LSB		(PAG01H_UPPER_OFFSET + 0x8B)
-#define QSFP_DD_WAVELENGTH_TOL_MSB		(PAG01H_UPPER_OFFSET + 0x8C)
-#define QSFP_DD_WAVELENGTH_TOL_LSB		(PAG01H_UPPER_OFFSET + 0x8D)
+#define QSFP_DD_NOM_WAVELENGTH_MSB		0xA
+#define QSFP_DD_NOM_WAVELENGTH_LSB		0xB
+#define QSFP_DD_WAVELENGTH_TOL_MSB		0xC
+#define QSFP_DD_WAVELENGTH_TOL_LSB		0xD
 
 /* Signal integrity controls */
-#define QSFP_DD_SIG_INTEG_TX_OFFSET		(PAG01H_UPPER_OFFSET + 0xA1)
-#define QSFP_DD_SIG_INTEG_RX_OFFSET		(PAG01H_UPPER_OFFSET + 0xA2)
+#define QSFP_DD_SIG_INTEG_TX_OFFSET		0xA1
+#define QSFP_DD_SIG_INTEG_RX_OFFSET		0xA2
 
 #define YESNO(x) (((x) != 0) ? "Yes" : "No")
 #define ONOFF(x) (((x) != 0) ? "On" : "Off")
 
 void qsfp_dd_show_all(const __u8 *id);
 
+void cmis4_show_all(const struct ethtool_module_eeprom *page_zero,
+		    const struct ethtool_module_eeprom *page_one);
+
 #endif /* QSFP_DD_H__ */
qsfp.c +72 -55

166 lines not on this page · raw message

qsfp.h +28 -24

60 lines not on this page · raw message

sff-common.c +3 -0
index 5285645..2815951 100644
@@ -139,6 +139,9 @@ void sff8024_show_identifier(const __u8 *id, int id_offset)
 	case SFF8024_ID_QSFP_DD:
 		printf(" (QSFP-DD Double Density 8X Pluggable Transceiver (INF-8628))\n");
 		break;
+	case SFF8024_ID_DSFP:
+		printf(" (DSFP Dual Small Form Factor Pluggable Transceiver)\n");
+		break;
 	default:
 		printf(" (reserved or unknown)\n");
 		break;
sff-common.h +2 -1
index cfb5d0e..2183f41 100644
@@ -62,7 +62,8 @@
 #define  SFF8024_ID_CDFP_S3				0x16
 #define  SFF8024_ID_MICRO_QSFP			0x17
 #define  SFF8024_ID_QSFP_DD				0x18
-#define  SFF8024_ID_LAST				SFF8024_ID_QSFP_DD
+#define  SFF8024_ID_DSFP				0x1B
+#define  SFF8024_ID_LAST				SFF8024_ID_DSFP
 #define  SFF8024_ID_UNALLOCATED_LAST	0x7F
 #define  SFF8024_ID_VENDOR_START		0x80
 #define  SFF8024_ID_VENDOR_LAST			0xFF
Signature · 1 line
2.26.2
#5 lore raw

PATCH 3/4 ethtool: Rename QSFP-DD identifiers to use CMIS 4.0

In reply to Moshe Shemesh

From: Vladyslav Tarasiuk <[email protected]>

QSFP-DD and DSFP EEPROM layout complies to CMIS 4.0 specification. As DSFP support is added, there are currently two standards, which share the same infrastructure. Rename QSFP_DD and qsfp_dd occurrences to use CMIS4 or cmis4 respectively to make function names generic for any module compliant to CMIS 4.0.

---
 Makefile.am             |   2 +-
 qsfp-dd.c => cmis4.c    | 210 ++++++++++++++++++++--------------------
 cmis4.h                 | 128 ++++++++++++++++++++++++
 netlink/module-eeprom.c |   2 +-
 qsfp-dd.h               | 128 ------------------------
 qsfp.c                  |   2 +-
 6 files changed, 236 insertions(+), 236 deletions(-)
 rename qsfp-dd.c => cmis4.c (56%)
 create mode 100644 cmis4.h
 delete mode 100644 qsfp-dd.h
Makefile.am +1 -1
index 9734bde..1913f84 100644
@@ -17,7 +17,7 @@ ethtool_SOURCES += \
 		  smsc911x.c at76c50x-usb.c sfc.c stmmac.c	\
 		  sff-common.c sff-common.h sfpid.c sfpdiag.c	\
 		  ixgbevf.c tse.c vmxnet3.c qsfp.c qsfp.h fjes.c lan78xx.c \
-		  igc.c qsfp-dd.c qsfp-dd.h bnxt.c
+		  igc.c cmis4.c cmis4.h bnxt.c
 endif
 
 if ENABLE_BASH_COMPLETION
cmis4.c renamed from qsfp-dd.c +105 -105

402 lines not on this page · raw message

cmis4.h new file +128 -0

128 lines not on this page · raw message

netlink/module-eeprom.c +1 -1
index 768a261..5f58125 100644
@@ -11,7 +11,7 @@
 
 #include "../sff-common.h"
 #include "../qsfp.h"
-#include "../qsfp-dd.h"
+#include "../cmis4.h"
 #include "../internal.h"
 #include "../common.h"
 #include "../list.h"
qsfp-dd.h deleted +0 -128

128 lines not on this page · raw message

qsfp.c +1 -1
index a4d7e08..5923c0d 100644
@@ -58,7 +58,7 @@
 #include "internal.h"
 #include "sff-common.h"
 #include "qsfp.h"
-#include "qsfp-dd.h"
+#include "cmis4.h"
 
 #define MAX_DESC_SIZE	42
 
Signature · 1 line
2.26.2
#6 lore raw

PATCH 4/4 ethtool: Update manpages for getmodule (-m) command

In reply to Moshe Shemesh

From: Vladyslav Tarasiuk <[email protected]>

Add page, bank and i2c parameters and mention change in offset and length treatment if either one of new parameters is specified by the user.

---
 ethtool.8.in | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
ethtool.8.in +14 -0
index fe49b66..9516458 100644
@@ -359,6 +359,9 @@ ethtool \- query or control network driver and hardware settings
 .B2 hex on off
 .BN offset
 .BN length
+.BN page
+.BN bank
+.BN i2c
 .HP
 .B ethtool \-\-show\-priv\-flags
 .I devname
@@ -1154,6 +1157,17 @@ Changes the number of multi-purpose channels.
 Retrieves and if possible decodes the EEPROM from plugin modules, e.g SFP+, QSFP.
 If the driver and module support it, the optical diagnostic information is also
 read and decoded.
+When either one of
+.I page,
+.I bank
+or
+.I i2c
+parameters is specified, dumps only of a single page or its portion is
+allowed. In such a case
+.I offset
+and
+.I length
+parameters are treated relatively to EEPROM page boundaries.
 .TP
 .B \-\-show\-priv\-flags
 Queries the specified network device for its private flags.  The
Signature · 1 line
2.26.2
#8 lore raw
In reply to Moshe Shemesh
Quoted 9 lines

From: Moshe Shemesh [mailto:[email protected]]
Sent: Friday, April 23, 2021 12:23 AM
To: Michal Kubecek <[email protected]>; Andrew Lunn <[email protected]>; Jakub Kicinski <[email protected]>; Don Bollinger <[email protected]>; [email protected]
Cc: Vladyslav Tarasiuk <[email protected]>; Moshe Shemesh <[email protected]>
Subject: [PATCH ethtool-next 0/4] Extend module EEPROM API

Quoted 3 lines

Ethtool supports module EEPROM dumps via the ethtool -m <dev> command.
But in current state its functionality is limited - offset and length

parameters,

Quoted 1 line

which are used to specify a linear desired region of EEPROM data to dump,

is

Quoted 8 lines

not enough, considering emergence of complex module EEPROM layouts such as CMIS 4.0.

Moreover, CMIS 4.0 extends the amount of pages that may be accessible by introducing another parameter for page addressing - banks. Besides, currently module EEPROM is represented as a chunk of concatenated pages, where lower 128 bytes of all pages, except page 00h, are omitted. Offset and length are used to address parts of this fake

linear

Quoted 12 lines

memory. But in practice drivers, which implement get_module_info() and get_module_eeprom() ethtool ops still calculate page number and set I2C address on their own.

This series adds support in ethtool -m of dumping an arbitrary page specified by page number, bank number and I2C address. Implement netlink handler for ethtool -m in order to make such requests to the kernel and extend CLI by adding corresponding parameters.
New command line format:
ethtool -m <dev> [hex on|off] [raw on|off] [offset N] [length N] [page N]
[bank N] [i2c N]

Quoted 1 line

Netlink infrastructure works on per-page basis and allows dumps of a

single

Quoted 21 lines

page at once. But in case user requests human-readable output, which currently may require more than one page, userspace can make such additional calls to kernel on demand and place pages in a linked list. It allows to get pages from cache on demand and pass them to refactored SFF decoders.

Vladyslav Tarasiuk (4):
ethtool: Add netlink handler for getmodule (-m)
ethtool: Refactor human-readable module EEPROM output for new API
ethtool: Rename QSFP-DD identifiers to use CMIS 4.0
ethtool: Update manpages to reflect changes to getmodule (-m) command

 Makefile.am             |   3 +-
 qsfp-dd.c => cmis4.c    | 220 +++++++++++---------
 cmis4.h                 | 128 ++++++++++++
 ethtool.8.in            |  14 ++
 ethtool.c               |   4 +
 internal.h              |  12 ++
 list.h                  |  34 ++++
 netlink/desc-ethtool.c  |  13 ++
 netlink/extapi.h        |   2 +
Quoted 8 lines
 netlink/module-eeprom.c | 438
++++++++++++++++++++++++++++++++++++++++
 qsfp-dd.h               | 125 ------------
 qsfp.c                  | 129 +++++++-----
 qsfp.h                  |  52 ++---
 sff-common.c            |   3 +
 sff-common.h            |   3 +-
 15 files changed, 876 insertions(+), 304 deletions(-)  rename qsfp-dd.c

=>

Quoted 1 line

cmis4.c (55%) create mode 100644 cmis4.h create mode 100644 list.h

create

Quoted 4 lines

mode 100644 netlink/module-eeprom.c delete mode 100644 qsfp-dd.h

--
2.26.2

Will there be an ethtool option to write to module eeprom in CMIS format? There are routine functions to configure the devices that require writing appropriate values to various registers. Byte 26 allows software control of low power mode, squelch and software reset. Page 10h is full of Lane and Data Path Control registers.

Beyond the spec, but allowed by the spec, there are vendor specific capabilities like firmware download that require bulk write (up to 128 bytes per write).

Using the full capabilities of these devices will require write capability. Ethtool is the only path that will be allowed.

Don

#3 lore raw

RE: [PATCH ethtool-next 2/4] ethtool: Refactor human-readable module EEPROM output

In reply to Moshe Shemesh
Quoted 43 lines

From: Moshe Shemesh [mailto:[email protected]]
Sent: Friday, April 23, 2021 12:23 AM
To: Michal Kubecek <[email protected]>; Andrew Lunn <[email protected]>; Jakub Kicinski <[email protected]>; Don Bollinger <[email protected]>; [email protected]
Cc: Vladyslav Tarasiuk <[email protected]>; Moshe Shemesh <[email protected]>
Subject: [PATCH ethtool-next 2/4] ethtool: Refactor human-readable module EEPROM output

From: Vladyslav Tarasiuk <[email protected]>

Reuse existing SFF8636 and QSFP-DD infrastructures to implement EEPROM decoders, which work with paged memory. Add support for human-readable output for QSFP, QSFP28, QSFP Plus, QSFP-DD and DSFP transreceivers from netlink 'ethtool -m' handler.

---
 internal.h              |   2 +
 netlink/module-eeprom.c |  13 ++++
 qsfp-dd.c               |  44 +++++++++++---
 qsfp-dd.h               |  29 +++++----
 qsfp.c                  | 127 +++++++++++++++++++++++-----------------
 qsfp.h                  |  52 ++++++++--------
 sff-common.c            |   3 +
 sff-common.h            |   3 +-
 8 files changed, 171 insertions(+), 102 deletions(-)
internal.h +2 -0
index 2affebe..33e619b 100644
@@ -391,6 +391,8 @@ void sff8472_show_all(const __u8 *id);
 
 /* QSFP Optics diagnostics */
 void sff8636_show_all(const __u8 *id, __u32 eeprom_len);
+void sff8636_show_all_paged(const struct ethtool_module_eeprom
 *page_zero,
+			    const struct ethtool_module_eeprom
 *page_three);
 
Quoted 2 lines

/* FUJITSU Extended Socket network device */ int fjes_dump_regs(struct
ethtool_drvinfo *info, struct ethtool_regs *regs); diff --git

a/netlink/module-

Quoted 147 lines

eeprom.c b/netlink/module-eeprom.c index 7298087..768a261 100644

netlink/module-eeprom.c +1 -0
@@ -291,6 +291,7 @@ static bool page_available(struct
 ethtool_module_eeprom *which)
 	case SFF8024_ID_QSFP_PLUS:
 		return (!which->bank && which->page <= 3);
 	case SFF8024_ID_QSFP_DD:
+	case SFF8024_ID_DSFP:
 		return !(flat_mem && which->page);
 	default:
netlink/module-eeprom.c +14 -0
 		return true;
@@ -323,6 +324,7 @@ static int decoder_prefetch(struct nl_context *nlctx)
 		request.page = 3;
 		break;
 	case SFF8024_ID_QSFP_DD:
+	case SFF8024_ID_DSFP:
 		memset(&request, 0, sizeof(request));
 		request.i2c_address = ETH_I2C_ADDRESS_LOW;
 		request.offset = 128;
@@ -336,13 +338,24 @@ static int decoder_prefetch(struct nl_context
 *nlctx)
 
 static void decoder_print(void)
 {
+	struct ethtool_module_eeprom *page_three = cache_get(3, 0,
+ETH_I2C_ADDRESS_LOW);
 	struct ethtool_module_eeprom *page_zero = cache_get(0, 0,
 ETH_I2C_ADDRESS_LOW);
+	struct ethtool_module_eeprom *page_one = cache_get(1, 0,
+ETH_I2C_ADDRESS_LOW);
 	u8 module_id = page_zero->data[SFF8636_ID_OFFSET];
 
 	switch (module_id) {
 	case SFF8024_ID_SFP:
 		sff8079_show_all(page_zero->data);
 		break;
+	case SFF8024_ID_QSFP:
+	case SFF8024_ID_QSFP28:
+	case SFF8024_ID_QSFP_PLUS:
+		sff8636_show_all_paged(page_zero, page_three);
+		break;
+	case SFF8024_ID_QSFP_DD:
+	case SFF8024_ID_DSFP:
+		cmis4_show_all(page_zero, page_one);
+		break;
 	default:
 		dump_hex(stdout, page_zero->data, page_zero->length,

page_zero->offset);

netlink/module-eeprom.c +0 -0
 		break;
qsfp-dd.c +6 -0
index 900bbb5..5c2e4a0 100644
@@ -274,6 +274,20 @@ static void qsfp_dd_show_mod_lvl_monitors(const
 __u8 *id)
 		  OFFSET_TO_U16(QSFP_DD_CURR_CURR_OFFSET));
 }
 
+static void qsfp_dd_show_link_len_from_page(const __u8
 *page_one_data)
+{
+	qsfp_dd_print_smf_cbl_len(page_one_data);
+	sff_show_value_with_unit(page_one_data,
 QSFP_DD_OM5_LEN_OFFSET,
+				 "Length (OM5)", 2, "m");
+	sff_show_value_with_unit(page_one_data,

QSFP_DD_OM4_LEN_OFFSET,

qsfp-dd.c +2 -0
+				 "Length (OM4)", 2, "m");
+	sff_show_value_with_unit(page_one_data,

QSFP_DD_OM3_LEN_OFFSET,

qsfp-dd.c +2 -0
+				 "Length (OM3 50/125um)", 2, "m");
+	sff_show_value_with_unit(page_one_data,

QSFP_DD_OM2_LEN_OFFSET,

qsfp-dd.c +24 -9
+				 "Length (OM2 50/125um)", 1, "m");
+}
+
+
 /**
  * Print relevant info about the maximum supported fiber media length
  * for each type of fiber media at the maximum module-supported bit rate.
@@ -283,15 +297,7 @@ static void qsfp_dd_show_mod_lvl_monitors(const
 __u8 *id)
  */
 static void qsfp_dd_show_link_len(const __u8 *id)  {
-	qsfp_dd_print_smf_cbl_len(id);
-	sff_show_value_with_unit(id, QSFP_DD_OM5_LEN_OFFSET,
-				 "Length (OM5)", 2, "m");
-	sff_show_value_with_unit(id, QSFP_DD_OM4_LEN_OFFSET,
-				 "Length (OM4)", 2, "m");
-	sff_show_value_with_unit(id, QSFP_DD_OM3_LEN_OFFSET,
-				 "Length (OM3 50/125um)", 2, "m");
-	sff_show_value_with_unit(id, QSFP_DD_OM2_LEN_OFFSET,
-				 "Length (OM2 50/125um)", 1, "m");
+	qsfp_dd_show_link_len_from_page(id + PAG01H_UPPER_OFFSET);
 }
 
 /**
@@ -331,3 +337,23 @@ void qsfp_dd_show_all(const __u8 *id)
 	qsfp_dd_show_vendor_info(id);
 	qsfp_dd_show_rev_compliance(id);
 }
+
+void cmis4_show_all(const struct ethtool_module_eeprom *page_zero,
+		    const struct ethtool_module_eeprom *page_one) {
+	const __u8 *page_zero_data = page_zero->data;
+
+	qsfp_dd_show_identifier(page_zero_data);
+	qsfp_dd_show_power_info(page_zero_data);
+	qsfp_dd_show_connector(page_zero_data);
+	qsfp_dd_show_cbl_asm_len(page_zero_data);
+	qsfp_dd_show_sig_integrity(page_zero_data);
+	qsfp_dd_show_mit_compliance(page_zero_data);
+	qsfp_dd_show_mod_lvl_monitors(page_zero_data);
+
+	if (page_one)
+		qsfp_dd_show_link_len_from_page(page_one->data);
+
+	qsfp_dd_show_vendor_info(page_zero_data);
+	qsfp_dd_show_rev_compliance(page_zero_data);
+}
qsfp-dd.h +0 -0
index f589c4e..fddb188 100644
@@ -96,30 +96,33 @@
 /*-----------------------------------------------------------------------
  * Upper Memory Page 0x01: contains advertising fields that define

properties
* that are unique to active modules and cable assemblies.
- * RealOffset = 1 * 0x80 + LocalOffset
+ * GlobalOffset = 2 * 0x80 + LocalOffset
*/

qsfp-dd.h +1 -2
-#define PAG01H_UPPER_OFFSET			(0x01 * 0x80)
+#define PAG01H_UPPER_OFFSET			(0x02 * 0x80)
 
 /* Supported Link Length (Page 1) */
-#define QSFP_DD_SMF_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x84)
-#define QSFP_DD_OM5_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x85)
-#define QSFP_DD_OM4_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x86)
-#define QSFP_DD_OM3_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x87)
-#define QSFP_DD_OM2_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x88)

qsfp-dd.h line 108

Quoted 5 lines
qsfp-dd.h +5 -0
+#define QSFP_DD_SMF_LEN_OFFSET			0x4
+#define QSFP_DD_OM5_LEN_OFFSET			0x5
+#define QSFP_DD_OM4_LEN_OFFSET			0x6
+#define QSFP_DD_OM3_LEN_OFFSET			0x7
+#define QSFP_DD_OM2_LEN_OFFSET			0x8

I see here you have switched from offsets from the beginning of flat linear memory to offsets within the upper half page. I recommend actually using the values in the spec, which are offset from the base of the page. I know the first 128 bytes are just copies of page 0, and aren't being used. But the specs all describe these register offsets in the range 128-255. This is also the actual values the driver is sending to the device. There is actually no good reason to redefine these values as if they were offsets from 128.

Thus, QSFP_DD_SMF_LEN_OFFSET should be 0x84, just like the spec says, and just like the offset the driver would send to the module to get this byte. It will be MUCH easier to compare hundreds of hard coded values to the spec if you aren't mentally translating them every time they are copied or reviewed.

Don

#7 lore raw

RE: [PATCH ethtool-next 4/4] ethtool: Update manpages for getmodule (-m) command

In reply to Moshe Shemesh
Quoted 37 lines

From: Moshe Shemesh [mailto:[email protected]]
Sent: Friday, April 23, 2021 12:23 AM
To: Michal Kubecek <[email protected]>; Andrew Lunn <[email protected]>; Jakub Kicinski <[email protected]>; Don Bollinger <[email protected]>; [email protected]
Cc: Vladyslav Tarasiuk <[email protected]>; Moshe Shemesh <[email protected]>
Subject: [PATCH ethtool-next 4/4] ethtool: Update manpages for getmodule (-m) command

From: Vladyslav Tarasiuk <[email protected]>

Add page, bank and i2c parameters and mention change in offset and length treatment if either one of new parameters is specified by the user.

---
 ethtool.8.in | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
ethtool.8.in +0 -0
@@ -359,6 +359,9 @@ ethtool \- query or control network driver and

hardware settings
.B2 hex on off
.BN offset
.BN length
+.BN page
+.BN bank
+.BN i2c
.HP
.B ethtool \-\-show\-priv\-flags
.I devname

ethtool.8.in +0 -0
@@ -1154,6 +1157,17 @@ Changes the number of multi-purpose channels.
 Retrieves and if possible decodes the EEPROM from plugin modules, e.g
Quoted 2 lines

SFP+, QSFP.
If the driver and module support it, the optical diagnostic information

is also

ethtool.8.in Changes the number of multi-purpose channels.

Quoted 9 lines

read and decoded.

ethtool.8.in +8 -0
+When either one of
+.I page,
+.I bank
+or
+.I i2c
+parameters is specified, dumps only of a single page or its portion is
+allowed. In such a case .I offset and .I length parameters are treated
+relatively to EEPROM page boundaries.

You want 'relative', not 'relatively'.

Please spend a few more words on this. Basically there are two choices. Assuming lower memory cannot be accessed when page 2 is specified, the offset of the first byte of page 2 is either 0 or 128. I can't tell which of those choices you mean.

Also, based on the code in the other patches, I assume you mean that the first byte of page 2 is at offset 0. I recommend against that. The specs all assume that the first byte ***of the paged area*** of page 2 (or any other page) is at 128. Hundreds of registers are specified in each spec, all with offsets in the range 128-255. The ONLY purpose of this option to ethtool is to manage those registers, per those specs. Forcing every user to translate between the spec and the tool is going to be tedious and error prone.

Quoted 5 lines

.TP
.B \-\-show\-priv\-flags
Queries the specified network device for its private flags. The
--
2.26.2

Don

#9 lore raw
In reply to Don Bollinger
Quoted 4 lines

There are routine functions to configure the devices that require writing appropriate values to various registers. Byte 26 allows software control of low power mode, squelch and software reset. Page 10h is full of Lane and Data Path Control registers.

These all sounds like foot canons when in user space control. I would expect the MAC and or SFP driver to make use of these features, no need to export them to user space, at least not in a raw format. I could however imagine ethtool commands to manipulate specific features, passing the request to the MAC to perform, so it knows what is going on.

Quoted 3 lines

Beyond the spec, but allowed by the spec, there are vendor specific capabilities like firmware download that require bulk write (up to 128 bytes per write).

This one is not so easy. Since it is vendor specific, we need to consider how to actually make it vendor generic from Ethtool, or maybe devlink. Maybe code in the kernel which matches on the vendor string in the SFP EEPROM, and provides a standardized API towards ethtool, and does whatever magic is needed towards the SFP. But it gets messy when you don't have direct access to the SFP, there is a layer of firmware in the middle, which is often the case.

Andrew

#10 lore raw
Quoted 6 lines
Quoted 4 lines

There are routine functions to configure the devices that require writing appropriate values to various registers. Byte 26 allows software control of low power mode, squelch and software reset. Page 10h is full of Lane and Data Path Control registers.

These all sounds like foot canons when in user space control. I would

expect

Quoted 10 lines

the MAC and or SFP driver to make use of these features, no need to export them to user space, at least not in a raw format. I could however imagine ethtool commands to manipulate specific features, passing the request to the MAC to perform, so it knows what is going on.

Quoted 3 lines

Beyond the spec, but allowed by the spec, there are vendor specific capabilities like firmware download that require bulk write (up to 128 bytes per write).

This one is not so easy. Since it is vendor specific, we need to consider

how to

Quoted 5 lines

actually make it vendor generic from Ethtool, or maybe devlink. Maybe code in the kernel which matches on the vendor string in the SFP EEPROM, and provides a standardized API towards ethtool, and does whatever magic is needed towards the SFP. But it gets messy when you don't have direct access to the SFP, there is a layer of firmware in the middle, which is

often

Quoted 3 lines

the case.

Andrew

Here we go again... It is my experience that there are far more capabilities in these devices than will ever be captured in ethtool. Module vendors can provide additional value to their customers by putting innovative features into their modules, and providing software applications to take advantage of those features. These features don't necessarily impact the network stack. They may be used to draw additional diagnostic data from the devices, or to enable management features like flashing colored lights built into custom modules. I've written code to do these and more things which are unique to one vendor, and valued by their customers.

I'm asking for a generic interface that allows read/write access to arbitrary registers. Put the warnings in the documentation, limit access to it, but make it available.

Don

#4 lore raw

Re: [PATCH ethtool-next 2/4] ethtool: Refactor human-readable module EEPROM output

In reply to Don Bollinger

Hi Don

Please trim the text of the email when replying. Standard netiquette best practices.

Quoted 15 lines
Quoted 15 lines
qsfp-dd.h +1 -2
-#define PAG01H_UPPER_OFFSET			(0x01 * 0x80)
+#define PAG01H_UPPER_OFFSET			(0x02 * 0x80)
 
 /* Supported Link Length (Page 1) */
-#define QSFP_DD_SMF_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x84)
-#define QSFP_DD_OM5_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x85)
-#define QSFP_DD_OM4_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x86)
-#define QSFP_DD_OM3_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x87)
-#define QSFP_DD_OM2_LEN_OFFSET
	(PAG01H_UPPER_OFFSET + 0x88)

+#define QSFP_DD_SMF_LEN_OFFSET 0x4

Quoted 8 lines

qsfp-dd.h line 108

Quoted 4 lines
qsfp-dd.h +4 -0
+#define QSFP_DD_OM5_LEN_OFFSET			0x5
+#define QSFP_DD_OM4_LEN_OFFSET			0x6
+#define QSFP_DD_OM3_LEN_OFFSET			0x7
+#define QSFP_DD_OM2_LEN_OFFSET			0x8

I see here you have switched from offsets from the beginning of flat linear memory to offsets within the upper half page. I recommend actually using the values in the spec, which are offset from the base of the page.

I agree with this. Being able to easily map between spec and code is important.

Andrew

#11 lore raw
In reply to Don Bollinger
Quoted 9 lines

Here we go again... It is my experience that there are far more capabilities in these devices than will ever be captured in ethtool. Module vendors can provide additional value to their customers by putting innovative features into their modules, and providing software applications to take advantage of those features. These features don't necessarily impact the network stack. They may be used to draw additional diagnostic data from the devices, or to enable management features like flashing colored lights built into custom modules. I've written code to do these and more things which are unique to one vendor, and valued by their customers.

Sorry, but not going to happen. Ethernet PHYs can have lots of addition registers on stop of what 802.3 specifies. Vendors do add additional functionality. And we do support some of it, like configuring downshift, energy detect power down, cable diagnostics in a generic manor. And we are open to adding more such features. People can contribute code which multiple vendors might implement. We then have well documented APIs which are the same across different vendors.

For LEDs you should be using the Linux LED class drivers. The Ethernet PHYs are slowly moving that way. Very slowly :-(

Both MAC and Ethernet PHY drivers have tunables. I would suggest using this concept, but applied to SFPs. This is how most of the additional PHY features are supported. But first you need to add an SFP driver framework, which matches on the fields in the EEPROM to load the driver specific to an SFP. That then gives you a place to add such code.

Andrew