Skip to contentSkip to conversation

cmis: Miscellaneous fixes

PATCH New Ido Schimmel 1 participant 9 messages Jul 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover cmis: Miscellaneous fixes

Patch #1 fixes an issue reported by a user. The rest fix valid issues pointed out by Claude Code after I asked it to validate the CMIS parser against the CMIS specification.

Note that these are not regressions (never worked).

Ido Schimmel (8):
cmis: Fix printing of Tx bias current
cmis: Fix printing of channel-level flags
cmis: Fix printing of CDB EPL pages
module-common: Fix printing of transmitter technology for CMIS
transceivers
module-common: Avoid undefined behavior with CMIS transceivers
module-common: Add missing CMIS transmitter technologies
cmis: Fix printing of attenuation and wavelength
cmis: Fix printing of link length

 cmis.c          | 65 +++++++++++++++++++++++++++++++---------------
 cmis.h          |  1 +
 module-common.c | 68 +++++++++++++++++++++++++++----------------------
 module-common.h | 57 +++++++++++++++--------------------------
 qsfp.c          |  5 ++--
 sff-common.h    |  4 +--
 6 files changed, 108 insertions(+), 92 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/8 cmis: Fix printing of Tx bias current

In CMIS, unlike SFF-8636 and SFF-8472, the Tx bias current can be scaled (i.e., multiplied by 1 / 2 / 4). Fix the application of the scaling factor from shift right to shift left. In addition, increase the size of the field that stores the scaled value from 16-bits to 32-bits to avoid truncation.

Fixes 340d88ee1289 ("cmis: Parse and print diagnostic information")
---
 cmis.c       | 10 +++++-----
 sff-common.h |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)
