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-8472 Rev. 11.4 table 3.4: Connector values */
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 separate connector" }, /* SFF-8436 */
94 /* SFF-8472 Rev. 11.4 table 3.5: Transceiver codes */
95 /* 10G Ethernet/IB compliance codes, byte 3 */
96 static struct _nv eth_10g[] = {
97 { 0x80, "10G Base-ER" },
98 { 0x40, "10G Base-LRM" },
99 { 0x20, "10G Base-LR" },
100 { 0x10, "10G Base-SR" },
103 { 0x02, "1X Copper Active" },
104 { 0x01, "1X Copper Passive" },
108 /* Ethernet compliance codes, byte 6 */
109 static struct _nv eth_compat[] = {
111 { 0x40, "BASE-BX10" },
112 { 0x20, "100BASE-FX" },
113 { 0x10, "100BASE-LX/LX10" },
114 { 0x08, "1000BASE-T" },
115 { 0x04, "1000BASE-CX" },
116 { 0x02, "1000BASE-LX" },
117 { 0x01, "1000BASE-SX" },
121 /* FC link length, byte 7 */
122 static struct _nv fc_len[] = {
123 { 0x80, "very long distance" },
124 { 0x40, "short distance" },
125 { 0x20, "intermediate distance" },
126 { 0x10, "long distance" },
127 { 0x08, "medium distance" },
131 /* Channel/Cable technology, byte 7-8 */
132 static struct _nv cab_tech[] = {
133 { 0x0400, "Shortwave laser (SA)" },
134 { 0x0200, "Longwave laser (LC)" },
135 { 0x0100, "Electrical inter-enclosure (EL)" },
136 { 0x80, "Electrical intra-enclosure (EL)" },
137 { 0x40, "Shortwave laser (SN)" },
138 { 0x20, "Shortwave laser (SL)" },
139 { 0x10, "Longwave laser (LL)" },
140 { 0x08, "Active Cable" },
141 { 0x04, "Passive Cable" },
145 /* FC Transmission media, byte 9 */
146 static struct _nv fc_media[] = {
147 { 0x80, "Twin Axial Pair" },
148 { 0x40, "Twisted Pair" },
149 { 0x20, "Miniature Coax" },
150 { 0x10, "Viao Coax" },
151 { 0x08, "Miltimode, 62.5um" },
152 { 0x04, "Multimode, 50um" },
154 { 0x01, "Single Mode" },
158 /* FC Speed, byte 10 */
159 static struct _nv fc_speed[] = {
160 { 0x80, "1200 MBytes/sec" },
161 { 0x40, "800 MBytes/sec" },
162 { 0x20, "1600 MBytes/sec" },
163 { 0x10, "400 MBytes/sec" },
164 { 0x08, "3200 MBytes/sec" },
165 { 0x04, "200 MBytes/sec" },
166 { 0x01, "100 MBytes/sec" },
170 /* SFF-8436 Rev. 4.8 table 33: Specification compliance */
172 /* 10/40G Ethernet compliance codes, byte 128 + 3 */
173 static struct _nv eth_1040g[] = {
174 { 0x80, "Extended" },
175 { 0x40, "10GBASE-LRM" },
176 { 0x20, "10GBASE-LR" },
177 { 0x10, "10GBASE-SR" },
178 { 0x08, "40GBASE-CR4" },
179 { 0x04, "40GBASE-SR4" },
180 { 0x02, "40GBASE-LR4" },
181 { 0x01, "40G Active Cable" },
184 #define SFF_8636_EXT_COMPLIANCE 0x80
186 /* SFF-8024 Rev. 3.4 table 4.4: Extended Specification Compliance */
187 static struct _nv eth_extended_comp[] = {
188 { 0xFF, "Reserved" },
189 { 0x1A, "2 lambda DWDM 100G" },
190 { 0x19, "100G ACC or 25GAUI C2M ACC" },
191 { 0x18, "100G AOC or 25GAUI C2M AOC" },
192 { 0x17, "100G CLR4" },
193 { 0x16, "10GBASE-T with SFI electrical interface" },
194 { 0x15, "G959.1 profile P1L1-2D2" },
195 { 0x14, "G959.1 profile P1S1-2D2" },
196 { 0x13, "G959.1 profile P1I1-2D1" },
197 { 0x12, "40G PSM4 Parallel SMF" },
198 { 0x11, "4 x 10GBASE-SR" },
199 { 0x10, "40GBASE-ER4" },
200 { 0x0F, "Reserved" },
201 { 0x0D, "25GBASE-CR CA-N" },
202 { 0x0C, "25GBASE-CR CA-S" },
203 { 0x0B, "100GBASE-CR4 or 25GBASE-CR CA-L" },
204 { 0x0A, "Reserved" },
205 { 0x09, "100G CWDM4 MSA without FEC" },
206 { 0x08, "100G ACC (Active Copper Cable)" },
207 { 0x07, "100G PSM4 Parallel SMF" },
208 { 0x06, "100G CWDM4 MSA with FEC" },
209 { 0x05, "100GBASE-SR10" },
210 { 0x04, "100GBASE-ER4" },
211 { 0x03, "100GBASE-LR4" },
212 { 0x02, "100GBASE-SR4" },
213 { 0x01, "100G AOC (Active Optical Cable) or 25GAUI C2M ACC" },
214 { 0x00, "Unspecified" }
217 /* SFF-8636 Rev. 2.5 table 6.3: Revision compliance */
218 static struct _nv rev_compl[] = {
219 { 0x1, "SFF-8436 rev <=4.8" },
220 { 0x2, "SFF-8436 rev <=4.8" },
221 { 0x3, "SFF-8636 rev <=1.3" },
222 { 0x4, "SFF-8636 rev <=1.4" },
223 { 0x5, "SFF-8636 rev <=1.5" },
224 { 0x6, "SFF-8636 rev <=2.0" },
225 { 0x7, "SFF-8636 rev <=2.5" },
226 { 0x0, "Unspecified" }
230 find_value(struct _nv *x, int value)
232 for (; x->n != NULL; x++)
239 find_zero_bit(struct _nv *x, int value, int sz)
245 for (v = 1, m = 1 << (8 * sz); v < m; v *= 2) {
246 if ((value & v) == 0)
248 if ((s = find_value(x, value & v)) != NULL) {
258 convert_sff_identifier(char *buf, size_t size, uint8_t value)
263 if (value <= SFF_8024_ID_LAST)
264 x = sff_8024_id[value];
267 x = "Vendor specific";
272 snprintf(buf, size, "%s", x);
276 convert_sff_connector(char *buf, size_t size, uint8_t value)
280 if ((x = find_value(conn, value)) == NULL) {
281 if (value >= 0x0D && value <= 0x1F)
283 else if (value >= 0x24 && value <= 0x7F)
286 x = "Vendor specific";
289 snprintf(buf, size, "%s", x);
293 convert_sff_rev_compliance(char *buf, size_t size, uint8_t value)
300 x = find_value(rev_compl, value);
302 snprintf(buf, size, "%s", x);
306 get_sfp_identifier(struct i2c_info *ii, char *buf, size_t size)
310 read_i2c(ii, SFF_8472_BASE, SFF_8472_ID, 1, &data);
311 convert_sff_identifier(buf, size, data);
315 get_sfp_connector(struct i2c_info *ii, char *buf, size_t size)
319 read_i2c(ii, SFF_8472_BASE, SFF_8472_CONNECTOR, 1, &data);
320 convert_sff_connector(buf, size, data);
324 get_qsfp_identifier(struct i2c_info *ii, char *buf, size_t size)
328 read_i2c(ii, SFF_8436_BASE, SFF_8436_ID, 1, &data);
329 convert_sff_identifier(buf, size, data);
333 get_qsfp_connector(struct i2c_info *ii, char *buf, size_t size)
337 read_i2c(ii, SFF_8436_BASE, SFF_8436_CONNECTOR, 1, &data);
338 convert_sff_connector(buf, size, data);
342 printf_sfp_transceiver_descr(struct i2c_info *ii, char *buf, size_t size)
345 const char *tech_class, *tech_len, *tech_tech, *tech_media, *tech_speed;
353 /* Read bytes 3-10 at once */
354 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 8, &xbuf[3]);
356 /* Check 10G ethernet first */
357 tech_class = find_zero_bit(eth_10g, xbuf[3], 1);
358 if (tech_class == NULL) {
359 /* No match. Try 1G */
360 tech_class = find_zero_bit(eth_compat, xbuf[6], 1);
363 tech_len = find_zero_bit(fc_len, xbuf[7], 1);
364 tech_tech = find_zero_bit(cab_tech, xbuf[7] << 8 | xbuf[8], 2);
365 tech_media = find_zero_bit(fc_media, xbuf[9], 1);
366 tech_speed = find_zero_bit(fc_speed, xbuf[10], 1);
368 printf("Class: %s\n", tech_class);
369 printf("Length: %s\n", tech_len);
370 printf("Tech: %s\n", tech_tech);
371 printf("Media: %s\n", tech_media);
372 printf("Speed: %s\n", tech_speed);
376 get_sfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
378 const char *tech_class;
381 unsigned char qbuf[8];
382 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 8, (uint8_t *)qbuf);
384 /* Check 10G Ethernet/IB first */
385 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START, 1, &code);
386 tech_class = find_zero_bit(eth_10g, code, 1);
387 if (tech_class == NULL) {
388 /* No match. Try Ethernet 1G */
389 read_i2c(ii, SFF_8472_BASE, SFF_8472_TRANS_START + 3,
391 tech_class = find_zero_bit(eth_compat, code, 1);
394 if (tech_class == NULL)
395 tech_class = "Unknown";
397 snprintf(buf, size, "%s", tech_class);
401 get_qsfp_transceiver_class(struct i2c_info *ii, char *buf, size_t size)
403 const char *tech_class;
406 read_i2c(ii, SFF_8436_BASE, SFF_8436_CODE_E1040100G, 1, &code);
408 /* Check for extended specification compliance */
409 if (code & SFF_8636_EXT_COMPLIANCE) {
410 read_i2c(ii, SFF_8436_BASE, SFF_8436_OPTIONS_START, 1, &code);
411 tech_class = find_value(eth_extended_comp, code);
413 /* Check 10/40G Ethernet class only */
414 tech_class = find_zero_bit(eth_1040g, code, 1);
416 if (tech_class == NULL)
417 tech_class = "Unknown";
419 snprintf(buf, size, "%s", tech_class);
423 * Print SFF-8472/SFF-8436 string to supplied buffer.
424 * All (vendor-specific) strings are padded right with '0x20'.
427 convert_sff_name(char *buf, size_t size, char *xbuf)
431 for (p = &xbuf[16]; *(p - 1) == 0x20; p--)
434 snprintf(buf, size, "%s", xbuf);
438 convert_sff_date(char *buf, size_t size, char *xbuf)
441 snprintf(buf, size, "20%c%c-%c%c-%c%c", xbuf[0], xbuf[1],
442 xbuf[2], xbuf[3], xbuf[4], xbuf[5]);
446 get_sfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
450 memset(xbuf, 0, sizeof(xbuf));
451 read_i2c(ii, SFF_8472_BASE, SFF_8472_VENDOR_START, 16, (uint8_t *)xbuf);
452 convert_sff_name(buf, size, xbuf);
456 get_sfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
460 memset(xbuf, 0, sizeof(xbuf));
461 read_i2c(ii, SFF_8472_BASE, SFF_8472_PN_START, 16, (uint8_t *)xbuf);
462 convert_sff_name(buf, size, xbuf);
466 get_sfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
470 memset(xbuf, 0, sizeof(xbuf));
471 read_i2c(ii, SFF_8472_BASE, SFF_8472_SN_START, 16, (uint8_t *)xbuf);
472 convert_sff_name(buf, size, xbuf);
476 get_sfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
480 memset(xbuf, 0, sizeof(xbuf));
481 /* Date code, see Table 3.8 for description */
482 read_i2c(ii, SFF_8472_BASE, SFF_8472_DATE_START, 6, (uint8_t *)xbuf);
483 convert_sff_date(buf, size, xbuf);
487 get_qsfp_vendor_name(struct i2c_info *ii, char *buf, size_t size)
491 memset(xbuf, 0, sizeof(xbuf));
492 read_i2c(ii, SFF_8436_BASE, SFF_8436_VENDOR_START, 16, (uint8_t *)xbuf);
493 convert_sff_name(buf, size, xbuf);
497 get_qsfp_vendor_pn(struct i2c_info *ii, char *buf, size_t size)
501 memset(xbuf, 0, sizeof(xbuf));
502 read_i2c(ii, SFF_8436_BASE, SFF_8436_PN_START, 16, (uint8_t *)xbuf);
503 convert_sff_name(buf, size, xbuf);
507 get_qsfp_vendor_sn(struct i2c_info *ii, char *buf, size_t size)
511 memset(xbuf, 0, sizeof(xbuf));
512 read_i2c(ii, SFF_8436_BASE, SFF_8436_SN_START, 16, (uint8_t *)xbuf);
513 convert_sff_name(buf, size, xbuf);
517 get_qsfp_vendor_date(struct i2c_info *ii, char *buf, size_t size)
521 memset(xbuf, 0, sizeof(xbuf));
522 read_i2c(ii, SFF_8436_BASE, SFF_8436_DATE_START, 6, (uint8_t *)xbuf);
523 convert_sff_date(buf, size, xbuf);
527 print_sfp_vendor(struct i2c_info *ii, char *buf, size_t size)
531 memset(xbuf, 0, sizeof(xbuf));
533 get_qsfp_vendor_name(ii, xbuf, 20);
534 get_qsfp_vendor_pn(ii, &xbuf[20], 20);
535 get_qsfp_vendor_sn(ii, &xbuf[40], 20);
536 get_qsfp_vendor_date(ii, &xbuf[60], 20);
538 get_sfp_vendor_name(ii, xbuf, 20);
539 get_sfp_vendor_pn(ii, &xbuf[20], 20);
540 get_sfp_vendor_sn(ii, &xbuf[40], 20);
541 get_sfp_vendor_date(ii, &xbuf[60], 20);
544 snprintf(buf, size, "vendor: %s PN: %s SN: %s DATE: %s",
545 xbuf, &xbuf[20], &xbuf[40], &xbuf[60]);
549 * Converts internal templerature (SFF-8472, SFF-8436)
550 * 16-bit unsigned value to human-readable representation:
552 * Internally measured Module temperature are represented
553 * as a 16-bit signed twos complement value in increments of
554 * 1/256 degrees Celsius, yielding a total range of –128C to +128C
555 * that is considered valid between –40 and +125C.
559 convert_sff_temp(char *buf, size_t size, uint8_t *xbuf)
564 d += (double)xbuf[1] / 256;
566 snprintf(buf, size, "%.2f C", d);
570 * Retrieves supplied voltage (SFF-8472, SFF-8436).
571 * 16-bit usigned value, treated as range 0..+6.55 Volts
574 convert_sff_voltage(char *buf, size_t size, uint8_t *xbuf)
578 d = (double)((xbuf[0] << 8) | xbuf[1]);
579 snprintf(buf, size, "%.2f Volts", d / 10000);
583 * Converts value in @xbuf to both milliwats and dBm
584 * human representation.
587 convert_sff_power(struct i2c_info *ii, char *buf, size_t size, uint8_t *xbuf)
592 mW = (xbuf[0] << 8) + xbuf[1];
594 /* Convert mw to dbm */
595 dbm = 10.0 * log10(1.0 * mW / 10000);
598 * Assume internally-calibrated data.
599 * This is always true for SFF-8346, and explicitly
600 * checked for SFF-8472.
603 /* Table 3.9, bit 5 is set, internally calibrated */
604 snprintf(buf, size, "%d.%02d mW (%.2f dBm)",
605 mW / 10000, (mW % 10000) / 100, dbm);
609 get_sfp_temp(struct i2c_info *ii, char *buf, size_t size)
613 memset(xbuf, 0, sizeof(xbuf));
614 read_i2c(ii, SFF_8472_DIAG, SFF_8472_TEMP, 2, xbuf);
615 convert_sff_temp(buf, size, xbuf);
619 get_sfp_voltage(struct i2c_info *ii, char *buf, size_t size)
623 memset(xbuf, 0, sizeof(xbuf));
624 read_i2c(ii, SFF_8472_DIAG, SFF_8472_VCC, 2, xbuf);
625 convert_sff_voltage(buf, size, xbuf);
629 get_qsfp_temp(struct i2c_info *ii, char *buf, size_t size)
633 memset(xbuf, 0, sizeof(xbuf));
634 read_i2c(ii, SFF_8436_BASE, SFF_8436_TEMP, 2, xbuf);
635 if ((xbuf[0] == 0xFF && xbuf[1] == 0xFF) || (xbuf[0] == 0 && xbuf[1] == 0))
637 convert_sff_temp(buf, size, xbuf);
642 get_qsfp_voltage(struct i2c_info *ii, char *buf, size_t size)
646 memset(xbuf, 0, sizeof(xbuf));
647 read_i2c(ii, SFF_8436_BASE, SFF_8436_VCC, 2, xbuf);
648 convert_sff_voltage(buf, size, xbuf);
652 get_sfp_rx_power(struct i2c_info *ii, char *buf, size_t size)
656 memset(xbuf, 0, sizeof(xbuf));
657 read_i2c(ii, SFF_8472_DIAG, SFF_8472_RX_POWER, 2, xbuf);
658 convert_sff_power(ii, buf, size, xbuf);
662 get_sfp_tx_power(struct i2c_info *ii, char *buf, size_t size)
666 memset(xbuf, 0, sizeof(xbuf));
667 read_i2c(ii, SFF_8472_DIAG, SFF_8472_TX_POWER, 2, xbuf);
668 convert_sff_power(ii, buf, size, xbuf);
672 get_qsfp_rx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
676 memset(xbuf, 0, sizeof(xbuf));
677 read_i2c(ii, SFF_8436_BASE, SFF_8436_RX_CH1_MSB + (chan-1)*2, 2, xbuf);
678 convert_sff_power(ii, buf, size, xbuf);
682 get_qsfp_tx_power(struct i2c_info *ii, char *buf, size_t size, int chan)
686 memset(xbuf, 0, sizeof(xbuf));
687 read_i2c(ii, SFF_8436_BASE, SFF_8436_TX_CH1_MSB + (chan-1)*2, 2, xbuf);
688 convert_sff_power(ii, buf, size, xbuf);
692 get_qsfp_rev_compliance(struct i2c_info *ii, char *buf, size_t size)
697 read_i2c(ii, SFF_8436_BASE, SFF_8436_STATUS, 1, &xbuf);
698 convert_sff_rev_compliance(buf, size, xbuf);
702 get_qsfp_br(struct i2c_info *ii)
708 read_i2c(ii, SFF_8436_BASE, SFF_8436_BITRATE, 1, &xbuf);
711 read_i2c(ii, SFF_8436_BASE, SFF_8636_BITRATE, 1, &xbuf);
719 * Reads i2c data from opened kernel socket.
722 read_i2c(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len,
731 ii->ifr->ifr_data = (caddr_t)&req;
735 memset(&req, 0, sizeof(req));
741 l = (len > sizeof(req.data)) ? sizeof(req.data) : len;
743 if (ioctl(ii->fd, SIOCGI2C, ii->ifr) != 0) {
748 memcpy(&buf[i], req.data, l);
758 dump_i2c_data(struct i2c_info *ii, uint8_t addr, uint8_t off, uint8_t len)
760 unsigned char buf[16];
764 memset(buf, 0, sizeof(buf));
765 read = (len > sizeof(buf)) ? sizeof(buf) : len;
766 read_i2c(ii, addr, off, read, buf);
767 if (ii->error != 0) {
768 fprintf(stderr, "Error reading i2c info\n");
773 for (i = 0; i < read; i++)
774 printf("%02X ", buf[i]);
782 print_qsfp_status(struct i2c_info *ii, int verbose)
784 char buf[80], buf2[40], buf3[40];
790 /* Transceiver type */
791 get_qsfp_identifier(ii, buf, sizeof(buf));
792 get_qsfp_transceiver_class(ii, buf2, sizeof(buf2));
793 get_qsfp_connector(ii, buf3, sizeof(buf3));
795 printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
796 print_sfp_vendor(ii, buf, sizeof(buf));
798 printf("\t%s\n", buf);
801 get_qsfp_rev_compliance(ii, buf, sizeof(buf));
803 printf("\tcompliance level: %s\n", buf);
805 bitrate = get_qsfp_br(ii);
806 if (ii->error == 0 && bitrate > 0)
807 printf("\tnominal bitrate: %u Mbps\n", bitrate);
811 * The standards in this area are not clear when the
812 * additional measurements are present or not. Use a valid
813 * temperature reading as an indicator for the presence of
814 * voltage and TX/RX power measurements.
816 if (get_qsfp_temp(ii, buf, sizeof(buf)) == 0) {
817 get_qsfp_voltage(ii, buf2, sizeof(buf2));
818 printf("\tmodule temperature: %s voltage: %s\n", buf, buf2);
819 for (i = 1; i <= 4; i++) {
820 get_qsfp_rx_power(ii, buf, sizeof(buf), i);
821 get_qsfp_tx_power(ii, buf2, sizeof(buf2), i);
822 printf("\tlane %d: RX: %s TX: %s\n", i, buf, buf2);
827 printf("\n\tSFF8436 DUMP (0xA0 128..255 range):\n");
828 dump_i2c_data(ii, SFF_8436_BASE, 128, 128);
829 printf("\n\tSFF8436 DUMP (0xA0 0..81 range):\n");
830 dump_i2c_data(ii, SFF_8436_BASE, 0, 82);
835 print_sfp_status(struct i2c_info *ii, int verbose)
837 char buf[80], buf2[40], buf3[40];
838 uint8_t diag_type, flags;
840 /* Read diagnostic monitoring type */
841 read_i2c(ii, SFF_8472_BASE, SFF_8472_DIAG_TYPE, 1, (caddr_t)&diag_type);
846 * Read monitoring data IFF it is supplied AND is
847 * internally calibrated
849 flags = SFF_8472_DDM_DONE | SFF_8472_DDM_INTERNAL;
850 if ((diag_type & flags) == flags)
853 /* Transceiver type */
854 get_sfp_identifier(ii, buf, sizeof(buf));
855 get_sfp_transceiver_class(ii, buf2, sizeof(buf2));
856 get_sfp_connector(ii, buf3, sizeof(buf3));
858 printf("\tplugged: %s %s (%s)\n", buf, buf2, buf3);
859 print_sfp_vendor(ii, buf, sizeof(buf));
861 printf("\t%s\n", buf);
864 printf_sfp_transceiver_descr(ii, buf, sizeof(buf));
866 * Request current measurements iff they are provided:
868 if (ii->do_diag != 0) {
869 get_sfp_temp(ii, buf, sizeof(buf));
870 get_sfp_voltage(ii, buf2, sizeof(buf2));
871 printf("\tmodule temperature: %s Voltage: %s\n", buf, buf2);
872 get_sfp_rx_power(ii, buf, sizeof(buf));
873 get_sfp_tx_power(ii, buf2, sizeof(buf2));
874 printf("\tRX: %s TX: %s\n", buf, buf2);
878 printf("\n\tSFF8472 DUMP (0xA0 0..127 range):\n");
879 dump_i2c_data(ii, SFF_8472_BASE, 0, 128);
884 sfp_status(int s, struct ifreq *ifr, int verbose)
889 /* Prepare necessary into pass to i2c reader */
890 memset(&ii, 0, sizeof(ii));
895 * Try to read byte 0 from i2c:
896 * Both SFF-8472 and SFF-8436 use it as
897 * 'identification byte'.
898 * Stop reading status on zero as value -
899 * this might happen in case of empty transceiver slot.
902 read_i2c(&ii, SFF_8472_BASE, SFF_8472_ID, 1, (caddr_t)&id_byte);
903 if (ii.error != 0 || id_byte == 0)
907 case SFF_8024_ID_QSFP:
908 case SFF_8024_ID_QSFPPLUS:
909 case SFF_8024_ID_QSFP28:
910 print_qsfp_status(&ii, verbose);
913 print_sfp_status(&ii, verbose);