summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/plat/mem/prdfMemThresholds.C
blob: 136635d9460b5e3a9a2813723737114e038234d0 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/plat/mem/prdfMemThresholds.C $       */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2013,2017                        */
/* [+] 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  prdfMemThresholds.C
 *  @brief Utility functions used to get specific memory thresholds.
 */

// Framework includes
#include <prdfExtensibleChip.H>
#include <prdfMfgThresholdMgr.H>
#include <prdfPlatServices.H>

// Platform includes
#include <prdfMemThresholds.H>
#include <prdfMemUtils.H>

using namespace TARGETING;

namespace PRDF
{

using namespace PlatServices;

enum DefaultThresholds
{
    MCA_RCD_PARITY_NON_MNFG_TH = 32, ///< Non-MNFG RCD parity error TH
    MCA_IUE_NON_MNFG_TH        = 8,  ///< Non-MNFG IUE TH
    MBA_RCE_NON_MNFG_TH        = 8,  ///< Non-MNFG RCE TH
    MBA_SCRUB_CE_NON_MNFG_TH   = 80, ///< Non-MNFG Scrub soft/inter CE TH
};

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

/**
 * @brief  Returns the manufacturing memory CE thresholds Per 2GB ( base ).
 */
uint8_t getMnfgCeTh()
{
    #ifndef __HOSTBOOT_RUNTIME

    return MfgThresholdMgr::getInstance()->
            getThreshold( TARGETING::ATTR_MNFG_TH_CEN_MBA_IPL_SOFT_CE_TH_ALGO );

    #else

    return MfgThresholdMgr::getInstance()->
            getThreshold( TARGETING::ATTR_MNFG_TH_CEN_MBA_RT_SOFT_CE_TH_ALGO );

    #endif

}

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

#ifdef __HOSTBOOT_MODULE

ThresholdResolution::ThresholdPolicy getRcdParityTh()
{
    uint32_t th = MCA_RCD_PARITY_NON_MNFG_TH;

    if ( mfgMode() )
    {
        th = MfgThresholdMgr::getInstance()->
                                   getThreshold(ATTR_MNFG_TH_RCD_PARITY_ERRORS);
    }

    return ThresholdResolution::ThresholdPolicy( th,
                                                 ThresholdResolution::ONE_DAY );
}

#endif

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

#ifdef __HOSTBOOT_MODULE

ThresholdResolution::ThresholdPolicy getIueTh()
{
    uint32_t th = MCA_IUE_NON_MNFG_TH;

    if ( mfgMode() )
    {
        th = MfgThresholdMgr::getInstance()->
                                         getThreshold(ATTR_MNFG_TH_MEMORY_IUES);
    }

    return ThresholdResolution::ThresholdPolicy( th,
                                                 ThresholdResolution::ONE_DAY );
}

#endif

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

ThresholdResolution::ThresholdPolicy getRceThreshold()
{
    uint32_t th = MBA_RCE_NON_MNFG_TH;

    if ( mfgMode() )
    {
        th = MfgThresholdMgr::getInstance()->
                           getThreshold( ATTR_MNFG_TH_CEN_MBA_RT_RCE_PER_RANK );

        if( th > MBA_RCE_NON_MNFG_TH ) th = MBA_RCE_NON_MNFG_TH;
    }

    return ThresholdResolution::ThresholdPolicy( th,
                                                 ThresholdResolution::ONE_DAY );
}

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

template <TYPE T>
void getMnfgMemCeTh( ExtensibleChip * i_chip, const MemRank & i_rank,
                     uint32_t & o_cePerDram, uint32_t & o_cePerRank,
                     uint32_t & o_cePerDimm )
{
    // Get base threshold ( 2GB ).
    uint8_t baseTh = getMnfgCeTh();

    // A base threhold of 0 indicates there should be no thresholding.
    if ( 0 == baseTh )
    {
        o_cePerDram = o_cePerRank = o_cePerDimm =
            MfgThreshold::INFINITE_LIMIT_THR;
    }
    else
    {
        // Get DRAM size
        uint8_t size = MemUtils::getDramSize<T>( i_chip, i_rank.getDimmSlct() );

        // Get number of ranks per DIMM select.
        uint8_t rankCount = getNumRanksPerDimm<T>( i_chip->getTrgt(),
                                                   i_rank.getDimmSlct() );
        PRDF_ASSERT( 0 != rankCount ); // Code bug.

        // Get number of allowed CEs.
        uint8_t baseAllowed = baseTh - 1;

        // Calculate CEs per DRAM.
        //   The DRAM size is in MBAXCR[6:7], where 0 = 2Gb, 1 = 4Gb, 2 = 8Gb,
        //   and 3 = 16 Gb. So the allowed CEs per DRAM can be calculated with
        //   the following:
        //         perDram = base * 2^(MBAXCR[6:7]+1) * (9/16)
        //     or, perDram = (base << MBAXCR[6:7]+1)  * (9/16)
        uint32_t computeBase = (baseAllowed << (size+1)) * 9;
        o_cePerDram = (computeBase + 8) / 16;

        // Calculate CEs per DIMM.
        o_cePerDimm = ((computeBase * (2 + rankCount)) + 8) / 16;

        // Calculate CEs per rank per DIMM.
        // Same as perDimm where rankCount is 1;
        o_cePerRank = ((computeBase * (2 + 1)) + 8) / 16;
    }
}

// need these templates to avoid linker errors
template
void getMnfgMemCeTh<TYPE_MCA>( ExtensibleChip * i_chip, const MemRank & i_rank,
                               uint32_t & o_cePerDram, uint32_t & o_cePerRank,
                               uint32_t & o_cePerDimm );

template
void getMnfgMemCeTh<TYPE_MBA>( ExtensibleChip * i_chip, const MemRank & i_rank,
                               uint32_t & o_cePerDram, uint32_t & o_cePerRank,
                               uint32_t & o_cePerDimm );

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

template <TYPE T>
uint32_t getScrubCeThreshold( ExtensibleChip * i_chip, const MemRank & i_rank )
{
    uint32_t o_thr = MBA_SCRUB_CE_NON_MNFG_TH;

    if ( mfgMode() )
    {
        uint32_t junk1 = 0, junk2 = 0;

        getMnfgMemCeTh<T>( i_chip, i_rank, o_thr, junk1, junk2 );

        // getMnfgMemCeTh() returns the number of CEs allowed. Will need to add
        // one to get the real threshold.
        o_thr++;
    }

    return o_thr;
}

// need these templates to avoid linker errors
template
uint32_t getScrubCeThreshold<TYPE_MCA>( ExtensibleChip * i_chip,
                                        const MemRank & i_rank );
template
uint32_t getScrubCeThreshold<TYPE_MBA>( ExtensibleChip * i_chip,
                                        const MemRank & i_rank );

} // end namespace PRDF

OpenPOWER on IntegriCloud