1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright (c) 2018, Joyent, Inc.
* Copyright 2021 Oxide Computer Company
*/
/*
* Basic testing of the SMBIOS 3.2 Slot extensions.
*/
#include "smbios_test.h"
static const char *smbios_test_name = "The One Slot";
static uint8_t smbios_slot_bus = 0x42;
static uint8_t smbios_slot_df = 0x23;
static uint8_t smbios_slot_info = 0x65;
static uint16_t smbios_slot_pitch = 0x12af;
static size_t smbios_slot_34_contlen = offsetof(smb_slot_cont_t, smbsl_height);
static void
smbios_test_slot_fill(smb_slot_t *slot)
{
bzero(slot, sizeof (smb_slot_t));
slot->smbsl_hdr.smbh_type = SMB_TYPE_SLOT;
slot->smbsl_hdr.smbh_len = sizeof (smb_slot_t);
slot->smbsl_name = 1;
slot->smbsl_type = SMB_SLT_PCIE3G16;
slot->smbsl_width = SMB_SLW_16X;
slot->smbsl_length = SMB_SLL_SHORT;
slot->smbsl_id = htole16(1);
slot->smbsl_ch1 = SMB_SLCH1_33V;
slot->smbsl_ch2 = SMB_SLCH2_PME;
slot->smbsl_sg = htole16(1);
slot->smbsl_bus = smbios_slot_bus;
slot->smbsl_df = smbios_slot_df;
slot->smbsl_dbw = SMB_SLW_16X;
}
boolean_t
smbios_test_slot_mktable(smbios_test_table_t *table)
{
smb_slot_t slot;
smb_slot_peer_t peers[2];
smbios_test_slot_fill(&slot);
slot.smbsl_hdr.smbh_len += sizeof (peers);
slot.smbsl_npeers = 2;
peers[0].smbspb_group_no = htole16(1);
peers[0].smbspb_bus = 0x42;
peers[0].smbspb_df = 0x42;
peers[0].smbspb_width = SMB_SLW_8X;
peers[1].smbspb_group_no = htole16(1);
peers[1].smbspb_bus = 0x23;
peers[1].smbspb_df = 0x31;
peers[1].smbspb_width = SMB_SLW_8X;
(void) smbios_test_table_append(table, &slot, sizeof (slot));
smbios_test_table_append_raw(table, peers, sizeof (peers));
smbios_test_table_append_string(table, smbios_test_name);
smbios_test_table_str_fini(table);
smbios_test_table_append_eot(table);
return (B_TRUE);
}
static boolean_t
smbios_test_slot_mktable_nopeers(smbios_test_table_t *table, boolean_t is_35)
{
smb_slot_t slot;
smb_slot_cont_t cont;
size_t contlen;
if (is_35) {
contlen = sizeof (cont);
} else {
contlen = smbios_slot_34_contlen;
}
smbios_test_slot_fill(&slot);
slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + contlen;
cont.smbsl_info = smbios_slot_info;
cont.smbsl_pwidth = SMB_SLW_32X;
cont.smbsl_pitch = htole16(smbios_slot_pitch);
cont.smbsl_height = SMB_SLHT_LP;
(void) smbios_test_table_append(table, &slot, sizeof (slot));
smbios_test_table_append_raw(table, &cont, contlen);
smbios_test_table_append_string(table, smbios_test_name);
smbios_test_table_str_fini(table);
smbios_test_table_append_eot(table);
return (B_TRUE);
}
/*
* 3.4 introduced additional data after peers. This version constructs a variant
* with no peers.
*/
boolean_t
smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *table)
{
return (smbios_test_slot_mktable_nopeers(table, B_FALSE));
}
boolean_t
smbios_test_slot_mktable_35(smbios_test_table_t *table)
{
return (smbios_test_slot_mktable_nopeers(table, B_TRUE));
}
boolean_t
smbios_test_slot_mktable_34_peers(smbios_test_table_t *table)
{
smb_slot_t slot;
smb_slot_cont_t cont;
smb_slot_peer_t peers[1];
smbios_test_slot_fill(&slot);
slot.smbsl_npeers = 1;
slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + 5 * slot.smbsl_npeers +
smbios_slot_34_contlen;
peers[0].smbspb_group_no = htole16(1);
peers[0].smbspb_bus = 0x42;
peers[0].smbspb_df = 0x9a;
peers[0].smbspb_width = SMB_SLW_8X;
cont.smbsl_info = smbios_slot_info;
cont.smbsl_pwidth = SMB_SLW_32X;
cont.smbsl_pitch = htole16(smbios_slot_pitch);
(void) smbios_test_table_append(table, &slot, sizeof (slot));
smbios_test_table_append_raw(table, peers, sizeof (peers));
smbios_test_table_append_raw(table, &cont, smbios_slot_34_contlen);
smbios_test_table_append_string(table, smbios_test_name);
smbios_test_table_str_fini(table);
smbios_test_table_append_eot(table);
return (B_TRUE);
}
static boolean_t
smbios_test_slot_common(smbios_slot_t *slot)
{
uint_t errs = 0;
if (strcmp(slot->smbl_name, smbios_test_name) != 0) {
warnx("slot name mismatch, expected %s, found %s",
smbios_test_name, slot->smbl_name);
errs++;
}
if (slot->smbl_type != SMB_SLT_PCIE3G16) {
warnx("incorrect slot type, found %u", slot->smbl_type);
errs++;
}
if (slot->smbl_width != SMB_SLW_16X) {
warnx("incorrect slot width, found %u", slot->smbl_width);
errs++;
}
if (slot->smbl_length != SMB_SLL_SHORT) {
warnx("incorrect slot length, found %u", slot->smbl_length);
errs++;
}
if (slot->smbl_dbw != SMB_SLW_16X) {
warnx("incorrect slot data bus width, found %u",
slot->smbl_dbw);
errs++;
}
if (slot->smbl_bus != smbios_slot_bus) {
warnx("incorrect slot bus id, found 0x%x\n", slot->smbl_bus);
}
if (slot->smbl_df != smbios_slot_df) {
warnx("incorrect slot df id, found 0x%x\n", slot->smbl_df);
}
if (errs > 0) {
return (B_FALSE);
}
return (B_TRUE);
}
boolean_t
smbios_test_slot_verify(smbios_hdl_t *hdl)
{
smbios_struct_t sp;
smbios_slot_t slot;
uint_t npeers;
smbios_slot_peer_t *peers;
uint_t errs = 0;
if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) {
warnx("failed to lookup SMBIOS slot: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) {
warnx("failed to get SMBIOS slot info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (!smbios_test_slot_common(&slot)) {
errs++;
}
if (slot.smbl_npeers != 2) {
warnx("incorrect number of slot peers, found %u",
slot.smbl_npeers);
errs++;
}
if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) {
warnx("failed to get SMBIOS peer info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (npeers != 2) {
warnx("got wrong number of slot peers: %u", npeers);
return (B_FALSE);
}
if (peers[0].smblp_group != 1) {
warnx("incorrect group for peer 0: %u", peers[0].smblp_group);
errs++;
}
if (peers[0].smblp_data_width != SMB_SLW_8X) {
warnx("incorrect data width for peer 0: %u",
peers[0].smblp_data_width);
errs++;
}
if (peers[0].smblp_device != (0x42 >> 3)) {
warnx("incorrect PCI device for peer 0: %u",
peers[0].smblp_device);
errs++;
}
if (peers[0].smblp_function != (0x42 & 0x7)) {
warnx("incorrect PCI function for peer 0: %u",
peers[0].smblp_function);
errs++;
}
if (peers[1].smblp_group != 1) {
warnx("incorrect group for peer 1: %u", peers[1].smblp_group);
errs++;
}
if (peers[1].smblp_device != (0x31 >> 3)) {
warnx("incorrect PCI device for peer 1: %u",
peers[1].smblp_device);
errs++;
}
if (peers[1].smblp_function != (0x31 & 0x7)) {
warnx("incorrect PCI function for peer 1: %u",
peers[1].smblp_function);
errs++;
}
if (peers[1].smblp_data_width != SMB_SLW_8X) {
warnx("incorrect data width for peer 1: %u",
peers[1].smblp_data_width);
errs++;
}
smbios_info_slot_peers_free(hdl, npeers, peers);
if (slot.smbl_info != 0) {
warnx("found wrong slot info: 0x%x", slot.smbl_info);
errs++;
}
if (slot.smbl_pwidth != 0) {
warnx("found wrong slot physical width: 0x%x",
slot.smbl_pwidth);
errs++;
}
if (slot.smbl_pitch != 0) {
warnx("found wrong slot pitch: 0x%x", slot.smbl_pitch);
errs++;
}
if (errs > 0) {
return (B_FALSE);
}
return (B_TRUE);
}
static boolean_t
smbios_test_slot_common_nopeers(smbios_hdl_t *hdl, smbios_struct_t *sp,
smbios_slot_t *slot)
{
uint_t errs = 0;
uint_t npeers;
smbios_slot_peer_t *peers;
if (slot->smbl_npeers != 0) {
warnx("incorrect number of slot peers, found %u",
slot->smbl_npeers);
errs++;
}
if (smbios_info_slot_peers(hdl, sp->smbstr_id, &npeers, &peers) != 0) {
warnx("failed to get SMBIOS peer info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (npeers != 0) {
warnx("got wrong number of slot peers: %u", npeers);
errs++;
}
if (peers != NULL) {
warnx("expected NULL peers pointer, but found %p", peers);
errs++;
}
smbios_info_slot_peers_free(hdl, npeers, peers);
if (slot->smbl_info != smbios_slot_info) {
warnx("found wrong slot info: 0x%x, expected 0x%x",
slot->smbl_info, smbios_slot_info);
errs++;
}
if (slot->smbl_pwidth != SMB_SLW_32X) {
warnx("found wrong slot physical width: 0x%x, expected 0x%x",
slot->smbl_pwidth, SMB_SLW_32X);
errs++;
}
if (slot->smbl_pitch != smbios_slot_pitch) {
warnx("found wrong slot pitch: 0x%x, expected 0x%x",
slot->smbl_pitch, smbios_slot_pitch);
errs++;
}
return (errs == 0);
}
boolean_t
smbios_test_slot_verify_34_nopeers(smbios_hdl_t *hdl)
{
smbios_struct_t sp;
smbios_slot_t slot;
uint_t errs = 0;
if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) {
warnx("failed to lookup SMBIOS slot: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) {
warnx("failed to get SMBIOS slot info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (!smbios_test_slot_common(&slot)) {
errs++;
}
if (!smbios_test_slot_common_nopeers(hdl, &sp, &slot)) {
errs++;
}
if (errs > 0) {
return (B_FALSE);
}
return (B_TRUE);
}
/*
* This is a variant of smbios_test_slot_verify_34_nopeers() that specifically
* uses an older library version and ensures that we don't overrun the
* smbios_slot_t.
*/
boolean_t
smbios_test_slot_verify_34_overrun(smbios_hdl_t *hdl)
{
smbios_struct_t sp;
smbios_slot_t slot;
uint_t errs = 0;
/*
* We purposefully set the values that are part of SMBIOS 3.5+ to bad
* values to make sure that we don't end up zeroing them.
*/
slot.smbl_height = 0xba;
if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) {
warnx("failed to lookup SMBIOS slot: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) {
warnx("failed to get SMBIOS slot info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (slot.smbl_height != 0xba) {
warnx("smbios 3.4 slot structure was overrun, smbl_height "
"unexpectedly set to 0x%x", slot.smbl_height);
errs++;
}
if (!smbios_test_slot_common(&slot)) {
errs++;
}
if (!smbios_test_slot_common_nopeers(hdl, &sp, &slot)) {
errs++;
}
if (errs > 0) {
return (B_FALSE);
}
return (B_TRUE);
}
boolean_t
smbios_test_slot_verify_35(smbios_hdl_t *hdl)
{
smbios_struct_t sp;
smbios_slot_t slot;
uint_t errs = 0;
if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) {
warnx("failed to lookup SMBIOS slot: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) {
warnx("failed to get SMBIOS slot info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (!smbios_test_slot_common(&slot)) {
errs++;
}
if (!smbios_test_slot_common_nopeers(hdl, &sp, &slot)) {
errs++;
}
if (slot.smbl_height != SMB_SLHT_LP) {
warnx("found wrong slot height: 0x%x, expected 0x%x",
slot.smbl_height, SMB_SLHT_LP);
errs++;
}
if (errs > 0) {
return (B_FALSE);
}
return (B_TRUE);
}
boolean_t
smbios_test_slot_verify_34_peers(smbios_hdl_t *hdl)
{
smbios_struct_t sp;
smbios_slot_t slot;
uint_t npeers;
smbios_slot_peer_t *peers;
uint_t errs = 0;
if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) {
warnx("failed to lookup SMBIOS slot: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) {
warnx("failed to get SMBIOS slot info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (!smbios_test_slot_common(&slot)) {
errs++;
}
if (slot.smbl_npeers != 1) {
warnx("incorrect number of slot peers, found %u",
slot.smbl_npeers);
errs++;
}
if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) {
warnx("failed to get SMBIOS peer info: %s",
smbios_errmsg(smbios_errno(hdl)));
return (B_FALSE);
}
if (npeers != 1) {
warnx("got wrong number of slot peers: %u", npeers);
errs++;
}
if (peers[0].smblp_group != 1) {
warnx("incorrect group for peer 0: %u", peers[0].smblp_group);
errs++;
}
if (peers[0].smblp_data_width != SMB_SLW_8X) {
warnx("incorrect data width for peer 0: %u",
peers[0].smblp_data_width);
errs++;
}
if (peers[0].smblp_bus != 0x42) {
warnx("incorrect PCI bus for peer 0: %u",
peers[0].smblp_bus);
errs++;
}
if (peers[0].smblp_device != (0x9a >> 3)) {
warnx("incorrect PCI device for peer 0: %u",
peers[0].smblp_device);
errs++;
}
if (peers[0].smblp_function != (0x9a & 0x7)) {
warnx("incorrect PCI function for peer 0: %u",
peers[0].smblp_function);
errs++;
}
smbios_info_slot_peers_free(hdl, npeers, peers);
if (slot.smbl_info != smbios_slot_info) {
warnx("found wrong slot info: 0x%x, expected 0x%x",
slot.smbl_info, smbios_slot_info);
errs++;
}
if (slot.smbl_pwidth != SMB_SLW_32X) {
warnx("found wrong slot physical width: 0x%x, expected 0x%x",
slot.smbl_pwidth, SMB_SLW_32X);
errs++;
}
if (slot.smbl_pitch != smbios_slot_pitch) {
warnx("found wrong slot pitch: 0x%x, expected 0x%x",
slot.smbl_pitch, smbios_slot_pitch);
errs++;
}
if (errs > 0) {
return (B_FALSE);
}
return (B_TRUE);
}
|