summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/plat/pegasus/prdfDramRepairs.C
blob: cfcf67afa6c5808492eae8a385913c563a893610 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/plat/pegasus/prdfDramRepairs.C $            */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/** @file prdfDramRepairs.C */

#include <diag/prdf/prdfMain.H>
#include <diag/prdf/common/prdf_service_codes.H>
#include "common/iipconst.h"
#include <prdfGlobal.H>
#include <prdfTrace.H>
#include <prdfErrlUtil.H>
#include "common/prdfEnums.H"
#include "common/plat/pegasus/prdfCenMbaCaptureData.H"
#include "common/plat/pegasus/prdfCalloutUtil.H"
#include "common/plat/pegasus/prdfCenDqBitmap.H"
#include "common/plat/pegasus/prdfCenMarkstore.H"
#include "common/plat/pegasus/prdfCenSymbol.H"
#include "common/plat/pegasus/prdfMemoryMru.H"
#include "framework/service/prdfPlatServices.H"

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

namespace PRDF
{

static const uint8_t INVALID_SYMBOL = 0xff;

bool validSymbol(uint8_t i_symbol)
{
    return i_symbol != INVALID_SYMBOL;
}

void commitRestoreCallout( void (*i_func)(errlHndl_t &, void *), void * i_data,
                           TargetHandle_t i_mba )
{
    PRDF_DENTER("commitRestoreCallout");

    errlHndl_t err = NULL;

    PRDF_HW_CREATE_ERRL(
            err,
            ERRL_SEV_PREDICTIVE,
            ERRL_ETYPE_NOT_APPLICABLE,
            SRCI_MACH_CHECK,
            SRCI_NO_ATTR,
            PRDF_RESTORE_DRAM_REPAIR,
            FSP_DEFAULT_REFCODE,
            PRDF_DETECTED_FAIL_HARDWARE_PROBABLE,
            0, 0, 0, 0, // user data
            HWSV_SYS_NO_TERMINATE,
            false); // no pld check

    // add the callout

    (*i_func)(err, i_data);

    bool term = false;

    CenMbaCaptureData::addDramRepairsData( i_mba, err );

    PRDF_HW_COMMIT_ERRL(
            term,
            err,
            HWSV::HWSV_DECONFIG_DEFER,
            ERRL_ACTION_REPORT,
            HWSV_CONTINUE);

    if(term)
    {
        // FIXME...this is a little goofy.
        // Should be scrubbed with RTC 51552

        PRDF_COMMIT_ERRL(err, ERRL_ACTION_REPORT);
    }
}

void addMemMruCallout(errlHndl_t & io_log, void * i_memMru)
{
    PRDF_DENTER("addMemMruCallout");

    if ( NULL != i_memMru )
    {
        MemoryMru *memMru = static_cast<MemoryMru *>(i_memMru);

        TargetHandleList partList = memMru->getCalloutList();
        for ( TargetHandleList::iterator it = partList.begin();
              it != partList.end(); it++ )
        {
            PRDF_HW_ADD_CALLOUT(
                        *it,
                        SRCI_PRIORITY_HIGH,
                        HWSV::HWSV_DECONFIG,
                        HWSV::HWSV_DECONFIG_GARD,
                        io_log,
                        false, // don't write src to vpd
                        GARD_Predictive,
                        ERRL_SEV_PREDICTIVE,
                        false); // don't update hcdb
        }
    }
}

void addDimmCallout(errlHndl_t & io_log, void * i_dimm)
{
    PRDF_DENTER("addDimmCallout");

    PRDF_HW_ADD_CALLOUT(
            static_cast<TargetHandle_t>(i_dimm),
            SRCI_PRIORITY_HIGH,
            HWSV::HWSV_DECONFIG,
            HWSV::HWSV_DECONFIG_GARD,
            io_log,
            false, // don't write src to vpd
            GARD_Predictive,
            ERRL_SEV_PREDICTIVE,
            false); // don't update hcdb
}

bool processRepairedRanks( TargetHandle_t i_mba, uint8_t i_repairedRankMask )
{
    PRDF_DENTER("processRepairedRanks: %p, 0x%02x",
            i_mba, i_repairedRankMask);

    // check the argument ranks for repairs
    // that violate RAS policy

    bool calloutMade = false;

    // check each rank for repairs
    // that violate RAS policy

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

        CenRank rank ( r );
        CenMark mark;

        if ( SUCCESS != PlatServices::mssGetMarkStore(i_mba, rank, mark) )
        {
            continue; // skip this rank
        }

        CenSymbol sp0, sp1, sp;

        if ( SUCCESS != PlatServices::mssGetSteerMux(i_mba, rank, sp0, sp1, sp))
        {
            continue; // skip this rank
        }

        if ( (sp0.isValid() || sp1.isValid() || sp.isValid()) &&
             mark.getCM().isValid() )
        {
            // This rank has both a steer and a chip mark. Call out the DIMM
            // with the chip mark.

            MemoryMru memoryMru( i_mba, rank, mark.getCM() );

            commitRestoreCallout( &addMemMruCallout, &memoryMru, i_mba );

            calloutMade = true;
        }
    }

