summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/test/hwpftest.H
blob: 25e749f70e3a4dbe80139fa40f6af9bc3fd0228b (plain)
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
/*  IBM_PROLOG_BEGIN_TAG
 *  This is an automatically generated prolog.
 *
 *  $Source: src/usr/hwpf/test/hwpftest.H $
 *
 *  IBM CONFIDENTIAL
 *
 *  COPYRIGHT International Business Machines Corp. 2011-2012
 *
 *  p1
 *
 *  Object Code Only (OCO) source materials
 *  Licensed Internal Code Source Materials
 *  IBM HostBoot Licensed Internal Code
 *
 *  The source code for this program is not published or other-
 *  wise divested of its trade secrets, irrespective of what has
 *  been deposited with the U.S. Copyright Office.
 *
 *  Origin: 30
 *
 *  IBM_PROLOG_END_TAG
 */
#ifndef __HWPFTEST_H
#define __HWPFTEST_H

/**
 *  @file hwpftest.H
 *
 *  @brief Test case for HWPF implementation
*/

#include <cxxtest/TestSuite.H>
#include <fapi.H>
#include <fapiPlatHwpInvoker.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <targeting/common/commontargeting.H>
#include <targeting/common/utilFilter.H>
#include <fapiHwpExecInitFile.H>
#include <spd/spdenums.H>

using namespace fapi;
using namespace TARGETING;

struct ifScom_t {
    uint64_t addr;
    uint64_t data;
};

struct hwpfTestArgs_t {
    ifScom_t      ifScom;
    fapi::Target  fapiTarget;
    uint32_t      count;
    tid_t         tid;
    struct {
        uint64_t  Write:1;    // 1 = Write
        uint64_t  AttrTest:1; // 1 = run Attr access test
        uint64_t  ScomTest:1; // 1 = run Scom register access test
    };
};

static const uint32_t ATTR_TEST_VALUE   = 10;
static const uint32_t MAX_TEST_TASKS    = 30;
static const uint32_t CREATE_TASK_PAIRS = 6;
static const uint32_t MAX_TEST_COUNT    = 0x000001FF;

/**
 * @brief repeated Scom access and Attrubute access through Fapi until
 *        MAX_TEST_COUNT accesses has been done or an error occurs.
 */
void testHwpScomAcc( void *i_phwpTestArgs )
{
    fapi::ReturnCode l_rc = fapi::FAPI_RC_SUCCESS;
    ecmdDataBufferBase l_ScomData(64);

    hwpfTestArgs_t * l_args = static_cast<hwpfTestArgs_t *>(i_phwpTestArgs);

    // repeat as long as no error and in running mode until count reaches
    // at MAX_TEST_COUNT or an error occurs
    for (l_args->count = 0; l_args->count != MAX_TEST_COUNT; ++l_args->count)
    {
        if (l_args->Write)
        {
            if (l_args->ScomTest)
            {
                // set up ecmdDataBuffer with written data
                l_ScomData.setDoubleWord(0, (l_args->ifScom).data);
                l_rc = fapiPutScom( l_args->fapiTarget,
                                    (l_args->ifScom).addr, l_ScomData );

                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_TRACE("testHwpScomAcc: Error from fapiPutScom");
                    break;
                }
            }

            if (l_args->AttrTest)
            {
                uint8_t l_uint8_1 = ATTR_TEST_VALUE;
                l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT8_1, NULL, l_uint8_1);
                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_TRACE("testHwpScomAcc: ATTR_SCRATCH_UINT8_1. "
                             "Error from SET");
                    break;
                }
            }
        }
        else
        {
            if (l_args->ScomTest)
            {
                l_rc = fapiGetScom( l_args->fapiTarget,
                                    (l_args->ifScom).addr, l_ScomData );
                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_TRACE("testHwpScomAcc: Error RC from fapiGetScom");
                    break;
                }
                if ((l_args->ifScom).data != l_ScomData.getDoubleWord(0))
                {
                    (l_args->ifScom).data = l_ScomData.getDoubleWord(0);
                    TS_TRACE("testHwpScomAcc: Error Data from fapiGetScom");
                    break;
                }
            }

            if (l_args->AttrTest)
            {
                uint8_t l_uint8_2 = 0xff;
                l_rc = FAPI_ATTR_GET(ATTR_SCRATCH_UINT8_1, NULL, l_uint8_2);
                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_TRACE("testHwpScomAcc: ATTR_SCRATCH_UINT8_1."
                            "  Error RC from GET");
                    break;
                }
                if (l_uint8_2 != ATTR_TEST_VALUE)
                {
                    TS_TRACE("testHwpScomAcc: ATTR_SCRATCH_UINT8_1."
                            " Error data %d from GET", l_uint8_2);
                    break;
                }
            }
        }
    }
}

