Skip to contentSkip to conversation

ethtool: Add QSFP-DD support

PATCH Superseded Adrian Pop 4 participants 9 messages Jul 31, 2020 – Aug 6, 2020

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Adrian Pop

author
#0 lore raw

PATCH 1/1 ethtool: Add QSFP-DD support

The Common Management Interface Specification (CMIS) for QSFP-DD shares some similarities with other form factors such as QSFP or SFP, but due to the fact that the module memory map is different, the current ethtool version is not able to provide relevant information about an interface.

This patch adds QSFP-DD support to ethtool. The changes are similar to the ones already existing in qsfp.c, but customized to use the memory addresses and logic as defined in the specifications document.

Page 0x00 (lower and higher memory) are always implemented, so the ethtool expects at least 256 bytes if the identifier matches the one for QSFP-DD. For optical connected cables, additional pages are usually available (the contain module defined thresholds or lane diagnostic information). In this case, ethtool expects to receive 768 bytes in the following format:

    +----------+----------+----------+----------+----------+----------+
    |   Page   |   Page   |   Page   |   Page   |   Page   |   Page   |
    |   0x00   |   0x00   |   0x01   |   0x02   |   0x10   |   0x11   |
    |  (lower) | (higher) | (higher) | (higher) | (higher) | (higher) |
    |   128B   |   128B   |   128B   |   128B   |   128B   |   128B   |
    +----------+----------+----------+----------+----------+----------

Several functions from qsfp.c could be reused, so an additional parameter was added to each and the functions were moved to sff-common.c.

---
 Makefile.am  |   7 +-
 qsfp-dd.c    | 561 +++++++++++++++++++++++++++++++++++++++++++++++++++
 qsfp-dd.h    | 236 ++++++++++++++++++++++
 qsfp.c       |  60 ++----
 qsfp.h       |   8 -
 sff-common.c |  52 +++++
 sff-common.h |  26 ++-
 7 files changed, 894 insertions(+), 56 deletions(-)
 create mode 100644 qsfp-dd.c
 create mode 100644 qsfp-dd.h
Makefile.am +4 -3
index 2abb274..9fd8024 100644
@@ -17,7 +17,8 @@ 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
+		  igc.c \
+		  qsfp-dd.c qsfp-dd.h
 endif
 
 if ENABLE_BASH_COMPLETION
@@ -47,12 +48,12 @@ endif
 
 TESTS = test-cmdline
 check_PROGRAMS = test-cmdline
-test_cmdline_SOURCES = test-cmdline.c test-common.c $(ethtool_SOURCES) 
+test_cmdline_SOURCES = test-cmdline.c test-common.c $(ethtool_SOURCES)
 test_cmdline_CFLAGS = -DTEST_ETHTOOL
 if !ETHTOOL_ENABLE_NETLINK
 TESTS += test-features
 check_PROGRAMS += test-features
-test_features_SOURCES = test-features.c test-common.c $(ethtool_SOURCES) 
+test_features_SOURCES = test-features.c test-common.c $(ethtool_SOURCES)
 test_features_CFLAGS = -DTEST_ETHTOOL
 endif
 
qsfp-dd.c new file +561 -0

561 lines not on this page · raw message

qsfp-dd.h new file +236 -0

236 lines not on this page · raw message

qsfp.c +19 -41

105 lines not on this page · raw message

qsfp.h +0 -8
index 3215932..9636b0c 100644
@@ -31,14 +31,6 @@
 #define	SFF8636_ID_OFFSET	0x00
 
 #define	SFF8636_REV_COMPLIANCE_OFFSET	0x01
-#define	 SFF8636_REV_UNSPECIFIED		0x00
-#define	 SFF8636_REV_8436_48			0x01
-#define	 SFF8636_REV_8436_8636			0x02
-#define	 SFF8636_REV_8636_13			0x03
-#define	 SFF8636_REV_8636_14			0x04
-#define	 SFF8636_REV_8636_15			0x05
-#define	 SFF8636_REV_8636_20			0x06
-#define	 SFF8636_REV_8636_27			0x07
 
 #define	SFF8636_STATUS_2_OFFSET	0x02
 /* Flat Memory:0- Paging, 1- Page 0 only */
sff-common.c +52 -0

73 lines not on this page · raw message

sff-common.h +22 -4
index 5562b4d..0d04851 100644
@@ -26,7 +26,17 @@
 #include <stdio.h>
 #include "internal.h"
 
