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

/**
 *  @file prdfCenMbaCaptureData.C
 *  @brief Utility Functions to capture MBA data
 */

#include <prdfCenMbaCaptureData.H>

// Framwork includes
#include <iipServiceDataCollector.h>
#include <prdfDramRepairUsrData.H>
#include <prdfErrlUtil.H>
#include <prdfExtensibleChip.H>
#include <prdfRasServices.H>
#include <utilmem.H>
#include <UtilHash.H>

// Pegasus includes
#include <prdfCenDqBitmap.H>
#include <prdfCenMarkstore.H>
#include <prdfCenMbaDataBundle.H>
#include <prdfCenMembufDataBundle.H>

using namespace TARGETING;

namespace PRDF
{

using namespace PlatServices;

namespace CenMbaCaptureData
{

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

void addMemChipletFirRegs( ExtensibleChip * i_membChip, CaptureData & io_cd )
{
    #define PRDF_FUNC "[CenMbaCaptureData::addMemChipletFirRegs] "

    int32_t l_rc = SUCCESS;

    do
    {
        if ( NULL == i_membChip )
        {
            PRDF_ERR( PRDF_FUNC "Given target is NULL" );
            break;
        }

        if ( TYPE_MEMBUF != getTargetType(i_membChip->GetChipHandle()) )
        {
            PRDF_ERR( PRDF_FUNC "Invalid target type: i_membChip=0x%08x",
                      i_membChip->GetId() );
            break;
        }

        SCAN_COMM_REGISTER_CLASS * cs_global, * re_global, * spa_global;
        cs_global  = i_membChip->getRegister("GLOBAL_CS_FIR");
        re_global  = i_membChip->getRegister("GLOBAL_RE_FIR");
        spa_global = i_membChip->getRegister("GLOBAL_SPA_FIR");
        l_rc  = cs_global->Read() | re_global->Read() | spa_global->Read();
        if ( SUCCESS != l_rc )
        {
            PRDF_ERR( PRDF_FUNC "Failed to read a GLOBAL register on "
                      "0x%08x", i_membChip->GetId() );
            break;
        }

        // If global bit 3 is not on, can't scom mem chiplets or mba's
        if( ! (cs_global->IsBitSet(3) ||
               re_global->IsBitSet(3) ||
               spa_global->IsBitSet(3)) )
        {
            break;
        }

        i_membChip->CaptureErrorData(io_cd,
                                     Util::hashString("MemChipletRegs"));

        CenMembufDataBundle * membdb = getMembufDataBundle( i_membChip );

        for ( uint32_t i = 0; i < MAX_MBA_PER_MEMBUF; i++ )
        {
            ExtensibleChip * mbaChip = membdb->getMbaChip(i);
            if ( NULL == mbaChip )
            {
                PRDF_ERR( PRDF_FUNC "MEM_CHIPLET registers indicated an "
                          "attention but no chip found: i_membChip=0x%08x "
                          "i=%d", i_membChip->GetId(), i );
                continue;
            }

            mbaChip->CaptureErrorData(io_cd,
                                      Util::hashString("MemChipletRegs") );
        }

    } while (0);

    #undef PRDF_FUNC
}

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

void addEccData( TargetHandle_t i_mbaTrgt, errlHndl_t io_errl )
{
    CaptureData cd;

    // Add DRAM repairs data from hardware.
    captureDramRepairsData( i_mbaTrgt, cd );

    // Add DRAM repairs data from VPD.
    captureDramRepairsVpd( i_mbaTrgt, cd );

    ErrDataService::AddCapData( cd, io_errl );
}

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

void captureDramRepairsData( TARGETING::TargetHandle_t i_mbaTrgt,
                             CaptureData & io_cd )
{
    #define PRDF_FUNC "[CenMbaCaptureData::captureDramRepairsData] "
    using namespace fapi; // for spare config

    int32_t rc = SUCCESS;
    DramRepairMbaData mbaData;

    mbaData.header.isSpareDram = false;
    std::vector<CenRank> masterRanks;

    do
    {
        rc = getMasterRanks( i_mbaTrgt, masterRanks );
        if ( SUCCESS != rc )
        {
            PRDF_ERR( PRDF_FUNC "getMasterRanks() failed" );
            break;
        }
        if( masterRanks.empty() )
        {
            PRDF_ERR( PRDF_FUNC "Master Rank list size is 0");
            break;;
        }
        uint8_t spareConfig = ENUM_ATTR_VPD_DIMM_SPARE_NO_SPARE;
        // check for spare DRAM. Port does not matter.
        // Also this configuration is same for all ranks on MBA.
        rc = getDimmSpareConfig( i_mbaTrgt, masterRanks[0], 0, spareConfig );
        if( SUCCESS != rc )
        {
            PRDF_ERR( PRDF_FUNC "getDimmSpareConfig() failed" );
            break;
        }

        if( ENUM_ATTR_VPD_DIMM_SPARE_NO_SPARE != spareConfig )
            mbaData.header.isSpareDram = true;

        // Iterate all ranks to get DRAM repair data
        for ( std::vector<CenRank>::iterator it = masterRanks.begin();
              it != masterRanks.end(); it++ )
        {
            // Get chip/symbol marks
            CenMark mark;
            rc = mssGetMarkStore( i_mbaTrgt, *it, mark );
            if ( SUCCESS != rc )
            {
                PRDF_ERR( PRDF_FUNC "mssGetMarkStore() Failed");
                continue;
            }

            // Get DRAM spares
            CenSymbol sp0, sp1, ecc;
            rc = mssGetSteerMux( i_mbaTrgt, *it, sp0, sp1, ecc );
            if ( SUCCESS != rc )
            {
                PRDF_ERR( PRDF_FUNC "mssGetSteerMux() failed");
                continue;
            }

            // Add data
            DramRepairRankData rankData = { (*it).getMaster(),
                                            mark.getCM().getSymbol(),
                                            mark.getSM().getSymbol(),
                                            sp0.getSymbol(),
                                            sp1.getSymbol(),
                                            ecc.getSymbol() };
            if ( rankData.valid() )
            {
                mbaData.rankDataList.push_back(rankData);
            }
        }
        // If MBA had some DRAM repair data, add header information
        if( mbaData.rankDataList.size() > 0 )
        {
            mbaData.header.rankCount = mbaData.rankDataList.size();
            mbaData.header.isX4Dram =  isDramWidthX4( i_mbaTrgt );
            UtilMem dramStream;
            dramStream << mbaData;

            #ifndef PPC
            // Fix endianness issues with non PPC machines.
            // This is a workaround. Though UtilMem takes care of endianness,
            // It seems with capture data its not working
            const size_t sz_word = sizeof(uint32_t);

            // Align data with 32 bit boundary
            for (uint32_t i = 0; i < ( dramStream.size()%sz_word ); i++)
            {
                uint8_t dummy = 0;
                dramStream << dummy;
            }
            for ( uint32_t i = 0; i < ( dramStream.size()/sz_word); i++ )
            {
                ((uint32_t*)dramStream.base())[i] =
                            htonl(((uint32_t*)dramStream.base())[i]);
            }
            #endif

            // Allocate space for the capture data.
            BitString dramRepairData ( ( dramStream.size() )*8,
                                               (CPU_WORD *) dramStream.base() );
            io_cd.Add( i_mbaTrgt, Util::hashString("DRAM_REPAIRS_DATA"),
                       dramRepairData );
        }
    }while(0);

    if( FAIL == rc )
        PRDF_ERR( PRDF_FUNC "Failed for MBA 0x%08X", getHuid( i_mbaTrgt ) );

    #undef PRDF_FUNC
}

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

void captureDramRepairsVpd( TargetHandle_t i_mbaTrgt, CaptureData & io_cd )
{
    #define PRDF_FUNC "[captureDramRepairsVpd] "

    // Get the maximum capture data size.
    static const size_t sz_rank  = sizeof(uint8_t);
    static const size_t sz_entry = MBA_DIMMS_PER_RANK * DIMM_DQ_RANK_BITMAP_SIZE;
    static const size_t sz_word  = sizeof(CPU_WORD);
    int32_t rc = SUCCESS;

    do
    {
        std::vector<CenRank> masterRanks;
        rc = getMasterRanks( i_mbaTrgt, masterRanks );
        if ( SUCCESS != rc )
        {
            PRDF_ERR( PRDF_FUNC "getMasterRanks() failed" );
            break;
        }

        if( masterRanks.empty() )
        {
            PRDF_ERR( PRDF_FUNC "Master Rank list size is 0");
            break;
        }

        // Get the maximum capture data size.
        size_t sz_maxData = masterRanks.size() * (sz_rank + sz_entry);

        // Adjust the size for endianness.
        sz_maxData = ((sz_maxData + sz_word-1) / sz_word) * sz_word;

        // Initialize to 0.
        uint8_t capData[sz_maxData];
        memset( capData, 0x00, sz_maxData );

        // Iterate all ranks to get VPD data
        uint32_t idx = 0;
        for ( std::vector<CenRank>::iterator it = masterRanks.begin();
              it != masterRanks.end(); it++ )
        {
            CenDqBitmap bitmap;
            uint8_t rank = it->getMaster();

            if ( SUCCESS != getBadDqBitmap(i_mbaTrgt, *it, bitmap, true) )
            {
                PRDF_ERR( PRDF_FUNC "getBadDqBitmap() failed: MBA=0x%08x"
                          " rank=%d", getHuid(i_mbaTrgt), rank );
                continue; // skip this rank
            }

            if ( bitmap.badDqs() ) // make sure the data is non-zero
            {
                // Add the rank, then the entry data.
                capData[idx] = rank;              idx += sz_rank;
                memcpy(&capData[idx], bitmap.getData(), sz_entry);
                idx += sz_entry;
            }
        }

        if( 0 == idx ) break; // Nothing to capture

        // Fix endianness issues with non PPC machines.
        size_t sz_capData = idx;
        sz_capData = ((sz_capData + sz_word-1) / sz_word) * sz_word;
        for ( uint32_t i = 0; i < (sz_capData/sz_word); i++ )
            ((CPU_WORD*)capData)[i] = htonl(((CPU_WORD*)capData)[i]);

        // Add data to capture data.
        BitString bs ( sz_capData*8, (CPU_WORD *) &capData );
        io_cd.Add( i_mbaTrgt, Util::hashString("DRAM_REPAIRS_VPD"), bs );

    }while(0);

    if( FAIL == rc )
        PRDF_ERR( PRDF_FUNC "Failed for MBA 0x%08X", getHuid( i_mbaTrgt ) );

    #undef PRDF_FUNC
}

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

void addExtMemMruData( const MemoryMru & i_memMru, errlHndl_t io_errl )
{
    #define PRDF_FUNC "[addExtMemMruData] "

    MemoryMruData::ExtendedData extMemMru ( i_memMru.toUint32() );

    do
    {
        int32_t l_rc = SUCCESS;

        TargetHandle_t mbaTrgt = i_memMru.getMbaTrgt();

        // Get the DRAM width.
        extMemMru.isX4Dram = isDramWidthX4( mbaTrgt ) ? 1 : 0;

        // Get the DIMM type.
        bool isBufDimm = false;
        l_rc = isMembufOnDimm( mbaTrgt, isBufDimm );
        if ( SUCCESS != l_rc )
        {
            PRDF_ERR( PRDF_FUNC "isMembufOnDimm() failed. MBA:0x%08x",
                      getHuid(mbaTrgt) );
            break;
        }
        extMemMru.isBufDimm = isBufDimm ? 1 : 0;

        if ( isBufDimm )
        {
            // Get the raw card type (CDIMMS only).
            CEN_SYMBOL::WiringType cardType = CEN_SYMBOL::WIRING_INVALID;
            l_rc = getMemBufRawCardType( mbaTrgt, cardType );
            if ( SUCCESS != l_rc )
            {
                PRDF_ERR( PRDF_FUNC "getMemBufRawCardType() failed. MBA:0x%08x",
                          getHuid(mbaTrgt) );
                break;
            }
            extMemMru.cardType = cardType;
        }
        else
        {
            // Get the 80-byte DQ map (ISDIMMS only). This is only needed if
            // the MemoryMru contains a single DIMM callout with a valid symbol.
            if ( i_memMru.getSymbol().isValid() )
            {
                TargetHandleList partList = i_memMru.getCalloutList();
                if ( 1         != partList.size()           ||
                     TYPE_DIMM != getTargetType(partList[0]) )
                {
                    PRDF_ERR( PRDF_FUNC "Symbol is valid but callout is not a "
                              "single DIMM." );
                    break;
                }

                errlHndl_t l_errl = getFapiDimmDqAttr( partList[0],
                                                   &(extMemMru.dqMapping[0]) );
                if ( NULL != l_errl )
                {
                    PRDF_ERR( PRDF_FUNC "getFapiDimmDqAttr() failed. "
                              "DIMM:0x%08x", getHuid(partList[0]) );
                    PRDF_COMMIT_ERRL( l_errl, ERRL_ACTION_REPORT );
                    break;
                }
            }
        }

        // If we reach this point, nothing failed and the data is valid.
        extMemMru.isValid = 1;

    } while (0);

    size_t sz_buf = sizeof(extMemMru);
    uint8_t buf[sz_buf]; memset( buf, 0x00, sz_buf );

    buf[0] = (extMemMru.mmMeld.u >> 24) & 0xff;
    buf[1] = (extMemMru.mmMeld.u >> 16) & 0xff;
    buf[2] = (extMemMru.mmMeld.u >>  8) & 0xff;
    buf[3] =  extMemMru.mmMeld.u        & 0xff;

    buf[4] = extMemMru.cardType;

    buf[5] = extMemMru.isBufDimm << 7 |
             extMemMru.isX4Dram  << 6 |
             extMemMru.isValid   << 5;

    memcpy( &buf[8], &extMemMru.dqMapping[0], sizeof(extMemMru.dqMapping) );

    // Add the extended MemoryMru to the error log.
    PRDF_ADD_FFDC( io_errl, buf, sz_buf, ErrlVer1, ErrlMruData );

    #undef PRDF_FUNC
}

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

}  //end namespace MbaCaptureData

} // end namespace PRDF


OpenPOWER on IntegriCloud