xref: /titanic_44/usr/src/test/util-tests/tests/libsff/libsff_opts.c (revision 48a4016cae8aa2b8b3d8b258eb22e0c781912bed)
1*48a4016cSRobert Mustacchi /*
2*48a4016cSRobert Mustacchi  * This file and its contents are supplied under the terms of the
3*48a4016cSRobert Mustacchi  * Common Development and Distribution License ("CDDL"), version 1.0.
4*48a4016cSRobert Mustacchi  * You may only use this file in accordance with the terms of version
5*48a4016cSRobert Mustacchi  * 1.0 of the CDDL.
6*48a4016cSRobert Mustacchi  *
7*48a4016cSRobert Mustacchi  * A full copy of the text of the CDDL should have accompanied this
8*48a4016cSRobert Mustacchi  * source.  A copy of the CDDL is also available via the Internet at
9*48a4016cSRobert Mustacchi  * http://www.illumos.org/license/CDDL.
10*48a4016cSRobert Mustacchi  */
11*48a4016cSRobert Mustacchi 
12*48a4016cSRobert Mustacchi /*
13*48a4016cSRobert Mustacchi  * Copyright (c) 2017, Joyent, Inc.
14*48a4016cSRobert Mustacchi  */
15*48a4016cSRobert Mustacchi 
16*48a4016cSRobert Mustacchi /*
17*48a4016cSRobert Mustacchi  * Print and tests SFF options values.
18*48a4016cSRobert Mustacchi  */
19*48a4016cSRobert Mustacchi 
20*48a4016cSRobert Mustacchi #include <stdio.h>
21*48a4016cSRobert Mustacchi #include <errno.h>
22*48a4016cSRobert Mustacchi #include <strings.h>
23*48a4016cSRobert Mustacchi #include <err.h>
24*48a4016cSRobert Mustacchi #include <libsff.h>
25*48a4016cSRobert Mustacchi 
26*48a4016cSRobert Mustacchi /*
27*48a4016cSRobert Mustacchi  * Pick up private sff header file with offsets from lib/libsff.
28*48a4016cSRobert Mustacchi  */
29*48a4016cSRobert Mustacchi #include "sff.h"
30*48a4016cSRobert Mustacchi 
31*48a4016cSRobert Mustacchi static void
lso_print_array(nvlist_t * nvl,const char * key)32*48a4016cSRobert Mustacchi lso_print_array(nvlist_t *nvl, const char *key)
33*48a4016cSRobert Mustacchi {
34*48a4016cSRobert Mustacchi 	int ret;
35*48a4016cSRobert Mustacchi 	uint_t i, count;
36*48a4016cSRobert Mustacchi 	char **vals;
37*48a4016cSRobert Mustacchi 
38*48a4016cSRobert Mustacchi 	if ((ret = nvlist_lookup_string_array(nvl, key, &vals, &count)) != 0) {
39*48a4016cSRobert Mustacchi 		errx(1, "TEST FAILED failed to find key %s: %s\n", key,
40*48a4016cSRobert Mustacchi 		    strerror(ret));
41*48a4016cSRobert Mustacchi 	}
42*48a4016cSRobert Mustacchi 
43*48a4016cSRobert Mustacchi 	(void) puts(key);
44*48a4016cSRobert Mustacchi 	for (i = 0; i < count; i++) {
45*48a4016cSRobert Mustacchi 		(void) printf("\t%d\t%s\n", i, vals[i]);
46*48a4016cSRobert Mustacchi 	}
47*48a4016cSRobert Mustacchi }
48*48a4016cSRobert Mustacchi 
49*48a4016cSRobert Mustacchi int
main(void)50*48a4016cSRobert Mustacchi main(void)
51*48a4016cSRobert Mustacchi {
52*48a4016cSRobert Mustacchi 	int ret;
53*48a4016cSRobert Mustacchi 	uint8_t buf[256];
54*48a4016cSRobert Mustacchi 	nvlist_t *nvl;
55*48a4016cSRobert Mustacchi 
56*48a4016cSRobert Mustacchi 	/*
57*48a4016cSRobert Mustacchi 	 * Set every shared bit for options then print them all out. Note we
58*48a4016cSRobert Mustacchi 	 * include reserved bits so that way if someone ends up adding something
59*48a4016cSRobert Mustacchi 	 * to one of the reserved fields, we end up printing it.
60*48a4016cSRobert Mustacchi 	 */
61*48a4016cSRobert Mustacchi 	bzero(buf, sizeof (buf));
62*48a4016cSRobert Mustacchi 	buf[SFF_8472_OPTIONS_HI] = 0xff;
63*48a4016cSRobert Mustacchi 	buf[SFF_8472_OPTIONS_LOW] = 0xff;
64*48a4016cSRobert Mustacchi 	buf[SFF_8472_ENHANCED_OPTIONS] = 0xff;
65*48a4016cSRobert Mustacchi 
66*48a4016cSRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
67*48a4016cSRobert Mustacchi 		errx(1, "TEST FAILED: failed to parse SFP options "
68*48a4016cSRobert Mustacchi 		    "values: %s\n", strerror(ret));
69*48a4016cSRobert Mustacchi 	}
70*48a4016cSRobert Mustacchi 
71*48a4016cSRobert Mustacchi 	lso_print_array(nvl, LIBSFF_KEY_OPTIONS);
72*48a4016cSRobert Mustacchi 	lso_print_array(nvl, LIBSFF_KEY_EXTENDED_OPTIONS);
73*48a4016cSRobert Mustacchi 
74*48a4016cSRobert Mustacchi 	nvlist_free(nvl);
75*48a4016cSRobert Mustacchi 
76*48a4016cSRobert Mustacchi 	/*
77*48a4016cSRobert Mustacchi 	 * Now for QSFP+
78*48a4016cSRobert Mustacchi 	 */
79*48a4016cSRobert Mustacchi 	(void) puts("\n\nQSFP\n");
80*48a4016cSRobert Mustacchi 	bzero(buf, sizeof (buf));
81*48a4016cSRobert Mustacchi 	buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
82*48a4016cSRobert Mustacchi 	buf[SFF_8636_OPTIONS_HI] = 0xff;
83*48a4016cSRobert Mustacchi 	buf[SFF_8636_OPTIONS_MID] = 0xff;
84*48a4016cSRobert Mustacchi 	buf[SFF_8636_OPTIONS_LOW] = 0xff;
85*48a4016cSRobert Mustacchi 	buf[SFF_8636_ENHANCED_OPTIONS] = 0xff;
86*48a4016cSRobert Mustacchi 
87*48a4016cSRobert Mustacchi 	if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
88*48a4016cSRobert Mustacchi 		errx(1, "TEST FAILED: failed to parse QSFP options "
89*48a4016cSRobert Mustacchi 		    "values: %s\n", strerror(ret));
90*48a4016cSRobert Mustacchi 	}
91*48a4016cSRobert Mustacchi 
92*48a4016cSRobert Mustacchi 	lso_print_array(nvl, LIBSFF_KEY_OPTIONS);
93*48a4016cSRobert Mustacchi 	lso_print_array(nvl, LIBSFF_KEY_ENHANCED_OPTIONS);
94*48a4016cSRobert Mustacchi 
95*48a4016cSRobert Mustacchi 	nvlist_free(nvl);
96*48a4016cSRobert Mustacchi 
97*48a4016cSRobert Mustacchi 	return (0);
98*48a4016cSRobert Mustacchi }
99