    PRDF_DEXIT("processRepairedRanks");

    return calloutMade;
}

bool processBadDimms(TargetHandle_t i_mba, uint8_t i_badDimmMask)
{
    PRDF_DENTER("processBadDimms: %p, 0x%02x", i_mba, i_badDimmMask);

    const struct DimmPortAssoc
    {
        uint8_t port;
        uint8_t dimm;
        uint8_t enc;

    } dimmPortAssoc[] = {

        {0, 0, 0x8},
        {0, 1, 0x4},
        {1, 0, 0x2},
        {1, 1, 0x1},
    };

    uint64_t calloutCount = 0;

    // callout the argument dimms

    // get all the dimms connected to this MBA

    TARGETING::TargetHandleList dimms = PlatServices::getConnected(
            i_mba, TARGETING::TYPE_DIMM);

    // convert the encoded dimms that had too many repairs to
    // dimm targets

    TargetHandleList::iterator dit = dimms.end();

    while(dit-- != dimms.begin())
    {
        uint8_t port = 0, dimm = 0;

        if(SUCCESS != PlatServices::getMbaPort(*dit, port))
        {
            // skip this dimm
            continue;
        }

        if(SUCCESS != PlatServices::getMbaDimm(*dit, dimm))
        {
            // skip this dimm
            continue;
        }

        // see if the passed in dimm
        // was flagged as bad by the restore procedure

        bool match = false;

        const DimmPortAssoc * it = dimmPortAssoc
            + sizeof(dimmPortAssoc)/sizeof(*dimmPortAssoc);

        while(!match && it-- != dimmPortAssoc)
        {
            if(i_badDimmMask & it->enc
                    && port == it->port
                    && dimm == it->dimm)
            {
                // this dimm is a match

                match = true;
            }
        }

        // call them out

        if(match)
        {
            ++calloutCount;
            commitRestoreCallout( &addDimmCallout, *dit, i_mba );
        }
    }

    PRDF_DEXIT("processBadDimms: bad dimm count: %d", calloutCount);

    return 0 != calloutCount;
}

bool processDq(TargetHandle_t i_mba)
{
    using namespace TARGETING;
    using namespace PlatServices;

    PRDF_DENTER("processDq: %p", i_mba);

    // callout any dimms on the argument MBA
    // that have any bad dq

    uint64_t calloutCount = 0;

    for ( uint32_t r = 0; r < MAX_RANKS_PER_MBA; r++ )
    {
        CenRank rank ( r );
        CenDqBitmap bitmap;

        if ( SUCCESS != getBadDqBitmap(i_mba, rank, bitmap, true) )
        {
            continue; // skip this rank
        }

        for ( uint32_t p = 0; p < PORT_SLCT_PER_MBA; p++ )
        {
            bool badDqs = false;
            if ( SUCCESS != bitmap.badDqs(p, badDqs) )
            {
                continue; // skip this DIMM
            }

            if ( !badDqs )
            {
                continue; // skip this DIMM
            }

            TargetHandleList list = CalloutUtil::getConnectedDimms( i_mba,
                                                                    rank, p );
            if ( 0 == list.size() )
            {
                PRDF_ERR( "[processDq] bad bits present but no connected "
                          "DIMM: MBA=0x%08x rank=%d port=%d", getHuid(i_mba),
                          rank.flatten(), p );
                continue;
            }

            for ( TargetHandleList::iterator i = list.begin();
                  i < list.end(); i++ )
            {
                ++calloutCount;
                commitRestoreCallout( &addDimmCallout, *i, i_mba );
            }
        }
    }

    PRDF_DEXIT("processDq: bad dq dimm count: %d", calloutCount);

    return 0 != calloutCount;
}