-#define SFF8024_ID_OFFSET				0x00
+/* Revision compliance */
+#define	 SFF8636_REV_UNSPECIFIED		0x00
+#define	 SFF8636_REV_8436_48			0x01
+#define	 SFF8636_REV_8436_8636			0x02
+#define	 SFF8636_REV_8636_13			0x03
+#define	 SFF8636_REV_8636_14			0x04
+#define	 SFF8636_REV_8636_15			0x05
+#define	 SFF8636_REV_8636_20			0x06
+#define	 SFF8636_REV_8636_27			0x07
+
+#define  SFF8024_ID_OFFSET				0x00
 #define  SFF8024_ID_UNKNOWN				0x00
 #define  SFF8024_ID_GBIC				0x01
 #define  SFF8024_ID_SOLDERED_MODULE		0x02
@@ -51,7 +61,8 @@
 #define  SFF8024_ID_HD8X_FANOUT			0x15
 #define  SFF8024_ID_CDFP_S3				0x16
 #define  SFF8024_ID_MICRO_QSFP			0x17
-#define  SFF8024_ID_LAST				SFF8024_ID_MICRO_QSFP
+#define  SFF8024_ID_QSFP_DD				0x18
+#define  SFF8024_ID_LAST				SFF8024_ID_QSFP_DD
 #define  SFF8024_ID_UNALLOCATED_LAST	0x7F
 #define  SFF8024_ID_VENDOR_START		0x80
 #define  SFF8024_ID_VENDOR_LAST			0xFF
@@ -76,8 +87,14 @@
 #define  SFF8024_CTOR_RJ45				0x22
 #define  SFF8024_CTOR_NO_SEPARABLE		0x23
 #define  SFF8024_CTOR_MXC_2x16			0x24
-#define  SFF8024_CTOR_LAST				SFF8024_CTOR_MXC_2x16
-#define  SFF8024_CTOR_UNALLOCATED_LAST	0x7F
+#define  SFF8024_CTOR_CS_OPTICAL		0x25
+#define  SFF8024_CTOR_CS_OPTICAL_MINI		0x26
+#define  SFF8024_CTOR_MPO_2X12		    	0x27
+#define  SFF8024_CTOR_MPO_1X16		    	0x28
+#define  SFF8024_CTOR_LAST			SFF8024_CTOR_MPO_1X16
+
+#define  SFF8024_CTOR_NO_SEP_QSFP_DD 		0x6F
+#define  SFF8024_CTOR_UNALLOCATED_LAST		0x7F
 #define  SFF8024_CTOR_VENDOR_START		0x80
 #define  SFF8024_CTOR_VENDOR_LAST		0xFF
 
@@ -185,5 +202,6 @@ void sff8024_show_oui(const __u8 *id, int id_offset);
 void sff8024_show_identifier(const __u8 *id, int id_offset);
 void sff8024_show_connector(const __u8 *id, int ctor_offset);
 void sff8024_show_encoding(const __u8 *id, int encoding_offset, int sff_type);
+void sff_show_revision_compliance(const __u8 *id, int rev_offset);
 
 #endif /* SFF_COMMON_H__ */
Signature · 1 line
2.17.1
#1 lore raw
Quoted 15 lines · Adrian Pop

The Common Management Interface Specification (CMIS) for QSFP-DD shares some similarities with other form factors such as QSFP or SFP, but due to the fact that the module memory map is different, the current ethtool version is not able to provide relevant information about an interface.

This patch adds QSFP-DD support to ethtool. The changes are similar to the ones already existing in qsfp.c, but customized to use the memory addresses and logic as defined in the specifications document.

Page 0x00 (lower and higher memory) are always implemented, so the ethtool expects at least 256 bytes if the identifier matches the one for QSFP-DD. For optical connected cables, additional pages are usually available (the contain module defined thresholds or lane diagnostic information). In this case, ethtool expects to receive 768 bytes in the following format:

Quoted 6 lines
    +----------+----------+----------+----------+----------+----------+
    |   Page   |   Page   |   Page   |   Page   |   Page   |   Page   |
    |   0x00   |   0x00   |   0x01   |   0x02   |   0x10   |   0x11   |
    |  (lower) | (higher) | (higher) | (higher) | (higher) | (higher) |
    |   128B   |   128B   |   128B   |   128B   |   128B   |   128B   |
    +----------+----------+----------+----------+----------+----------

Hi Adrian

Didn't we discuss that page 3 might be useful? I would prefer not to document that pages 0x10 and 0x11 would follow page 2 until we have a driver which does actually provide pages 0x10 and 0x11.

Andrew

