2 * Copyright (c) 2014 Alexander V. Chernikov. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 static const char rcsid[] =
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/ioctl.h>
34 #include <sys/socket.h>
37 #include <net/sff8436.h>
38 #include <net/sff8472.h>
52 int fd; /* fd to issue SIOCGI2C */
53 int error; /* Store first error */
54 int qsfp; /* True if transceiver is QSFP */
55 int do_diag; /* True if we need to request DDM */
56 struct ifreq *ifr; /* Pointer to pre-filled ifreq */
59 static int read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off,
60 uint8_t len, uint8_t *buf);
61 static void dump_i2c_data(struct i2c_info *ii, uint8_t addr, uint8_t off,
69 const char *find_value(struct _nv *x, int value);
70 const char *find_zero_bit(struct _nv *x, int value, int sz);
72 /* SFF-8024 Rev. 4.1 Table 4-3: Connector Types */
73 static struct _nv conn[] = {
76 { 0x02, "Fibre Channel Style 1 copper" },
77 { 0x03, "Fibre Channel Style 2 copper" },
79 { 0x05, "Fibre Channel coaxial" },
80 { 0x06, "FiberJack" },
85 { 0x0B, "Optical pigtail" },
86 { 0x0C, "MPO Parallel Optic" },
88 { 0x21, "Copper pigtail" },
90 { 0x23, "No separable connector" },
95 /* SFF-8472 Rev. 11.4 table 3.5: Transceiver codes */
96 /* 10G Ethernet/IB compliance codes, byte 3 */
97 static struct _nv eth_10g[] = {
98 { 0x80, "10G Base-ER" },
99 { 0x40, "10G Base-LRM" },
100 { 0x20, "10G Base-LR" },
101 { 0x10, "10G Base-SR" },
104 { 0x02, "1X Copper Active" },
105 { 0x01, "1X Copper Passive" },
109 /* Ethernet compliance codes, byte 6 */
110 static struct _nv eth_compat[] = {
112 { 0x40, "BASE-BX10" },
113 { 0x20, "100BASE-FX" },
114 { 0x10, "100BASE-LX/LX10" },
115 { 0x08, "1000BASE-T" },
116 { 0x04, "1000BASE-CX" },
117 { 0x02, "1000BASE-LX" },
118 { 0x01, "1000BASE-SX" },
122 /* FC link length, byte 7 */
123 static struct _nv fc_len[] = {
124 { 0x80, "very long distance" },
125 { 0x40, "short distance" },
126 { 0x20, "intermediate distance" },
127 { 0x10, "long distance" },
128 { 0x08, "medium distance" },
132 /* Channel/Cable technology, byte 7-8 */
133 static struct _nv cab_tech[] = {
134 { 0x0400, "Shortwave laser (SA)" },
135 { 0x0200, "Longwave laser (LC)" },
136 { 0x0100, "Electrical inter-enclosure (EL)" },
137 { 0x80, "Electrical intra-enclosure (EL)" },
138 { 0x40, "Shortwave laser (SN)" },
139 { 0x20, "Shortwave laser (SL)" },
140 { 0x10, "Longwave laser (LL)" },
141 { 0x08, "Active Cable" },
142 { 0x04, "Passive Cable" },
146 /* FC Transmission media, byte 9 */
147 static struct _nv fc_media[] = {
148 { 0x80, "Twin Axial Pair" },
149 { 0x40, "Twisted Pair" },
150 { 0x20, "Miniature Coax" },
151 { 0x10, "Viao Coax" },
152 { 0x08, "Miltimode, 62.5um" },
153 { 0x04, "Multimode, 50um" },
155 { 0x01, "Single Mode" },
159 /* FC Speed, byte 10 */
160 static struct _nv fc_speed[] = {
161 { 0x80, "1200 MBytes/sec" },
162 { 0x40, "800 MBytes/sec" },
163 { 0x20, "1600 MBytes/sec" },
164 { 0x10, "400 MBytes/sec" },
165 { 0x08, "3200 MBytes/sec" },
166 { 0x04, "200 MBytes/sec" },
167 { 0x01, "100 MBytes/sec" },
171 /* SFF-8436 Rev. 4.8 table 33: Specification compliance */
173 /* 10/40G Ethernet compliance codes, byte 128 + 3 */
174 static struct _nv eth_1040g[] = {
175 { 0x80, "Extended" },
176 { 0x40, "10GBASE-LRM" },
177 { 0x20, "10GBASE-LR" },
178 { 0x10, "10GBASE-SR" },
179 { 0x08, "40GBASE-CR4" },
180 { 0x04, "40GBASE-SR4" },
181 { 0x02, "40GBASE-LR4" },
182 { 0x01, "40G Active Cable" },
185 #define SFF_8636_EXT_COMPLIANCE 0x80
187 /* SFF-8024 Rev. 4.2 table 4-4: Extended Specification Compliance */
188 static struct _nv eth_extended_comp[] = {
189 { 0xFF, "Reserved" },
190 { 0x21, "100G PAM4 BiDi" },
191 { 0x20, "100G SWDM4" },
192 { 0x1F, "40G SWDM4" },
193 { 0x1E, "2.5GBASE-T" },
194 { 0x1D, "5GBASE-T" },
195 { 0x1C, "10GBASE-T Short Reach" },
196 { 0x1B, "100G 1550nm WDM" },
197 { 0x1A, "100GE-DWDM2" },
198 { 0x19, "100G ACC or 25GAUI C2M ACC" },
199 { 0x18, "100G AOC or 25GAUI C2M AOC" },
200 { 0x17, "100G CLR4" },
201 { 0x16, "10GBASE-T with SFI electrical interface" },
202 { 0x15, "G959.1 profile P1L1-2D2" },
203 { 0x14, "G959.1 profile P1S1-2D2" },
204 { 0x13, "G959.1 profile P1I1-2D1" },
205 { 0x12, "40G PSM4 Parallel SMF" },
206 { 0x11, "4 x 10GBASE-SR" },
207 { 0x10, "40GBASE-ER4" },
208 { 0x0F, "Reserved" },
209 { 0x0E, "Reserved" },
210 { 0x0D, "25GBASE-CR CA-N" },
211 { 0x0C, "25GBASE-CR CA-S" },
212 { 0x0B, "100GBASE-CR4 or 25GBASE-CR CA-L" },
213 { 0x0A, "Reserved" },
214 { 0x09, "Obsolete" },
215 { 0x08, "100G ACC (Active Copper Cable) or 25GAUI C2M ACC" },
216 { 0x07, "100G PSM4 Parallel SMF" },
217 { 0x06, "100G CWDM4" },
218 { 0x05, "100GBASE-SR10" },
219 { 0x04, "100GBASE-ER4 or 25GBASE-ER" },
220 { 0x03, "100GBASE-LR4 or 25GBASE-LR" },
221 { 0x02, "100GBASE-SR4 or 25GBASE-SR" },
222 { 0x01, "100G AOC (Active Optical Cable) or 25GAUI C2M AOC" },
223 { 0x00, "Unspecified" }
226 /* SFF-8636 Rev. 2.9 table 6.3: Revision compliance */
227 static struct _nv rev_compl[] = {
228 { 0x1, "SFF-8436 rev <=4.8" },
229 { 0x2, "SFF-8436 rev <=4.8" },
230 { 0x3, "SFF-8636 rev <=1.3" },
231 { 0x4, "SFF-8636 rev <=1.4" },
232 { 0x5, "SFF-8636 rev <=1.5" },
233 { 0x6, "SFF-8636 rev <=2.0" },
234 { 0x7, "SFF-8636 rev <=2.7" },
235 { 0x8, "SFF-8636 rev >=2.8" },
236 { 0x0, "Unspecified" }
240 find_value(struct _nv *x, int value)
242 for (; x->n != NULL; x++)
249 find_zero_bit(struct _nv *x, int value, int sz)
255 for (v = 1, m = 1 << (8 * sz); v < m; v *= 2) {
256 if ((value & v) == 0)
258 if ((s = find_value(x, value & v)) != NULL) {
268 convert_sff_identifier(char *buf, size_t size, uint8_t value)
273 if (value <= SFF_8024_ID_LAST)
274 x = sff_8024_id[value];
277 x = "Vendor specific";
282 snprintf(buf, size, "%s", x);
286 convert_sff_connector(char *buf, size_t size, uint8_t value)
290 if ((x = find_value(conn, value)) == NULL) {
291 if (value >= 0x0D && value <= 0x1F)
293 else if (value >= 0x24 && value <= 0x7F)
296 x = "Vendor specific";
299 snprintf(buf, size, "%s", x);
303 convert_sff_rev_compliance(char *buf, size_t size, uint8_t value)
310 x = find_value(rev_compl, value);
312 snprintf(buf, size, "%s", x);
316 get_sfp_identifier(struct i2c_info *ii, char *buf, size_t size)
320 read_i2c(ii, SFF_8472_BASE, SFF_8472_ID, 1, &data);
321 convert_sff_identifier(buf, size, data);
325 get_sfp_connector(struct i2c_info *ii, char *buf, size_t size)
329 read_i2c(ii, SFF_8472_BASE, SFF_8472_CONNECTOR, 1, &data);
330 convert_sff_connector(buf, size, data);
334 get_qsfp_identifier(struct i2c_info *ii, char *buf, size_t size)
338 read_i2c(ii, SFF_8436_BASE, SFF_8436_ID, 1, &data);
339 convert_sff_identifier(buf, size, data);
343 get_qsfp_connector(struct i2c_info *ii, char *buf, size_t size)
347 read_i2c(ii, SFF_8436_BASE, SFF_8436_CONNECTOR, 1, &data);
348 convert_sff_connector(buf, size, data);
352 printf_sfp_transceiver_descr(struct i2c_info *ii, char *buf, size_t size)
355 const char *tech_class, *tech_len, *tech_tech, *tech_media, *tech_speed;
363 /* Read bytes 3-10 at once */
364 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 8, &xbuf[3]);
366 /* Check 10G ethernet first */
367 tech_class = find_zero_bit(eth_10g, xbuf[3], 1);
368 if (tech_class == NULL) {
369 /* No match. Try 1G */
370 tech_class = find_zero_bit(eth_compat, xbuf[6], 1);
373 tech_len = find_zero_bit(fc_len, xbuf[7], 1);
374 tech_tech = find_zero_bit(cab_tech, xbuf[7] << 8 | xbuf[8], 2);
375 tech_media = find_zero_bit(fc_media, xbuf[9], 1);
376 tech_speed = find_zero_bit(fc_speed, xbuf[10], 1);
378 printf("Class: %s\n", tech_class);
379 printf("Length: %s\n", tech_len);
380 printf("Tech: %s\n", tech_tech);
381 printf("Media: %s\n", tech_media);
382 printf("Speed: %s\n", tech_speed);
386 get_sfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
388 const char *tech_class;
391 /* Use extended compliance code if it's valid */
392 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS, 1, &code);
394 tech_class = find_value(eth_extended_comp, code);
396 /* Next, check 10G Ethernet/IB CCs */
397 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 1, &code);
398 tech_class = find_zero_bit(eth_10g, code, 1);
399 if (tech_class == NULL) {
400 /* No match. Try Ethernet 1G */
401 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START + 3,
403 tech_class = find_zero_bit(eth_compat, code, 1);
407 if (tech_class == NULL)
408 tech_class = "Unknown";
410 snprintf(buf, size, "%s", tech_class);
414 get_qsfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
416 const char *tech_class;
419 read_i2c(ii, SFF_8436_BASE, SFF_8436_CODE_E1040100G, 1, &code);
421 /* Check for extended specification compliance */
422 if (code & SFF_8636_EXT_COMPLIANCE) {
423 read_i2c(ii, SFF_8436_BASE, SFF_8436_OPTIONS_START, 1, &code);
424 tech_class = find_value(eth_extended_comp, code);
426 /* Check 10/40G Ethernet class only */
427 tech_class = find_zero_bit(eth_1040g, code, 1);
429 if (tech_class == NULL)
430 tech_class = "Unknown";
432 snprintf(buf, size, "%s", tech_class);
436 * Print SFF-8472/SFF-8436 string to supplied buffer.
437 * All (vendor-specific) strings are padded right with '0x20'.
440 convert_sff_name(char *buf, size_t size, char *xbuf)
444 for (p = &xbuf[16]; *(p - 1) == 0x20; p--)
447 snprintf(buf, size, "%s", xbuf);
451 convert_sff_date(char *buf, size_t size, char *xbuf)
454 snprintf(buf, size, "20%c%c-%c%c-%c%c", xbuf[0], xbuf[1],
455 xbuf[2], xbuf[3], xbuf[4], xbuf[5]);
459 get_sfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
463 memset(xbuf, 0, sizeof(xbuf));
464 read_i2c(ii, SFF_8472_BASE, SFF_8472_VENDOR_START, 16, (uint8_t *)xbuf);
465 convert_sff_name(buf, size, xbuf);
469 get_sfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
473 memset(xbuf, 0, sizeof(xbuf));
474 read_i2c(ii, SFF_8472_BASE, SFF_8472_PN_START, 16, (uint8_t *)xbuf);
475 convert_sff_name(buf, size, xbuf);
479 get_sfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
483 memset(xbuf, 0, sizeof(xbuf));
484 read_i2c(ii, SFF_8472_BASE, SFF_8472_SN_START, 16, (uint8_t *)xbuf);
485 convert_sff_name(buf, size, xbuf);
489 get_sfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
493 memset(xbuf, 0, sizeof(xbuf));
494 /* Date code, see Table 3.8 for description */
495 read_i2c(ii, SFF_8472_BASE, SFF_8472_DATE_START, 6, (uint8_t *)xbuf);
496 convert_sff_date(buf, size, xbuf);
500 get_qsfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
504 memset(xbuf, 0, sizeof(xbuf));
505 read_i2c(ii, SFF_8436_BASE, SFF_8436_VENDOR_START, 16, (uint8_t *)xbuf);
506 convert_sff_name(buf, size, xbuf);
510 get_qsfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
514 memset(xbuf, 0, sizeof(xbuf));
515 read_i2c(ii, SFF_8436_BASE, SFF_8436_PN_START, 16, (uint8_t *)xbuf);
516 convert_sff_name(buf, size, xbuf);
520 get_qsfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
524 memset(xbuf, 0, sizeof(xbuf));
525 read_i2c(ii, SFF_8436_BASE, SFF_8436_SN_START, 16, (uint8_t *)xbuf);
526 convert_sff_name(buf, size, xbuf);
530 get_qsfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
534 memset(xbuf, 0, sizeof(xbuf));
535 read_i2c(ii, SFF_8436_BASE, SFF_8436_DATE_START, 6, (uint8_t *)xbuf);
536 convert_sff_date(buf, size, xbuf);
540 print_sfp_vendor(struct i2c_info *ii, char *buf, size_t size)
544 memset(xbuf, 0, sizeof(xbuf));
546 get_qsfp_vendor_name(ii, xbuf, 20);
547 get_qsfp_vendor_pn(ii, &xbuf[20], 20);
548 get_qsfp_vendor_sn(ii, &xbuf[40], 20);
549 get_qsfp_vendor_date(ii, &xbuf[60], 20);
551 get_sfp_vendor_name(ii, xbuf, 20);
552 get_sfp_vendor_pn(ii, &xbuf[20], 20);
553 get_sfp_vendor_sn(ii, &xbuf[40], 20);
554 get_sfp_vendor_date(ii, &xbuf[60], 20);
557 snprintf(buf, size, "vendor: %s PN: %s SN: %s DATE: %s",
558 xbuf, &xbuf[20], &xbuf[40], &xbuf[60]);
562 * Converts internal templerature (SFF-8472, SFF-8436)
563 * 16-bit unsigned value to human-readable representation:
565 * Internally measured Module temperature are represented
566 * as a 16-bit signed twos complement value in increments of
567 * 1/256 degrees Celsius, yielding a total range of –128C to +128C
568 * that is considered valid between –40 and +125C.
572 convert_sff_temp(char *buf, size_t size, uint8_t *xbuf)
577 d += (double)xbuf[1] / 256;
579 snprintf(buf, size, "%.2f C", d);
583 * Retrieves supplied voltage (SFF-8472, SFF-8436).
584 * 16-bit usigned value, treated as range 0..+6.55 Volts
587 convert_sff_voltage(char *buf, size_t size, uint8_t *xbuf)
591 d = (double)((xbuf[0] << 8) | xbuf[1]);
592 snprintf(buf, size, "%.2f Volts", d / 10000);
596 * Converts value in @xbuf to both milliwats and dBm
597 * human representation.
600 convert_sff_power(struct i2c_info *ii, char *buf, size_t size, uint8_t *xbuf)
605 mW = (xbuf[0] << 8) + xbuf[1];
607 /* Convert mw to dbm */
608 dbm = 10.0 * log10(1.0 * mW / 10000);
611 * Assume internally-calibrated data.
612 * This is always true for SFF-8346, and explicitly
613 * checked for SFF-8472.
616 /* Table 3.9, bit 5 is set, internally calibrated */
617 snprintf(buf, size, "%d.%02d mW (%.2f dBm)",
618 mW / 10000, (mW % 10000) / 100, dbm);
622 get_sfp_temp(struct i2c_info *ii, char *buf, size_t size)
626 memset(xbuf, 0, sizeof(xbuf));
627 read_i2c(ii, SFF_8472_DIAG, SFF_8472_TEMP, 2, xbuf);
628 convert_sff_temp(buf, size, xbuf);
632 get_sfp_voltage(struct i2c_info *ii, char *buf, size_t size)
636 memset(xbuf, 0, sizeof(xbuf));
637 read_i2c(ii, SFF_8472_DIAG, SFF_8472_VCC, 2, xbuf);
638 convert_sff_voltage(buf, size, xbuf);
642 get_qsfp_temp(struct i2c_info *ii, char *buf, size_t size)
646 memset(xbuf, 0, sizeof(xbuf));
647 read_i2c(ii, SFF_8436_BASE, SFF_8436_TEMP, 2, xbuf);
648 if ((xbuf[0] == 0xFF && xbuf[1] == 0xFF) || (xbuf[0] == 0 && xbuf[1] == 0))
650 convert_sff_temp(buf, size, xbuf);
655 get_qsfp_voltage(struct i2c_info *ii, char *buf, size_t size)
659 memset(xbuf, 0, sizeof(xbuf));
660 read_i2c(ii, SFF_8436_BASE, SFF_8436_VCC, 2, xbuf);
661 convert_sff_voltage(buf, size, xbuf);
665 get_sfp_rx_power(struct i2c_info *ii, char *buf, size_t size)
669 memset(xbuf, 0, sizeof(xbuf));
670 read_i2c(ii, SFF_8472_DIAG, SFF_8472_RX_POWER, 2, xbuf);
671 convert_sff_power(ii, buf, size, xbuf);
675 get_sfp_tx_power(struct i2c_info *ii, char *buf, size_t size)
679 memset(xbuf, 0, sizeof(xbuf));
680 read_i2c(ii, SFF_8472_DIAG, SFF_8472_TX_POWER, 2, xbuf);
681 convert_sff_power(ii, buf, size, xbuf);
685 get_qsfp_rx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
689 memset(xbuf, 0, sizeof(xbuf));
690 read_i2c(ii, SFF_8436_BASE, SFF_8436_RX_CH1_MSB + (chan-1)*2, 2, xbuf);
691 convert_sff_power(ii, buf, size, xbuf);
695 get_qsfp_tx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
699 memset(xbuf, 0, sizeof(xbuf));
700 read_i2c(ii, SFF_8436_BASE, SFF_8436_TX_CH1_MSB + (chan-1)*2, 2, xbuf);
701 convert_sff_power(ii, buf, size, xbuf);
705 get_qsfp_rev_compliance(struct i2c_info *ii, char *buf, size_t size)
710 read_i2c(ii, SFF_8436_BASE, SFF_8436_STATUS, 1, &xbuf);
711 convert_sff_rev_compliance(buf, size, xbuf);
715 get_qsfp_br(struct i2c_info *ii)
721 read_i2c(ii, SFF_8436_BASE, SFF_8436_BITRATE, 1, &xbuf);
724 read_i2c(ii, SFF_8436_BASE, SFF_8636_BITRATE, 1, &xbuf);
732 * Reads i2c data from opened kernel socket.
735 read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
744 ii->ifr->ifr_data = (caddr_t)&req;
748 memset(&req, 0, sizeof(req));
754 l = MIN(sizeof(req.data), len);
756 if (ioctl(ii->fd, SIOCGI2C, ii->ifr) != 0) {
761 memcpy(&buf[i], req.data, l);
771 dump_i2c_data(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len)
773 unsigned char buf[16];
777 memset(buf, 0, sizeof(buf));
778 read = MIN(sizeof(buf), len);
779 read_i2c(ii, addr, off, read, buf);
780 if (ii->error != 0) {
781 fprintf(stderr, "Error reading i2c info\n");
786 for (i = 0; i < read; i++)
787 printf("%02X ", buf[i]);
795 print_qsfp_status(struct i2c_info *ii, int verbose)
797 char buf[80], buf2[40], buf3[40];
803 /* Transceiver type */
804 get_qsfp_identifier(ii, buf, sizeof(buf));
805 get_qsfp_transceiver_class(ii, buf2, sizeof(buf2));
806 get_qsfp_connector(ii, buf3, sizeof(buf3));
808 printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
809 print_sfp_vendor(ii, buf, sizeof(buf));
811 printf("\t%s\n", buf);
814 get_qsfp_rev_compliance(ii, buf, sizeof(buf));
816 printf("\tcompliance level: %s\n", buf);
818 bitrate = get_qsfp_br(ii);
819 if (ii->error == 0 && bitrate > 0)
820 printf("\tnominal bitrate: %u Mbps\n", bitrate);
824 * The standards in this area are not clear when the
825 * additional measurements are present or not. Use a valid
826 * temperature reading as an indicator for the presence of
827 * voltage and TX/RX power measurements.
829 if (get_qsfp_temp(ii, buf, sizeof(buf)) == 0) {
830 get_qsfp_voltage(ii, buf2, sizeof(buf2));
831 printf("\tmodule temperature: %s voltage: %s\n", buf, buf2);
832 for (i = 1; i <= 4; i++) {
833 get_qsfp_rx_power(ii, buf, sizeof(buf), i);
834 get_qsfp_tx_power(ii, buf2, sizeof(buf2), i);
835 printf("\tlane %d: RX: %s TX: %s\n", i, buf, buf2);
840 printf("\n\tSFF8436 DUMP (0xA0 128..255 range):\n");
841 dump_i2c_data(ii, SFF_8436_BASE, 128, 128);
842 printf("\n\tSFF8436 DUMP (0xA0 0..81 range):\n");
843 dump_i2c_data(ii, SFF_8436_BASE, 0, 82);
848 print_sfp_status(struct i2c_info *ii, int verbose)
850 char buf[80], buf2[40], buf3[40];
851 uint8_t diag_type, flags;
853 /* Read diagnostic monitoring type */
854 read_i2c(ii, SFF_8472_BASE, SFF_8472_DIAG_TYPE, 1, (caddr_t)&diag_type);
859 * Read monitoring data IFF it is supplied AND is
860 * internally calibrated
862 flags = SFF_8472_DDM_DONE | SFF_8472_DDM_INTERNAL;
863 if ((diag_type & flags) == flags)
866 /* Transceiver type */
867 get_sfp_identifier(ii, buf, sizeof(buf));
868 get_sfp_transceiver_class(ii, buf2, sizeof(buf2));
869 get_sfp_connector(ii, buf3, sizeof(buf3));
871 printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
872 print_sfp_vendor(ii, buf, sizeof(buf));
874 printf("\t%s\n", buf);
877 printf_sfp_transceiver_descr(ii, buf, sizeof(buf));
879 * Request current measurements iff they are provided:
881 if (ii->do_diag != 0) {
882 get_sfp_temp(ii, buf, sizeof(buf));
883 get_sfp_voltage(ii, buf2, sizeof(buf2));
884 printf("\tmodule temperature: %s Voltage: %s\n", buf, buf2);
885 get_sfp_rx_power(ii, buf, sizeof(buf));
886 get_sfp_tx_power(ii, buf2, sizeof(buf2));
887 printf("\tRX: %s TX: %s\n", buf, buf2);
891 printf("\n\tSFF8472 DUMP (0xA0 0..127 range):\n");
892 dump_i2c_data(ii, SFF_8472_BASE, 0, 128);
897 sfp_status(int s, struct ifreq *ifr, int verbose)
902 /* Prepare necessary into pass to i2c reader */
903 memset(&ii, 0, sizeof(ii));
908 * Try to read byte 0 from i2c:
909 * Both SFF-8472 and SFF-8436 use it as
910 * 'identification byte'.
911 * Stop reading status on zero as value -
912 * this might happen in case of empty transceiver slot.
915 read_i2c(&ii, SFF_8472_BASE, SFF_8472_ID, 1, (caddr_t)&id_byte);
916 if (ii.error != 0 || id_byte == 0)
920 case SFF_8024_ID_QSFP:
921 case SFF_8024_ID_QSFPPLUS:
922 case SFF_8024_ID_QSFP28:
923 print_qsfp_status(&ii, verbose);
926 print_sfp_status(&ii, verbose);