summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/lib/mc/perf_reg.C
blob: ef9933edb1e5b39ba1a51af626fb9dcd50df0de3 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/mc/perf_reg.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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 perf_reg.C
/// @brief Subroutines to manipulate the memory controller performance registers
///
// *HWP HWP Owner: Stephen Glancy <sglancy@us.ibm.com>
// *HWP HWP Backup: Andre Marin <aamarin@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 3
// *HWP Consumed by: FSP:HB

#include <fapi2.H>

#include <p9_mc_scom_addresses.H>
#include <p9_mc_scom_addresses_fld.H>

#include <lib/mss_attribute_accessors.H>
#include <lib/shared/mss_const.H>
#include <lib/mc/mc.H>
#include <generic/memory/lib/utils/scom.H>
#include <lib/dimm/kind.H>
#include <generic/memory/lib/utils/find.H>

using fapi2::TARGET_TYPE_MCA;
using fapi2::TARGET_TYPE_MCS;
using fapi2::TARGET_TYPE_DIMM;

namespace mss
{

namespace mc
{

///
/// @brief Perform initializations of the MC performance registers
/// @note Some of these bits are taken care of in the scom initfiles
/// @param[in] i_target the target which has the MCA to map
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode setup_perf2_register(const fapi2::Target<TARGET_TYPE_MCA>& i_target)
{
    fapi2::buffer<uint64_t> l_data;

    // Get the values we need to put in the register
    uint64_t l_value;
    FAPI_TRY( calculate_perf2(i_target, l_value) );

    // Setup the registers
    FAPI_TRY( mss::getScom(i_target, MCS_0_PORT02_MCPERF2, l_data) );

    // Per S. Powell 7/16, setup these registers but don't enable the function yet. So enable bits are
    // intentionally not set
    l_data.insertFromRight<MCS_PORT02_MCPERF2_REFRESH_BLOCK_CONFIG,
                           MCS_PORT02_MCPERF2_REFRESH_BLOCK_CONFIG_LEN>(l_value);

    FAPI_TRY( mss::putScom(i_target, MCS_0_PORT02_MCPERF2, l_data) );

fapi_try_exit:
    return fapi2::FAPI2_RC_SUCCESS;
}

///
/// @brief Calculate the value of the MC perf2 register.
/// @param[in] i_target the target which has the MCA to map
/// @param[out] o_value the perf2 value for the MCA
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode calculate_perf2(const fapi2::Target<TARGET_TYPE_MCA>& i_target, uint64_t& o_value)
{
    //
    // From Senor Powell 7/16
    // if (slots=1, masters=1)
    //   MCPERF2_Refresh_Block_Config=0b000
    // if (slots=1, masters=2)
    //   MCPERF2_Refresh_Block_Config=0b001
    // if (slots=1, masters=4)
    //  MCPERF2_Refresh_Block_Config=0b100
    // if (slots=2, masters=1)
    //  MCPERF2_Refresh_Block_Config=0b010
    // if (slots=2, masters=2)
    //  MCPERF2_Refresh_Block_Config=0b011
    // if (slots=2, masters=4)
    //  MCPERF2_Refresh_Block_Config=0b100
    //
    // if slot0 is 2 masters and slot1 is 1 master, just choose the 2 slot, 2 masters setting.
    // (i.e., choose the max(mranks_dimm1, mranks_dimm2)

    constexpr uint64_t l_refresh_values[MAX_DIMM_PER_PORT][MAX_RANK_PER_DIMM] =
    {
        {0b000, 0b001, 0, 0b100}, // Skip the ol' 3 rank DIMM
        {0b010, 0b011, 0, 0b100}
    };

    FAPI_INF("Calculating perf2 register for MCA%d (%d)", mss::pos(i_target), mss::index(i_target));

    // Find the DIMM on this port with the most master ranks.
    // That's how we know which element in the table to use.
    // uint8_t so I can use it to read from an attribute directly

    uint8_t l_mrank_index = 0;
    uint8_t l_master_ranks_zero = 0;
    uint8_t l_master_ranks_one = 0;

    fapi2::buffer<uint64_t> l_data;

    const auto l_dimm = mss::find_targets<TARGET_TYPE_DIMM>(i_target);
    const auto l_slot_index = l_dimm.size() - 1;

    switch(l_dimm.size())
    {
        // No DIMM, nothing to do
        case 0:
            return fapi2::FAPI2_RC_SUCCESS;
            break;

        // One DIMM, we've got the slots of fun
        case 1:
            FAPI_TRY( mss::eff_num_master_ranks_per_dimm(l_dimm[0], l_mrank_index) );
            --l_mrank_index;
            FAPI_INF("1 DIMM mranks: D0[%d] index %d", l_mrank_index + 1, l_mrank_index);
            break;

        // Two DIMM, find the max of the master ranks
        case 2:
            {
                FAPI_TRY( mss::eff_num_master_ranks_per_dimm(l_dimm[0], l_master_ranks_zero) );
                FAPI_TRY( mss::eff_num_master_ranks_per_dimm(l_dimm[1], l_master_ranks_one) );

                l_mrank_index = std::max(l_master_ranks_zero, l_master_ranks_one) - 1;
                FAPI_INF("2 DIMM mranks: D0[%d] D1[%d] index %d", l_master_ranks_zero, l_master_ranks_one, l_mrank_index);
            }
            break;

        default:
            // We have a bug - no way to get more than 2 DIMM in a dual-drop system
            FAPI_ERR("seeing %d DIMM on %s", l_dimm.size(), mss::c_str(i_target));
            fapi2::Assert(false);
            break;
    };

    FAPI_INF("Refresh Block Config: %u ([%d][%d] populated slots: %d, max mranks: %d)",
             l_refresh_values[l_slot_index][l_mrank_index],
             l_slot_index, l_mrank_index,
             l_slot_index + 1, l_mrank_index + 1);

    o_value = l_refresh_values[l_slot_index][l_mrank_index];

fapi_try_exit:
    return fapi2::current_err;
}

} // namespace

} // namespace
OpenPOWER on IntegriCloud