#2 lore raw
In reply to Adrian Pop

Hi Adrian, thanks again for submitting this patch. I got two comments off-list. Sharing them here.

Quoted 32 lines · Adrian Pop
qsfp-dd.c new file +32 -0
+/**
+ * Print the cable assembly length, for both passive copper and active
+ * optical or electrical cables. The base length (bits 5-0) must be
+ * multiplied with the SMF length multiplier (bits 7-6) to obtain the
+ * correct value. Relevant documents:
+ * [1] CMIS Rev. 3, pag. 59, section 1.7.3.10, Table 31
+ * [2] CMIS Rev. 4, pag. 94, section 8.3.10, Table 8-19
+ */
+static void qsfp_dd_show_cbl_asm_len(const __u8 *id)
+{
+	static const char *fn = "Cable assembly length";
+	float mul = 1.0f;
+	float val = 0.0f;
+
+	/* Check if max length */
+	if (id[QSFP_DD_CBL_ASM_LEN_OFFSET] == QSFP_DD_6300M_MAX_LEN) {
+		printf("\t%-41s : > 6.3km\n", fn);
+		return;
+	}
+
+	/* Get the multiplier from the first two bits */
+	switch (id[QSFP_DD_CBL_ASM_LEN_OFFSET] & QSFP_DD_LEN_MUL_MASK) {
+	case QSFP_DD_MULTIPLIER_00:
+		mul = 0.1f;
+		break;
+	case QSFP_DD_MULTIPLIER_01:
+		mul = 1.0f;
+		break;
+	case QSFP_DD_MULTIPLIER_10:
+		mul = 10.0f;
+		break;
+	case QSFP_DD_MULTIPLIER_11:

qsfp-dd.c line 122

Quoted 10 lines
qsfp-dd.c new file +10 -0
+		mul = 100.0f;
+		break;
+	default:
+		break;
+	}
+
+	/* Get base value from first 6 bits and multiply by mul */
+	val = (id[QSFP_DD_CBL_ASM_LEN_OFFSET] & QSFP_DD_LEN_VAL_MASK);
+	val = (float)val * mul;
+	printf("\t%-41s : %0.2fkm\n", fn, val);

Should be:

printf("\t%-41s : %0.2fm\n", fn, val);

Since the specification says "Link length base value in meters".

Before:

Cable assembly length : 0.50km

After:

Cable assembly length : 0.50m

Quoted 1 line

+}

...

Quoted 81 lines
qsfp-dd.h new file +75 -0
new file mode 100644
index 0000000..a7a7051
@@ -0,0 +1,236 @@
+#ifndef QSFP_DD_H__
+#define QSFP_DD_H__
+
+#define QSFP_DD_PAG_SIZE			0x80
+#define QSFP_DD_EEPROM_5PAG			(0x80 * 6)
+#define QSFP_DD_MAX_CHANNELS			0x08
+#define QSFP_DD_MAX_DESC_SIZE			0x2A
+#define QSFP_DD_READ_TX				0x00
+#define QSFP_DD_READ_RX				0x01
+
+/* Struct for the current/power of a channel */
+struct qsfp_dd_channel_diags {
+	__u16 bias_cur;
+	__u16 rx_power;
+	__u16 tx_power;
+};
+
+struct qsfp_dd_diags {
+	/* Voltage in 0.1mV units; the first 4 elements represent
+	 * the high/low alarm, high/low warning and the last one
+	 * represent the current voltage of the module.
+	 */
+	__u16 sfp_voltage[4];
+
+	/**
+	 * Temperature in 16-bit signed 1/256 Celsius; the first 4
+	 * elements represent the high/low alarm, high/low warning
+	 * and the last one represent the current temp of the module.
+	 */
+	__s16 sfp_temp[4];
+
+	/* Tx bias current in 2uA units */
+	__u16 bias_cur[4];
+
+	/* Measured TX Power */
+	__u16 tx_power[4];
+
+	/* Measured RX Power */
+	__u16 rx_power[4];
+
+	/* Rx alarms and warnings */
+	bool rxaw[QSFP_DD_MAX_CHANNELS][4];
+
+	/* Tx alarms and warnings */
+	bool txaw[QSFP_DD_MAX_CHANNELS][4];
+
+	struct qsfp_dd_channel_diags scd[QSFP_DD_MAX_CHANNELS];
+};
+
+#define HA					0
+#define LA					1
+#define HW					2
+#define LW					3
+
+/* Identifier and revision compliance (Page 0) */
+#define	QSFP_DD_ID_OFFSET			0x00
+#define QSFP_DD_REV_COMPLIANCE_OFFSET		0x01
+
+#define QSFP_DD_MODULE_TYPE_OFFSET		0x55
+#define QSFP_DD_MT_MMF				0x01
+#define QSFP_DD_MT_SMF				0x02
+
+/* Module-Level Monitors (Page 0) */
+#define QSFP_DD_CURR_TEMP_OFFSET		0x0E
+#define QSFP_DD_CURR_CURR_OFFSET		0x10
+
+#define QSFP_DD_CTOR_OFFSET			0xCB
+
+/* Vendor related information (Page 0) */
+#define QSFP_DD_VENDOR_NAME_START_OFFSET	0x81
+#define QSFP_DD_VENDOR_NAME_END_OFFSET		0x90
+
+#define QSFP_DD_VENDOR_OUI_OFFSET		0x91
+
+#define QSFP_DD_VENDOR_PN_START_OFFSET		0x94

