summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/plat/mem/prdfRestoreDramRepairs.C
blob: fc389000a9c782560639c25958dbf9277f01e261 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/plat/mem/prdfRestoreDramRepairs.C $         */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,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                                                     */

/** @file prdfDramRepairs.C */

#include <diag/prdf/prdfMain.H>
#include <prdf_service_codes.H>
#include "common/iipconst.h"
#include <iipSystem.h>
#include <prdfGlobal.H>
#include <prdfTrace.H>
#include <prdfErrlUtil.H>
#include "common/prdfEnums.H"
#include "common/plat/mem/prdfMemCaptureData.H"
#include "common/plat/mem/prdfMemDqBitmap.H"
#include "common/plat/mem/prdfMemMark.H"
#include "common/plat/mem/prdfP9McaExtraSig.H"
#include "common/plat/mem/prdfMemSymbol.H"
#include "common/plat/mem/prdfMemoryMru.H"
#include <prdfPlatServices.H>

using namespace HWAS;
using namespace std;
using namespace TARGETING;

namespace PRDF
{

using namespace PlatServices;

namespace RDR // local utility functions to support PRDF::restoreDramRepairs()
{

// Creates and returns an error log.
template<TARGETING::TYPE T>
errlHndl_t createErrl( uint32_t i_reasonCode, TargetHandle_t i_trgt,
                       uint32_t i_signature )
{
    uint64_t userdata12 = PRDF_GET_UINT64_FROM_UINT32( getHuid(i_trgt), 0 );
    uint64_t userdata34 = PRDF_GET_UINT64_FROM_UINT32( i_signature,    0 );

    // Note that the error log tags are not needed because PRD uses its own
    // signature parser.

    errlHndl_t errl = new ERRORLOG::ErrlEntry(
                            ERRORLOG::ERRL_SEV_PREDICTIVE,  // severity
                            PRDF_RESTORE_DRAM_REPAIR,       // module ID
                            i_reasonCode,                   // reason code
                            userdata12,                     // user data 1 & 2
                            userdata34 );                   // user data 3 & 4

    // Add capture data. Need to do this now before the DIMM callouts are made
    // because the VPD is cleared if a DIMM is added to the callout list.
    MemCaptureData::addEccData<T>( i_trgt, errl );

    return errl;
}

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

// If an error log is given, will add DRAM repairs FFDC and traces to error log,
// then commit the error log.
template<TARGETING::TYPE T>
void commitErrl( errlHndl_t i_errl, TargetHandle_t i_trgt )
{
    if ( NULL != i_errl )
    {
        // Add traces
        i_errl->collectTrace( PRDF_COMP_NAME, 512 );

        // Commit the error log
        ERRORLOG::errlCommit( i_errl, PRDF_COMP_ID );
    }
}

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

template<TARGETING::TYPE T>
void __calloutDimm( errlHndl_t & io_errl, TargetHandle_t i_portTrgt,
                    TargetHandle_t i_dimmTrgt, bool i_nvdimmNoGard = false )
{
    #define PRDF_FUNC "[RDR::__calloutDimm] "

    PRDF_ASSERT( nullptr != i_portTrgt );
    PRDF_ASSERT( T == getTargetType(i_portTrgt) );

    PRDF_ASSERT( nullptr != i_dimmTrgt );
    PRDF_ASSERT( TYPE_DIMM == getTargetType(i_dimmTrgt) );

    HWAS::DeconfigEnum deconfigPolicy = HWAS::DELAYED_DECONFIG;
    HWAS::GARD_ErrorType gardPolicy   = HWAS::GARD_Predictive;

    #ifdef CONFIG_NVDIMM
    // For the "RDR: All repairs used" case, If the DIMM is an NVDIMM, change
    // the gard and deconfig options to no gard/deconfig and call
    // nvdimmNotifyProtChange to indicate a save/restore may work.
    if ( i_nvdimmNoGard )
    {
        deconfigPolicy = HWAS::NO_DECONFIG;
        gardPolicy     = HWAS::GARD_NULL;

        uint32_t l_rc = PlatServices::nvdimmNotifyProtChange( i_dimmTrgt,
            NVDIMM::NVDIMM_RISKY_HW_ERROR );
        if ( SUCCESS != l_rc )
        {
            PRDF_TRAC( PRDF_FUNC "nvdimmNotifyProtChange(0x%08x) "
                       "failed.", PlatServices::getHuid(i_dimmTrgt) );
        }
    }
    #endif

    io_errl->addHwCallout( i_dimmTrgt, HWAS::SRCI_PRIORITY_HIGH,
                           deconfigPolicy, gardPolicy );


    // Clear the VPD on this DIMM. The DIMM has been garded, but it is possible
    // the customer will want to ungard the DIMM. Without clearing the VPD, the
    // DIMM will be permanently garded because the customer has no ability to
    // clear the VPD. Therefore, we will clear the VPD on this DIMM. If the
    // customer takes the risk of ungarding the DIMM (that they should replace),
    // the repairs will need to be rediscovered.

    // Do not clear the VPD if we had an NVDIMM that we avoided garding.
    if ( !i_nvdimmNoGard )
    {
        std::vector<MemRank> ranks;
        getMasterRanks<T>( i_portTrgt, ranks, getDimmSlct(i_dimmTrgt) );

        for ( auto & rank : ranks )
        {
            if ( SUCCESS != clearBadDqBitmap(i_portTrgt, rank) )
            {
                PRDF_ERR( PRDF_FUNC "clearBadDqBitmap(0x%08x,0x%02x) failed",
                          getHuid(i_portTrgt), rank.getKey() );
                continue;
            }
        }
    }

    #undef PRDF_FUNC
}

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

// If there were analysis errors, will create and commit an error log with 2nd
// level support callout.
template<TARGETING::TYPE T>
void commitSoftError( uint32_t i_reasonCode, TargetHandle_t i_trgt,
                      uint32_t i_signature, bool i_analysisErrors )
{
    if ( i_analysisErrors )
    {
        errlHndl_t errl = createErrl<T>( i_reasonCode, i_trgt, i_signature );
        errl->addProcedureCallout( HWAS::EPUB_PRC_LVL_SUPP,
                                   HWAS::SRCI_PRIORITY_HIGH );
        commitErrl<T>( errl, i_trgt );
    }
}

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

template<TARGETING::TYPE T>
bool processRepairedRanks( TargetHandle_t i_trgt, uint8_t i_repairedRankMask )
{
    #define PRDF_FUNC "[processRepairedRanks] "

    // The bits in i_repairedRankMask represent ranks that have repairs. Query
    // hardware and compare against RAS policies.

    bool o_calloutMade  = false;
    bool analysisErrors = false;

    errlHndl_t errl = NULL; // Initially NULL, will create if needed.

    do
    {
        // Keep a list of DIMMs to callout. Note that we are using a map with
        // the DIMM target as the key so that we can maintain a unique list. The
        // map value has no significance.
        std::map<TargetHandle_t, uint32_t> calloutList;

        ExtensibleChip * chip = (ExtensibleChip *)systemPtr->GetChip(i_trgt);

        for ( uint8_t r = 0; r < MASTER_RANKS_PER_PORT; ++r )
        {
            if ( 0 == (i_repairedRankMask & (0x80 >> r)) )
            {
                continue; // this rank didn't have any repairs
            }

            MemRank rank ( r );

            MemMark cm;
            if ( SUCCESS != MarkStore::readChipMark<T>( chip, rank, cm ) )
            {
                PRDF_ERR( PRDF_FUNC "readChipMark<T>(0x%08x,0x%02x) "
                          "failed", chip->getHuid(), rank.getKey() );
                continue; // skip this rank
            }

            MemMark sm;
            if ( SUCCESS != MarkStore::readSymbolMark<T>( chip, rank, sm ) )
            {
                PRDF_ERR( PRDF_FUNC "readSymbolMark<T>(0x%08x,0x%02x) "
                          "failed", chip->getHuid(), rank.getKey() );
                continue; // skip this rank
            }

            if ( cm.isValid() && sm.isValid() ) // CM and SM used
            {
                // All repairs on the rank have been used. Callout all repairs.

                if ( NULL == errl )
                {
                    errl = createErrl<T>( PRDF_DETECTED_FAIL_HARDWARE,
                                          i_trgt, PRDFSIG_RdrRepairsUsed );
                }

                std::vector<MemSymbol> symList;
                symList.push_back( cm.getSymbol() );
                symList.push_back( sm.getSymbol() );

                for ( auto & sym : symList )
                {
                    if ( !sym.isValid() ) continue;

                    MemoryMru mm( i_trgt, rank, sym );

                    // Add all parts to the error log.
                    for ( auto & dimm : mm.getCalloutList() )
                    {
                        calloutList[dimm] = 1;
                    }

                    // Add the MemoryMru to the capture data.
                    MemCaptureData::addExtMemMruData( mm, errl );
                }

                o_calloutMade = true;
            }
        }

        // Callout all DIMMs in the map.
        for ( auto const & dimm : calloutList )
        {
            bool nvdimmNoGard = false;
            #ifdef CONFIG_NVDIMM
            if ( isNVDIMM(dimm.first) ) nvdimmNoGard = true;
            #endif

            __calloutDimm<T>( errl, i_trgt, dimm.first, nvdimmNoGard );
        }

        // Commit the error log, if needed.
        commitErrl<T>( errl, i_trgt );

        // Commit an additional error log indicating something failed in the
        // analysis, if needed.
        commitSoftError<T>( PRDF_DETECTED_FAIL_SOFTWARE, i_trgt,
                            PRDFSIG_RdrInternalFail, analysisErrors );
    }while(0);

    return o_calloutMade;

    #undef PRDF_FUNC
}


template
bool processRepairedRanks<TYPE_MCA>( TargetHandle_t i_trgt,
                                     uint8_t i_repairedRankMask );
template
bool processRepairedRanks<TYPE_OCMB_CHIP>( TargetHandle_t i_trgt,
                                           uint8_t i_repairedRankMask );

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

template<>
bool processRepairedRanks<TYPE_MBA>( TargetHandle_t i_trgt,
                                     uint8_t i_repairedRankMask )
{
    #define PRDF_FUNC "[processRepairedRanks] "

    // The bits in i_repairedRankMask represent ranks that have repairs. Query
    // hardware and compare against RAS policies.

    bool o_calloutMade  = false;

    bool analysisErrors = false;

    errlHndl_t errl = NULL; // Initially NULL, will create if needed.

    bool isCen = isMembufOnDimm<TYPE_MBA>( i_trgt );
    bool isX4 = isDramWidthX4( i_trgt );

    for ( uint8_t r = 0; r < MASTER_RANKS_PER_PORT; ++r )
    {
        if ( 0 == (i_repairedRankMask & (0x80 >> r)) )
        {
            continue; // this rank didn't have any repairs
        }

        MemRank rank ( r );
        MemMark chipMark, symMark;

        ExtensibleChip * chip = (ExtensibleChip *)systemPtr->GetChip( i_trgt );

        if (SUCCESS != MarkStore::readChipMark<TYPE_MBA>(chip, rank, chipMark))
        {
            PRDF_ERR( PRDF_FUNC "readChipMark() failed: MBA=0x%08x "
                    "rank=0x%02x", getHuid(i_trgt), rank.getKey() );
            analysisErrors = true;
            continue; // skip this rank
        }

        if (SUCCESS != MarkStore::readSymbolMark<TYPE_MBA>(chip, rank, symMark))
        {
            PRDF_ERR( PRDF_FUNC "readSymbolMark() failed: MBA=0x%08x "
                    "rank=0x%02x", getHuid(i_trgt), rank.getKey() );
            analysisErrors = true;
            continue; // skip this rank
        }


        MemSymbol sp0, sp1, ecc;
        if ( SUCCESS != mssGetSteerMux<TYPE_MBA>(i_trgt, rank, sp0, sp1, ecc) )
        {
            PRDF_ERR( PRDF_FUNC "mssGetSteerMux() failed: MBA=0x%08x "
                      "rank=%d", getHuid(i_trgt), rank.getMaster() );
            analysisErrors = true;
            continue; // skip this rank
        }

        bool isCm  = chipMark.isValid();                // chip mark
        bool isSm  = symMark.isValid();                 // symbol mark
        bool isSp  = (sp0.isValid() || sp1.isValid());  // either DRAM spare
        bool isEcc = ecc.isValid();                     // ECC spare

        if ( isCm &&                                    // CM used
             ( ( isCen && isSp && (!isX4 || isEcc)) ||  // all spares used
               (!isCen &&         ( isSm || isEcc)) ) ) // SM or ECC used
        {
            // All repairs on the rank have been used. Callout all repairs.

            if ( NULL == errl )
            {
                errl = createErrl<TYPE_MBA>( PRDF_DETECTED_FAIL_HARDWARE,
                                             i_trgt, PRDFSIG_RdrRepairsUsed );
            }

            // Keep a list of DIMMs to callout. Note that we are using a map
            // with the DIMM target as the key so that we can maintain a
            // unique list. The map value has no significance.
            std::map<TargetHandle_t, uint32_t> calloutList;
            std::vector<MemSymbol> symList;
            symList.push_back( chipMark.getSymbol() );
            symList.push_back( symMark.getSymbol() );
            symList.push_back( sp0          );
            symList.push_back( sp1          );
            symList.push_back( ecc          );

            for ( auto & sym : symList )
            {
                if ( !sym.isValid() ) continue;

                MemoryMru mm( i_trgt, rank, sym );

                // Add all parts to the error log.
                for ( auto & dimm : mm.getCalloutList() )
                {
                    calloutList[dimm] = 1;
                }

                // Add the MemoryMru to the capture data.
                MemCaptureData::addExtMemMruData( mm, errl );
            }

            // Callout all DIMMs in the map.
            for ( auto const & dimm : calloutList )
            {
                bool nvdimmNoGard = false;
                #ifdef CONFIG_NVDIMM
                if ( isNVDIMM(dimm.first) ) nvdimmNoGard = true;
                #endif

                __calloutDimm<TYPE_MBA>(errl, i_trgt, dimm.first, nvdimmNoGard);
            }

            o_calloutMade = true;
        }
    }

    // Commit the error log, if needed.
    commitErrl<TYPE_MBA>( errl, i_trgt );

    // Commit an additional error log indicating something failed in the
    // analysis, if needed.
    commitSoftError<TYPE_MBA>( PRDF_DETECTED_FAIL_SOFTWARE, i_trgt,
                               PRDFSIG_RdrInternalFail, analysisErrors );

    return o_calloutMade;

    #undef PRDF_FUNC
}

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


template<TARGETING::TYPE T>
bool processBadDimms( TargetHandle_t i_trgt, uint8_t i_badDimmMask )
{
    #define PRDF_FUNC "[processBadDimms] "

    // The bits in i_badDimmMask represent DIMMs that have exceeded the
    // available repairs. Callout these DIMMs.

    bool o_calloutMade  = false;
    bool analysisErrors = false;

    errlHndl_t errl = NULL; // Initially NULL, will create if needed.

    // Iterate the list of all DIMMs
    TargetHandleList dimms = getConnected( i_trgt, TYPE_DIMM );
    for ( auto & dimm : dimms )
    {
        // i_badDimmMask is defined as a 2-bit mask where a bit set means that
        // DIMM had more bad bits than could be repaired. Note: the value is
        // actually a 4-bit field for use with Centaur, but we only use the
        // first 2 bits of that field here.
        uint8_t mask = 0x80 >> getDimmSlct(dimm);

        if ( 0 != (i_badDimmMask & mask) )
        {
            if ( NULL == errl )
            {
                errl = createErrl<T>( PRDF_DETECTED_FAIL_HARDWARE,
                                      i_trgt, PRDFSIG_RdrRepairUnavail );
            }

            __calloutDimm<T>( errl, i_trgt, dimm );

            o_calloutMade = true;
        }
    }

    // Commit the error log, if needed.
    commitErrl<T>( errl, i_trgt );

    // Commit an additional error log indicating something failed in the
    // analysis, if needed.
    commitSoftError<T>( PRDF_DETECTED_FAIL_SOFTWARE, i_trgt,
                        PRDFSIG_RdrInternalFail, analysisErrors );

    return o_calloutMade;

    #undef PRDF_FUNC
}

template
bool processBadDimms<TYPE_MCA>( TargetHandle_t i_trgt, uint8_t i_badDimmMask );
template
bool processBadDimms<TYPE_OCMB_CHIP>( TargetHandle_t i_trgt,
                                      uint8_t i_badDimmMask );

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

template<>
bool processBadDimms<TYPE_MBA>( TargetHandle_t i_trgt, uint8_t i_badDimmMask )
{
    #define PRDF_FUNC "[processBadDimms] "

    // The bits in i_badDimmMask represent DIMMs that have exceeded the
    // available repairs. Callout these DIMMs.

    bool o_calloutMade  = false;
    bool analysisErrors = false;

    errlHndl_t errl = nullptr; // Initially NULL, will create if needed.

    // Iterate the list of all DIMMs be
    TargetHandleList dimms = getConnected( i_trgt, TYPE_DIMM );
    for ( auto & dimm : dimms )
    {
        uint8_t portSlct = getDimmPort( dimm );
        uint8_t dimmSlct = getDimmSlct( dimm );

        // The 4 bits of i_badDimmMask is defined as p0d0, p0d1, p1d0, and p1d1.
        uint8_t mask = 0x8 >> (portSlct * MAX_PORT_PER_MBA + dimmSlct);

        if ( 0 != (i_badDimmMask & mask) )
        {
            if ( NULL == errl )
            {
                errl = createErrl<TYPE_MBA>( PRDF_DETECTED_FAIL_HARDWARE,
                                             i_trgt, PRDFSIG_RdrRepairUnavail );
            }

            __calloutDimm<TYPE_MBA>( errl, i_trgt, dimm );

            o_calloutMade = true;
        }
    }

    // Commit the error log, if needed.
    commitErrl<TYPE_MBA>( errl, i_trgt );

    // Commit an additional error log indicating something failed in the
    // analysis, if needed.
    commitSoftError<TYPE_MBA>( PRDF_DETECTED_FAIL_SOFTWARE, i_trgt,
                               PRDFSIG_RdrInternalFail, analysisErrors );

    return o_calloutMade;

    #undef PRDF_FUNC
}

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

template<TARGETING::TYPE T>
bool screenBadDqs( TargetHandle_t i_trgt, const std::vector<MemRank> & i_ranks )
{
    #define PRDF_FUNC "[screenBadDqs<T>] "

    // Callout any attached DIMMs that have any bad DQs.

    bool o_calloutMade  = false;
    bool analysisErrors = false;

    for ( auto & rank : i_ranks )
    {
        // The HW procedure to read the bad DQ attribute will callout the DIMM
        // if it has DRAM Repairs VPD and the DISABLE_DRAM_REPAIRS MNFG policy
        // flag is set. PRD will simply need to iterate through all the ranks
        // to ensure all DIMMs are screen and the procedure will do the rest.
        MemDqBitmap bitmap;
        if ( SUCCESS != getBadDqBitmap(i_trgt, rank, bitmap) )
        {
            PRDF_ERR( PRDF_FUNC "getBadDqBitmap() failed: TRGT=0x%08x "
                      "rank=0x%02x", getHuid(i_trgt), rank.getKey() );
            analysisErrors = true;
            continue; // skip this rank
        }
    }

    // Commit an additional error log indicating something failed in the
    // analysis, if needed.
    commitSoftError<T>( PRDF_DETECTED_FAIL_SOFTWARE, i_trgt,
                        PRDFSIG_RdrInternalFail, analysisErrors );

    return o_calloutMade;

    #undef PRDF_FUNC
}

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

template<TARGETING::TYPE>
void deployDramSpares( TargetHandle_t i_trgt,
                       const std::vector<MemRank> & i_ranks );

template<>
void deployDramSpares<TYPE_MCA>( TargetHandle_t i_trgt,
                                 const std::vector<MemRank> & i_ranks ){}
template<>
void deployDramSpares<TYPE_MBA>( TargetHandle_t i_trgt,
                                 const std::vector<MemRank> & i_ranks )
{
    bool x4 = isDramWidthX4( i_trgt );
    bool cenDimm = isMembufOnDimm<TYPE_MBA>( i_trgt );

    for ( auto & rank : i_ranks )
    {
        // Doesn't matter which DRAM is spared as long as they are all spared.
        // Also, make sure the ECC spare is on a different DRAM than the spare
        // DRAM.
        MemSymbol symPort0 = MemSymbol::fromSymbol( i_trgt, rank, 71 );
        MemSymbol symPort1 = MemSymbol::fromSymbol( i_trgt, rank, 39 );
        MemSymbol symEccSp = MemSymbol::fromSymbol( i_trgt, rank, 67 );

        int32_t l_rc = SUCCESS;

        if ( cenDimm )
        {
            l_rc |= mssSetSteerMux<TYPE_MBA>( i_trgt, rank, symPort0, false );
            l_rc |= mssSetSteerMux<TYPE_MBA>( i_trgt, rank, symPort1, false );
        }

        if ( x4 )
            l_rc |= mssSetSteerMux<TYPE_MBA>( i_trgt, rank, symEccSp, true );

        if ( SUCCESS != l_rc )
        {
            // mssSetSteerMux() will print a trace and commit the error log,
            // however, we need to handle the return code or we get a compile
            // warning in Hostboot.
            continue;
        }
    }
}

template<>
void deployDramSpares<TYPE_OCMB_CHIP>( TargetHandle_t i_trgt,
                                       const std::vector<MemRank> & i_ranks )
{
    for ( auto & rank : i_ranks )
    {
        MemSymbol sym = MemSymbol::fromSymbol( i_trgt, rank, 71 );

        int32_t l_rc = mssSetSteerMux<TYPE_OCMB_CHIP>(i_trgt, rank, sym, false);
        if ( SUCCESS != l_rc )
        {
            // mssSetSteerMux() will print a trace and commit the error log,
            // however, we need to handle the return code or we get a compile
            // warning in Hostboot.
            continue;
        }
    }
}

} // end namespace RDR

//------------------------------------------------------------------------------
// External functions - declared in prdfMain.H
//------------------------------------------------------------------------------

template<TARGETING::TYPE T>
uint32_t restoreDramRepairs( TargetHandle_t i_trgt )
{
    #define PRDF_FUNC "PRDF::restoreDramRepairs<T>"

    PRDF_ENTER( PRDF_FUNC "(0x%08x)", getHuid(i_trgt) );

    // will unlock when going out of scope
    PRDF_SYSTEM_SCOPELOCK;

    bool calloutMade = false;

    do
    {
        // Will need the chip and system objects initialized for several parts
        // of this function and sub-functions.
        if ( (false == g_initialized) || (nullptr == systemPtr) )
        {
            errlHndl_t errl = noLock_initialize();
            if ( nullptr != errl )
            {
                PRDF_ERR( PRDF_FUNC "Failed to initialize PRD" );
                RDR::commitErrl<T>( errl, i_trgt );
                break;
            }
        }

        std::vector<MemRank> ranks;
        getMasterRanks<T>( i_trgt, ranks );

        bool spareDramDeploy = mnfgSpareDramDeploy();

        if ( spareDramDeploy )
        {
            // Deploy all spares for MNFG corner tests.
            RDR::deployDramSpares<T>( i_trgt, ranks );
        }

        if ( areDramRepairsDisabled() )
        {
            // DRAM Repairs are disabled in MNFG mode, so screen all DIMMs with
            // VPD information.
            if ( RDR::screenBadDqs<T>(i_trgt, ranks) )
                calloutMade = true;

            // No need to continue because there will not be anything to
            // restore.
            break;
        }

        if ( spareDramDeploy )
        {
            // This is an error. The MNFG spare DRAM deply bit is set, but DRAM
            // Repairs have not been disabled.

            PRDF_ERR( "[" PRDF_FUNC "] MNFG spare deploy enabled, but DRAM "
                      "repairs are not disabled" );

            RDR::commitSoftError<T>( PRDF_INVALID_CONFIG, i_trgt,
                                     PRDFSIG_RdrInvalidConfig, true );

            break; // Assume user meant to disable DRAM repairs.
        }

        uint8_t rankMask = 0, dimmMask = 0;
        if ( SUCCESS != mssRestoreDramRepairs<T>( i_trgt, rankMask,
                                                  dimmMask) )
        {
            // Can't check anything if this doesn't work.
            PRDF_ERR( "[" PRDF_FUNC "] mssRestoreDramRepairs() failed" );
            break;
        }

        // Callout DIMMs with too many bad bits and not enough repairs available
        if ( RDR::processBadDimms<T>(i_trgt, dimmMask) )
            calloutMade = true;

        // Check repaired ranks for RAS policy violations.
        if ( RDR::processRepairedRanks<T>(i_trgt, rankMask) )
            calloutMade = true;

    } while(0);

    PRDF_EXIT( PRDF_FUNC "(0x%08x)", getHuid(i_trgt) );

    return calloutMade ? FAIL : SUCCESS;

    #undef PRDF_FUNC
}

template
uint32_t restoreDramRepairs<TYPE_MCA>( TargetHandle_t i_trgt );
template
uint32_t restoreDramRepairs<TYPE_MBA>( TargetHandle_t i_trgt );
template
uint32_t restoreDramRepairs<TYPE_OCMB_CHIP>( TargetHandle_t i_trgt );

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

} // end namespace PRDF

OpenPOWER on IntegriCloud