summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/lib/dimm/ddr4/state_machine.H
blob: 60fa5d9dbda2a33b252ea3b80bc91300db0ffde1 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/dimm/ddr4/state_machine.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,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 state_machine.H
/// @brief state_machine delcaration
///
// *HWP HWP Owner: Andre Marin <aamarin@us.ibm.com>
// *HWP HWP Backup: Brian Silver <bsilver@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: HB:FSP

#ifndef _MSS_STATE_MACHINE_H_
#define _MSS_STATE_MACHINE_H_

#include <fapi2.H>
#include <lib/utils/c_str.H>
#include <lib/utils/checker.H>

namespace mss
{

enum class transition
{
    RISING_EDGE, ///< Looking for 1st Low to High transition
    FALLING_EDGE, ///< Looking for 1st High to Low transition
};

enum class fsm_state
{
    UNINITIALIZED, ///< Initial state
    HIGH, ///< High state (logical 1)
    LOW, ///< Low state (logical 0)
    DONE, ///< Final state (First 1->0 or 0->1 transition)
};

///
/// @class state_machine
/// @brief State machine for LRDIMM training
///
class state_machine
{
    public:
        fsm_state iv_state;
        uint64_t iv_delay;

        ///
        /// @brief Default ctor
        /// @param[in] i_target DIMM target
        ///
        state_machine(const fapi2::Target< fapi2::TARGET_TYPE_DIMM >& i_target):
            iv_state(fsm_state::UNINITIALIZED),
            iv_delay(0),
            iv_target(i_target)
        {}

        ///
        /// @brief Default dctor
        ///
        ~state_machine() = default;

        ///
        /// @brief Sets current state
        /// @tparam T first transition we are looking for
        /// @param[in] i_data DRAM DQ data
        /// @param[in] i_nibble current nibble
        /// @param[in] i_phase_timing current phase step
        ///
        template< transition T >
        fapi2::ReturnCode next_transition( const fapi2::variable_buffer& i_data,
                                           const uint64_t i_nibble,
                                           const uint64_t i_phase_timing)
        {
            switch(iv_state)
            {
                case fsm_state::UNINITIALIZED:
                    uninitialized(i_data, i_nibble, i_phase_timing);
                    break;

                case fsm_state::HIGH:
                    high<T>(i_data, i_nibble, i_phase_timing);
                    break;

                case fsm_state::LOW:
                    low<T>(i_data, i_nibble, i_phase_timing);
                    break;

                case fsm_state::DONE:
                    FAPI_INF("%s No state change. Already in DONE state.", mss::c_str(iv_target) );
                    break;

                default:
                    // By default we are unitialized, we switch state based on
                    // AADR & AAER register data that represents DRAM DQ data.
                    // If we got here something bad happened, iv_state was corrupted somehow.
                    // Lets tell someone with FFDC
                    FAPI_TRY( check::invalid_dq_data(iv_target, false, i_data, i_phase_timing, i_nibble) );
                    break;
            }// switch

        fapi_try_exit:
            return fapi2::current_err;
        }

    private:
        static constexpr size_t NIBBLE_OFFSET = 4;
        const fapi2::Target< fapi2::TARGET_TYPE_DIMM > iv_target;
        char iv_str_buffer[fapi2::MAX_ECMD_STRING_LEN];

        ///
        /// @brief Helper function to set uninitialized state transition
        /// @param[in] i_data DRAM DQ data
        /// @param[in] i_nibble current nibble
        /// @param[in] i_phase_timing current phase step
        ///
        void uninitialized( const fapi2::variable_buffer& i_data,
                            const uint64_t i_nibble,
                            const uint64_t i_phase_timing );

        ///
        /// @brief Helper function to set high state transition
        /// @tparam T first transition we are looking for
        /// @param[in] i_data DRAM DQ data
        /// @param[in] i_nibble current nibble
        /// @param[in] i_phase_timing current phase step
        ///
        template< transition T >
        void high( const fapi2::variable_buffer& i_data,
                   const uint64_t i_nibble,
                   const uint64_t i_phase_timing );

        ///
        /// @brief Helper function to set low state transition
        /// @tparam T first transition we are looking for
        /// @param[in] i_data DRAM DQ data
        /// @param[in] i_nibble current nibble
        /// @param[in] i_phase_timing current phase step
        ///
        template< transition T >
        void low( const fapi2::variable_buffer& i_data,
                  const uint64_t i_nibble,
                  const uint64_t i_phase_timing );

        ///
        /// @brief Helper function for trace boilerplate
        /// @param[in] i_data DRAM DQ data
        /// @param[in] i_nibble current nibble
        /// @param[in] i_phase_timing current phase step
        ///
        void print_debug( const fapi2::variable_buffer& i_data,
                          const uint64_t i_nibble,
                          const uint64_t i_phase_timing );
};

}// mss

#endif
OpenPOWER on IntegriCloud