qsfp-dd.h line 85

Quoted 10 lines
qsfp-dd.h new file +10 -0
+#define QSFP_DD_VENDOR_PN_END_OFFSET		0xA3
+
+#define QSFP_DD_VENDOR_REV_START_OFFSET		0xA4
+#define QSFP_DD_VENDOR_REV_END_OFFSET		0xA5
+
+#define QSFP_DD_VENDOR_SN_START_OFFSET		0xA6
+#define QSFP_DD_VENDOR_SN_END_OFFSET		0xB5
+
+#define QSFP_DD_DATE_YEAR_OFFSET		0xB6
+#define QSFP_DD_DATE_VENDOR_LOT_OFFSET		0xBD

According to the specification (section 8.3.7), the offset is 188, so should be 0xBC.

Before:

Date code : 200507 _

After:

Date code : 200507

author
#3 lore raw

Hi Andrew, Ido!

Quoted 2 lines

Hi Adrian, thanks again for submitting this patch. I got two comments off-list. Sharing them here.

Thanks for pointing that out, I took a look and you're right. I'll fix them.

Quoted 3 lines

Didn't we discuss that page 3 might be useful? I would prefer not to document that pages 0x10 and 0x11 would follow page 2 until we have a driver which does actually provide pages 0x10 and 0x11.

Should I just remove that bit about 0x10 and 0x11 from the commit message (so keep only the first two paragraphs) and leave the code as it is?

Adrian

#4 lore raw
In reply to Adrian Pop
Quoted 22 lines · Adrian Pop

The Common Management Interface Specification (CMIS) for QSFP-DD shares some similarities with other form factors such as QSFP or SFP, but due to the fact that the module memory map is different, the current ethtool version is not able to provide relevant information about an interface.

This patch adds QSFP-DD support to ethtool. The changes are similar to the ones already existing in qsfp.c, but customized to use the memory addresses and logic as defined in the specifications document.

Page 0x00 (lower and higher memory) are always implemented, so the ethtool expects at least 256 bytes if the identifier matches the one for QSFP-DD. For optical connected cables, additional pages are usually available (the contain module defined thresholds or lane diagnostic information). In this case, ethtool expects to receive 768 bytes in the following format:

    +----------+----------+----------+----------+----------+----------+
    |   Page   |   Page   |   Page   |   Page   |   Page   |   Page   |
    |   0x00   |   0x00   |   0x01   |   0x02   |   0x10   |   0x11   |
    |  (lower) | (higher) | (higher) | (higher) | (higher) | (higher) |
    |   128B   |   128B   |   128B   |   128B   |   128B   |   128B   |
    +----------+----------+----------+----------+----------+----------
Quoted 5 lines

Several functions from qsfp.c could be reused, so an additional parameter was added to each and the functions were moved to sff-common.c.

AFAICS the kernel counterpart is going to reach mainline in 5.9-rc1 merge window. Please base your patch on "next" branch or wait until next is merged into master after 5.8 release (which should be later today or tomorrow).

Quoted 17 lines
---
 Makefile.am  |   7 +-
 qsfp-dd.c    | 561 +++++++++++++++++++++++++++++++++++++++++++++++++++
 qsfp-dd.h    | 236 ++++++++++++++++++++++
 qsfp.c       |  60 ++----
 qsfp.h       |   8 -
 sff-common.c |  52 +++++
 sff-common.h |  26 ++-
 7 files changed, 894 insertions(+), 56 deletions(-)
 create mode 100644 qsfp-dd.c
 create mode 100644 qsfp-dd.h
