1*59596c01SRobert Mustacchi /*
2*59596c01SRobert Mustacchi * This file and its contents are supplied under the terms of the
3*59596c01SRobert Mustacchi * Common Development and Distribution License ("CDDL"), version 1.0.
4*59596c01SRobert Mustacchi * You may only use this file in accordance with the terms of version
5*59596c01SRobert Mustacchi * 1.0 of the CDDL.
6*59596c01SRobert Mustacchi *
7*59596c01SRobert Mustacchi * A full copy of the text of the CDDL should have accompanied this
8*59596c01SRobert Mustacchi * source. A copy of the CDDL is also available via the Internet at
9*59596c01SRobert Mustacchi * http://www.illumos.org/license/CDDL.
10*59596c01SRobert Mustacchi */
11*59596c01SRobert Mustacchi
12*59596c01SRobert Mustacchi /*
13*59596c01SRobert Mustacchi * Copyright (c) 2017, Joyent, Inc.
14*59596c01SRobert Mustacchi */
15*59596c01SRobert Mustacchi
16*59596c01SRobert Mustacchi /*
17*59596c01SRobert Mustacchi * Print and tests SFF Wavelength values. Note that in both SFF 8472 and SFF
18*59596c01SRobert Mustacchi * 8636 the wavelength values also double for various copper complaince values.
19*59596c01SRobert Mustacchi * We check both forms here. Note that the copper compliance in SFF 8472 is
20*59596c01SRobert Mustacchi * currently tested in libsff_compliance.c. SFF 8636's Copper Attenuation values
21*59596c01SRobert Mustacchi * are tested here.
22*59596c01SRobert Mustacchi */
23*59596c01SRobert Mustacchi
24*59596c01SRobert Mustacchi #include <stdio.h>
25*59596c01SRobert Mustacchi #include <errno.h>
26*59596c01SRobert Mustacchi #include <strings.h>
27*59596c01SRobert Mustacchi #include <err.h>
28*59596c01SRobert Mustacchi #include <libsff.h>
29*59596c01SRobert Mustacchi
30*59596c01SRobert Mustacchi /*
31*59596c01SRobert Mustacchi * Pick up private sff header file with offsets from lib/libsff.
32*59596c01SRobert Mustacchi */
33*59596c01SRobert Mustacchi #include "sff.h"
34*59596c01SRobert Mustacchi
35*59596c01SRobert Mustacchi int
main(void)36*59596c01SRobert Mustacchi main(void)
37*59596c01SRobert Mustacchi {
38*59596c01SRobert Mustacchi int ret, i;
39*59596c01SRobert Mustacchi uint8_t buf[256];
40*59596c01SRobert Mustacchi nvlist_t *nvl;
41*59596c01SRobert Mustacchi char *val;
42*59596c01SRobert Mustacchi char *attenuate[] = { LIBSFF_KEY_ATTENUATE_2G, LIBSFF_KEY_ATTENUATE_5G,
43*59596c01SRobert Mustacchi LIBSFF_KEY_ATTENUATE_7G, LIBSFF_KEY_ATTENUATE_12G, NULL };
44*59596c01SRobert Mustacchi char *wave[] = { LIBSFF_KEY_WAVELENGTH, LIBSFF_KEY_WAVE_TOLERANCE,
45*59596c01SRobert Mustacchi NULL };
46*59596c01SRobert Mustacchi
47*59596c01SRobert Mustacchi bzero(buf, sizeof (buf));
48*59596c01SRobert Mustacchi buf[SFF_8472_WAVELENGTH_HI] = 0x12;
49*59596c01SRobert Mustacchi buf[SFF_8472_WAVELENGTH_LOW] = 0x34;
50*59596c01SRobert Mustacchi
51*59596c01SRobert Mustacchi if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
52*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to parse SFP wavelength "
53*59596c01SRobert Mustacchi "values: %s\n", strerror(ret));
54*59596c01SRobert Mustacchi }
55*59596c01SRobert Mustacchi
56*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_WAVELENGTH, &val)) !=
57*59596c01SRobert Mustacchi 0) {
58*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to find %s: %s when "
59*59596c01SRobert Mustacchi "parsing key %d: %s\n", LIBSFF_KEY_WAVELENGTH,
60*59596c01SRobert Mustacchi strerror(ret));
61*59596c01SRobert Mustacchi }
62*59596c01SRobert Mustacchi (void) printf("%s: %s\n", LIBSFF_KEY_WAVELENGTH, val);
63*59596c01SRobert Mustacchi nvlist_free(nvl);
64*59596c01SRobert Mustacchi
65*59596c01SRobert Mustacchi /*
66*59596c01SRobert Mustacchi * Make sure wavelength is missing if we specify a copper compliance.
67*59596c01SRobert Mustacchi */
68*59596c01SRobert Mustacchi bzero(buf, sizeof (buf));
69*59596c01SRobert Mustacchi buf[SFF_8472_COMPLIANCE_SFP] = 0x08;
70*59596c01SRobert Mustacchi buf[SFF_8472_WAVELENGTH_HI] = 0x12;
71*59596c01SRobert Mustacchi buf[SFF_8472_WAVELENGTH_LOW] = 0x34;
72*59596c01SRobert Mustacchi
73*59596c01SRobert Mustacchi if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
74*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to parse SFP wavelength "
75*59596c01SRobert Mustacchi "values: %s\n", strerror(ret));
76*59596c01SRobert Mustacchi }
77*59596c01SRobert Mustacchi
78*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_WAVELENGTH, &val)) !=
79*59596c01SRobert Mustacchi ENOENT) {
80*59596c01SRobert Mustacchi errx(1, "TEST FALIED: found unexpected return value for key "
81*59596c01SRobert Mustacchi "%s: %d\n", LIBSFF_KEY_WAVELENGTH, ret);
82*59596c01SRobert Mustacchi }
83*59596c01SRobert Mustacchi
84*59596c01SRobert Mustacchi nvlist_free(nvl);
85*59596c01SRobert Mustacchi
86*59596c01SRobert Mustacchi bzero(buf, sizeof (buf));
87*59596c01SRobert Mustacchi buf[SFF_8472_COMPLIANCE_SFP] = 0x04;
88*59596c01SRobert Mustacchi buf[SFF_8472_WAVELENGTH_HI] = 0x12;
89*59596c01SRobert Mustacchi buf[SFF_8472_WAVELENGTH_LOW] = 0x34;
90*59596c01SRobert Mustacchi
91*59596c01SRobert Mustacchi if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
92*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to parse SFP wavelength "
93*59596c01SRobert Mustacchi "values: %s\n", strerror(ret));
94*59596c01SRobert Mustacchi }
95*59596c01SRobert Mustacchi
96*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_WAVELENGTH, &val)) !=
97*59596c01SRobert Mustacchi ENOENT) {
98*59596c01SRobert Mustacchi errx(1, "TEST FALIED: found unexpected return value for key "
99*59596c01SRobert Mustacchi "%s: %d\n", LIBSFF_KEY_WAVELENGTH, ret);
100*59596c01SRobert Mustacchi }
101*59596c01SRobert Mustacchi
102*59596c01SRobert Mustacchi nvlist_free(nvl);
103*59596c01SRobert Mustacchi
104*59596c01SRobert Mustacchi /*
105*59596c01SRobert Mustacchi * Now for QSFP+
106*59596c01SRobert Mustacchi */
107*59596c01SRobert Mustacchi (void) puts("\n\nQSFP\n");
108*59596c01SRobert Mustacchi
109*59596c01SRobert Mustacchi /* First copper */
110*59596c01SRobert Mustacchi bzero(buf, sizeof (buf));
111*59596c01SRobert Mustacchi buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
112*59596c01SRobert Mustacchi buf[SFF_8636_DEVICE_TECH] = 0xa0;
113*59596c01SRobert Mustacchi
114*59596c01SRobert Mustacchi buf[SFF_8636_ATTENUATE_2G] = 0x42;
115*59596c01SRobert Mustacchi buf[SFF_8636_ATTENUATE_5G] = 0x43;
116*59596c01SRobert Mustacchi buf[SFF_8636_ATTENUATE_7G] = 0x44;
117*59596c01SRobert Mustacchi buf[SFF_8636_ATTENUATE_12G] = 0x45;
118*59596c01SRobert Mustacchi
119*59596c01SRobert Mustacchi if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
120*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to parse QSFP BR "
121*59596c01SRobert Mustacchi "values: %s\n", strerror(ret));
122*59596c01SRobert Mustacchi }
123*59596c01SRobert Mustacchi
124*59596c01SRobert Mustacchi for (i = 0; attenuate[i] != NULL; i++) {
125*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string(nvl, attenuate[i], &val)) !=
126*59596c01SRobert Mustacchi 0) {
127*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to find %s: %s when "
128*59596c01SRobert Mustacchi "parsing key %d: %s\n", attenuate[i],
129*59596c01SRobert Mustacchi strerror(ret));
130*59596c01SRobert Mustacchi }
131*59596c01SRobert Mustacchi (void) printf("%s: %s\n", attenuate[i], val);
132*59596c01SRobert Mustacchi }
133*59596c01SRobert Mustacchi
134*59596c01SRobert Mustacchi for (i = 0; wave[i] != NULL; i++) {
135*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string(nvl, wave[i], &val)) !=
136*59596c01SRobert Mustacchi ENOENT) {
137*59596c01SRobert Mustacchi errx(1, "TEST FALIED: found unexpected return value "
138*59596c01SRobert Mustacchi "for key %s: %d\n", attenuate[i], ret);
139*59596c01SRobert Mustacchi }
140*59596c01SRobert Mustacchi
141*59596c01SRobert Mustacchi }
142*59596c01SRobert Mustacchi nvlist_free(nvl);
143*59596c01SRobert Mustacchi
144*59596c01SRobert Mustacchi /* Now normal wavelengths */
145*59596c01SRobert Mustacchi bzero(buf, sizeof (buf));
146*59596c01SRobert Mustacchi buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
147*59596c01SRobert Mustacchi
148*59596c01SRobert Mustacchi buf[SFF_8636_WAVELENGTH_NOMINAL_HI] = 0x12;
149*59596c01SRobert Mustacchi buf[SFF_8636_WAVELENGTH_NOMINAL_LOW] = 0x34;
150*59596c01SRobert Mustacchi buf[SFF_8636_WAVELENGTH_TOLERANCE_HI] = 0x56;
151*59596c01SRobert Mustacchi buf[SFF_8636_WAVELENGTH_TOLERANCE_LOW] = 0x78;
152*59596c01SRobert Mustacchi
153*59596c01SRobert Mustacchi if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
154*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to parse QSFP Wavelength "
155*59596c01SRobert Mustacchi "values: %s\n", strerror(ret));
156*59596c01SRobert Mustacchi }
157*59596c01SRobert Mustacchi
158*59596c01SRobert Mustacchi for (i = 0; wave[i] != NULL; i++) {
159*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string(nvl, wave[i], &val)) != 0) {
160*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to find %s: %s when "
161*59596c01SRobert Mustacchi "parsing key %d: %s\n", wave[i], strerror(ret));
162*59596c01SRobert Mustacchi }
163*59596c01SRobert Mustacchi (void) printf("%s: %s\n", wave[i], val);
164*59596c01SRobert Mustacchi }
165*59596c01SRobert Mustacchi
166*59596c01SRobert Mustacchi for (i = 0; attenuate[i] != NULL; i++) {
167*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string(nvl, attenuate[i], &val)) !=
168*59596c01SRobert Mustacchi ENOENT) {
169*59596c01SRobert Mustacchi errx(1, "TEST FALIED: found unexpected return value "
170*59596c01SRobert Mustacchi "for key %s: %d\n", attenuate[i], ret);
171*59596c01SRobert Mustacchi }
172*59596c01SRobert Mustacchi
173*59596c01SRobert Mustacchi }
174*59596c01SRobert Mustacchi nvlist_free(nvl);
175*59596c01SRobert Mustacchi
176*59596c01SRobert Mustacchi return (0);
177*59596c01SRobert Mustacchi }
178