class HwpfTest: public CxxTest::TestSuite
{
public:

    /**
      * @brief Test HWPF trace
      */
    void testHwpf1()
    {
        // Trace into all the FAPI trace buffers
        uint32_t l_val = 4;
        const char * l_pStr = "test-str";

        FAPI_INF("Test INF Trace");
        FAPI_INF("Test INF Trace. hex: 0x%x", l_val);
        FAPI_INF("Test INF Trace. string: %s", l_pStr);
        FAPI_INF("Test INF Trace. 0x%x, %s", l_val, l_pStr);

        FAPI_IMP("Test IMP Trace");
        FAPI_IMP("Test IMP Trace. hex: 0x%x", l_val);
        FAPI_IMP("Test IMP Trace. string: %s", l_pStr);
        FAPI_IMP("Test IMP Trace. 0x%x, %s", l_val, l_pStr);

        FAPI_ERR("Test ERR Trace");
        FAPI_ERR("Test ERR Trace. hex: 0x%x", l_val);
        FAPI_ERR("Test ERR Trace. string: %s", l_pStr);
        FAPI_ERR("Test ERR Trace. 0x%x, %s", l_val, l_pStr);

        FAPI_DBG("Test DBG Trace");
        FAPI_DBG("Test DBG Trace. hex: 0x%x", l_val);
        FAPI_DBG("Test DBG Trace. string: %s", l_pStr);
        FAPI_DBG("Test DBG Trace. 0x%x, %s", l_val, l_pStr);

        return;
    }

    /**
     * @brief Test HWPF: call a test procedure that generates an error
     */
    void testHwpf2()
    {
        errlHndl_t l_err = NULL;

        // Get the master processor chip
        TARGETING::Target* l_pTarget = NULL;
        TARGETING::targetService().masterProcChipTargetHandle(l_pTarget);

        // Create a FAPI Target and invoke the hwpTestError HWP. The HWP
        // returns an error to test out error handling
        fapi::Target l_fapiTarget(TARGET_TYPE_PROC_CHIP,
                                  reinterpret_cast<void *> (l_pTarget));

        FAPI_INVOKE_HWP(l_err, hwpTestError, l_fapiTarget);

        if (l_err)
        {
            // Delete the error rather than committing it to avoid it getting
            // interpreted as a real problem
            TS_TRACE("testHwpf2: Unit Test passed. "
                     "hwpTestError failed. Error deleted");
            delete l_err;
            l_err = NULL;
        }
        else
        {
            TS_FAIL("testHwpf2: Unit Test failed. "
                    "hwpTestError passed. Error logged");
        }
    }

    /**
     * @brief Test HWPF Config: call a test procedure that exercises the FAPI
     *        config query functions
     */
    void testHwpf3()
    {
        errlHndl_t l_err = NULL;

        // Get the master processor chip
        TARGETING::Target* l_pTarget = NULL;
        TARGETING::targetService().masterProcChipTargetHandle(l_pTarget);

        // Create a FAPI Target and invoke the hwpTestConfig HWP. The HWP
        // exercises the FAPI config query functions
        fapi::Target l_fapiTarget(TARGET_TYPE_PROC_CHIP,
                                  reinterpret_cast<void *> (l_pTarget));

        FAPI_INVOKE_HWP(l_err, hwpTestConfig, l_fapiTarget);

        if (l_err)
        {
            TS_FAIL("testHwpf3: Unit Test failed. "
                    "hwpTestConfig failed. Error logged");
            errlCommit(l_err,HWPF_COMP_ID);
        }
        else
        {
            TS_TRACE("testHwpf3: Unit Test passed. "
                     "hwpTestConfig passed. Error logged");
        }
    }

