xref: /illumos-gate/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c (revision 069e6b7e31ba5dcbc5441b98af272714d9a5455c)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright (c) 2018, Joyent, Inc.
14  */
15 
16 /*
17  * Basic testing of the SMBIOS 3.2 Slot extensions.
18  */
19 
20 #include "smbios_test.h"
21 
22 static const char *smbios_test_name = "The One Slot";
23 
24 boolean_t
25 smbios_test_slot_mktable(smbios_test_table_t *table)
26 {
27 	smb_slot_t slot;
28 	smb_slot_peer_t peers[2];
29 	const uint8_t endstring = 0;
30 
31 	slot.smbsl_hdr.smbh_type = SMB_TYPE_SLOT;
32 	slot.smbsl_hdr.smbh_len = sizeof (smb_slot_t) + sizeof (peers);
33 
34 	slot.smbsl_name = 1;
35 	slot.smbsl_type = SMB_SLT_PCIE3G16;
36 	slot.smbsl_width = SMB_SLW_16X;
37 	slot.smbsl_length = SMB_SLL_SHORT;
38 	slot.smbsl_id = htole16(1);
39 	slot.smbsl_ch1 = SMB_SLCH1_33V;
40 	slot.smbsl_ch2 = SMB_SLCH2_PME;
41 	slot.smbsl_sg = htole16(1);
42 	slot.smbsl_bus = 0x42;
43 	slot.smbsl_df = 0x23;
44 	slot.smbsl_dbw = SMB_SLW_16X;
45 	slot.smbsl_npeers = 2;
46 	peers[0].smbspb_group_no = htole16(1);
47 	peers[0].smbspb_bus = 0x42;
48 	peers[0].smbspb_df = 0x42;
49 	peers[0].smbspb_width = SMB_SLW_8X;
50 
51 	peers[1].smbspb_group_no = htole16(1);
52 	peers[1].smbspb_bus = 0x23;
53 	peers[1].smbspb_df = 0x31;
54 	peers[1].smbspb_width = SMB_SLW_8X;
55 
56 	(void) smbios_test_table_append(table, &slot, sizeof (slot));
57 	(void) smbios_test_table_append_raw(table, peers, sizeof (peers));
58 	(void) smbios_test_table_append_string(table, smbios_test_name);
59 	(void) smbios_test_table_append_raw(table, &endstring,
60 	    sizeof (endstring));
61 
62 	smbios_test_table_append_eot(table);
63 
64 	return (B_TRUE);
65 }
66 
67 boolean_t
68 smbios_test_slot_verify(smbios_hdl_t *hdl)
69 {
70 	smbios_struct_t sp;
71 	smbios_slot_t slot;
72 	uint_t npeers;
73 	smbios_slot_peer_t *peers;
74 	uint_t errs = 0;
75 
76 	if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) {
77 		warnx("failed to lookup SMBIOS slot: %s",
78 		    smbios_errmsg(smbios_errno(hdl)));
79 		return (B_FALSE);
80 	}
81 
82 	if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) {
83 		warnx("failed to get SMBIOS slot info: %s",
84 		    smbios_errmsg(smbios_errno(hdl)));
85 		return (B_FALSE);
86 	}
87 
88 	/*
89 	 * Verify everything we'd expect about the slot.
90 	 */
91 	if (strcmp(slot.smbl_name, smbios_test_name) != 0) {
92 		warnx("slot name mismatch, expected %s, found %s",
93 		    smbios_test_name, slot.smbl_name);
94 		errs++;
95 	}
96 
97 	if (slot.smbl_type != SMB_SLT_PCIE3G16) {
98 		warnx("incorrect slot type, found %u", slot.smbl_type);
99 		errs++;
100 	}
101 
102 	if (slot.smbl_width != SMB_SLW_16X) {
103 		warnx("incorrect slot width, found %u", slot.smbl_width);
104 		errs++;
105 	}
106 
107 	if (slot.smbl_length != SMB_SLL_SHORT) {
108 		warnx("incorrect slot length, found %u", slot.smbl_length);
109 		errs++;
110 	}
111 
112 	if (slot.smbl_dbw != SMB_SLW_16X) {
113 		warnx("incorrect slot data bus width, found %u", slot.smbl_dbw);
114 		errs++;
115 	}
116 
117 	if (slot.smbl_npeers != 2) {
118 		warnx("incorrect number of slot peers, found %u",
119 		    slot.smbl_npeers);
120 		errs++;
121 	}
122 
123 	if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) {
124 		warnx("failed to get SMBIOS peer info: %s",
125 		    smbios_errmsg(smbios_errno(hdl)));
126 		return (B_FALSE);
127 	}
128 
129 	if (npeers != 2) {
130 		warnx("got wrong number of slot peers: %u\n",
131 		    npeers);
132 		return (B_FALSE);
133 	}
134 
135 	if (peers[0].smblp_group != 1) {
136 		warnx("incorrect group for peer 0: %u", peers[0].smblp_group);
137 		errs++;
138 	}
139 
140 	if (peers[0].smblp_data_width != SMB_SLW_8X) {
141 		warnx("incorrect data width for peer 0: %u",
142 		    peers[0].smblp_data_width);
143 		errs++;
144 	}
145 
146 	if (peers[0].smblp_device != (0x42 >> 3)) {
147 		warnx("incorrect PCI device for peer 0: %u",
148 		    peers[0].smblp_device);
149 		errs++;
150 	}
151 
152 	if (peers[0].smblp_function != (0x42 & 0x7)) {
153 		warnx("incorrect PCI function for peer 0: %u",
154 		    peers[0].smblp_function);
155 		errs++;
156 	}
157 
158 	if (peers[1].smblp_group != 1) {
159 		warnx("incorrect group for peer 1: %u", peers[1].smblp_group);
160 		errs++;
161 	}
162 
163 	if (peers[1].smblp_device != (0x31 >> 3)) {
164 		warnx("incorrect PCI device for peer 1: %u",
165 		    peers[1].smblp_device);
166 		errs++;
167 	}
168 
169 	if (peers[1].smblp_function != (0x31 & 0x7)) {
170 		warnx("incorrect PCI function for peer 1: %u",
171 		    peers[1].smblp_function);
172 		errs++;
173 	}
174 
175 	if (peers[1].smblp_data_width != SMB_SLW_8X) {
176 		warnx("incorrect data width for peer 1: %u",
177 		    peers[1].smblp_data_width);
178 		errs++;
179 	}
180 
181 	smbios_info_slot_peers_free(hdl, npeers, peers);
182 
183 	if (errs > 0) {
184 		return (B_FALSE);
185 	}
186 
187 	return (B_TRUE);
188 }
189