summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/lib/workarounds/dqs_align_workarounds.C
blob: 123329307086531d038e55e4a50f67e9125c8616 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/workarounds/dqs_align_workarounds.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 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                                                     */

#include <fapi2.H>
#include <lib/workarounds/dqs_align_workarounds.H>
#include <p9_mc_scom_addresses.H>
#include <mss_attribute_accessors.H>
#include <lib/phy/seq.H>
#include <lib/phy/phy_cntrl.H>

namespace mss
{

namespace workarounds
{

namespace dqs_align
{

///
/// @brief Sets tRFC cyles for sequencer
/// @param[in] i_target the fapi2 target of the port
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
fapi2::ReturnCode set_timing0_trfc(const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target)
{
    // May need to add freq/tRFI attr dependency later but for now use this value
    // Provided by Ryan King
    constexpr size_t TRFC_CYCLES = 9;

    fapi2::buffer<uint64_t> l_data;
    FAPI_TRY( mss::seq::read_timing0(i_target, l_data) );

    mss::seq::set_trfc_cycles(l_data, TRFC_CYCLES);
    FAPI_TRY( mss::seq::write_timing0(i_target, l_data) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Set PHY sequencer to trigger refresh during init cal
/// @param[in] i_target the fapi2 target of the port
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
fapi2::ReturnCode set_init_cal_refresh(const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target)
{
    // Hard coded settings provided by Ryan King for this workaround
    constexpr size_t REF_COUNT = 0xF;
    constexpr size_t REF_CNTL = 0b11;
    constexpr size_t REF_INTERVAL = 0b0010011;

    fapi2::buffer<uint64_t> l_data;
    FAPI_TRY( mss::pc::read_init_cal_config1(i_target, l_data) );

    mss::pc::set_refresh_count(l_data, REF_COUNT);
    mss::pc::set_refresh_control(l_data, REF_CNTL);
    mss::pc::set_refresh_all_ranks(l_data, mss::HIGH);
    mss::pc::set_snoop_dis(l_data, mss::LOW);
    mss::pc::set_refresh_interval(l_data, REF_INTERVAL);

    FAPI_TRY( mss::pc::write_init_cal_config1(i_target, l_data) )

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Clear the PHY sequencer refresh
/// @param[in] i_target the fapi2 target of the port
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
fapi2::ReturnCode clear_init_cal_refresh(const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target)
{
    // Turns off refresh
    constexpr size_t REF_CNTL = 0b00;

    fapi2::buffer<uint64_t> l_data;
    FAPI_TRY( mss::pc::read_init_cal_config1(i_target, l_data) );

    mss::pc::set_refresh_control(l_data, REF_CNTL);

    FAPI_TRY( mss::pc::write_init_cal_config1(i_target, l_data) )

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Set PHY sequencer to trigger refresh during init cal
/// @param[in] i_target the fapi2 target of the port
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
fapi2::ReturnCode turn_on_refresh(const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target)
{
    uint8_t l_attr = 0;
    FAPI_TRY( mss::phy_seq_refresh(i_target, l_attr) );

    if( l_attr == fapi2::ENUM_ATTR_MSS_PHY_SEQ_REFRESH_DISABLE )
    {
        FAPI_INF("Skipping workaround to trigger refresh for the PHY sequencer %s", mss::c_str(i_target));
        return fapi2::FAPI2_RC_SUCCESS;
    }

    FAPI_TRY( set_timing0_trfc(i_target),
              "set_timing0_trfc() failed for %s", mss::c_str(i_target) );

    FAPI_TRY( set_init_cal_refresh(i_target),
              "set_init_cal_refresh() failed for %s", mss::c_str(i_target) );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Turn off refresh after dqs training has been run
/// @param[in] i_target the fapi2 target of the port
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS if ok
///
fapi2::ReturnCode turn_off_refresh(const fapi2::Target<fapi2::TARGET_TYPE_MCA>& i_target)
{
    uint8_t l_attr = 0;
    FAPI_TRY( mss::phy_seq_refresh(i_target, l_attr) );

    if( l_attr == fapi2::ENUM_ATTR_MSS_PHY_SEQ_REFRESH_DISABLE )
    {
        FAPI_INF("Refresh for PHY sequencer is already off %s", mss::c_str(i_target));
        return fapi2::FAPI2_RC_SUCCESS;
    }

    FAPI_TRY( clear_init_cal_refresh(i_target),
              "set_init_cal_refresh() failed for %s", mss::c_str(i_target) );

fapi_try_exit:
    return fapi2::current_err;
}

}
}
}
OpenPOWER on IntegriCloud