    /**
     * @brief Test HWPF Attributes: call a test procedure that exercises
     *        the FAPI scratch attributes
     */
    void testHwpf4()
    {
        errlHndl_t l_err = NULL;

        FAPI_INVOKE_HWP(l_err, hwpTestAttributes);

        if (l_err)
        {
            TS_FAIL("testHwpf4: Unit Test failed. "
                    "hwpTestAttributes failed. Error logged");
            errlCommit(l_err,HWPF_COMP_ID);
        }
        else
        {
            TS_TRACE("testHwpf4: Unit Test passed. "
                     "hwpTestAttributes passed. Error logged");
        }
    }

    /**
     * @brief Test HWPF InitFile: call the procedure that exercises a
     *        sample initfile
     */
    void testHwpf5()
    {
        typedef struct ifScom {
            uint64_t addr;
            uint64_t origData;
            uint64_t writtenData;
        }ifScom_t;

        //Note:  this data is based on the sample.initfile.
        //If the initfile changes, this data will also need to be changed.
        ifScom_t l_ifScomData[] =
        {
            {0x000000000006002b, 0, 0x0000000000000000 |
                                    (0x00000000000000C4ll << (64 - (32 + 8)))},
            {0x000000000006002c, 0, (0x0000000000000001ll << (64 - 8)) |
                                    (0x0000000000000008ll << (64 - (24 + 8)))},
            {0x000000000006800b, 0, 0},
            {0x000000000006800c, 0, (0x8000000000000000 >> 0x17) |
                                    (0x0000000000000060ll << (64 - (24 + 8))) |
                                    0x0000000000003000},
            {0x0000000013010002, 0, 0xAABBC00000000000},
            {0x0000000013030007, 0, 0x00000CDE00000000},
            {0x0000000013013283, 0, 0x3c90000000000000 |
                                    (0x8000000000000000 >> 0x0c) |
                                    (0x8000000000000000 >> 0x0d) |
                                    (0x0306400412000000 >> 0x0e)},
            {0x0000000013013284, 0, 0x3c90000000000000},
            {0x0000000013013285, 0, (0x8000000000000000 >> 0x0f) |
                                    (0x8000000000000000 >> 0x10) |
                                    (0x8000000000000000 >> 0x13) |
                                    (0x0306400412000000 >> 0x15) },
            {0x0000000013013286, 0, 0x0000000000000192},
            {0x0000000013013287, 0, 0x0000000000000182},
            {0x0000000013013288, 0, 0x0000000000000192},
            {0x0000000013013289, 0, (0x8000000000000000 >> 0x17) |
                                    (0x4000000000000000 >> 0x18)}
        };

        fapi::ReturnCode l_rc = fapi::FAPI_RC_SUCCESS;
        ecmdDataBufferBase l_ScomData(64);

        do {
            // Set up some attributes for testing
            uint8_t l_uint8 = 1;
            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT8_1, NULL, l_uint8);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT8_1. Error from SET");
                break;
            }

            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT8_2, NULL, l_uint8);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT8_2. Error from SET");
                break;
            }

            uint32_t l_uint32 = 3;
            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT32_1, NULL, l_uint32);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT32_1. Error from SET");
                break;
            }

            l_uint32 = 0;
            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT32_2, NULL, l_uint32);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT32_2. Error from SET");
                break;
            }

            uint64_t l_uint64 = 2;
            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT64_1, NULL, l_uint64);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT64_1. Error from SET");
                break;
            }

            l_uint64 = 0;
            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT64_2, NULL, l_uint64);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT64_2. Error from SET");
                break;
            }

            uint8_t l_uint8array1[32];
            l_uint8array1[0] = 1;
            l_uint8array1[1] = 4;
            l_uint8array1[2] = 1;
            l_uint8array1[3] = 2;
            l_uint8array1[7] = 1;
            l_uint8array1[17] = 6;
            l_uint8array1[18] = 6;
            l_uint8array1[31] = 8;
            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT8_ARRAY_1,
                                                       NULL, l_uint8array1);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT8_ARRAY_1. "
                        " Error from SET");
                break;
            }

            uint8_t l_uint8array2[2][3][4];
            l_uint8array2[0][1][2] = 0xC4;
            l_uint8array2[1][2][3] = 0xBE;
            l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT8_ARRAY_2,
                                                       NULL, l_uint8array2);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_SCRATCH_UINT8_ARRAY_2. "
                        "Error from SET");
                break;
            }

            // Test ATTR_IS_SIMULATION access through FAPI
            uint8_t l_flag;
            l_rc = FAPI_ATTR_GET(ATTR_IS_SIMULATION, NULL, l_flag);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_IS_SIMULATION. Error from GET");
                break;
            }
            else
            {
                //printk("ATTR_IS_SIMULATION = %d\n", l_flag);
            }

            //Set the targets

            std::vector<fapi::Target> l_target;

            // Get the master processor chip & set it as the main target for Scom ops
            TARGETING::Target* l_pTarget = NULL;
            TARGETING::targetService().masterProcChipTargetHandle(l_pTarget);

            fapi::Target l_fapiTarget(TARGET_TYPE_PROC_CHIP,
                                      reinterpret_cast<void *> (l_pTarget));
            l_target.push_back(l_fapiTarget);

            // Get the target for the MBA chiplets of the first MEMBUF chip
            TARGETING::PredicateCTM l_membufChip(TARGETING::CLASS_CHIP,
                                                 TARGETING::TYPE_MEMBUF);

            TARGETING::TargetRangeFilter l_filter(
                TARGETING::targetService().begin(),
                TARGETING::targetService().end(),
                &l_membufChip);

            PredicateCTM l_mba(CLASS_UNIT,TYPE_MBA);

            // Just look at the first MEMBUF chip
            if (l_filter)
            {
                TargetHandleList l_list;
                (void) targetService().getAssociated(
                    l_list,
                    *l_filter,
                    TARGETING::TargetService::CHILD,
                    TARGETING::TargetService::ALL,
                    &l_mba);

                if (2 == l_list.size())
                {
                    for (size_t i = 0; i < l_list.size(); i++)
                    {
                        //Set the associated targets
                        fapi::Target l_fapiTargetAssoc(fapi::TARGET_TYPE_MBA_CHIPLET,
                            reinterpret_cast<void *>(l_list.at(i)));
                        l_target.push_back(l_fapiTargetAssoc);
                    }
                }
                else
                {
                    TS_FAIL("testHwpf5: Incorrect # of MBAs found: %u",
                        l_list.size());

                    size_t l_ffdc = l_list.size();
                    size_t & FFDC_IF_TEST_NUM_MBAS_FOUND = l_ffdc;
                    FAPI_SET_HWP_ERROR(l_rc,
                        RC_HWP_EXEC_INITFILE_TEST_INCORRECT_NUM_MBAS_FOUND);
                    break;
                }
            }
            else
            {
                TS_FAIL("testHwpf5: No MEMBUFs found");
                FAPI_SET_HWP_ERROR(l_rc, RC_HWP_EXEC_INITFILE_TEST_NO_MEMBUF_FOUND);
                break;
            }

            // Test ATTR_EC attribute access through FAPI
            uint8_t l_EC_R = 0xFF;

            l_rc = FAPI_ATTR_GET_PRIVILEGED(ATTR_EC, &l_fapiTarget, l_EC_R);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_EC. Error from GET");
                break;
            }

            // Test ATTR_FUNCTIONAL attribute access through FAPI
            uint8_t l_functional = 0xff;
            l_rc = FAPI_ATTR_GET(ATTR_FUNCTIONAL, &l_fapiTarget, l_functional);
            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: ATTR_FUNCTIONAL. Error from GET");
                break;
            }
            else
            {
                FAPI_INF("testHwpf5: Master chip ATTR_FUNCTIONAL: %d", l_functional);
            }

            //printk("EC = %d\n", l_EC_R);

            /*
            // Save original scom data to restore at end of test
            for (uint32_t i = 0; i < sizeof(l_ifScomData)/sizeof(ifScom_t); i++)
            {
                l_rc = fapiGetScom(l_fapiTarget, l_ifScomData[i].addr,
                                                                   l_ScomData);
                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_FAIL("testHwpf5: Error from fapiGetScom");
                    break;
                }

                l_ifScomData[i].origData = l_ScomData.getDoubleWord(0);
            }

            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                break;
            }
            */

            // Set scom data to 0 to start from known state for bit ops
            l_ScomData.setDoubleWord(0, 0ll);
            for (uint32_t i = 0; i < sizeof(l_ifScomData)/sizeof(ifScom_t); i++)
            {
                l_rc = fapiPutScom(l_fapiTarget, l_ifScomData[i].addr,
                                                                   l_ScomData);
                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_FAIL("testHwpf5: Error from fapiPutScom");
                    break;
                }
            }

            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                break;
            }

            //Call Hwp to execute the initfile
            FAPI_EXEC_HWP(l_rc, fapiHwpExecInitFile, l_target, "sample.if");

            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                TS_FAIL("testHwpf5: Error from fapiHwpExecInitFile");
                break;
            }

            //Verify the data written
            for (uint32_t i = 0; i < sizeof(l_ifScomData)/sizeof(ifScom_t); i++)
            {
                l_rc = fapiGetScom(l_fapiTarget, l_ifScomData[i].addr,
                                                                   l_ScomData);
                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_FAIL("testHwpf5: Error from fapiGetScom");
                    break;
                }

                if (l_ScomData.getDoubleWord(0) != l_ifScomData[i].writtenData)
                {
                    TS_FAIL("testHwpf5: GetScom addr 0x%.16llX "
                            "data read 0x%.16llX data expected 0x%.16llX",
                             l_ifScomData[i].addr, l_ScomData.getDoubleWord(0),
                             l_ifScomData[i].writtenData);
                    FAPI_SET_HWP_ERROR(l_rc, RC_HWP_EXEC_INITFILE_TEST_FAILED);
                    break;
                }
            }

            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                break;
            }

            /*
            // Restore the original Scom data
            //uint32_t l_ecmdRc = ECMD_DBUF_SUCCESS;
            for (uint32_t i = 0; i < sizeof(l_ifScomData)/sizeof(ifScom_t); i++)
            {
                l_ecmdRc = l_ScomData.setDoubleWord(0,l_ifScomData[i].origData);
                if (l_ecmdRc != ECMD_DBUF_SUCCESS)
                {
                    TS_FAIL("testHwpf5: fapiPutScom to restore, error from "
                            "ecmdDataBuffer setDoubleWord() - rc 0x%.8X",
                            l_ecmdRc);
                    l_rc.setEcmdError(l_ecmdRc);
                    break;
                }

                l_rc = fapiPutScom(l_fapiTarget, l_ifScomData[i].addr,
                                                                   l_ScomData);
                if (l_rc != fapi::FAPI_RC_SUCCESS)
                {
                    TS_FAIL("testHwpf5: Error from fapiGetScom");
                    break;
                }
            }

            if (l_rc != fapi::FAPI_RC_SUCCESS)
            {
                break;
            }
            */

        } while (0);

        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            fapiLogError(l_rc);
            TS_FAIL("testHwpf5: Unit Test failed. Error logged");
        }
        else
        {
            TS_TRACE("testHwpf5: Unit Test passed. "
                     "fapiHwpExecInitFile passed.");
        }
    }

    /**
     * @brief Test case for stressing the taskmgr, memory usage, and HWPF API
     *        It starts (CREATE_TASK_PAIRS * 2) tasks.
     */
    void testHwpf6()
    {
        fapi::ReturnCode l_rc = fapi::FAPI_RC_SUCCESS;

        // Get the sys target handle
        TARGETING::Target* l_pTarget = NULL;
        TARGETING::targetService().getTopLevelTarget(l_pTarget);

        uint8_t l_vpoMode = 0;

        if (l_pTarget &&
            l_pTarget->tryGetAttr<TARGETING::ATTR_IS_SIMULATION>(l_vpoMode) &&
            l_vpoMode == 0)
        {
            static const uint32_t NUM_OF_SCOMREGS = 6;
            ifScom_t l_ifScom[NUM_OF_SCOMREGS] =
            {
                {0x000000000006002b, 0x0000000000000183},
                {0x000000000006002c, 0x0000000000000183},
                {0x000000000006800b, 0},
                {0x000000000006800c, 0x8000000000000000 >> 0x17},
                {0x0000000013010002, 0xAABBC00000000000},
                {0x0000000013030007, 0x00000CDE00000000},
            };

            // Get the master processor chip
            l_pTarget = NULL;
            TARGETING::targetService().masterProcChipTargetHandle(l_pTarget);

            // Create a FAPI Target of the master processor
            fapi::Target l_fapiTarget(TARGET_TYPE_PROC_CHIP,
                                          reinterpret_cast<void *> (l_pTarget));

            hwpfTestArgs_t l_args[MAX_TEST_TASKS] = {{{0},},};

            uint8_t l_index = 0;
            uint32_t i;

            for (i = 0; i < (CREATE_TASK_PAIRS * 2); i++)
            {
                // start one task
                l_args[i].ifScom      = l_ifScom[l_index];
                l_args[i].fapiTarget  = l_fapiTarget;
                l_args[i].Write       = (i % 2) ? 0 : 1;
                l_args[i].AttrTest    = 1;
                l_args[i].ScomTest    = 1;
                l_args[i].tid = task_create(testHwpScomAcc,
                                            static_cast<void *>(&l_args[i]));
                // Change ifScom register after a pair of tasks started
                l_index = (i % 2) ? (l_index + 1) % NUM_OF_SCOMREGS : l_index;
            }

            int status;

            for (i = 0; i < MAX_TEST_TASKS; i++)
            {
                if (l_args[i].ifScom.addr != 0)
                {
                    task_wait_tid( l_args[i].tid, &status,  NULL );
                }
            }

            for (i = 0; i < NUM_OF_SCOMREGS; i++)
            {
                ecmdDataBufferBase l_ScomData(64);
                l_rc = fapiGetScom( l_fapiTarget, l_ifScom[i].addr,
                                                             l_ScomData );
                if (l_rc != fapi::FAPI_RC_SUCCESS ||
                    l_ScomData.getDoubleWord(0) != l_ifScom[i].data)
                {
                    TS_FAIL("testHwpf6: Scom register has unexpected data");
                    break;
                }
            }

            if (l_rc.ok() && i == NUM_OF_SCOMREGS)
            {
                uint8_t l_uint8 = 0;
                l_rc = FAPI_ATTR_GET(ATTR_SCRATCH_UINT8_1, NULL, l_uint8);
                if (l_rc != fapi::FAPI_RC_SUCCESS || l_uint8 != ATTR_TEST_VALUE)
                {
                    TS_FAIL("testHwpf6: ATTR_SCRATCH_UINT8_1"
                             " has unexpected data");
                }
                else
                {
                    TS_TRACE("testHwpf6: Unit Test passed.");
                }
            }
        }
    }

