summaryrefslogtreecommitdiffstats
path: root/src/usr/ibscom/test/ibscomtest.H
blob: e71473dbf9b0b57f202f40f9d5620e2649567ef6 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/ibscom/test/ibscomtest.H $                            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2014              */
/*                                                                        */
/* 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 __IBSCOMTEST_H
#define __IBSCOMTEST_H

/**
 *  @file ibscomtest.H
 *
 *  @brief Test case for inband scom code
*/

#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <devicefw/userif.H>
#include <ibscom/ibscomreasoncodes.H>
#include <devicefw/driverif.H>
#include <sys/time.h>

extern trace_desc_t* g_trac_ibscom;

using namespace TARGETING;


class IBscomTest: public CxxTest::TestSuite
{
  public:

    /**
     * @brief inband scom test #1
     *        Write values and read back to verify
     */
    void test_IBscom(void)
    {

        uint64_t fails = 0;
        uint64_t total = 0;
        errlHndl_t l_err = NULL;

        TARGETING::Target* l_testTarget = NULL;

        // Target: Find a Centaur on the Master processor
        TARGETING::Target* l_procTarget = NULL;
        TARGETING::targetService().masterProcChipTargetHandle(l_procTarget);
        assert(l_procTarget != NULL);

        TARGETING::PredicateCTM l_cent(TARGETING::CLASS_CHIP,
                                       TARGETING::TYPE_MEMBUF,
                                       TARGETING::MODEL_NA);
        TARGETING::PredicateHwas functionalPredicate;
        functionalPredicate.functional(true);

        TARGETING::PredicatePostfixExpr cent_query;
        cent_query.push(&l_cent).push(&functionalPredicate).And();

        TARGETING::TargetHandleList centaur_list;
        TARGETING::targetService().
          getAssociated(centaur_list,
                        l_procTarget,
                        TARGETING::TargetService::CHILD_BY_AFFINITY,
                        TARGETING::TargetService::ALL,
                        &cent_query);

        if( centaur_list.size() < 1 )
        {
            TS_FAIL( "test_IBscom> ERROR : Unable to find a Centaur chip" );
            return;
        }
        l_testTarget = *(centaur_list.begin());
        TRACFCOMP(g_trac_ibscom,"test_IBscom> Using target %.8X", TARGETING::get_huid(l_testTarget));

        ScomSwitches l_switches = l_testTarget->getAttr<ATTR_SCOM_SWITCHES>();
        if( !l_switches.useInbandScom )
        {
            TRACFCOMP(g_trac_ibscom,"Skipping test_IBscom because ibscom is not enabled");
            return;
        }

        TRACDCOMP(g_trac_ibscom,
                  "IBscomTest::test_IBscom> Read original data from Centaur");


        const uint64_t addrs[] = {0x02010803/*0:26*/, 0x03010403/*0:21*/};
        uint64_t orig_data[2] = {0};
        uint64_t new_data1[] = {0x123456E000000000, 0xFEEDB00000000000};
        uint64_t read_data[2] = {0};
        uint64_t read_data_fsi[2] = {0};
        size_t op_size = sizeof(uint64_t);
        const uint64_t junk = 0x1122334455667788;

        //Save off initial register content via FSI
        for(uint32_t i=0; i<2; i++)
        {
            op_size = sizeof(uint64_t);
            l_err = deviceOp( DeviceFW::READ,
                              l_testTarget,
                              &orig_data[i],
                              op_size,
                              DEVICE_FSISCOM_ADDRESS(addrs[i]) );
            if( l_err )
            {
                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Orig Read: Error from device : addr=0x%X, RC=%X",
                          addrs[i], l_err->reasonCode() );
                TS_FAIL( "test_IBscom1> ERROR : Unexpected error log from saving original data." );
                fails++;
                errlCommit(l_err,IBSCOM_COMP_ID);
            }
            total++;

            // OR in the original data so we don't clear mask bits
            new_data1[i] |= orig_data[i];
        }

        //Read the data with IBSCOM
        for(uint32_t i=0; i<2; i++)
        {
            TRACDCOMP(g_trac_ibscom,
                      "IBscomTest::test_IBscom> Read data");

            //reset size
            op_size = sizeof(uint64_t);
            read_data[i] = junk;
            l_err = deviceOp( DeviceFW::READ,
                              l_testTarget,
                              &read_data[i],
                              op_size,
                              DEVICE_IBSCOM_ADDRESS(addrs[i]) );
            if( l_err )
            {
                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Read: Error from device : addr=0x%X, RC=%X",
                          addrs[i], l_err->reasonCode() );
                TS_FAIL( "test_IBscom> ERROR : Error log from IBSCOM read" );
                fails++;
                errlCommit(l_err,IBSCOM_COMP_ID);
            }