cmis.c +5 -5
index f494268ba3b7..a4bf455c2a77 100644
@@ -517,7 +517,7 @@ cmis_parse_dom_chan_lvl_monitors_bank(const struct cmis_memory_map *map,
 
 		sd->scd[chan].bias_cur = OFFSET_TO_U16_PTR(page_11h,
 							   tx_bias_offset);
-		sd->scd[chan].bias_cur >>= bias_mul;
+		sd->scd[chan].bias_cur <<= bias_mul;
 		sd->scd[chan].rx_power = OFFSET_TO_U16_PTR(page_11h,
 							   rx_power_offset);
 		sd->scd[chan].tx_power = OFFSET_TO_U16_PTR(page_11h,
@@ -544,16 +544,16 @@ static void cmis_parse_dom_chan_lvl_thresh(const struct cmis_memory_map *map,
 
 	sd->bias_cur[HALRM] = OFFSET_TO_U16_PTR(map->page_02h,
 						CMIS_TX_BIAS_HALRM_OFFSET);
-	sd->bias_cur[HALRM] >>= bias_mul;
+	sd->bias_cur[HALRM] <<= bias_mul;
 	sd->bias_cur[LALRM] = OFFSET_TO_U16_PTR(map->page_02h,
 						CMIS_TX_BIAS_LALRM_OFFSET);
-	sd->bias_cur[LALRM] >>= bias_mul;
+	sd->bias_cur[LALRM] <<= bias_mul;
 	sd->bias_cur[HWARN] = OFFSET_TO_U16_PTR(map->page_02h,
 						CMIS_TX_BIAS_HWARN_OFFSET);
-	sd->bias_cur[HWARN] >>= bias_mul;
+	sd->bias_cur[HWARN] <<= bias_mul;
 	sd->bias_cur[LWARN] = OFFSET_TO_U16_PTR(map->page_02h,
 						CMIS_TX_BIAS_LWARN_OFFSET);
-	sd->bias_cur[LWARN] >>= bias_mul;
+	sd->bias_cur[LWARN] <<= bias_mul;
 
 	sd->tx_power[HALRM] = OFFSET_TO_U16_PTR(map->page_02h,
 						CMIS_TX_PWR_HALRM_OFFSET);
sff-common.h +2 -2
index 3c02a69ec7f6..59ae21038c9c 100644
@@ -126,7 +126,7 @@
 
 /* Channel Monitoring Fields */
 struct sff_channel_diags {
-	__u16 bias_cur;      /* Measured bias current in 2uA units */
+	__u32 bias_cur;      /* Measured bias current in 2uA units */
 	__u16 rx_power;      /* Measured RX Power */
 	__u16 tx_power;      /* Measured TX Power */
 };
@@ -157,7 +157,7 @@ struct sff_diags {
 	/* SFP Temp in 16-bit signed 1/256 Celcius */
 	__s16 sfp_temp[5];
 	/* Measured bias current in 2uA units */
-	__u16 bias_cur[5];
+	__u32 bias_cur[5];
 	/* Measured TX Power */
 	__u16 tx_power[5];
 	/* Measured RX Power */
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/8 cmis: Fix printing of channel-level flags

In reply to Ido Schimmel

CMIS encodes different channel-level flags (e.g., "Laser bias current high alarm") in different bytes where each bit corresponds to the value of the flag in a different channel. Since CMIS supports more than 8 channels, these flags can be banked (e.g., channels 1-8 in bank 0, channels 9-16 in bank 1 etc.).

The code is currently applying the wrong bit mask (the channel number itself) when extracting the per-channel flag. Fix the calculation of the bit mask so that the channel offset (0-7) in the current bank determines the number of bits that are shifted.

Fixes 340d88ee1289 ("cmis: Parse and print diagnostic information")
---
 cmis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmis.c +1 -1
index a4bf455c2a77..16f168a3b1af 100644
@@ -766,7 +766,7 @@ static void cmis_show_dom_chan_lvl_flag(const struct cmis_memory_map *map,
 		char str[80];
 		bool value;
 
-		value = page_11h[module_aw_chan_flags[flag].offset] & chan;
+		value = page_11h[module_aw_chan_flags[flag].offset] & (1 << i);
 		if (is_json_context()) {
 			print_bool(PRINT_JSON, NULL, NULL, value);
 		} else {
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/8 cmis: Fix printing of CDB EPL pages

In reply to Ido Schimmel

The "CdbMaxPagesEPL" field is 4-bits. The code currently assumes that the value of the field directly determines the number of EPL pages, but values 5 / 6 / 7 correspond to 8 / 12 / 16 EPL pages.

Fix the printing of the number of EPL pages by using a translation table and avoid printing the field if the value is reserved (i.e., 8-15).

Fixes fe8e296aa023 ("cmis: Print CDB messaging support advertisement")
---
 cmis.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
cmis.c +7 -3
index 16f168a3b1af..da1ced75e4ef 100644
@@ -924,10 +924,14 @@ static void cmis_show_cdb_mode(const struct cmis_memory_map *map)
 
 static void cmis_show_cdb_epl_pages(const struct cmis_memory_map *map)
 {
-	__u8 epl_pages = map->page_01h[CMIS_CDB_ADVER_OFFSET] &
-			 CMIS_CDB_ADVER_EPL_MASK;
+	static const __u8 epl_page_count[] = { 0, 1, 2, 3, 4, 8, 12, 16 };
+	__u8 epl = map->page_01h[CMIS_CDB_ADVER_OFFSET] &
+		CMIS_CDB_ADVER_EPL_MASK;
 
-	module_print_any_uint("CDB EPL pages", epl_pages, NULL);
+	if (epl >= ARRAY_SIZE(epl_page_count))
+		return;
+
+	module_print_any_uint("CDB EPL pages", epl_page_count[epl], NULL);
 }
 
 static void cmis_show_cdb_rw_len(const struct cmis_memory_map *map)
Signature · 1 line
2.55.0
#4 lore raw

PATCH 4/8 module-common: Fix printing of transmitter technology for CMIS transceivers

In reply to Ido Schimmel

In CMIS, the transceiver technology is encoded in the "MediaInterfaceTechnology" field which is 8-bits, while in SFF-8636 it is encoded in the 4 MSBs of the "Device Technology" field. Both specifications share the same encoding for the common values (0-15), but CMIS supports more values given the field is 8-bits.

Given the common encoding, cited commit consolidated the printing of this field between CMIS and SFF-8636. The CMIS parser passes the "MediaInterfaceTechnology" field and the SFF-8636 parser passes the "Device Technology" field while masking the 4 LSBs. This creates a situation where both parsers pass different values for the same transmitter technology (e.g., "1310 nm VCSEL" is 0x01 in CMIS and 0x10 in SFF-8636). To overcome this, the common code matches on two values for each transmitter technology.

While this works most of the time, it is going to create a problem for CMIS transceivers that utilize the 4 MSBs of the "MediaInterfaceTechnology" field.

Fix by creating a common encoding for the transmitter technology field and have the SFF-8636 parser pass the shifted value of the "Device Technology" field to the common code. That way both parsers pass the same value for a given transmitter technology.

Fixes 504c4f573571 ("module_common: Add a new file to all the common code for all module types")
---
 cmis.c          |  4 ++--
 module-common.c | 47 +++++++++++++++-----------------------------
 module-common.h | 52 +++++++++++++++----------------------------------
 qsfp.c          |  5 ++---
 4 files changed, 36 insertions(+), 72 deletions(-)
cmis.c +2 -2
index da1ced75e4ef..19a3eb7cf925 100644
@@ -254,11 +254,11 @@ static void cmis_show_sig_integrity(const struct cmis_memory_map *map)
  */
 static void cmis_show_mit_compliance(const struct cmis_memory_map *map)
 {
-	u16 value = map->page_00h[CMIS_MEDIA_INTF_TECH_OFFSET];
+	__u8 value = map->page_00h[CMIS_MEDIA_INTF_TECH_OFFSET];
 
 	module_show_mit_compliance(value);
 
-	if (value >= CMIS_COPPER_UNEQUAL) {
+	if (value >= MODULE_TT_COPPER_UNEQUAL) {
 		module_print_any_uint("Attenuation at 5GHz",
 				      map->page_00h[CMIS_COPPER_ATT_5GHZ], "db");
 		module_print_any_uint("Attenuation at 7GHz",
module-common.c +16 -31

87 lines not on this page · raw message

module-common.h +16 -36

58 lines not on this page · raw message

qsfp.c +2 -3
index c82a3dec9b0b..20b6c2173284 100644
@@ -562,12 +562,11 @@ static void sff8636_show_rate_identifier(const struct sff8636_memory_map *map)
 static void
 sff8636_show_wavelength_or_copper_compliance(const struct sff8636_memory_map *map)
 {
-	u16 value = map->page_00h[SFF8636_DEVICE_TECH_OFFSET] &
-			SFF8636_TRANS_TECH_MASK;
+	__u8 value = map->page_00h[SFF8636_DEVICE_TECH_OFFSET] >> 4;
 
 	module_show_mit_compliance(value);
 
-	if (value >= SFF8636_TRANS_COPPER_PAS_UNEQUAL) {
+	if (value >= MODULE_TT_COPPER_UNEQUAL) {
 		module_print_any_uint("Attenuation at 2.5GHz",
 				      map->page_00h[SFF8636_WAVELEN_HIGH_BYTE_OFFSET],
 				      "db");
Signature · 1 line
2.55.0
#5 lore raw

PATCH 5/8 module-common: Avoid undefined behavior with CMIS transceivers

In reply to Ido Schimmel

While the function that handles the printing of the transmitter technology handles all the values passed by the SFF-8636 parser (0-15), it does not handle all the values that can be passed by the CMIS parser where this field is 8-bits.

Fix by adding a default case that will initialize "description" to "Reserved or unknown".

Fixes 88ca347ef35a ("Add QSFP-DD support")
---
 module-common.c | 3 +++
 1 file changed, 3 insertions(+)
module-common.c +3 -0
index 997dd2b37ce7..ea4514ab3899 100644
@@ -628,6 +628,9 @@ void module_show_mit_compliance(u16 value)
 		snprintf(description, SFF_MAX_DESC_LEN, "%s linear active equalizers",
 			 cc);
 		break;
+	default:
+		strncpy(description, "Reserved or unknown", SFF_MAX_DESC_LEN);
+		break;
 	}
 
 	sff_print_any_hex_field("Transmitter technology",
Signature · 1 line
2.55.0
#6 lore raw

PATCH 6/8 module-common: Add missing CMIS transmitter technologies

In reply to Ido Schimmel

Add missing transmitter technologies from table 8-40 in CMIS 5.3. This is a prerequisite for the next patch to help us distinguish between copper and optical transceivers.

Fixes 88ca347ef35a ("Add QSFP-DD support")
---
 module-common.c | 18 ++++++++++++++++++
 module-common.h |  5 +++++
 2 files changed, 23 insertions(+)
module-common.c +18 -0
index ea4514ab3899..f8e4681d8d63 100644
@@ -628,6 +628,24 @@ void module_show_mit_compliance(u16 value)
 		snprintf(description, SFF_MAX_DESC_LEN, "%s linear active equalizers",
 			 cc);
 		break;
+	case MODULE_TT_C_BAND_LASER:
+		strncpy(description, "C-band tunable laser", SFF_MAX_DESC_LEN);
+		break;
+	case MODULE_TT_L_BAND_LASER:
+		strncpy(description, "L-band tunable laser", SFF_MAX_DESC_LEN);
+		break;
+	case MODULE_TT_COPPER_NF_LINEAR:
+		snprintf(description, SFF_MAX_DESC_LEN,
+			 "%s near and far end linear active equalizers", cc);
+		break;
+	case MODULE_TT_COPPER_F_LINEAR:
+		snprintf(description, SFF_MAX_DESC_LEN,
+			 "%s far end linear active equalizers", cc);
+		break;
+	case MODULE_TT_COPPER_N_LINEAR:
+		snprintf(description, SFF_MAX_DESC_LEN,
+			 "%s near end linear active equalizers", cc);
+		break;
 	default:
 		strncpy(description, "Reserved or unknown", SFF_MAX_DESC_LEN);
 		break;
module-common.h +5 -0
index fba1d36f7f86..e9bf8c19a9bb 100644
@@ -99,6 +99,11 @@ enum module_type {
 #define MODULE_TT_COPPER_F_EQUAL		0x0D
 #define MODULE_TT_COPPER_N_EQUAL		0x0E
 #define MODULE_TT_COPPER_LINEAR_EQUAL		0x0F
+#define MODULE_TT_C_BAND_LASER			0x10
+#define MODULE_TT_L_BAND_LASER			0x11
+#define MODULE_TT_COPPER_NF_LINEAR		0x12
+#define MODULE_TT_COPPER_F_LINEAR		0x13
+#define MODULE_TT_COPPER_N_LINEAR		0x14
 
 /* Module Flags (Page 0) */
 #define CMIS_VCC_AW_OFFSET			0x09
Signature · 1 line
2.55.0
#7 lore raw

PATCH 7/8 cmis: Fix printing of attenuation and wavelength

In reply to Ido Schimmel

The CMIS parser uses the same trick as the SFF-8636 parser to identify copper cables for which attenuation should be printed. That is, it considers every transmitter technology value above 0x09 as an indication that it is dealing with a copper cable. This is not true for CMIS transceivers which support more transmitter technologies compared to SFF-8636. For example, according to table 8-40 in CMIS 5.3, 0x10 is "C-band tunable laser".

Fix the identification of copper cables by only matching on the relevant transmitter technology values. For all the rest, only print the wavelength if Page 01h is supported and the nominal wavelength is not 0.

Fixes 88ca347ef35a ("Add QSFP-DD support")
---
 cmis.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
cmis.c +24 -9
index 19a3eb7cf925..351e18484854 100644
@@ -255,10 +255,20 @@ static void cmis_show_sig_integrity(const struct cmis_memory_map *map)
 static void cmis_show_mit_compliance(const struct cmis_memory_map *map)
 {
 	__u8 value = map->page_00h[CMIS_MEDIA_INTF_TECH_OFFSET];
+	float wl, wl_tol;
 
 	module_show_mit_compliance(value);
 
-	if (value >= MODULE_TT_COPPER_UNEQUAL) {
+	switch (value) {
+	case MODULE_TT_COPPER_UNEQUAL:
+	case MODULE_TT_COPPER_PASS_EQUAL:
+	case MODULE_TT_COPPER_NF_EQUAL:
+	case MODULE_TT_COPPER_F_EQUAL:
+	case MODULE_TT_COPPER_N_EQUAL:
+	case MODULE_TT_COPPER_LINEAR_EQUAL:
+	case MODULE_TT_COPPER_NF_LINEAR:
+	case MODULE_TT_COPPER_F_LINEAR:
+	case MODULE_TT_COPPER_N_LINEAR:
 		module_print_any_uint("Attenuation at 5GHz",
 				      map->page_00h[CMIS_COPPER_ATT_5GHZ], "db");
 		module_print_any_uint("Attenuation at 7GHz",
@@ -269,15 +279,20 @@ static void cmis_show_mit_compliance(const struct cmis_memory_map *map)
 		module_print_any_uint("Attenuation at 25.8GHz",
 				      map->page_00h[CMIS_COPPER_ATT_25P8GHZ],
 				      "db");
-	} else if (map->page_01h) {
-		module_print_any_float("Laser wavelength",
-				       (((map->page_01h[CMIS_NOM_WAVELENGTH_MSB] << 8) |
-				        map->page_01h[CMIS_NOM_WAVELENGTH_LSB]) * 0.05),
-				       "nm");
-		module_print_any_float("Laser wavelength tolerance",
-				       (((map->page_01h[CMIS_WAVELENGTH_TOL_MSB] << 8) |
-				        map->page_01h[CMIS_WAVELENGTH_TOL_LSB]) * 0.005),
+		break;
+	default:
+		if (!map->page_01h)
+			break;
+		wl = ((map->page_01h[CMIS_NOM_WAVELENGTH_MSB] << 8) |
+		      map->page_01h[CMIS_NOM_WAVELENGTH_LSB]) * 0.05;
+		wl_tol = ((map->page_01h[CMIS_WAVELENGTH_TOL_MSB] << 8) |
+			  map->page_01h[CMIS_WAVELENGTH_TOL_LSB]) * 0.005;
+		if (!wl)
+			break;
+		module_print_any_float("Laser wavelength", wl, "nm");
+		module_print_any_float("Laser wavelength tolerance", wl_tol,
 				       "nm");
+		break;
 	}
 }
 
Signature · 1 line
2.55.0
#8 lore raw

PATCH 8/8 cmis: Fix printing of link length

In reply to Ido Schimmel

The CMIS parser only supports link length multipliers of 0.1 and 1, but revision 5.0 of the specification (May 2021) added a multiplier of 10 and revision 5.3 (September 2024) added multipliers of 50, 100, 200 and 500.

Add support for the missing multipliers.

Fixes 88ca347ef35a ("Add QSFP-DD support")
---
 cmis.c | 8 +++++++-
 cmis.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)
cmis.c +7 -1
index 351e18484854..7a7e928ebb2f 100644
@@ -188,6 +188,7 @@ static void cmis_show_cbl_asm_len(const struct cmis_memory_map *map)
  */
 static void cmis_print_smf_cbl_len(const struct cmis_memory_map *map)
 {
+	static const float smf_mul2[] = { 50.0f, 100.0f, 200.0f, 500.0f };
 	static const char *fn = "Length (SMF)";
 	float mul = 1.0f;
 	float val = 0.0f;
@@ -203,7 +204,12 @@ static void cmis_print_smf_cbl_len(const struct cmis_memory_map *map)
 	case CMIS_MULTIPLIER_01:
 		mul = 1.0f;
 		break;
-	default:
+	case CMIS_MULTIPLIER_10:
+		mul = 10.0f;
+		break;
+	case CMIS_MULTIPLIER_11:
+		mul = smf_mul2[(map->page_01h[CMIS_SMF_LEN_MUL2_OFFSET] &
+				CMIS_LEN_MUL_MASK) >> 6];
 		break;
 	}
 
cmis.h +1 -0
index 82fd2456a3ec..387809e00cd5 100644
@@ -120,6 +120,7 @@
 #define CMIS_OM4_LEN_OFFSET			0x86
 #define CMIS_OM3_LEN_OFFSET			0x87
 #define CMIS_OM2_LEN_OFFSET			0x88
+#define CMIS_SMF_LEN_MUL2_OFFSET		0x89
 
 /* Wavelength (Page 1) */
 #define CMIS_NOM_WAVELENGTH_MSB			0x8A
Signature · 1 line
2.55.0