summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/plat/mem/prdfMemTdCtlr.C
blob: 564dafdf4d1cb83563b434a1ac395034bf5e5956 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/plat/mem/prdfMemTdCtlr.C $                  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] 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                                                     */

#include <prdfMemTdCtlr.H>

// Platform includes
#include <prdfCenMbaDataBundle.H>
#include <prdfMemAddress.H>
#include <prdfMemCaptureData.H>
#include <prdfMemScrubUtils.H>
#include <prdfP9McaDataBundle.H>
#include <prdfP9McbistExtraSig.H>
#include <prdfParserEnums.H>
#include <UtilHash.H> // for Util::hashString

// External includes
#include <util/misc.H>

using namespace TARGETING;

namespace PRDF
{

using namespace PlatServices;

//------------------------------------------------------------------------------

template<TARGETING::TYPE T>
TdRankListEntry __getStopRank( ExtensibleChip * i_chip, const MemAddr & i_addr )
{
    MemRank stopRank = i_addr.getRank();

    // ############################ SIMICs only ############################
    // We have found it to be increasingly difficult to simulate the MCBMCAT
    // register in SIMICs. We tried copying the address in the MCBEA
    // registers, but the HWP code will input the last possible address to
    // the MCBEA registers, but it is likely that this address is not a
    // configured address. MCBIST commands are tolerant of this, where MBA
    // maintenance commands are not. Also, there are multiple possible
    // subtests for MCBIST commands. So it is difficult to determine which
    // subtest will be the last configured address. To maintain sanity, we
    // will simply short-circuit the code and ensure we always get the last
    // configured rank.
    if ( ::Util::isSimicsRunning() )
    {
        std::vector<MemRank> list;
        getSlaveRanks<T>( i_chip->getTrgt(), list );
        PRDF_ASSERT( !list.empty() ); // func target with no config ranks

        stopRank = list.back(); // Get the last configured rank.
    }
    // #####################################################################

    return TdRankListEntry( i_chip, stopRank );
}

//------------------------------------------------------------------------------

template <TARGETING::TYPE T>
uint32_t MemTdCtlr<T>::handleCmdComplete( STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[MemTdCtlr::handleCmdComplete] "

    uint32_t o_rc = SUCCESS;

    do
    {
        // Make sure the TD controller is initialized.
        o_rc = initialize();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "initialize() failed" );
            break;
        }

        #ifndef __HOSTBOOT_RUNTIME // IPL only

        // TODO: RTC 179251 asserting here doesn't give us enough FFDC to debug
        //       why we got this erroneous attention. Eventually, we will want
        //       to add the capture data to the assert error log. Until then
        //       exit with a bad RC and make the error log predictive.
        // PRDF_ASSERT( isInMdiaMode() ); // MDIA must be running.
        if ( !isInMdiaMode() )
        {
            PRDF_ERR( PRDF_FUNC "IPL cmd complete attn outside of MDIA" );
            o_rc = FAIL;
            break;
        }