void deployDramSpares(TargetHandle_t i_mba)
{
    using namespace fapi;

    bool x4 = PlatServices::isDramWidthX4(i_mba);

    for ( uint32_t r = 0; r < MAX_RANKS_PER_MBA; r++ )
    {
        CenRank rank ( r );
        CenSymbol symbol = CenSymbol::fromSymbol( i_mba, rank, 0 );

        // ignore errors from putSteerMux

        static_cast<void>(
                PlatServices::mssSetSteerMux(i_mba, rank, symbol, false) );

        if( x4 )
        {
            static_cast<void>(
                    PlatServices::mssSetSteerMux(i_mba, rank, symbol, true) );
        }
    }
}

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

int32_t restoreDramRepairs( TargetHandle_t i_mba )
{
    PRDF_ENTER( "restoreDramRepairs(0x%08x)", PlatServices::getHuid(i_mba) );

    bool calloutMade = false;

    uint8_t repairedRankMask = 0, badDimmMask = 0;

    do {

        if(PlatServices::isMemoryPreservingIpl())
        {
            // nothing to do in MPIPL

            break;
        }

        bool spareDramDeploy = PlatServices::mnfgSpareDramDeploy();

        if(spareDramDeploy)
        {
            deployDramSpares(i_mba);
        }

        // in mfg mode, check dq and don't restore anything

        if(PlatServices::areDramRepairsDisabled())
        {
            if(processDq(i_mba))
            {
                calloutMade = true;
            }

            break;
        }

        if(spareDramDeploy)
        {
            // this is an error...the spare dram
            // deploy bit was set but we weren't
            // in mfg mode...log an error for MFG

            errlHndl_t err = NULL;

            PRDF_ERR( "[restoreDramRepairs] "
                    "The specified combination of mfg policy flags is invalid");

            /*@
             * @errortype
             * @reasoncode PRDF_INVALID_CONFIG
             * @subsys EPUB_FIRMWARE_SUBSYS
             * @moduleid PRDF_RESTORE_DRAM_REPAIR
             * @devdesc The specified combination of policy flags is invalid.
             */
            PRDF_CREATE_ERRL(
                    err,
                    ERRL_SEV_PREDICTIVE,
                    ERRL_ETYPE_NOT_APPLICABLE,
                    SRCI_MACH_CHECK,
                    SRCI_NO_ATTR,
                    PRDF_RESTORE_DRAM_REPAIR,
                    FSP_DEFAULT_REFCODE,
                    PRDF_INVALID_CONFIG,
                    0, 0, 0, 0);
            PRDF_COMMIT_ERRL(err, ERRL_ACTION_REPORT);

            // assume mfg mode (no repairs) ...

            break;
        }

        if(SUCCESS != PlatServices::mssRestoreDramRepairs(
                    i_mba,
                    repairedRankMask,
                    badDimmMask))
        {
            // can't check anything if
            // this doesn't work

            PRDF_ERR( "[restoreDramRepairs] "
                    "PlatServices::mssRestoreDramRepairs failed" );

            break;
        }

        // callout bad dimms

        if(processBadDimms(
                    i_mba,
                    badDimmMask))
        {
            calloutMade = true;
        }

        // check repaired ranks for
        // RAS policy violations

        if(processRepairedRanks(
                    i_mba,
                    repairedRankMask))
        {
            calloutMade = true;
        }

    } while(0);

    PRDF_EXIT( "restoreDramRepairs(0x%08x)", PlatServices::getHuid(i_mba) );

    return calloutMade ? FAIL : SUCCESS;
}

} // end namespace PRDF

OpenPOWER on IntegriCloud