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 options values.
18*59596c01SRobert Mustacchi */
19*59596c01SRobert Mustacchi
20*59596c01SRobert Mustacchi #include <stdio.h>
21*59596c01SRobert Mustacchi #include <errno.h>
22*59596c01SRobert Mustacchi #include <strings.h>
23*59596c01SRobert Mustacchi #include <err.h>
24*59596c01SRobert Mustacchi #include <libsff.h>
25*59596c01SRobert Mustacchi
26*59596c01SRobert Mustacchi /*
27*59596c01SRobert Mustacchi * Pick up private sff header file with offsets from lib/libsff.
28*59596c01SRobert Mustacchi */
29*59596c01SRobert Mustacchi #include "sff.h"
30*59596c01SRobert Mustacchi
31*59596c01SRobert Mustacchi static void
lso_print_array(nvlist_t * nvl,const char * key)32*59596c01SRobert Mustacchi lso_print_array(nvlist_t *nvl, const char *key)
33*59596c01SRobert Mustacchi {
34*59596c01SRobert Mustacchi int ret;
35*59596c01SRobert Mustacchi uint_t i, count;
36*59596c01SRobert Mustacchi char **vals;
37*59596c01SRobert Mustacchi
38*59596c01SRobert Mustacchi if ((ret = nvlist_lookup_string_array(nvl, key, &vals, &count)) != 0) {
39*59596c01SRobert Mustacchi errx(1, "TEST FAILED failed to find key %s: %s\n", key,
40*59596c01SRobert Mustacchi strerror(ret));
41*59596c01SRobert Mustacchi }
42*59596c01SRobert Mustacchi
43*59596c01SRobert Mustacchi (void) puts(key);
44*59596c01SRobert Mustacchi for (i = 0; i < count; i++) {
45*59596c01SRobert Mustacchi (void) printf("\t%d\t%s\n", i, vals[i]);
46*59596c01SRobert Mustacchi }
47*59596c01SRobert Mustacchi }
48*59596c01SRobert Mustacchi
49*59596c01SRobert Mustacchi int
main(void)50*59596c01SRobert Mustacchi main(void)
51*59596c01SRobert Mustacchi {
52*59596c01SRobert Mustacchi int ret;
53*59596c01SRobert Mustacchi uint8_t buf[256];
54*59596c01SRobert Mustacchi nvlist_t *nvl;
55*59596c01SRobert Mustacchi
56*59596c01SRobert Mustacchi /*
57*59596c01SRobert Mustacchi * Set every shared bit for options then print them all out. Note we
58*59596c01SRobert Mustacchi * include reserved bits so that way if someone ends up adding something
59*59596c01SRobert Mustacchi * to one of the reserved fields, we end up printing it.
60*59596c01SRobert Mustacchi */
61*59596c01SRobert Mustacchi bzero(buf, sizeof (buf));
62*59596c01SRobert Mustacchi buf[SFF_8472_OPTIONS_HI] = 0xff;
63*59596c01SRobert Mustacchi buf[SFF_8472_OPTIONS_LOW] = 0xff;
64*59596c01SRobert Mustacchi buf[SFF_8472_ENHANCED_OPTIONS] = 0xff;
65*59596c01SRobert Mustacchi
66*59596c01SRobert Mustacchi if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
67*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to parse SFP options "
68*59596c01SRobert Mustacchi "values: %s\n", strerror(ret));
69*59596c01SRobert Mustacchi }
70*59596c01SRobert Mustacchi
71*59596c01SRobert Mustacchi lso_print_array(nvl, LIBSFF_KEY_OPTIONS);
72*59596c01SRobert Mustacchi lso_print_array(nvl, LIBSFF_KEY_EXTENDED_OPTIONS);
73*59596c01SRobert Mustacchi
74*59596c01SRobert Mustacchi nvlist_free(nvl);
75*59596c01SRobert Mustacchi
76*59596c01SRobert Mustacchi /*
77*59596c01SRobert Mustacchi * Now for QSFP+
78*59596c01SRobert Mustacchi */
79*59596c01SRobert Mustacchi (void) puts("\n\nQSFP\n");
80*59596c01SRobert Mustacchi bzero(buf, sizeof (buf));
81*59596c01SRobert Mustacchi buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
82*59596c01SRobert Mustacchi buf[SFF_8636_OPTIONS_HI] = 0xff;
83*59596c01SRobert Mustacchi buf[SFF_8636_OPTIONS_MID] = 0xff;
84*59596c01SRobert Mustacchi buf[SFF_8636_OPTIONS_LOW] = 0xff;
85*59596c01SRobert Mustacchi buf[SFF_8636_ENHANCED_OPTIONS] = 0xff;
86*59596c01SRobert Mustacchi
87*59596c01SRobert Mustacchi if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
88*59596c01SRobert Mustacchi errx(1, "TEST FAILED: failed to parse QSFP options "
89*59596c01SRobert Mustacchi "values: %s\n", strerror(ret));
90*59596c01SRobert Mustacchi }
91*59596c01SRobert Mustacchi
92*59596c01SRobert Mustacchi lso_print_array(nvl, LIBSFF_KEY_OPTIONS);
93*59596c01SRobert Mustacchi lso_print_array(nvl, LIBSFF_KEY_ENHANCED_OPTIONS);
94*59596c01SRobert Mustacchi
95*59596c01SRobert Mustacchi nvlist_free(nvl);
96*59596c01SRobert Mustacchi
97*59596c01SRobert Mustacchi return (0);
98*59596c01SRobert Mustacchi }
99