git: 3a6bf8a72d49 - main - ifconfig: Improve CMIS parsing of breakout configs
Andrew Gallatin <[email protected]> Mon, 03 Aug 2026 16:54:30 +0000
| Newsgroups | gmane.os.freebsd.devel.cvs.src |
|---|---|
| Message-ID | <6a70c7c6.440cd.59ffcaab__31125.0410670013$1785776098$gmane$org@gitrepo.freebsd.org> |
The branch main has been updated by gallatin: URL: https://cgit.FreeBSD.org/src/commit/?id=3a6bf8a72d4922b53d75924c4645774ef37e27ff commit 3a6bf8a72d4922b53d75924c4645774ef37e27ff Author: Andrew Gallatin <[email protected]> AuthorDate: 2026-07-15 17:44:06 +0000 Commit: Andrew Gallatin <[email protected]> CommitDate: 2026-08-03 16:53:50 +0000 ifconfig: Improve CMIS parsing of breakout configs This fixes a bug where we do not report all lanes when a NIC configures a breakout. Eg, we reported all 4 lanes when a NIC configured the optics as 1x400g, but only printed the first lane's strength when configured as 4x100g. Fix this by actually parsing the active lane count, rather than pulling it from the default descriptor. While here, optionally print page 10h when -vvvv is specified. This aids in determining how a breakout is configured. I put it under an extra level of verbosity, as I don't want to let things get out of hand printing CMIS pages. Sponsored by: Netflix Reviewed by: kib, sumit.saxena_broadcom.com Differential Revision: https://reviews.freebsd.org/D58263 --- lib/libifconfig/libifconfig_sfp.c | 46 +++++++++++++++++++++++++++++++-------- lib/libifconfig/libifconfig_sfp.h | 3 ++- sbin/ifconfig/sfp.c | 5 +++++ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/lib/libifconfig/libifconfig_sfp.c b/lib/libifconfig/libifconfig_sfp.c index a2cddf89a13a..dcd5ef2e8e57 100644 --- a/lib/libifconfig/libifconfig_sfp.c +++ b/lib/libifconfig/libifconfig_sfp.c @@ -238,6 +238,27 @@ get_qsfp_info(struct i2c_info *ii, struct ifconfig_sfp_info *sfp) return (ii->error); } +/* Count active host lanes (nonzero AppSelCode) in the Active Control Set. */ +static uint8_t +get_cmis_active_lanes(struct i2c_info *ii) +{ + uint8_t dpconfig[CMIS_MAX_LANES]; + uint8_t lanes; + int i; + + lanes = 0; + read_i2c_page(ii, CMIS_BASE, 0x11, 0, CMIS_P11_ACS_DPCONFIG1, + sizeof(dpconfig), dpconfig); + if (ii->error != 0) + return (0); + + for (i = 0; i < CMIS_MAX_LANES; i++) { + if ((dpconfig[i] & CMIS_ACS_APPSEL_MASK) != 0) + lanes++; + } + return (lanes); +} + static int get_cmis_info(struct i2c_info *ii, struct ifconfig_sfp_info *sfp) { @@ -287,8 +308,10 @@ get_cmis_info(struct i2c_info *ii, struct ifconfig_sfp_info *sfp) break; } - /* Extract media lane count from app descriptor byte 2, bits 3:0 */ - sfp->sfp_cmis_lanes = app_desc[CMIS_APP_LANE_COUNT] & 0x0F; + /* Count active lanes; fall back to the descriptor's media lane count. */ + sfp->sfp_cmis_lanes = get_cmis_active_lanes(ii); + if (sfp->sfp_cmis_lanes == 0) + sfp->sfp_cmis_lanes = app_desc[CMIS_APP_LANE_COUNT] & 0x0F; return (ii->error); } @@ -657,15 +680,18 @@ ifconfig_sfp_get_sfp_status(ifconfig_handle_t *h, const char *name, if (ifconfig_sfp_id_is_cmis(ii.id)) { /* - * For CMIS, we need the lane count from the module info. - * Read the first Application Descriptor to get it. + * Match the active-lane count reported by get_cmis_info(); + * fall back to the first descriptor's media lane count. */ uint8_t app_desc[CMIS_APP_DESC_SIZE]; size_t channels; - read_i2c(&ii, CMIS_BASE, CMIS_APP_DESC_START, - CMIS_APP_DESC_SIZE, app_desc); - channels = app_desc[CMIS_APP_LANE_COUNT] & 0x0F; + channels = get_cmis_active_lanes(&ii); + if (channels == 0) { + read_i2c(&ii, CMIS_BASE, CMIS_APP_DESC_START, + CMIS_APP_DESC_SIZE, app_desc); + channels = app_desc[CMIS_APP_LANE_COUNT] & 0x0F; + } return (get_cmis_status(&ii, ss, channels)); } @@ -779,12 +805,14 @@ ifconfig_sfp_get_sfp_dump(ifconfig_handle_t *h, const char *name, return (-1); if (ifconfig_sfp_id_is_cmis(ii.id)) { - /* Lower memory (0-127), Page 00h (128-255), Page 11h */ + /* Lower memory (0-127), Page 00h, Page 11h, Page 10h */ read_i2c(&ii, CMIS_BASE, 0, 128, buf); read_i2c_page(&ii, CMIS_BASE, 0x00, 0, 128, 128, buf + 128); read_i2c_page(&ii, CMIS_BASE, 0x11, 0, 128, 128, buf + CMIS_DUMP_P11); + read_i2c_page(&ii, CMIS_BASE, 0x10, 0, 128, 128, + buf + CMIS_DUMP_P10); } else if (ifconfig_sfp_id_is_qsfp(ii.id)) { read_i2c(&ii, SFF_8436_BASE, QSFP_DUMP0_START, QSFP_DUMP0_SIZE, buf + QSFP_DUMP0_START); @@ -804,7 +832,7 @@ ifconfig_sfp_dump_region_count(const struct ifconfig_sfp_dump *dp) uint8_t id_byte = dp->data[0]; if (ifconfig_sfp_id_is_cmis((enum sfp_id)id_byte)) - return (3); + return (4); switch ((enum sfp_id)id_byte) { case SFP_ID_UNKNOWN: diff --git a/lib/libifconfig/libifconfig_sfp.h b/lib/libifconfig/libifconfig_sfp.h index 9ed4f684e5c4..725f96208066 100644 --- a/lib/libifconfig/libifconfig_sfp.h +++ b/lib/libifconfig/libifconfig_sfp.h @@ -85,10 +85,11 @@ struct ifconfig_sfp_status { #define CMIS_DUMP_SIZE 512 /**< CMIS dump buffer size */ #define CMIS_DUMP_P11 256 /**< offset of Page 11h in dump buffer */ +#define CMIS_DUMP_P10 384 /**< offset of Page 10h in dump buffer */ /** SFP module I2C memory dump * SFP modules have one region, QSFP modules have two. - * CMIS modules have three: lower memory, Page 00h, and Page 11h. + * CMIS modules have four: lower memory, Page 00h, Page 11h, and Page 10h. */ struct ifconfig_sfp_dump { uint8_t data[CMIS_DUMP_SIZE]; /**< memory dump data */ diff --git a/sbin/ifconfig/sfp.c b/sbin/ifconfig/sfp.c index f6400684ba7a..878a02a4a0da 100644 --- a/sbin/ifconfig/sfp.c +++ b/sbin/ifconfig/sfp.c @@ -122,6 +122,11 @@ sfp_status(if_ctx *ctx) printf("\n\tCMIS DUMP (Page 00h 128..255):\n"); hexdump(dump.data + 128, 128, "\t", HD_OMIT_COUNT | HD_OMIT_CHARS); + if (verbose > 3) { + printf("\n\tCMIS DUMP (Page 10h 128..255):\n"); + hexdump(dump.data + CMIS_DUMP_P10, 128, + "\t", HD_OMIT_COUNT | HD_OMIT_CHARS); + } printf("\n\tCMIS DUMP (Page 11h 128..255):\n"); hexdump(dump.data + CMIS_DUMP_P11, 128, "\t", HD_OMIT_COUNT | HD_OMIT_CHARS);