//    // unit test breakpoint
//    void testHwpf7()
//    {
//        fapi::Target  fapiTarget;
//        FAPI_INF("AT breakpoint");
//        fapiBreakPoint(fapiTarget,__LINE__);
//
//        // requires outside hb-istep resume  command to continue
//
//        FAPI_INF("RESUME from breakpoint");
//    }

    /**
     * @brief Test case Accessing DIMM SPD Attribute from FAPI
     *
     */
    void testHwpf8()
    {
        fapi::ReturnCode l_rc;

        do
        {
            // Get a DIMM Target
            TargetHandleList dimmList;
            getAllLogicalCards( dimmList,
                                TARGETING::TYPE_DIMM );

            if (dimmList.size())
            {
                fapi::Target l_dTarget(TARGET_TYPE_DIMM,
                                       static_cast<void *> (dimmList[0]));

                uint8_t opt[18] = { 0, };

                l_rc = FAPI_ATTR_GET(ATTR_SPD_MODULE_PART_NUMBER,
                                                       &l_dTarget, opt);

                if (l_rc.ok())
                {
                    FAPI_INF("testHwpf8: PN = %s", opt);
                }
                else
                {
                    TS_FAIL("testHwpf8: ATTR_SPD_MODULE_PART_NUMBER GET fails");
                }
            }

        } while(0);

    }

    /**
     * @brief Call a test procedure that exercises the Bad DQ data
     */
    void testHwpf9()
    {
        errlHndl_t l_err = NULL;

        // Look for functional DIMMs
        TARGETING::PredicateIsFunctional l_functional;
        TARGETING::PredicateCTM l_dimmFilter(CLASS_LOGICAL_CARD, TYPE_DIMM);
        TARGETING::PredicatePostfixExpr l_functionalDimms;
        l_functionalDimms.push(&l_dimmFilter).push(&l_functional).And();

        TARGETING::TargetRangeFilter l_filter(
            TARGETING::targetService().begin(),
            TARGETING::targetService().end(),
            &l_functionalDimms);

        // Look for the first functional DIMM
        if (l_filter)
        {
            // Get the associated MBA
            TARGETING::PredicateCTM l_mbaFilter(CLASS_UNIT, TYPE_MBA);
            TARGETING::TargetHandleList l_MBAs;

            TARGETING::targetService().getAssociated(l_MBAs, (*l_filter),
                TARGETING::TargetService::PARENT_BY_AFFINITY,
                TARGETING::TargetService::ALL,
                &l_mbaFilter);

            if (l_MBAs.size() == 1)
            {
                fapi::Target l_fapiTarget(TARGET_TYPE_MBA_CHIPLET,
                    static_cast<void *>(l_MBAs[0]));

                FAPI_INVOKE_HWP(l_err, fapiTestHwpDq, l_fapiTarget);

                if (l_err)
                {
                    TS_FAIL("testHwpf9: fapiTestHwpDq failed. Error logged");
                    errlCommit(l_err, HWPF_COMP_ID);
                }
                else
                {
                    TS_TRACE("testHwpf9: Unit Test passed");
                }
            }
            else
            {
                TS_FAIL("testHwpf9: Parent MBA not found");
            }
        }
        else
        {
            TS_TRACE("testHwpf9: No functional DIMMs found, skipping test");
        }
    }

    /**
     * @brief Access the test Chip EC Feature attributes
     */
    void testHwpf10()
    {
        fapi::ReturnCode l_rc;
        uint8_t l_chipHasFeature = 0xff;

        // Get the master processor chip
        TARGETING::Target* l_pTarget = NULL;
        TARGETING::targetService().masterProcChipTargetHandle(l_pTarget);

        // Create a FAPI Target
        fapi::Target l_fapiTarget(TARGET_TYPE_PROC_CHIP,
                                  reinterpret_cast<void *> (l_pTarget));

        l_rc = FAPI_ATTR_GET(ATTR_CHIP_EC_FEATURE_TEST1, &l_fapiTarget,
                             l_chipHasFeature);
        if (l_rc)
        {
            TS_FAIL("testHwpf10: ATTR_CHIP_EC_FEATURE_TEST1 get failed.");
        }
        else
        {
            FAPI_INF("testHwpf10: ATTR_CHIP_EC_FEATURE_TEST1: %d", l_chipHasFeature);

            l_chipHasFeature = 0xff;
            l_rc = FAPI_ATTR_GET(ATTR_CHIP_EC_FEATURE_TEST2, &l_fapiTarget,
                             l_chipHasFeature);
            if (l_rc)
            {
                TS_FAIL("testHwpf10: ATTR_CHIP_EC_FEATURE_TEST2 get failed.");
            }
            else
            {
                FAPI_INF("testHwpf10: ATTR_CHIP_EC_FEATURE_TEST2: %d", l_chipHasFeature);
            }
        }
    }

};

#endif
OpenPOWER on IntegriCloud