        // Inform MDIA the command has completed and PRD is starting analysis.
        // If MDIA started the command, the reset message will do the cleanup
        // for the super fast command.
        o_rc = mdiaSendEventMsg( iv_chip->getTrgt(), MDIA::RESET_TIMER );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "mdiaSendEventMsg(RESET_TIMER) failed" );
            break;
        }

        // If PRD started a super fast command, this will do the cleanup for the
        // super fast command.
        o_rc = cleanupSfRead<T>( iv_chip );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "cleanupSfRead(0x%08x) failed",
                      iv_chip->getHuid() );
            break;
        }

        #endif

        collectStateCaptureData( io_sc, TD_CTLR_DATA::START );

        if ( nullptr == iv_curProcedure )
        {
            // There are no TD procedures currently in progress.

            // Check for ECC errors, if they exist.
            bool errorsFound = false;
            o_rc = analyzeCmdComplete( errorsFound, io_sc );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "analyzeCmdComplete(0x%08x) failed",
                          iv_chip->getHuid() );
                break;
            }

            // If the command completed successfully with no error, the error
            // log will not have any useful information. Therefore, do not
            // commit the error log. This is done to avoid useless
            // informational error logs.
            if ( !errorsFound ) io_sc.service_data->setDontCommitErrl();
        }

        // Move onto the next step in the state machine.
        o_rc = nextStep( io_sc );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "nextStep() failed" );
            break;
        }

    } while (0);

    // Gather capture data even if something failed above.
    // NOTE: There is no need to capture the data if the command completed
    //       successfully with no errors because the error log will not be
    //       committed.
    if ( !io_sc.service_data->queryDontCommitErrl() )
    {
        collectStateCaptureData( io_sc, TD_CTLR_DATA::END );
        MemCaptureData::addEccData<T>( iv_chip, io_sc );
    }

    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( PRDF_FUNC "Failed on 0x%08x", iv_chip->getHuid() );

        // Just in case it was a legitimate command complete (error log not
        // committed) but something else failed.
        io_sc.service_data->clearDontCommitErrl();

        // Change signature indicating there was an error in analysis.
        io_sc.service_data->setSignature( iv_chip->getHuid(),
                                          PRDFSIG_CmdComplete_ERROR );

        // Something definitely failed, so callout 2nd level support.
        io_sc.service_data->SetCallout( LEVEL2_SUPPORT, MRU_HIGH );
        io_sc.service_data->setServiceCall();

        #ifndef __HOSTBOOT_RUNTIME // IPL only

        if ( isInMdiaMode() )
        {
            // Tell MDIA to skip further analysis on this target.
            uint32_t l_rc = mdiaSendEventMsg( iv_chip->getTrgt(),
                                              MDIA::STOP_TESTING );
            if ( SUCCESS != l_rc )
                PRDF_ERR( PRDF_FUNC "mdiaSendEventMsg(STOP_TESTING) failed" );
        }

        #endif
    }

    return o_rc;

    #undef PRDF_FUNC
}

//------------------------------------------------------------------------------

// This is a forward reference to a function that is locally defined in
// prdfMemTdCtlr_ipl.C and prdfMemTdCtlr_rt.C. The reason for this is that the
// MemTdCtlr template is only created for the MCBIST and MBA targets, not the
// MCA, but the ECC analysis is done on each MCA and MBA. Therefore, we needed
// some way to change the template to use the MCA. It is also a local function
// because this is only for MemTdCtlr internal use and it didn't make much sense
// to create a public function.
template<TARGETING::TYPE T>
uint32_t __checkEcc( ExtensibleChip * i_chip,
                     const MemAddr & i_addr, bool & o_errorsFound,
                     STEP_CODE_DATA_STRUCT & io_sc );

//------------------------------------------------------------------------------

template<TARGETING::TYPE T>
uint32_t __analyzeCmdComplete( ExtensibleChip * i_chip,
                               TdRankListEntry & o_stoppedRank,
                               const MemAddr & i_addr,
                               bool & o_errorsFound,
                               STEP_CODE_DATA_STRUCT & io_sc );

template<>
uint32_t __analyzeCmdComplete<TYPE_MCBIST>( ExtensibleChip * i_chip,
                                            TdRankListEntry & o_stoppedRank,
                                            const MemAddr & i_addr,
                                            bool & o_errorsFound,
                                            STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[__analyzeCmdComplete] "

    uint32_t o_rc = SUCCESS;

    o_errorsFound = false;

    do
    {
        // Get all ports in which the command was run.
        ExtensibleChipList portList;
        o_rc = getMcbistMaintPort<TYPE_MCBIST>( i_chip, portList );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "getMcbistMaintPort(0x%08x) failed",
                      i_chip->getHuid() );
            break;
        }

        // In broadcast mode, the rank configuration for all ports will be the
        // same. In non-broadcast mode, there will only be one MCA in the list.
        // Therefore, we can simply use the first MCA in the list for all
        // configs.
        ExtensibleChip * stopChip = portList.front();

        // Update iv_stoppedRank.
        o_stoppedRank = __getStopRank<TYPE_MCA>( stopChip, i_addr );

        // Check each MCA for ECC errors.
        for ( auto & mcaChip : portList )
        {
            bool errorsFound;
            uint32_t l_rc = __checkEcc<TYPE_MCA>( mcaChip, i_addr,
                                                  errorsFound, io_sc );
            if ( SUCCESS != l_rc )
            {
                PRDF_ERR( PRDF_FUNC "__checkEcc<TYPE_MCA>(0x%08x) failed",
                          mcaChip->getHuid() );
                o_rc |= l_rc; continue; // Try the other MCAs.
            }

            if ( errorsFound ) o_errorsFound = true;
        }
        if ( SUCCESS != o_rc ) break;

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t __analyzeCmdComplete<TYPE_OCMB_CHIP>( ExtensibleChip * i_chip,
                                               TdRankListEntry & o_stoppedRank,
                                               const MemAddr & i_addr,
                                               bool & o_errorsFound,
                                               STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[__analyzeCmdComplete] "

    uint32_t o_rc = SUCCESS;

    o_errorsFound = false;

    do
    {
        // Update iv_stoppedRank.
        o_stoppedRank = __getStopRank<TYPE_OCMB_CHIP>( i_chip, i_addr );

        // Check the OCMB for ECC errors.
        bool errorsFound;
        o_rc = __checkEcc<TYPE_OCMB_CHIP>( i_chip, i_addr, errorsFound, io_sc );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "__checkEcc<TYPE_OCMB_CHIP>(0x%08x) failed",
                      i_chip->getHuid() );
            o_rc |= o_rc;
            break;
        }

        if ( errorsFound ) o_errorsFound = true;
        if ( SUCCESS != o_rc ) break;
    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t __analyzeCmdComplete<TYPE_MBA>( ExtensibleChip * i_chip,
                                         TdRankListEntry & o_stoppedRank,
                                         const MemAddr & i_addr,
                                         bool & o_errorsFound,
                                         STEP_CODE_DATA_STRUCT & io_sc )
{
    // Update iv_stoppedRank.
    o_stoppedRank = __getStopRank<TYPE_MBA>( i_chip, i_addr );

    // Check the MBA for ECC errors.
    return __checkEcc<TYPE_MBA>(i_chip, i_addr, o_errorsFound, io_sc);
}

