summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/istep09/istep09HelperFuncs.C
blob: 30c4c099ce95f7c1b7530675e94c50cebed9b269 (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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/istep09/istep09HelperFuncs.C $                 */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2018                        */
/* [+] 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                                                     */

/******************************************************************************/
// Includes
/******************************************************************************/

#include "istep09HelperFuncs.H"

//  STD support
#include <map>

//  Support for all istep common functions
#include "istepHelperFuncs.H"          // captureError

//  Tracing support
#include <trace/interface.H>           // TRACFCOMP
#include <initservice/isteps_trace.H>  // g_trac_isteps_trace

//  Targeting support
#include <fapi2_target.H>              // fapi2::Target
#include <target.H>                    // Target

//  Error handling support
#include <errl/errlentry.H>            // errlHndl_t

//  HWP call support
#include <fapi2/plat_hwp_invoker.H>    // FAPI_INVOKE_HWP
#include <p9_io_xbus_pre_trainadv.H>   // p9_io_xbus_pre_trainadv
#include <p9_io_xbus_post_trainadv.H>  // p9_io_xbus_post_trainadv
#include <p9_io_obus_dccal.H>          // p9_io_obus_dccal
#include <p9_io_obus_pre_trainadv.H>   // p9_io_obus_pre_trainadv
#include <p9_io_obus_linktrain.H>      // p9_io_obus_link_train
#include <p9_io_obus_post_trainadv.H>  // p9_io_obus_post_trainadv

namespace ISTEP_09
{
using namespace ISTEP_ERROR;
using namespace ISTEPS_TRACE;
using namespace EDI_EI_INITIALIZATION;
using namespace TARGETING;

 /**
 *  hwpCallToString
 */
const char * hwpCallToString( HWP_CALL_TYPE i_hwpCall )
{
    const static std::map<HWP_CALL_TYPE, const char*> hwpCallToStringMap =
    {
        { P9_IO_XBUS_PRE_TRAINADV, "p9_io_xbus_pre_trainadv" },
        { P9_IO_XBUS_POST_TRAINADV, "p9_io_xbus_post_trainadv" },
        { P9_IO_OBUS_PRE_TRAINADV, "p9_io_obus_pre_trainadv" },
        { P9_IO_OBUS_POST_TRAINADV, "p9_io_obus_post_trainadv" },
        { P9_IO_OBUS_LINKTRAIN, "p9_io_obus_linktrain" },
        { P9_IO_OBUS_DCCAL, "p9_io_obus_dccal" },
    };

    if (hwpCallToStringMap.count(i_hwpCall) > 0)
    {
        return hwpCallToStringMap.at(i_hwpCall);
    }
    else
    {
        return "";
    }
}

/**
 *   trainXbus
 */
uint32_t trainXbus(HWP_CALL_TYPE   i_hwpCall,
                   IStepError     &o_stepError,
                   compId_t        i_componentId,
                   const Target*   i_firstTarget,
                   const Target*   i_secondTarget)
{
    // Cache the HWP call in string form
    const char* l_hwpCallStr = hwpCallToString(i_hwpCall);

    TRACFCOMP(g_trac_isteps_trace, ENTER_MRK"trainXbus (%s) entry", l_hwpCallStr);

    // Make sure target values are valid
    assert(nullptr != i_firstTarget, "The first target cannot be NULL");
    assert(nullptr != i_secondTarget, "The second target cannot be NULL");

    // An error handler
    errlHndl_t l_err(nullptr);

    // Enumerate the train failures that occur
    uint32_t l_numberOfTrainFailures(0);

    // Create Fapi2 targets from the given targets
    const fapi2::Target <fapi2::TARGET_TYPE_XBUS>
        l_firstFapi2Target(
        (const_cast<Target*>(i_firstTarget)));

    const fapi2::Target <fapi2::TARGET_TYPE_XBUS>
        l_secondFapi2Target(
        (const_cast<Target*>(i_secondTarget)));

    // group is either 0 or 1,
    // need to train both groups and allow for them to differ
    uint8_t l_this_group(0), l_connected_group(0);
    for (uint8_t l_group_loop = 0; l_group_loop < 4; ++l_group_loop)
    {
        l_this_group = l_group_loop / 2;      // 0, 0, 1, 1
        l_connected_group = l_group_loop % 2; // 0, 1, 1, 0

        TRACFCOMP(g_trac_isteps_trace,
                  "Running %s HWP on "
                  "this XBUS target 0x%.8X (group %d) and connected "
                  "target 0x%.8X (group %d)",
                  l_hwpCallStr,
                  get_huid(i_firstTarget),
                  l_this_group,
                  get_huid(i_secondTarget),
                  l_connected_group );

        if (P9_IO_XBUS_PRE_TRAINADV == i_hwpCall)
        {
            FAPI_INVOKE_HWP(l_err,
                            p9_io_xbus_pre_trainadv,
                            l_firstFapi2Target,
                            l_this_group,
                            l_secondFapi2Target,
                            l_connected_group );
        }
        else if (P9_IO_XBUS_POST_TRAINADV == i_hwpCall)
        {
            FAPI_INVOKE_HWP(l_err,
                            p9_io_xbus_post_trainadv,
                            l_firstFapi2Target,
                            l_this_group,
                            l_secondFapi2Target,
                            l_connected_group );
        }
        else
        {
            ++l_numberOfTrainFailures;
            TRACFCOMP(g_trac_isteps_trace,
                      "ERROR: Invalid/Uknown XBUS HWP call");
            break;
        }

        TRACFCOMP(g_trac_isteps_trace,
                  "%s : XBUS connection %s, "
                  "target 0x%.8X using group %d, connected target 0x%.8X "
                  "using group %d",
                  (l_err ? "ERROR" : "SUCCESS"),
                  l_hwpCallStr,
                  get_huid(i_firstTarget),
                  l_this_group,
                  get_huid(i_secondTarget),
                  l_connected_group );

        if (l_err)
        {
            ++l_numberOfTrainFailures;
            TargetHandleList l_targets =
                  { const_cast<TargetHandle_t>(i_firstTarget),
                    const_cast<TargetHandle_t>(i_secondTarget) };
            // Capture error and continue
            captureError(l_err,
                         o_stepError,
                         i_componentId,
                         l_targets);
        }
    }  // end for (l_group_loop = 0; l_group_loop < 4; l_group_loop++)

    TRACFCOMP(g_trac_isteps_trace, EXIT_MRK"trainXbus (%s) exit", l_hwpCallStr);

    return l_numberOfTrainFailures;
}

/**
 *   trainObus
 */
uint32_t trainObus(HWP_CALL_TYPE   i_hwpCall,
                   IStepError     &o_stepError,
                   compId_t        i_componentId,
                   const Target*   i_firstTarget,
                   const Target*   i_secondTarget)
{

    // Cache the HWP call in string form
    const char* l_hwpCallStr = hwpCallToString(i_hwpCall);

    TRACFCOMP(g_trac_isteps_trace, ENTER_MRK"trainObus (%s) entry", l_hwpCallStr);

    // Make sure target values are valid
    assert(nullptr != i_firstTarget, "The first target cannot be NULL");
    assert(nullptr != i_secondTarget, "The second target cannot be NULL");

    // An error handler
    errlHndl_t l_err(nullptr);

    // Enumerate the train failures that occur
    uint32_t l_numberOfTrainFailures(0);

    // Put targets in a container that can be traversed
    std::vector<const Target*> l_targets =
                { i_firstTarget,  i_secondTarget };

    // Iterate over the targets
    for (const auto l_target: l_targets)
    {
        // Convert current target to a fapi2 target
        const fapi2::Target <fapi2::TARGET_TYPE_OBUS>
            l_fapi2Target
            (const_cast<Target*>(l_target));

        TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                   "Running %s HWP on this OBUS target 0x%.8X",
                   l_hwpCallStr,
                   l_target);

        // Call the appropriate HWP method
        if (P9_IO_OBUS_DCCAL == i_hwpCall)
        {
            // I have no idea what this value means or how it came to be this
            // particular value.  It was replicated from
            // /fips920/src/hwsv/server/services/hwco/hwcoNodeSMP.C
            uint32_t l_laneVector = 0x00FFFFFF;
            FAPI_INVOKE_HWP(l_err,
                            p9_io_obus_dccal,
                            l_fapi2Target,
                            l_laneVector);
        }
        else if (P9_IO_OBUS_PRE_TRAINADV == i_hwpCall)
        {
            FAPI_INVOKE_HWP(l_err,
                            p9_io_obus_pre_trainadv,
                            l_fapi2Target);
        }
        else if (P9_IO_OBUS_LINKTRAIN == i_hwpCall)
        {
            FAPI_INVOKE_HWP(l_err,
                            p9_io_obus_linktrain,
                            l_fapi2Target);
        }
        else if (P9_IO_OBUS_POST_TRAINADV == i_hwpCall)
        {
            FAPI_INVOKE_HWP(l_err,
                            p9_io_obus_post_trainadv,
                            l_fapi2Target);
        }
        else
        {
            ++l_numberOfTrainFailures;
            TRACFCOMP(g_trac_isteps_trace,
                      "ERROR: Invalid/Uknown OBUS HWP call");
            break;
        }

        TRACFCOMP(g_trac_isteps_trace,
                  "%s : OBUS connection %s, target 0x%.8X",
                  (l_err ? "ERROR" : "SUCCESS"),
                  l_hwpCallStr,
                  get_huid(l_target));

        if (l_err)
        {
            ++l_numberOfTrainFailures;
            // Capture error and continue
            captureError(l_err,
                         o_stepError,
                         HWPF_COMP_ID,
                         l_target);

            // Skip training of second end point if doing link train or dccal
            if ( (P9_IO_OBUS_LINKTRAIN == i_hwpCall) ||
                 (P9_IO_OBUS_DCCAL == i_hwpCall) ) break;
        }
    } // end for (const auto l_target: l_targets)

    TRACFCOMP(g_trac_isteps_trace, EXIT_MRK"trainObus (%s) exit", l_hwpCallStr);

    return l_numberOfTrainFailures;
}

/**
 *   trainBusHandler
 */
bool trainBusHandler(TYPE                     i_busType,
                     HWP_CALL_TYPE            i_hwpCall,
                     ISTEP_ERROR::IStepError &o_stepError,
                     compId_t                 i_componentId,
                     const TargetPairs_t     &i_pbusConnections)
{
    bool retSuccess = true;

    if (i_pbusConnections.empty())
    {
        TRACFCOMP(g_trac_isteps_trace, "Connection bus list is empty. "
                  "HWP call %s will not be called.",
                  hwpCallToString(i_hwpCall));
    }

    // Iterate over the pbus connections
    for (const auto & l_pbusConnection: i_pbusConnections)
    {
        TRACFCOMP(g_trac_isteps_trace, "Attempting to train %s %s on "
                  "bus connections 0x%.8X and 0x%.8X",
                  (i_busType == TYPE_OBUS ? "OBUS" : (i_busType == TYPE_XBUS ? "XBUS" : "")),
                  hwpCallToString(i_hwpCall),
                  get_huid(l_pbusConnection.first),
                  get_huid(l_pbusConnection.second));

        uint32_t l_numberOfTrainFailures(0);

        if (TYPE_OBUS == i_busType)
        {
            l_numberOfTrainFailures = trainObus(i_hwpCall,
                                                o_stepError,
                                                i_componentId,
                                                l_pbusConnection.first,
                                                l_pbusConnection.second);
        }
        else if (TYPE_XBUS == i_busType)
        {
            l_numberOfTrainFailures = trainXbus(i_hwpCall,
                                                o_stepError,
                                                i_componentId,
                                                l_pbusConnection.first,
                                                l_pbusConnection.second);
        }
        else
        {
            ++l_numberOfTrainFailures;
            TRACFCOMP(g_trac_isteps_trace,
                      "ERROR: Invalid/Uknown BUS type");
        }

        if (l_numberOfTrainFailures)
        {
            TRACFCOMP(g_trac_isteps_trace,
                      "Running %s HWP resulted in %d errors",
                      hwpCallToString(i_hwpCall),
                      l_numberOfTrainFailures);

            retSuccess = false;
            // stop processing OBUS if encountered an error
            break;
        }
    }  // end  for (const auto & l_pbusConnection: i_pbusConnections)

    return retSuccess;
}


}  // end namespace ISTEP_09

OpenPOWER on IntegriCloud