Makefile.am +0 -0
index 2abb274..9fd8024 100644

Makefile.am ethtool_SOURCES += \ · line 21

Quoted 6 lines
Makefile.am +2 -1
@@ -17,7 +17,8 @@ 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
+		  igc.c \
+		  qsfp-dd.c qsfp-dd.h

There is no need to start a new line.

Quoted 8 lines
Makefile.am +0 -1
 endif
 
 if ENABLE_BASH_COMPLETION
@@ -47,12 +48,12 @@ endif
 
 TESTS = test-cmdline
 check_PROGRAMS = test-cmdline
-test_cmdline_SOURCES = test-cmdline.c test-common.c $(ethtool_SOURCES) 

Makefile.am endif · line 59

Quoted 10 lines
Makefile.am +2 -1
+test_cmdline_SOURCES = test-cmdline.c test-common.c $(ethtool_SOURCES)
 test_cmdline_CFLAGS = -DTEST_ETHTOOL
 if !ETHTOOL_ENABLE_NETLINK
 TESTS += test-features
 check_PROGRAMS += test-features
-test_features_SOURCES = test-features.c test-common.c $(ethtool_SOURCES) 
+test_features_SOURCES = test-features.c test-common.c $(ethtool_SOURCES)
 test_features_CFLAGS = -DTEST_ETHTOOL
 endif
 

Do not mix unrelated changes like whitespace cleanups with your functional changes, it makes it harder to see what the patch is doing. Please split the cleanups (there are some more in qsfp.c) into a separate patch.

Michal

author
#5 lore raw
Quoted 5 lines

AFAICS the kernel counterpart is going to reach mainline in 5.9-rc1 merge window. Please base your patch on "next" branch or wait until next is merged into master after 5.8 release (which should be later today or tomorrow).

I will wait until tomorrow and rebase my patch onto master then.

Quoted 5 lines

Do not mix unrelated changes like whitespace cleanups with your functional changes, it makes it harder to see what the patch is doing. Please split the cleanups (there are some more in qsfp.c) into a separate patch.

I'll create separate patches for functional changes/cleanups. Thanks for letting me know.

Adrian

#8 lore raw
In reply to Adrian Pop

I noticed one more minor problem:

qsfp-dd.c line 438

Quoted 11 lines · Adrian Pop
qsfp-dd.c new file +11 -0
+static void qsfp_dd_show_sig_optical_pwr(const __u8 *id, __u32 eeprom_len)
+{
+	static const char * const aw_strings[] = {
+		"%s power high alarm   (Channel %d)",
+		"%s power low alarm    (Channel %d)",
+		"%s power high warning (Channel %d)",
+		"%s power low warning  (Channel %d)"
+	};
+	__u8 module_type = id[QSFP_DD_MODULE_TYPE_OFFSET];
+	char field_desc[QSFP_DD_MAX_DESC_SIZE];
+	struct qsfp_dd_diags sd = { { 0 } };

This causes a compiler warning with recent gcc:

qsfp-dd.c: In function ‘qsfp_dd_show_sig_optical_pwr’:
qsfp-dd.c:438:9: warning: missing initializer for field ‘sfp_temp’ of ‘struct qsfp_dd_diags’ [-Wmissing-field-initializers]

    438 |  struct qsfp_dd_diags sd = { { 0 } };
        |         ^~~~~~~~~~~~~
  In file included from qsfp-dd.c:26:
  qsfp-dd.h:30:8: note: ‘sfp_temp’ declared here
     30 |  __s16 sfp_temp[4];
        |        ^~~~~~~~

An empty initializer like

	struct qsfp_dd_diags sd = {};

should be fine (and is already used in many other places).

Michal

#6 lore raw
In reply to Adrian Pop
Quoted 7 lines · Adrian Pop
Quoted 5 lines

AFAICS the kernel counterpart is going to reach mainline in 5.9-rc1 merge window. Please base your patch on "next" branch or wait until next is merged into master after 5.8 release (which should be later today or tomorrow).

I will wait until tomorrow and rebase my patch onto master then.

Branch "next" is merged into master now so you can base v2 on master.

Michal

author
#7 lore raw
Quoted 3 lines

Branch "next" is merged into master now so you can base v2 on master.

Hi Michal!

Just submitted v2. I fixed the little problems noticed by Ido and you. The submission consists of only one patch, since I noticed that some extra whitespace 'fixes' were wrongly introduced by my editor so I supposed the code is already well formatted and there's no need for a separate one. I hope everything is okay now.

Adrian