summaryrefslogtreecommitdiffstats
path: root/src/usr/fsi/test/fsiddtest.H
blob: 0b3a40bafa844107a50066473066b6e28309748f (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/fsi/test/fsiddtest.H $                                */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2018                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __FSIDDTEST_H
#define __FSIDDTEST_H

/**
 *  @file fsiddtest.H
 *
 *  @brief Test cases for FSI Device Driver
*/

#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <limits.h>
#include <devicefw/driverif.H>
#include <fsi/fsiif.H>
#include <fsi/fsi_reasoncodes.H>
#include <sys/time.h>
#include <targeting/common/attributes.H>
#include <targeting/common/utilFilter.H>

extern trace_desc_t* g_trac_fsi;

using namespace TARGETING;

class FsiDDTest : public CxxTest::TestSuite
{
  public:
    /**
     * @brief FSI DD test - Read/Write
     *        Perform basic read/write operations
     */
    void test_readWrite(void)
    {
        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_readWrite> Start" );
        uint64_t fails = 0;
        uint64_t total = 0;
        errlHndl_t l_err = NULL;

        // Setup some targets to use
        enum {
            PROC0,
            PROCWRAP,
            PROC1,
            PROC2,
            // @todo RTC 178802 Enable test cases turned off during bring up
            //CENTAUR0,
            //CENTAUR8,
            SENTINEL,
            NUM_TARGETS
        };
        TARGETING::Target* fsi_targets[NUM_TARGETS];
        for( uint64_t x = 0; x < NUM_TARGETS; x++ )
        {
            fsi_targets[x] = NULL;
        }

        TARGETING::Target* fsi_target = NULL;

        // master processor target
        TARGETING::EntityPath epath(TARGETING::EntityPath::PATH_PHYSICAL);
        epath.addLast(TARGETING::TYPE_SYS,0);
        epath.addLast(TARGETING::TYPE_NODE,0);
        epath.addLast(TARGETING::TYPE_PROC,0);
        fsi_target = TARGETING::targetService().toTarget(epath);
        fsi_targets[PROC0] = fsi_target;

        // other (wrap) processor target (physical:sys-0/node-0/proc-9)
        epath.removeLast();
        epath.addLast(TARGETING::TYPE_PROC,9);
        fsi_target = TARGETING::targetService().toTarget(epath);
        fsi_targets[PROCWRAP] = fsi_target;

        // other processor target (physical:sys-0/node-0/proc-1)
        epath.removeLast();
        epath.addLast(TARGETING::TYPE_PROC,1);
        fsi_target = TARGETING::targetService().toTarget(epath);
        fsi_targets[PROC1] = fsi_target;

        // @todo RTC 178802 Enable test cases turned off during bring up
        /*
        // alt-master processor target (physical:sys-0/node-0/proc-2)
        epath.removeLast();
        epath.addLast(TARGETING::TYPE_PROC,2);
        fsi_target = TARGETING::targetService().toTarget(epath);
        fsi_targets[PROC2] = fsi_target;

        // local centaur target (physical:sys-0/node-0/membuf-0)
        epath.removeLast();
        epath.addLast(TARGETING::TYPE_MEMBUF,0);
        fsi_target = TARGETING::targetService().toTarget(epath);
        fsi_targets[CENTAUR0] = fsi_target;

        // remote centaur target (physical:sys-0/node-0/membuf-8)
        epath.removeLast();
        epath.addLast(TARGETING::TYPE_MEMBUF,8);
        fsi_target = TARGETING::targetService().toTarget(epath);
        fsi_targets[CENTAUR8] = fsi_target;
        */

        // scratch data to use
        struct {
            int fsitarget;
            uint64_t addr;
            uint32_t data;
            bool writeable;
            bool present;
        } test_data[] = {
            //** Master Control Space
            // version number
            //CMFSI MVER
            { PROC0, 0x003074, 0x92010800, false, true },
            //MFSI MVER
            { PROC0, 0x003474, 0x92010800, false, true },

            //** Slave Regs (via absolute address)
            //DATA_0 from FSI2PIB off MFSI-0
            { PROC0, 0x081000, 0x12345678, true, false },
            //CHIPID from SHIFT off cMFSI-0
            { PROC0, 0x041028, 0x160E9049, false, false },
            //CMFSI MVER from Proc off MFSI-2
            { PROC0, 0x103074, 0x92010800, false, false },

            //** Slave Regs
            //DATA_0 from FSI2PIB off MFSI-0
            { PROCWRAP, 0x001000, 0x12345678, false, false },
            //DATA_1 from FSI2PIB off MFSI-0
            { PROCWRAP, 0x001004, 0xA5A5A5A5, true, false },

            //** Slave Regs
            //FEL from SHIFT off MFSI-1
            { PROC1, 0x001000, 0x88776655, true, false },

            //** Slave Regs
            //FEL from SHIFT off MFSI-2
            { PROC2, 0x001000, 0x12345678, true, false },

            // @todo RTC 178802 Enable test cases turned off during bring up
            //** Slave Regs
            //Config Table entry for slave0 off cMFSI-0
            //{ CENTAUR0, 0x000000, 0xC0010E95, false, false },
            //CHIPID from FSI2PIB off cMFSI-0
            //{ CENTAUR0, 0x001028, 0x160E9049, false, false },
            //FEL from SHIFT off cMFSI-0
            //{ CENTAUR0, 0x000C08, 0x12344321, true, false },

            // @todo RTC 178802 Enable test cases turned off during bring up
            //** Slave Regs
            //FEL from SHIFT off cMFSI-0 of MFSI-1
            //{ CENTAUR8, 0x001000, 0x33333333, true, false },
            //CHIPID from FSI2PIB off cMFSI-0 of MFSI-1
            //{ CENTAUR8, 0x001028, 0x160E9049, false, false },
        };
        const uint64_t NUM_ADDRS = sizeof(test_data)/sizeof(test_data[0]);

        // allocate some space to play with
        uint32_t read_data[NUM_ADDRS];
        size_t op_size = sizeof(uint32_t);

        // figure out which ports are valid to test in the current config
        uint64_t patterns_to_run = 0;
        for( uint64_t x = 0; x < NUM_ADDRS; x++ )
        {

            // direct writes to slave regs
            if( test_data[x].fsitarget == PROC0 )
            {
                if( ((0xFF0000 & test_data[x].addr) == 0x080000)
                    && (fsi_targets[PROCWRAP] != NULL)
                    && (fsi_targets[PROCWRAP]->
                        getAttr<TARGETING::ATTR_HWAS_STATE>().functional))
                {
                    test_data[x].present = true;
                }
                // @todo RTC 178802 Enable test cases turned off during bring up
                //else if( ((0xFF0000 & test_data[x].addr) == 0x040000)
                //         && (fsi_targets[CENTAUR0] != NULL)
                //         && (fsi_targets[CENTAUR0]->
                //             getAttr<TARGETING::ATTR_HWAS_STATE>().functional))
                //{
                //    test_data[x].present = true;
                //}
                else if( ((0xFF0000 & test_data[x].addr) == 0x100000)
                         && (fsi_targets[PROC2] != NULL)
                         && (fsi_targets[PROC2]->
                             getAttr<TARGETING::ATTR_HWAS_STATE>().functional))
                {
                    test_data[x].present = true;
                }
            }
            // otherwise only talk to chips that we see
            else if (( fsi_targets[test_data[x].fsitarget] != NULL)   &&
                     (fsi_targets[test_data[x].fsitarget]->
                      getAttr<TARGETING::ATTR_HWAS_STATE>().functional))
            {
                test_data[x].present = true;
            }
            else
            {
                test_data[x].present = false;
            }

            if( test_data[x].present )
            {
                patterns_to_run |= (0x8000000000000000 >> x);
            }
        }

        // read address X,Y,Z
        for( uint64_t x = 0; x < NUM_ADDRS; x++ )
        {
            if( !test_data[x].present )
            {
                continue;
            }

            total++;
            op_size = sizeof(uint32_t);
            l_err = DeviceFW::deviceRead(
                              fsi_targets[test_data[x].fsitarget],
                              &(read_data[x]),
                              op_size,
                              DEVICE_FSI_ADDRESS(test_data[x].addr) );
            if( l_err )
            {
                TRACFCOMP(g_trac_fsi, "FsiDDTest::test_readWrite> Error from device : [%d] addr=0x%X, RC=%X", x, test_data[x].addr, l_err->reasonCode() );
                TS_FAIL( "FsiDDTest::test_readWrite> ERROR : Unexpected error log from read1" );
                fails++;
                errlCommit(l_err,FSI_COMP_ID);
            }

            TRACDCOMP( g_trac_fsi, "READ Reg 0x%X = 0x%X", test_data[x].addr, read_data[x] );
        }

        // write X=A, Y=B, Z=C
        for( uint64_t x = 0; x < NUM_ADDRS; x++ )
        {
            if( !test_data[x].present )
            {
                continue;
            }

            if( test_data[x].writeable )
            {
                total++;
                op_size = sizeof(uint32_t);
                l_err = DeviceFW::deviceWrite(
                                  fsi_targets[test_data[x].fsitarget],
                                  &(test_data[x].data),
                                  op_size,
                                  DEVICE_FSI_ADDRESS(test_data[x].addr) );
                if( l_err )
                {
                    TRACFCOMP(g_trac_fsi, "FsiDDTest::test_readWrite> Error from device : [%d] addr=0x%X, RC=%X", x, test_data[x].addr, l_err->reasonCode() );
                    TS_FAIL( "FsiDDTest::test_readWrite> ERROR : Unexpected error log from write1" );
                    fails++;
                    errlCommit(l_err,FSI_COMP_ID);
                }
            }
        }

        // read X,Y,Z
        for( uint64_t x = 0; x < NUM_ADDRS; x++ )
        {
            if( !test_data[x].present )
            {
                continue;
            }

            total++;
            op_size = sizeof(uint32_t);
            l_err = DeviceFW::deviceRead(
                              fsi_targets[test_data[x].fsitarget],
                              &(read_data[x]),
                              op_size,
                              DEVICE_FSI_ADDRESS(test_data[x].addr) );
            if( l_err )
            {
                TRACFCOMP(g_trac_fsi, "FsiDDTest::test_readWrite> Error from device : [%d] addr=0x%X, RC=%X", x, test_data[x].addr, l_err->reasonCode() );
                TS_FAIL( "FsiDDTest::test_readWrite> ERROR : Unexpected error log from read2" );
                fails++;
                errlCommit(l_err,FSI_COMP_ID);
            }
        }

        // verify X==A, Y==B, Z==C
        for( uint64_t x = 0; x < NUM_ADDRS; x++ )
        {
            if( !test_data[x].present )
            {
                continue;
            }

            total++;
            if( read_data[x] != test_data[x].data )
            {
                TRACFCOMP(g_trac_fsi, "FsiDDTest::test_readWrite> Data mismatch : [%d] addr=0x%X, exp=0x%X, act=0x%X", x,  test_data[x].addr, test_data[x].data, read_data[x] );
//@TODO RTC:178802
//                TS_FAIL( "FsiDDTest::test_readWrite> ERROR : Data mismatch" );
//                fails++;
            }
        }

#if 0
        // put the original data back
        for( uint64_t x = 0; x < NUM_ADDRS; x++ )
        {
            op_size = sizeof(uint32_t);

            if( test_data[x].writeable )
            {
                total++;
                l_err = DeviceFW::deviceWrite(
                                  fsi_targets[test_data[x].fsitarget],
                                  &(test_data[x].data),
                                  op_size,
                                  DEVICE_FSI_ADDRESS(test_data[x].addr) );
                if( l_err )
                {
                    TRACFCOMP(g_trac_fsi, "FsiDDTest::test_readWrite> Error from device : addr=0x%X, RC=%X", test_data[x].addr, l_err->reasonCode() );
                    TS_FAIL( "FsiDDTest::test_readWrite> ERROR : Unexpected error log from write1" );
                    fails++;
                    errlCommit(l_err,FSI_COMP_ID);
                }
            }
        }
#endif


        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_readWrite> %d/%d fails (patterns=%.16X)", fails, total, patterns_to_run );
    };

    /**
     * @brief FSI DD test - bad targets
     *        Verify that we catch bad targets
     */
    void test_badTargets(void)
    {
        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_badTargets> Start" );
        uint64_t fails = 0;
        uint64_t total = 0;
        errlHndl_t l_err = NULL;
        uint32_t regdata = 0;

        // master sentinel should fail
        total++;
        size_t op_size = sizeof(uint32_t);
        l_err = DeviceFW::deviceRead(
                          TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
                          &regdata,
                          op_size,
                          DEVICE_FSI_ADDRESS(0x111111) );
        if( l_err && (l_err->reasonCode() == FSI::RC_MASTER_TARGET) )
        {
            delete l_err;
        }
        else
        {
            TRACFCOMP(g_trac_fsi, "FsiDDTest::test_badTargets> ERROR : Sentinel target did not fail as expected" );
            TS_FAIL( "FsiDDTest::test_badTargets> ERROR : Sentinel target did not fail as expected" );
            fails++;

            if( l_err )
            {
                errlCommit(l_err,FSI_COMP_ID);
            }
        }

        // NULL target should fail
        total++;
        op_size = sizeof(uint32_t);
        l_err = DeviceFW::deviceRead( NULL,
                                      &regdata,
                                      op_size,
                                      DEVICE_FSI_ADDRESS(0x111111) );
        if( l_err )
        {
            delete l_err;
        }
        else
        {
            TRACFCOMP(g_trac_fsi, "FsiDDTest::test_badTargets> ERROR : NULL target did not fail as expected" );
            TS_FAIL( "FsiDDTest::test_badTargets> ERROR : NULL target did not fail as expected" );
            fails++;
        }

        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_badTargets> %d/%d fails", fails, total );
    };

    /**
     * @brief FSI DD test - FFDC Collection
     *        Verify FFDC for errors
     */
    void test_FFDC(void)
    {
        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_FFDC> Start" );

        // @todo RTC 178802 Enable test cases turned off during bring up
        /*
        errlHndl_t l_err = NULL;

        // Find any Centaur target
        TARGETING::TargetHandleList l_memTargetList;
        getAllChips( l_memTargetList, TYPE_MEMBUF, true );
        if( l_memTargetList.empty() )
        {
            TRACFCOMP( g_trac_fsi, "FsiDDTest::test_FFDC> No Centaurs found..." );
        }
        else
        {
            TARGETING::Target* fsi_target = *(l_memTargetList.begin());

            l_err =  new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            FSI::MOD_FSIDD_INVALID,
                                            FSI::RC_BAD_REASONCODE,
                                            TARGETING::get_huid(fsi_target),
                                            FSI::FFDC_PRESENCE_FAIL);
            FSI::getFsiFFDC( FSI::FFDC_PRESENCE_FAIL, l_err, fsi_target );
            errlCommit(l_err,CXXTEST_COMP_ID);

            l_err =  new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            FSI::MOD_FSIDD_INVALID,
                                            FSI::RC_BAD_REASONCODE,
                                            TARGETING::get_huid(fsi_target),
                                            FSI::FFDC_READWRITE_FAIL);
            FSI::getFsiFFDC( FSI::FFDC_READWRITE_FAIL, l_err, fsi_target );
            errlCommit(l_err,CXXTEST_COMP_ID);

            l_err =  new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                            FSI::MOD_FSIDD_INVALID,
                                            FSI::RC_BAD_REASONCODE,
                                            TARGETING::get_huid(fsi_target),
                                            FSI::FFDC_PIB_FAIL);
            FSI::getFsiFFDC( FSI::FFDC_PIB_FAIL, l_err, fsi_target );
            errlCommit(l_err,CXXTEST_COMP_ID);
        }
        */
        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_FFDC> Finish" );
    };

    /**
     * @brief FSI DD test - FSI Link Info
     *        Spot check getFsiLinkInfo results
     */
    void test_getFsiLinkInfo(void)
    {
        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_getFsiLinkInfo> Start" );

        enum {
            PROC0,
            // @todo RTC 178802 Enable test cases turned off during bring up
            //CENTAUR4,
            NUM_TARGETS
        };
        TARGETING::Target* fsi_targets[NUM_TARGETS];
        for( size_t x = 0; x < NUM_TARGETS; x++ )
        {
            fsi_targets[x] = NULL;
        }

        TARGETING::Target* fsi_target = NULL;

        // master processor target
        TARGETING::EntityPath epath(TARGETING::EntityPath::PATH_PHYSICAL);
        epath.addLast(TARGETING::TYPE_SYS,0);
        epath.addLast(TARGETING::TYPE_NODE,0);
        epath.addLast(TARGETING::TYPE_PROC,0);
        fsi_target = TARGETING::targetService().toTarget(epath);
        fsi_targets[PROC0] = fsi_target;

        // @todo RTC 178802 Enable test cases turned off during bring up
        // local centaur target (physical:sys-0/node-0/membuf-4)
        //epath.removeLast();
        //epath.addLast(TARGETING::TYPE_MEMBUF,4);
        //fsi_target = TARGETING::targetService().toTarget(epath);
        //fsi_targets[CENTAUR4] = fsi_target;



        // loop through all of the targets we defined to
        //  check the data
        for( size_t x = 0; x < NUM_TARGETS; x++ )
        {
            if( fsi_targets[x] == NULL )
            {
                continue;
            }

            // Get the FSI port info for this target
            TARGETING::FSI_MASTER_TYPE type =
              fsi_targets[x]->getAttr<TARGETING::ATTR_FSI_MASTER_TYPE>();
            uint8_t slave_port =
              fsi_targets[x]->getAttr<TARGETING::ATTR_FSI_MASTER_PORT>();
            TARGETING::EntityPath masterpath =
              fsi_targets[x]->getAttr<TARGETING::ATTR_FSI_MASTER_CHIP>();
            TARGETING::Target* master =
              TARGETING::targetService().toTarget(masterpath);
            uint8_t master_port = 0;
            if( type != TARGETING::FSI_MASTER_TYPE_NO_MASTER )
            {
                master_port =
                  master->getAttr<TARGETING::ATTR_FSI_MASTER_PORT>()+1;
            }

            TRACFCOMP( g_trac_fsi, "sport=%d, mport=%d, master=%.8X, type=%d",slave_port,master_port, TARGETING::get_huid(master), master_port);
            // Compute the offset
            //   CMFSI ports start at 0x040000 and increment by 0x008000
            //   MFSI ports start at 0x080000 and increment by 0x080000
            //    (local CMFSI ports have no MFSI offset)
            uint32_t offset = (master_port * 0x080000);
            if( type == TARGETING::FSI_MASTER_TYPE_CMFSI )
            {
                offset += ((slave_port * 0x008000) + 0x040000);
            }

            // Now call the interface we want to test
            FSI::FsiLinkInfo_t linkinfo;
            FSI::getFsiLinkInfo( fsi_targets[x], linkinfo );

            // Compare the results
            TRACFCOMP( g_trac_fsi, "FsiDDTest::test_getFsiLinkInfo> Data for %.8X: exp=%.6X, act=%.6X", TARGETING::get_huid(fsi_targets[x]), offset, linkinfo.baseAddr );
            if( linkinfo.baseAddr != offset )
            {
                TS_FAIL( "FsiDDTest::test_getFsiLinkInfo> Mismatch for %.8X: exp=%.6X, act=%.6X", TARGETING::get_huid(fsi_targets[x]), offset, linkinfo.baseAddr );
            }
        }

        TRACFCOMP( g_trac_fsi, "FsiDDTest::test_getFsiLinkInfo> End" );
    }
};


#endif
OpenPOWER on IntegriCloud