            if(orig_data[i] != read_data[i])
            {
                TS_FAIL( "test_IBscom> ERROR : Data miss-match on IBSCOM read check." );

                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom>ERROR: addr=0x%.8x: Write data=0x%.16X, IBSCOM read data=0x%.16X",
                          addrs[i], new_data1[i], read_data[i]);
                fails++;
            }

            total++;
        }

        //Write in some new data with IBSCOM
        for(uint32_t i=0; i<2; i++)
        {
            TRACDCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Write new pattern: 0x%.16X", new_data1[i]);

            op_size = sizeof(uint64_t);
            l_err = deviceOp( DeviceFW::WRITE,
                              l_testTarget,
                              &new_data1[i],
                              op_size,
                              DEVICE_IBSCOM_ADDRESS(addrs[i]) );
            if( l_err )
            {
                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Write: Error from device : addr=0x%X, RC=%X",
                          addrs[i], l_err->reasonCode() );
                TS_FAIL( "ScomTest::test_IBscom> ERROR : Error log from IBSCOM Write" );
                fails++;
                errlCommit(l_err,IBSCOM_COMP_ID);
            }
            nanosleep( 0, 1000000 ); //sleep for 1ms

            total++;
        }

        //Read the data back with FSISCOM
        for(uint32_t i=0; i<2; i++)
        {
            TRACDCOMP(g_trac_ibscom,
                      "IBscomTest::test_IBscom> Read data back");

            //reset size
            op_size = sizeof(uint64_t);
            l_err = deviceOp( DeviceFW::READ,
                              l_testTarget,
                              &read_data_fsi[i],
                              op_size,
                              DEVICE_FSISCOM_ADDRESS(addrs[i]) );
            if( l_err )
            {
                TRACFCOMP(g_trac_ibscom, "IBscomTest::test_IBscom> Read: Error from device : addr=0x%X, RC=%X",
                          addrs[i], l_err->reasonCode() );
                TS_FAIL( "test_IBscom> ERROR : Error log from FSI Read" );
                fails++;
                errlCommit(l_err,IBSCOM_COMP_ID);
            }

            if(new_data1[i] != read_data_fsi[i])
            {
                TS_FAIL( "test_IBscom> ERROR : Data miss-match on FSI read-back check." );

                TRACFCOMP(g_trac_ibscom, "IBscomTest::test_IBscom>ERROR: addr=0x%.8x: Write data=0x%.16X, FSI read data=0x%.16X",
                          addrs[i], new_data1[i], read_data_fsi[i]);
                fails++;
            }
            total++;
        }

        //Write in some new data with FSISCOM
        uint64_t new_data2[] = {0xA5A5A50000000000/*0:26*/,
                                0x1122000000000000/*0:21*/};
        for(uint32_t i=0; i<2; i++)
        {
            TRACDCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Write new pattern: 0x%.16X", new_data2[i]);

            op_size = sizeof(uint64_t);
            l_err = deviceOp( DeviceFW::WRITE,
                              l_testTarget,
                              &new_data2[i],
                              op_size,
                              DEVICE_FSISCOM_ADDRESS(addrs[i]) );
            if( l_err )
            {
                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Write: Error from device : addr=0x%X, RC=%X",
                          addrs[i], l_err->reasonCode() );
                TS_FAIL( "ScomTest::test_IBscom> ERROR : Error log from FSI Write" );
                fails++;
                errlCommit(l_err,IBSCOM_COMP_ID);
            }

            total++;
        }


        //Read the data back with IBSCOM
        for(uint32_t i=0; i<2; i++)
        {
            TRACDCOMP(g_trac_ibscom,
                      "IBscomTest::test_IBscom> Read data back");

            //reset size
            op_size = sizeof(uint64_t);
            l_err = deviceOp( DeviceFW::READ,
                              l_testTarget,
                              &read_data[i],
                              op_size,
                              DEVICE_IBSCOM_ADDRESS(addrs[i]) );
            if( l_err )
            {
                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Read: Error from device : addr=0x%X, RC=%X",
                          addrs[i], l_err->reasonCode() );
                TS_FAIL( "test_IBscom> ERROR : Error log from IBSCOM read" );
                fails++;
                errlCommit(l_err,IBSCOM_COMP_ID);
            }

            if(new_data2[i] != read_data[i])
            {
                TS_FAIL( "test_IBscom> ERROR : Data miss-match on IBSCOM read-back check." );

                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom>ERROR: addr=0x%.8x: Write data=0x%.16X, IBSCOM read data=0x%.16X",
                          addrs[i], new_data1[i], read_data[i]);
                fails++;
            }

            total++;
        }

        //Restore original data.
        for(uint32_t i=0; i<2; i++)
        {
            op_size = sizeof(uint64_t);
            l_err = deviceWrite( l_testTarget,
                                 &orig_data[i],
                                 op_size,
                                 DEVICE_SCOM_ADDRESS(addrs[i]) );

            if( l_err )
            {
                TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom> Write Orig Data: Error from device : addr=0x%X, RC=%X",
                          addrs[i], l_err->reasonCode() );
                TS_FAIL( "test_IBscom> ERROR : Error log from write2" );
                fails++;
                errlCommit(l_err,IBSCOM_COMP_ID);
            }
        }

        TS_TRACE("test_IBscom runs successfully!");
        TRACFCOMP(g_trac_ibscom,
                  "IBscomTest::test_IBscom> %d/%d fails",
                  fails, total );

        return;
    }

    //TODO RTC: 72594: Add error path test cases when simics support
    //is available
    void test_IBscom_error(void)
    {
        TRACFCOMP(g_trac_ibscom,"Skipping test_IBscom_error because Simics is broken");
        return;

        uint64_t fails = 0;
        uint64_t total = 0;
        errlHndl_t l_err = NULL;

        TARGETING::Target* l_testTarget = NULL;

        // Target: Find a Centaur on the Master processor
        TARGETING::Target* l_procTarget = NULL;
        TARGETING::targetService().masterProcChipTargetHandle(l_procTarget);
        assert(l_procTarget != NULL);

        TARGETING::PredicateCTM l_cent(TARGETING::CLASS_CHIP,
                                       TARGETING::TYPE_MEMBUF,
                                       TARGETING::MODEL_NA);
        TARGETING::PredicatePostfixExpr cent_query;
        cent_query.push(&l_cent);


        TARGETING::TargetHandleList centaur_list;
        TARGETING::targetService().
          getAssociated(centaur_list,
                        l_procTarget,
                        TARGETING::TargetService::CHILD_BY_AFFINITY,
                        TARGETING::TargetService::ALL,
                        &cent_query);

        if( centaur_list.size() < 1 )
        {
            TS_FAIL( "test_IBscom_error> ERROR : Unable to find a Centaur chip" );
            return;
        }
        l_testTarget = *(centaur_list.begin());

        ScomSwitches l_switches = l_testTarget->getAttr<ATTR_SCOM_SWITCHES>();
        if( !l_switches.useInbandScom )
        {
            TRACFCOMP(g_trac_ibscom,"Skipping test_IBscom_error because ibscom is not enabled");
            return;
        }


        TRACDCOMP(g_trac_ibscom, "IBscomTest::test_IBscom_error> Read orignal data from Centaur");


        uint64_t new_data = 0x1234567ABABABA00;
        uint64_t read_data = 0;
        size_t op_size = sizeof(uint64_t);

        //Write a bad address
        uint64_t bad_addr = 0x02123456;
        TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom_error> Write bad address 0x%.16X", bad_addr);
        op_size = sizeof(uint64_t);
        l_err = deviceOp( DeviceFW::WRITE,
                          l_testTarget,
                          &new_data,
                          op_size,
                          DEVICE_IBSCOM_ADDRESS(bad_addr) );
        if( !l_err )
        {
            TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom_error> No error on bad address write" );
            TS_FAIL( "ScomTest::test_IBscom_error> No error on bad address write" );
            fails++;
        }
        else
        {
            delete l_err;
        }
        total++;
        nanosleep( 0, 1000000 ); //sleep for 1ms

        //Verify ibscom is still enabled, i.e. we didn't think it was a bus fail
        l_switches = l_testTarget->getAttr<ATTR_SCOM_SWITCHES>();
        total++;
        if( !l_switches.useInbandScom )
        {
            TS_FAIL( "ScomTest::test_IBscom_error> IBSCOM was wrongly disabled after bad address write" );
            fails++;
        }

        //Read a bad address
        bad_addr = 0x02876543;
        TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom_error> Write bad address 0x%.16X", bad_addr);
        op_size = sizeof(uint64_t);
        l_err = deviceOp( DeviceFW::READ,
                          l_testTarget,
                          &read_data,
                          op_size,
                          DEVICE_IBSCOM_ADDRESS(bad_addr) );
        if( !l_err )
        {
            TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom_error> No error on bad address read" );
            TS_FAIL( "ScomTest::test_IBscom_error> No error on bad address read" );
            fails++;
        }
        else
        {
            delete l_err;
        }
        total++;

        //Verify ibscom is still enabled, i.e. we didn't think it was a bus fail
        l_switches = l_testTarget->getAttr<ATTR_SCOM_SWITCHES>();
        total++;
        if( !l_switches.useInbandScom )
        {
            TS_FAIL( "ScomTest::test_IBscom_error> IBSCOM was wrongly disabled after bad address read" );
            fails++;
        }

        //Read a good address to prove things still work
        TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom_error> Read good address 0x%.16X", 0x02010803);
        op_size = sizeof(uint64_t);
        l_err = deviceOp( DeviceFW::READ,
                          l_testTarget,
                          &read_data,
                          op_size,
                          DEVICE_IBSCOM_ADDRESS(0x02010803) );
        if( l_err )
        {
            TRACFCOMP(g_trac_ibscom,"IBscomTest::test_IBscom_error> Error on read after fail" );
            TS_FAIL( "ScomTest::test_IBscom_error> Error on read after fail" );
            errlCommit(l_err,IBSCOM_COMP_ID);
            fails++;
        }
        total++;

        TS_TRACE("test_IBscom_error runs successfully!");
        TRACFCOMP(g_trac_ibscom,
                  "IBscomTest::test_IBscom_error> %d/%d fails",
                  fails, total );

        //TS_FAIL("FORCING ERROR TO STOP IPL");

        return;
    }
};

#endif
OpenPOWER on IntegriCloud