//------------------------------------------------------------------------------

template<TARGETING::TYPE T>
uint32_t MemTdCtlr<T>::analyzeCmdComplete( bool & o_errorsFound,
                                           STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[MemTdCtlr::analyzeCmdComplete] "

    uint32_t o_rc = SUCCESS;

    do
    {
        // First, get the address in which the command stopped.
        MemAddr addr;
        o_rc = getMemMaintAddr<T>( iv_chip, addr );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "getMemMaintAddr<T>(0x%08x) failed",
                      iv_chip->getHuid() );
            break;
        }

        // Then, check for ECC errors, if they exist.
        o_rc = __analyzeCmdComplete<T>( iv_chip, iv_stoppedRank,
                                        addr, o_errorsFound, io_sc );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "__analyzeCmdComplete<T>(0x%08x) failed",
                      iv_chip->getHuid() );
            break;
        }

        #ifdef __HOSTBOOT_RUNTIME

        if ( iv_queue.empty() )
        {
            // The queue is empty so it is possible that background scrubbing
            // only stopped for FFDC. If possible, simply resume the command
            // instead of starting a new one. This must be checked here instead
            // of in defaultStep() because a TD procedure could have been run
            // before defaultStep() and it is possible that canResumeBgScrub()
            // could give as a false positive in that case.
            o_rc = canResumeBgScrub( iv_resumeBgScrub, io_sc );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "canResumeBgScrub(0x%08x) failed",
                          iv_chip->getHuid() );
                break;
            }
        }
        else
        {
            // The analyzeCmdComplete() function is only called if there was a
            // command complete attention and there were no TD procedures
            // currently in progress. At this point, there are new TD procedures
            // in the queue so we want to mask certain fetch attentions to avoid
            // the complication of handling the attentions during the TD
            // procedures.
            o_rc = maskEccAttns();
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "maskEccAttns() failed" );
                break;
            }
        }

        #endif

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

//------------------------------------------------------------------------------

