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
|
/*
* 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 2022 Oxide Computer Company
*/
/*
* Test the memory decoding and normalization features at the heart of the
* zen_umc(4D) driver.
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <err.h>
#include <stdlib.h>
#include <sys/sysmacros.h>
#include "zen_umc_test.h"
static const char *
zen_umc_test_strerror(zen_umc_decode_failure_t fail)
{
switch (fail) {
case ZEN_UMC_DECODE_F_NONE:
return ("Actually succeeded");
case ZEN_UMC_DECODE_F_OUTSIDE_DRAM:
return ("Address outside of DRAM");
case ZEN_UMC_DECODE_F_NO_DF_RULE:
return ("Address didn't find a DF rule that matched");
case ZEN_UMC_DECODE_F_ILEAVE_UNDERFLOW:
return ("Interleave adjustments caused PA to underflow");
case ZEN_UMC_DECODE_F_CHAN_ILEAVE_NOTSUP:
return ("Unsupported channel interleave");
case ZEN_UMC_DECODE_F_COD_BAD_ILEAVE:
return ("Unsupported interleave settings for COD hash");
case ZEN_UMC_DECODE_F_NPS_BAD_ILEAVE:
return ("Unsupported interleave settings for NPS hash");
case ZEN_UMC_DECODE_F_BAD_REMAP_SET:
return ("Remap ruleset was invalid");
case ZEN_UMC_DECODE_F_BAD_REMAP_ENTRY:
return ("Remap entry was invalid");
case ZEN_UMC_DECODE_F_REMAP_HAS_BAD_COMP:
return ("Remap entry is not a valid component ID");
case ZEN_UMC_DECODE_F_CANNOT_MAP_FABID:
return ("Failed to find target fabric ID");
case ZEN_UMC_DECODE_F_UMC_DOESNT_HAVE_PA:
return ("Target UMC does not have a DRAM rule for PA");
case ZEN_UMC_DECODE_F_CALC_NORM_UNDERFLOW:
return ("Address normalization underflowed");
case ZEN_UMC_DECODE_F_NO_CS_BASE_MATCH:
return ("No chip-select matched normal address");
default:
return ("<unknown>");
}
}
static const char *
zen_umc_test_strenum(zen_umc_decode_failure_t fail)
{
switch (fail) {
case ZEN_UMC_DECODE_F_NONE:
return ("ZEN_UMC_DECODE_F_NONE");
case ZEN_UMC_DECODE_F_OUTSIDE_DRAM:
return ("ZEN_UMC_DECODE_F_OUTSIDE_DRAM");
case ZEN_UMC_DECODE_F_NO_DF_RULE:
return ("ZEN_UMC_DECODE_F_NO_DF_RULE");
case ZEN_UMC_DECODE_F_ILEAVE_UNDERFLOW:
return ("ZEN_UMC_DECODE_F_ILEAVE_UNDERFLOW");
case ZEN_UMC_DECODE_F_CHAN_ILEAVE_NOTSUP:
return ("ZEN_UMC_DECODE_F_CHAN_ILEAVE_NOTSUP");
case ZEN_UMC_DECODE_F_COD_BAD_ILEAVE:
return ("ZEN_UMC_DECODE_F_COD_BAD_ILEAVE");
case ZEN_UMC_DECODE_F_NPS_BAD_ILEAVE:
return ("ZEN_UMC_DECODE_F_NPS_BAD_ILEAVE");
case ZEN_UMC_DECODE_F_BAD_REMAP_SET:
return ("ZEN_UMC_DECODE_F_BAD_REMAP_SET");
case ZEN_UMC_DECODE_F_BAD_REMAP_ENTRY:
return ("ZEN_UMC_DECODE_F_BAD_REMAP_ENTRY");
case ZEN_UMC_DECODE_F_REMAP_HAS_BAD_COMP:
return ("ZEN_UMC_DECODE_F_REMAP_HAS_BAD_COMP");
case ZEN_UMC_DECODE_F_CANNOT_MAP_FABID:
return ("ZEN_UMC_DECODE_F_CANNOT_MAP_FABID");
case ZEN_UMC_DECODE_F_UMC_DOESNT_HAVE_PA:
return ("ZEN_UMC_DECODE_F_UMC_DOESNT_HAVE_PA");
case ZEN_UMC_DECODE_F_CALC_NORM_UNDERFLOW:
return ("ZEN_UMC_DECODE_F_CALC_NORM_UNDERFLOW");
case ZEN_UMC_DECODE_F_NO_CS_BASE_MATCH:
return ("ZEN_UMC_DECODE_F_NO_CS_BASE_MATCH");
default:
return ("<unknown>");
}
}
static boolean_t
zen_umc_test_fabric_one(const umc_fabric_test_t *test)
{
boolean_t ret = B_TRUE;
(void) printf("Running test: %s\n", test->uft_desc);
if (test->uft_compose) {
uint32_t fab, sock, die, comp;
boolean_t rtt = B_TRUE;
boolean_t valid;
valid = zen_fabric_id_valid_parts(test->uft_decomp,
test->uft_sock_id, test->uft_die_id, test->uft_comp_id);
if (!valid) {
if (test->uft_valid) {
(void) printf("\tInvalid fabric ID parts "
"found\n");
return (B_FALSE);
}
(void) printf("\tTEST PASSED: Invalid Fabric parts "
"detected\n");
return (B_TRUE);
} else {
if (!test->uft_valid) {
(void) printf("\tFabric ID parts validated, "
"but expected failure\n");
return (B_FALSE);
}
}
zen_fabric_id_compose(test->uft_decomp, test->uft_sock_id,
test->uft_die_id, test->uft_comp_id, &fab);
if (fab != test->uft_fabric_id) {
(void) printf("\tFabric ID mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->uft_fabric_id, fab);
ret = B_FALSE;
} else {
(void) printf("\tTEST PASSED: Fabric ID composition\n");
}
zen_fabric_id_decompose(test->uft_decomp, fab, &sock, &die,
&comp);
if (sock != test->uft_sock_id) {
(void) printf("\tRound-trip socket mismatch\n"
"\t\texpected %u\n\t\tfound %u\n",
test->uft_sock_id, sock);
ret = rtt = B_FALSE;
}
if (die != test->uft_die_id) {
(void) printf("\tRound-trip die mismatch\n"
"\t\texpected %u\n\t\tfound %u\n",
test->uft_die_id, die);
ret = rtt = B_FALSE;
}
if (comp != test->uft_comp_id) {
(void) printf("\tRound-trip comp mismatch\n"
"\t\texpected %u\n\t\tfound %u\n",
test->uft_comp_id, comp);
ret = rtt = B_FALSE;
}
if (rtt) {
(void) printf("\tTEST PASSED: Round-trip Fabric ID "
"decomposition\n");
}
} else {
uint32_t fab, sock, die, comp;
boolean_t valid;
valid = zen_fabric_id_valid_fabid(test->uft_decomp,
test->uft_fabric_id);
if (!valid) {
if (test->uft_valid) {
(void) printf("\tInvalid fabric ID found\n");
return (B_FALSE);
}
(void) printf("\tTEST PASSED: Successfully found "
"invalid fabric ID\n");
return (B_TRUE);
} else {
if (!test->uft_valid) {
(void) printf("\tFabric ID validated, "
"but expected to find an invalid one\n");
return (B_FALSE);
}
}
zen_fabric_id_decompose(test->uft_decomp, test->uft_fabric_id,
&sock, &die, &comp);
if (sock != test->uft_sock_id) {
(void) printf("\tsocket mismatch\n"
"\t\texpected %u\n\t\tfound %u\n",
test->uft_sock_id, sock);
ret = B_FALSE;
}
if (die != test->uft_die_id) {
(void) printf("\tdie mismatch\n"
"\t\texpected %u\n\t\tfound %u\n",
test->uft_die_id, die);
ret = B_FALSE;
}
if (comp != test->uft_comp_id) {
(void) printf("\tcomp mismatch\n"
"\t\texpected %u\n\t\tfound %u\n",
test->uft_comp_id, comp);
ret = B_FALSE;
}
if (ret) {
(void) printf("\tTEST PASSED: Fabric ID "
"Decomposition\n");
}
zen_fabric_id_compose(test->uft_decomp, sock, die, comp, &fab);
if (fab != test->uft_fabric_id) {
(void) printf("\tFabric ID mismatch on round trip\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->uft_fabric_id, fab);
ret = B_FALSE;
} else {
(void) printf("\tTEST PASSED: Round-trip Fabric ID "
"composition\n");
}
}
return (ret);
}
static boolean_t
zen_umc_test_decode_one(const umc_decode_test_t *test)
{
boolean_t pass;
zen_umc_decoder_t dec;
(void) printf("Running test: %s\n", test->udt_desc);
(void) printf("\tDecoding address: 0x%" PRIx64 "\n", test->udt_pa);
memset(&dec, '\0', sizeof (dec));
pass = zen_umc_decode_pa(test->udt_umc, test->udt_pa, &dec);
if (pass && !test->udt_pass) {
uint32_t sock, die, comp;
zen_fabric_id_decompose(&test->udt_umc->umc_decomp,
dec.dec_targ_fabid, &sock, &die, &comp);
(void) printf("\tdecode unexpectedly succeeded\n");
(void) printf("\texpected error '%s' (%s/0x%x)\n",
zen_umc_test_strerror(test->udt_fail),
zen_umc_test_strenum(test->udt_fail),
test->udt_fail);
(void) printf("\t\tdecoded socket: 0x%x\n", sock);
(void) printf("\t\tdecoded die: 0x%x\n", die);
(void) printf("\t\tdecoded component: 0x%x\n", comp);
(void) printf("\t\tnormal address: 0x%" PRIx64 "\n",
dec.dec_norm_addr);
(void) printf("\t\tdecoded dimm: 0x%x\n", dec.dec_dimm_no);
(void) printf("\t\tdecoded row: 0x%x\n", dec.dec_dimm_row);
(void) printf("\t\tdecoded column: 0x%x\n", dec.dec_dimm_col);
(void) printf("\t\tdecoded bank: 0x%x\n", dec.dec_dimm_bank);
(void) printf("\t\tdecoded bank group: 0x%x\n",
dec.dec_dimm_bank_group);
(void) printf("\t\tdecoded rm: 0x%x\n", dec.dec_dimm_rm);
(void) printf("\t\tdecoded cs: 0x%x\n", dec.dec_dimm_csno);
(void) printf("\ttest failed\n");
return (B_FALSE);
} else if (pass) {
uint32_t sock, die, comp;
boolean_t success = B_TRUE;
zen_fabric_id_decompose(&test->udt_umc->umc_decomp,
dec.dec_targ_fabid, &sock, &die, &comp);
if (test->udt_sock != UINT8_MAX &&
test->udt_sock != sock) {
(void) printf("\tsocket mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_sock, sock);
success = B_FALSE;
}
if (test->udt_die != UINT8_MAX &&
test->udt_die != die) {
(void) printf("\tdie mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_die, die);
success = B_FALSE;
}
if (test->udt_comp != UINT8_MAX &&
test->udt_comp != comp) {
(void) printf("\tcomp mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_comp, comp);
success = B_FALSE;
}
if (test->udt_norm_addr != UINT64_MAX &&
test->udt_norm_addr != dec.dec_norm_addr) {
(void) printf("\tnormalized address mismatch\n"
"\t\texpected 0x%" PRIx64 "\n"
"\t\tfound 0x%" PRIx64 "\n",
test->udt_norm_addr, dec.dec_norm_addr);
success = B_FALSE;
}
if (test->udt_dimm_no != UINT32_MAX &&
test->udt_dimm_no != dec.dec_dimm_no) {
(void) printf("\tDIMM number mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_no, dec.dec_dimm_no);
success = B_FALSE;
}
if (test->udt_dimm_col != UINT32_MAX &&
test->udt_dimm_col != dec.dec_dimm_col) {
(void) printf("\tcolumn mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_col, dec.dec_dimm_col);
success = B_FALSE;
}
if (test->udt_dimm_row != UINT32_MAX &&
test->udt_dimm_row != dec.dec_dimm_row) {
(void) printf("\trow mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_row, dec.dec_dimm_row);
success = B_FALSE;
}
if (test->udt_dimm_bank != UINT8_MAX &&
test->udt_dimm_bank != dec.dec_dimm_bank) {
(void) printf("\tbank mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_bank, dec.dec_dimm_bank);
success = B_FALSE;
}
if (test->udt_dimm_bank_group != UINT8_MAX &&
test->udt_dimm_bank_group != dec.dec_dimm_bank_group) {
(void) printf("\tbank group mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_bank_group, dec.dec_dimm_bank_group);
success = B_FALSE;
}
if (test->udt_dimm_subchan != UINT8_MAX &&
test->udt_dimm_subchan != dec.dec_dimm_subchan) {
(void) printf("\tsub-channel mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_subchan, dec.dec_dimm_subchan);
success = B_FALSE;
}
if (test->udt_dimm_rm != UINT8_MAX &&
test->udt_dimm_rm != dec.dec_dimm_rm) {
(void) printf("\tRM mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_rm, dec.dec_dimm_rm);
success = B_FALSE;
}
if (test->udt_dimm_cs != UINT8_MAX &&
test->udt_dimm_cs != dec.dec_dimm_csno) {
(void) printf("\tCS mismatch\n"
"\t\texpected 0x%x\n\t\tfound 0x%x\n",
test->udt_dimm_cs, dec.dec_dimm_csno);
success = B_FALSE;
}
if (success) {
(void) printf("\tTEST PASSED: Successfully decoded "
"PA\n");
} else {
(void) printf("\tTEST FAILED!\n");
}
return (success);
} else if (!pass && !test->udt_pass) {
if (dec.dec_fail != test->udt_fail) {
(void) printf("\terror mismatch\n"
"\t\texpected '%s' (%s/0x%x)\n"
"\t\tfound '%s' (%s/0x%x)\n",
zen_umc_test_strerror(test->udt_fail),
zen_umc_test_strenum(test->udt_fail),
test->udt_fail,
zen_umc_test_strerror(dec.dec_fail),
zen_umc_test_strenum(dec.dec_fail),
dec.dec_fail);
return (B_FALSE);
}
(void) printf("\tTEST PASSED: Correct error generated\n");
return (B_TRUE);
} else {
(void) printf("\tdecode failed with error '%s' (%s/0x%x)\n",
zen_umc_test_strerror(dec.dec_fail),
zen_umc_test_strenum(dec.dec_fail),
dec.dec_fail);
if (test->udt_norm_addr != UINT64_MAX) {
(void) printf("\t\texpected normal address: "
"0x%" PRIx64 "\n", test->udt_norm_addr);
}
if (test->udt_sock != UINT8_MAX) {
(void) printf("\t\texpected socket: 0x%x\n",
test->udt_sock);
}
if (test->udt_die != UINT8_MAX) {
(void) printf("\t\texpected die: 0x%x\n",
test->udt_die);
}
if (test->udt_comp != UINT8_MAX) {
(void) printf("\t\texpected comp: 0x%x\n",
test->udt_comp);
}
if (test->udt_dimm_no != UINT32_MAX) {
(void) printf("\t\texpected DIMM number: 0x%x\n",
test->udt_dimm_no);
}
if (test->udt_dimm_col != UINT32_MAX) {
(void) printf("\t\texpected column: 0x%x\n",
test->udt_dimm_col);
}
if (test->udt_dimm_row != UINT32_MAX) {
(void) printf("\t\texpected row: 0x%x\n",
test->udt_dimm_row);
}
if (test->udt_dimm_bank != UINT8_MAX) {
(void) printf("\t\texpected bank: 0x%x\n",
test->udt_dimm_bank);
}
if (test->udt_dimm_bank_group != UINT8_MAX) {
(void) printf("\t\texpected bank group: 0x%x\n",
test->udt_dimm_bank_group);
}
if (test->udt_dimm_subchan != UINT8_MAX) {
(void) printf("\t\texpected sub-channel: 0x%x\n",
test->udt_dimm_subchan);
}
if (test->udt_dimm_rm != UINT8_MAX) {
(void) printf("\t\texpected RM: 0x%x\n",
test->udt_dimm_rm);
}
if (test->udt_dimm_cs != UINT8_MAX) {
(void) printf("\t\texpected CS: 0x%x\n",
test->udt_dimm_cs);
}
return (B_FALSE);
}
}
static void
zen_umc_test_fabric(const umc_fabric_test_t *tests, uint_t *ntests,
uint_t *nfail)
{
for (uint_t i = 0; tests[i].uft_desc != NULL; i++) {
if (!zen_umc_test_fabric_one(&tests[i]))
*nfail += 1;
*ntests += 1;
}
}
static void
zen_umc_test_decode(const umc_decode_test_t *tests, uint_t *ntests,
uint_t *nfail)
{
for (uint_t i = 0; tests[i].udt_desc != NULL; i++) {
if (!zen_umc_test_decode_one(&tests[i]))
*nfail += 1;
*ntests += 1;
}
}
typedef struct zen_umc_test_set {
const char *set_name;
const umc_decode_test_t *set_test;
} zen_umc_test_set_t;
static const zen_umc_test_set_t zen_umc_test_set[] = {
{ "basic", zen_umc_test_basics },
{ "channel", zen_umc_test_chans },
{ "cod", zen_umc_test_cod },
{ "errors", zen_umc_test_errors },
{ "hole", zen_umc_test_hole },
{ "ilv", zen_umc_test_ilv },
{ "multi", zen_umc_test_multi },
{ "nps", zen_umc_test_nps },
{ "remap", zen_umc_test_remap },
};
static void
zen_umc_test_selected(int argc, char *argv[], uint_t *ntests, uint_t *nfail)
{
for (int i = 1; i < argc; i++) {
boolean_t ran = B_FALSE;
if (strcmp(argv[i], "fabric_ids") == 0) {
zen_umc_test_fabric(zen_umc_test_fabric_ids, ntests,
nfail);
continue;
}
for (uint_t t = 0; t < ARRAY_SIZE(zen_umc_test_set); t++) {
const zen_umc_test_set_t *s = &zen_umc_test_set[t];
if (strcmp(s->set_name, argv[i]) == 0) {
zen_umc_test_decode(s->set_test, ntests, nfail);
ran = B_TRUE;
break;
}
}
if (!ran) {
errx(EXIT_FAILURE, "Unknown test suite: %s", argv[i]);
}
}
}
int
main(int argc, char *argv[])
{
uint_t ntests = 0, nfail = 0;
if (argc > 1) {
zen_umc_test_selected(argc, argv, &ntests, &nfail);
} else {
zen_umc_test_fabric(zen_umc_test_fabric_ids, &ntests, &nfail);
for (uint_t i = 0; i < ARRAY_SIZE(zen_umc_test_set); i++) {
zen_umc_test_decode(zen_umc_test_set[i].set_test,
&ntests, &nfail);
}
}
(void) printf("%u/%u tests passed\n", ntests - nfail, ntests);
return (nfail > 0);
}
|