summaryrefslogtreecommitdiffstats
path: root/src/usr/util/utilcommonattr.C
blob: 32fdc5cfd2a51c45c54be54b814b0ef1420e6076 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/util/utilcommonattr.C $                               */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017,2019                        */
/* [+] 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 <util/utilcommonattr.H>

#include "utilbase.H"
#include <util/util_reasoncodes.H>
#include <errl/errlmanager.H>

#include <p9_frequency_buckets.H>
namespace Util
{

errlHndl_t getObusPllBucket(TARGETING::Target * i_chipTarget,
                            uint8_t &o_bucket_val,
                            const uint8_t i_index)
{
    errlHndl_t l_errl = nullptr;

    // Get the corresponding FREQ_O_MHZ frequency number
    TARGETING::ATTR_FREQ_O_MHZ_type l_freq_array;
    assert(i_chipTarget->
        tryGetAttr<TARGETING::ATTR_FREQ_O_MHZ>(l_freq_array),
        "getPllBucket() failed to get ATTR_FREQ_O_MHZ");

    // Get the frequency list from the chip
    const uint32_t *l_freqList = nullptr;

    TARGETING::ATTR_MODEL_type l_chipModel =
        i_chipTarget->getAttr<TARGETING::ATTR_MODEL>();

    TARGETING::ATTR_EC_type l_chipECLevel =
        i_chipTarget->getAttr<TARGETING::ATTR_EC>();

    if(l_chipModel == TARGETING::MODEL_NIMBUS)
    {
        switch (l_chipECLevel)
        {
            case 0x10:
                l_freqList = OBUS_PLL_FREQ_LIST_P9N_10;
                break;
            case 0x20:
                l_freqList = OBUS_PLL_FREQ_LIST_P9N_20;
                break;
            case 0x21:
                l_freqList = OBUS_PLL_FREQ_LIST_P9N_21;
                break;
            case 0x22:
                l_freqList = OBUS_PLL_FREQ_LIST_P9N_22;
                break;
            case 0x23:
                l_freqList = OBUS_PLL_FREQ_LIST_P9N_23;
                break;
            default:
                TRACFCOMP(g_util_trace, "Unknown EC level 0x%x for NIMBUS",
                    l_chipECLevel);
                break;
        }
    }
    else if(l_chipModel == TARGETING::MODEL_CUMULUS)
    {
        switch (l_chipECLevel)
        {
            case 0x10:
                l_freqList = OBUS_PLL_FREQ_LIST_P9C_10;
                break;
            case 0x11:
                l_freqList = OBUS_PLL_FREQ_LIST_P9C_11;
                break;
            case 0x12:
                l_freqList = OBUS_PLL_FREQ_LIST_P9C_12;
                break;
            case 0x13:
                l_freqList = OBUS_PLL_FREQ_LIST_P9C_13;
                break;
            default:
                TRACFCOMP(g_util_trace, "Unknown EC level 0x%x for CUMULUS",
                    l_chipECLevel);
                break;
        }
    }
    else if(l_chipModel == TARGETING::MODEL_AXONE)
    {
        switch (l_chipECLevel)
        {
            case 0x10:
                l_freqList = OBUS_PLL_FREQ_LIST_P9A_10;
                break;
            case 0x11:
                l_freqList = OBUS_PLL_FREQ_LIST_P9A_11;
                break;
            default:
                TRACFCOMP(g_util_trace, "Unknown EC level 0x%x for AXONE",
                    l_chipECLevel);
                break;
        }
    }
    //else
    //{
       // fall-through, will be caught by l_freqList nullptr check
    //}

    if(l_freqList != nullptr)
    {
        // Look up the frequency from the frequency list
        uint8_t i = 0;
        for (i = 0; i < OBUS_PLL_FREQ_BUCKETS; i++)
        {
            if(l_freqList[i] == l_freq_array[i_index])
            {
                o_bucket_val = i + 1; // bucket is "1" based
                break;
            }
        }

        // make an error if we did not find a matching frequency
        if(i == OBUS_PLL_FREQ_BUCKETS)
        {
            TRACFCOMP(g_util_trace, ERR_MRK
                "getObusPllBucket: Unable to find matching frequency of %d",
                l_freq_array[i_index])
            /*@
             * @errortype
             * @moduleid          UTIL_MOD_GET_OBUS_PLL_BUCKET
             * @reasoncode        UTIL_ERC_NO_MATCHING_FREQ
             * @userdata1         HB Target HUID
             * @userdata2         Input frequency
             * @devdesc           No matching frequency for PLL bucket
             * @custdesc          Firmware Error
             */
            l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                         UTIL_MOD_GET_OBUS_PLL_BUCKET,
                         UTIL_ERC_NO_MATCHING_FREQ,
                         TARGETING::get_huid(i_chipTarget),
                         l_freq_array[i_index]);
        }
    }
    else // l_freqList equals nullptr
    {
        TRACFCOMP(g_util_trace,
            ERR_MRK"getObusPllBucket: Unable to find frequency list" \
            " for model 0x%.8x, chip level 0x%x", l_chipModel, l_chipECLevel);

        /*@
         * @errortype
         * @moduleid          UTIL_MOD_GET_OBUS_PLL_BUCKET
         * @reasoncode        UTIL_ERC_NO_FREQ_LIST
         * @userdata1         HB Target HUID
         * @userdata1[0:31]   Chip model
         * @userdata2[32:63]  Chip EC level
         * @devdesc           Unable to find frequency list
         * @custdesc          Firmware Error
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                     UTIL_MOD_GET_OBUS_PLL_BUCKET,
                     UTIL_ERC_NO_FREQ_LIST,
                     TARGETING::get_huid(i_chipTarget),
                     TWO_UINT32_TO_UINT64(
                     l_chipModel,
                     l_chipECLevel)
                 );
    }

    return l_errl;
}

}
OpenPOWER on IntegriCloud