template <TARGETING::TYPE T>
void MemTdCtlr<T>::collectStateCaptureData( STEP_CODE_DATA_STRUCT & io_sc,
                                            const char * i_startEnd )
{
    #define PRDF_FUNC "[MemTdCtlr<T>::collectStateCaptureData] "

    // Get the number of entries in the TD queue (limit 16)
    TdQueue::Queue queue = iv_queue.getQueue();
    uint8_t queueCount = queue.size();
    if ( 16 < queueCount ) queueCount = 16;

    // Don't add anything if there is no data.
    if ( nullptr == iv_curProcedure && 0 == queueCount ) return;

    // Get the version to use.
    uint8_t version = TD_CTLR_DATA::VERSION_1;
    bool isNimbus = false;
    if ( MODEL_NIMBUS == getChipModel(getMasterProc()) )
    {
        version = TD_CTLR_DATA::VERSION_2;
        isNimbus = true;
    }
    else if ( MODEL_AXONE == getChipModel(getMasterProc()) )
    {
        version = TD_CTLR_DATA::VERSION_2;
    }

    // Get the IPL state.
    #ifdef __HOSTBOOT_RUNTIME
    uint8_t state = TD_CTLR_DATA::RT;
    #else
    uint8_t state = TD_CTLR_DATA::IPL;
    #endif

    // Get the buffer length (header + TD queue)
    uint32_t hdrLen = TD_CTLR_DATA::v1_HEADER;
    uint32_t entLen = TD_CTLR_DATA::v1_ENTRY;
    if ( TD_CTLR_DATA::VERSION_2 == version )
    {
        hdrLen = TD_CTLR_DATA::v2_HEADER;
        entLen = TD_CTLR_DATA::v2_ENTRY;
    }

    uint32_t bitLen = hdrLen + queueCount * entLen;

    // Init the buffer.
    BitStringBuffer bsb( bitLen );

    //##########################################################################
    // Header data
    //##########################################################################

    uint8_t curMrnk  = 0;
    uint8_t curSrnk  = 0;
    uint8_t curPhase = TdEntry::Phase::TD_PHASE_0;
    uint8_t curType  = TdEntry::TdType::INVALID_EVENT;
    uint8_t curPort  = 0;

    if ( nullptr != iv_curProcedure )
    {
        curMrnk  = iv_curProcedure->getRank().getMaster();
        curSrnk  = iv_curProcedure->getRank().getSlave();
        curPhase = iv_curProcedure->getPhase();
        curType  = iv_curProcedure->getType();

        if ( TD_CTLR_DATA::VERSION_2 == version )
        {
            curPort = iv_curProcedure->getChip()->getPos() % MAX_MCA_PER_MCBIST;
            if ( !isNimbus )
            {
                TargetHandle_t portTrgt = iv_curProcedure->getChip()->getTrgt();
                curPort = portTrgt->getAttr<ATTR_REL_POS>();
            }
        }
    }

    uint32_t pos = 0;

    bsb.setFieldJustify( pos, 1, state      ); pos+=1;
    bsb.setFieldJustify( pos, 3, version    ); pos+=3;
    bsb.setFieldJustify( pos, 3, curMrnk    ); pos+=3;
    bsb.setFieldJustify( pos, 3, curSrnk    ); pos+=3;
    bsb.setFieldJustify( pos, 4, curPhase   ); pos+=4;
    bsb.setFieldJustify( pos, 4, curType    ); pos+=4;
    bsb.setFieldJustify( pos, 4, queueCount ); pos+=4;

    if ( TD_CTLR_DATA::VERSION_2 == version )
    {
        bsb.setFieldJustify( pos, 2, curPort ); pos+=2;
    }

    //##########################################################################
    // TD Queue
    //##########################################################################

    for ( uint32_t n = 0; n < queueCount; n++ )
    {
        uint8_t itMrnk = queue[n]->getRank().getMaster();
        uint8_t itSrnk = queue[n]->getRank().getSlave();
        uint8_t itType = queue[n]->getType();
        uint8_t itPort = 0;

        if ( TD_CTLR_DATA::VERSION_2 == version )
        {
            itPort = queue[n]->getChip()->getPos() % MAX_MCA_PER_MCBIST;
            if ( !isNimbus )
            {
                TargetHandle_t portTrgt = queue[n]->getChip()->getTrgt();
                itPort = portTrgt->getAttr<ATTR_REL_POS>();
            }
        }

        bsb.setFieldJustify( pos, 3, itMrnk ); pos+=3;
        bsb.setFieldJustify( pos, 3, itSrnk ); pos+=3;
        bsb.setFieldJustify( pos, 4, itType ); pos+=4;

        if ( TD_CTLR_DATA::VERSION_2 == version )
        {
            bsb.setFieldJustify( pos, 2, itPort ); pos+=2;
        }
    }

    //##########################################################################
    // Add the capture data
    //##########################################################################

    CaptureData & cd = io_sc.service_data->GetCaptureData();
    cd.Add( iv_chip->getTrgt(), Util::hashString(i_startEnd), bsb );

    #undef PRDF_FUNC
}

//------------------------------------------------------------------------------

// Avoid linker errors with the template.
template class MemTdCtlr<TYPE_MCBIST>;
template class MemTdCtlr<TYPE_MBA>;
template class MemTdCtlr<TYPE_OCMB_CHIP>;

//------------------------------------------------------------------------------

} // end namespace PRDF

OpenPOWER on IntegriCloud