summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/memory/lib/ecc/galois.H
blob: 98135095550eeb2455bb27d141946ec3486772a1 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/ecc/galois.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 galois.H
/// @brief Translate ECC mark Galois codes to symbol and DQ
///
// *HWP HWP Owner: Louis Stermole <stermole@us.ibm.com>
// *HWP HWP Backup: Stephen Glancy <sglancy@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 3
// *HWP Consumed by: HB:FSP

#ifndef _MSS_ECC_GALOIS_H_
#define _MSS_ECC_GALOIS_H_

#include <lib/ecc/ecc_traits.H>

namespace mss
{

namespace ecc
{

///
/// @brief Return symbol value from a given Galois code
/// @tparam T fapi2 Target Type defaults to TARGET_TYPE_MCA
/// @tparam TT traits type defaults to eccTraits<T>
/// @param[in] i_galois the Galois code
/// @param[out] o_symbol symbol value represented by given Galois code
/// @return FAPI2_RC_SUCCESS iff all is ok
///
template< fapi2::TargetType T = fapi2::TARGET_TYPE_MCA, typename TT = eccTraits<T> >
fapi2::ReturnCode galois_to_symbol( const uint8_t i_galois, uint8_t& o_symbol )
{
    const auto& l_p = std::find(TT::symbol2galois, (TT::symbol2galois + MAX_DQ_BITS), i_galois);

    FAPI_ASSERT( l_p != (TT::symbol2galois + MAX_DQ_BITS),
                 fapi2::MSS_INVALID_GALOIS_TO_SYMBOL()
                 .set_GALOIS(i_galois),
                 "Invalid Galois code: 0x%02x",
                 i_galois);

    o_symbol = (l_p - TT::symbol2galois);

    return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Return Galois code from a given symbol value
/// @tparam T fapi2 Target Type defaults to TARGET_TYPE_MCA
/// @tparam TT traits type defaults to eccTraits<T>
/// @param[in] i_symbol the symbol value
/// @param[out] o_galois Galois code represented by given symbol
/// @return FAPI2_RC_SUCCESS iff all is ok
///
template< fapi2::TargetType T = fapi2::TARGET_TYPE_MCA, typename TT = eccTraits<T> >
fapi2::ReturnCode symbol_to_galois( const uint8_t i_symbol, uint8_t& o_galois )
{
    FAPI_ASSERT( i_symbol < MAX_DQ_BITS,
                 fapi2::MSS_INVALID_SYMBOL_FOR_GALOIS()
                 .set_SYMBOL(i_symbol),
                 "Invalid symbol: %d",
                 i_symbol);

    o_galois = TT::symbol2galois[i_symbol];

    return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Return symbol value from a given DQ index
/// @tparam T fapi2 Target Type defaults to TARGET_TYPE_MCA
/// @tparam TT traits type defaults to eccTraits<T>
/// @param[in] i_dq the DQ index
/// @param[out] o_symbol symbol value represented by given DQ index
/// @return FAPI2_RC_SUCCESS iff all is ok
///
template< fapi2::TargetType T = fapi2::TARGET_TYPE_MCA, typename TT = eccTraits<T> >
fapi2::ReturnCode dq_to_symbol( const uint8_t i_dq, uint8_t& o_symbol )
{
    const auto& l_p = std::find(TT::symbol2dq, (TT::symbol2dq + MAX_DQ_BITS), i_dq);

    FAPI_ASSERT( l_p != (TT::symbol2dq + MAX_DQ_BITS),
                 fapi2::MSS_INVALID_DQ_TO_SYMBOL()
                 .set_DQ(i_dq),
                 "Invalid DQ index: %d",
                 i_dq);

    o_symbol = (l_p - TT::symbol2dq);

    return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Return DQ index from a given symbol value
/// @tparam T fapi2 Target Type defaults to TARGET_TYPE_MCA
/// @tparam TT traits type defaults to eccTraits<T>
/// @param[in] i_symbol the symbol value
/// @param[out] o_dq DQ index represented by given symbol value
/// @return FAPI2_RC_SUCCESS iff all is ok
///
template< fapi2::TargetType T = fapi2::TARGET_TYPE_MCA, typename TT = eccTraits<T> >
fapi2::ReturnCode symbol_to_dq( const uint8_t i_symbol, uint8_t& o_dq )
{
    FAPI_ASSERT( i_symbol < MAX_DQ_BITS,
                 fapi2::MSS_INVALID_SYMBOL_TO_DQ()
                 .set_SYMBOL(i_symbol),
                 "symbol_to_dq: invalid symbol: %d",
                 i_symbol);

    o_dq = TT::symbol2dq[i_symbol];

    return fapi2::FAPI2_RC_SUCCESS;
fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Return DQ index from a given Galois code
/// @tparam T fapi2 Target Type defaults to TARGET_TYPE_MCA
/// @tparam TT traits type defaults to eccTraits<T>
/// @param[in] i_galois the Galois code
/// @param[out] o_dq DQ index represented by given Galois code
/// @return FAPI2_RC_SUCCESS iff all is ok
///
template< fapi2::TargetType T = fapi2::TARGET_TYPE_MCA, typename TT = eccTraits<T> >
fapi2::ReturnCode galois_to_dq( const uint8_t i_galois, uint8_t& o_dq  )
{
    uint8_t l_symbol = 0;

    FAPI_TRY( galois_to_symbol<T>(i_galois, l_symbol), "Failed galois_to_symbol");
    FAPI_TRY( symbol_to_dq<T>(l_symbol, o_dq), "Failed symbol_to_dq" );

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Return Galois code from a given DQ index
/// @tparam T fapi2 Target Type defaults to TARGET_TYPE_MCA
/// @tparam TT traits type defaults to eccTraits<T>
/// @param[in] i_dq the DQ index
/// @param[out] o_galois Galois code represented by given symbol
/// @return FAPI2_RC_SUCCESS iff all is ok
///
template< fapi2::TargetType T = fapi2::TARGET_TYPE_MCA, typename TT = eccTraits<T> >
fapi2::ReturnCode dq_to_galois( const uint8_t i_dq, uint8_t& o_galois )
{
    uint8_t l_symbol = 0;

    FAPI_TRY( mss::ecc::dq_to_symbol<T>(i_dq, l_symbol), "Failed dq_to_symbol");
    FAPI_TRY( mss::ecc::symbol_to_galois<T>(l_symbol, o_galois) , "Failed symbol_to_galois" );

fapi_try_exit:
    return fapi2::current_err;
}

} // close namespace ecc

} // close namespace mss
#endif
OpenPOWER on IntegriCloud