summaryrefslogtreecommitdiffstats
path: root/src/usr/targeting/runtime/rt_targeting.C
blob: b0aa06acabf6e0504bbc9b3342f01857558a4bd2 (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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/targeting/runtime/rt_targeting.C $                    */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2014                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <errl/errludlogregister.H>
#include <errl/errludtarget.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/iterators/rangefilter.H>
#include <targeting/common/predicates/predicatepostfixexpr.H>
#include <targeting/common/predicates/predicateattrval.H>
#include <targeting/common/predicates/predicatectm.H>
#include <targeting/common/utilFilter.H>
#include <targeting/common/trace.H>
#include <targeting/common/targreasoncodes.H>

#include <runtime/rt_targeting.H>

using namespace TARGETING;

namespace RT_TARG
{

errlHndl_t procRtTargetError(const TARGETING::Target * i_target)
{
    errlHndl_t err = NULL;
    uint32_t huid = get_huid(i_target);
    TRACFCOMP(g_trac_targeting,ERR_MRK
              "No proc target found for target. huid: %08x",
              huid);
    /*@
     * @errortype
     * @moduleid     TARG_RT_GET_RT_TARGET
     * @reasoncode   TARG_RT_NO_PROC_TARGET
     * @userdata1    HUID of the UNIT target
     * @devdesc      No processor target found for the UNIT
     */
    err =
        new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                TARGETING::TARG_RT_GET_RT_TARGET,
                                TARGETING::TARG_RT_NO_PROC_TARGET,
                                huid,
                                0,
                                true);

    ERRORLOG::ErrlUserDetailsTarget(i_target,"Runtime Target").
        addToLog(err);

    return err;
}


errlHndl_t getRtTarget(const TARGETING::Target* i_target,
                       rtChipId_t &o_chipId)
{
    errlHndl_t err = NULL;

    do
    {
        if(i_target == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
        {
            TARGETING::Target* masterProcChip = NULL;
            TARGETING::targetService().
                masterProcChipTargetHandle(masterProcChip);

            i_target = masterProcChip;
        }

        TARGETING::TYPE target_type = i_target->getAttr<TARGETING::ATTR_TYPE>();

        if(target_type == TARGETING::TYPE_PROC)
        {
            // use 0b0000.0000.0000.0000.0000.0000.00NN.NCCC:
            uint32_t fabId =
                i_target->getAttr<TARGETING::ATTR_FABRIC_NODE_ID>();

            uint32_t procPos =
                i_target->getAttr<TARGETING::ATTR_FABRIC_CHIP_ID>();

            o_chipId = (fabId << CHIPID_NODE_SHIFT) + procPos;
        }
        else if( target_type == TARGETING::TYPE_MEMBUF)
        {
            //MEMBUF
            // 0b1000.0000.0000.0000.0000.00NN.NCCC.MMMM
            // where NNN id node, CCC is chip, MMMM is memory channel
            //
            TARGETING::TargetHandleList targetList;

            getParentAffinityTargets(targetList,
                                    i_target,
                                    TARGETING::CLASS_UNIT,
                                    TARGETING::TYPE_MCS);

            if( targetList.empty() )
            {
                uint32_t huid = get_huid(i_target);
                TRACFCOMP(g_trac_targeting,ERR_MRK
                          "getRtTarget: No target found for huid: %08x",
                          huid);
                /*@
                 * @errortype
                 * @moduleid     TARG_RT_GET_RT_TARGET
                 * @reasoncode   TARG_RT_UNIT_TARGET_NOT_FOUND
                 * @userdata1    HUID of given MEMBUF target
                 * @devdesc      No MCS target(s) found for the
                 *               given MEMBUF target
                 */
                err =
                    new ERRORLOG::ErrlEntry
                    (ERRORLOG::ERRL_SEV_INFORMATIONAL,
                     TARGETING::TARG_RT_GET_RT_TARGET,
                     TARGETING::TARG_RT_UNIT_TARGET_NOT_FOUND,
                     huid,
                     0,
                     true);

                ERRORLOG::ErrlUserDetailsTarget(i_target,"Runtime Target").
                    addToLog(err);

                break;
            }

            TARGETING::Target * target = targetList[0];
            uint32_t pos = target->getAttr<TARGETING::ATTR_CHIP_UNIT>();

            targetList.clear();
            getParentAffinityTargets(targetList,
                                     target,
                                     TARGETING::CLASS_CHIP,
                                     TARGETING::TYPE_PROC);

            if(targetList.empty())
            {
                err = procRtTargetError(target);
                break;
            }

            TARGETING::Target * proc_target = targetList[0];

            err = getRtTarget(proc_target, o_chipId);
            if(err)
            {
                break;
            }

            o_chipId = (o_chipId << UNIT_ID_SHIFT);
            o_chipId += pos;
            o_chipId |= MEMBUF_ID_TYPE;
        }
        else if(target_type == TARGETING::TYPE_EX ||
                target_type == TARGETING::TYPE_CORE)
        {
            // EX/CORE
            // 0b0100.0000.0000.0000.0000.00NN.NCCC.PPPP
            // NNN is node, CCC is chip, PPPP is core
            uint32_t pos = i_target->getAttr<TARGETING::ATTR_CHIP_UNIT>();

            const TARGETING::Target * proc_target = getParentChip(i_target);
            if(proc_target == NULL)
            {
                err =  procRtTargetError(i_target);
                break;
            }

            err = getRtTarget(proc_target, o_chipId);
            if(err)
            {
                break;
            }

            o_chipId = (o_chipId << UNIT_ID_SHIFT);
            o_chipId += pos;
            o_chipId |= CORE_ID_TYPE;
        }
        else
        {
            uint32_t huid = get_huid(i_target);
            TRACFCOMP(g_trac_targeting,ERR_MRK
                      "Runtime target type %d not supported."
                      " huid: %08x",
                      target_type,
                      huid);
            /*@
             * @errortype
             * @moduleid     TARG_RT_GET_RT_TARGET
             * @reasoncode   TARG_RT_TARGET_TYPE_NOT_SUPPORTED
             * @userdata1    HUID of the target
             * @userdata2    target_type
             * @devdesc      Target type not supported by HBRT.
             */
            err =
                new ERRORLOG::ErrlEntry
                (ERRORLOG::ERRL_SEV_INFORMATIONAL,
                 TARGETING::TARG_RT_GET_RT_TARGET,
                 TARGETING::TARG_RT_TARGET_TYPE_NOT_SUPPORTED,
                 huid,
                 target_type,
                 true);

            ERRORLOG::ErrlUserDetailsTarget(i_target,"Runtime Target").
                addToLog(err);
        }
    } while(0);

    return err;
}


errlHndl_t getHbTarget(rtChipId_t i_rt_chip_id,
                       TARGETING::Target *& o_target)
{
    errlHndl_t err = NULL;
    o_target = NULL;

    do
    {
        uint64_t idType = i_rt_chip_id & CHIPID_ID_MASK;

        if(0 != (idType ==  MEMBUF_ID_TYPE))
        {
            //membuf
            uint64_t chip_id = i_rt_chip_id & UNIT_ID_MASK;
            uint32_t unitPos = chip_id & 0x0000000f;
            chip_id >>= UNIT_ID_SHIFT;
            TARGETING::Target * proc = NULL;
            TARGETING::Target * msc = NULL;

            err = getHbTarget(chip_id, proc);
            if(err)
            {
                break;
            }

            PredicateCTM mcsFilter(CLASS_UNIT, TYPE_MCS);
            PredicateAttrVal<ATTR_CHIP_UNIT> unitAttr(unitPos);
            PredicatePostfixExpr mcsUnitFilter;
            mcsUnitFilter.push(&mcsFilter).push(&unitAttr).And();

            TargetHandleList target_list;

            targetService().getAssociated( target_list,
                                           proc,
                                           TargetService::CHILD_BY_AFFINITY,
                                           TargetService::ALL,
                                           &mcsUnitFilter);

            // should only be one result
            if(target_list.size())
            {
                msc = target_list[0];

                target_list.clear();


                getChildAffinityTargets( target_list,
                                         msc,
                                         TARGETING::CLASS_CHIP,
                                         TARGETING::TYPE_MEMBUF);

                // should only be one result
                if(target_list.size())
                {
                    o_target = target_list[0];
                }
            }

            if(o_target == NULL) // no mcs and/or membuf found
            {
                TRACFCOMP(g_trac_targeting,ERR_MRK "getHbTarget: "
                          "MCS or MEMBUF target not found for chipId %08lx",
                          i_rt_chip_id);
                /*@
                 * @errortype
                 * @moduleid     TARGETING::TARG_RT_GET_HB_TARGET
                 * @reasoncode   TARG_RT_UNIT_TARGET_NOT_FOUND
                 * @userdata1    Runtime chip Id
                 * @devdesc      No MCS or MEMBUF target(s) found for the
                 *               given target
                 */
                err =
                    new ERRORLOG::ErrlEntry
                    (ERRORLOG::ERRL_SEV_INFORMATIONAL,
                     TARGETING::TARG_RT_GET_HB_TARGET,
                     TARGETING::TARG_RT_UNIT_TARGET_NOT_FOUND,
                     i_rt_chip_id,
                     0,
                     true);
            }

        }
        else if(0 != (idType == CORE_ID_TYPE))
        {
            // core/ex  will alway return EX chiplet as there is no concept
            //  (yet) of a core in fapi
            uint64_t chip_id = i_rt_chip_id & UNIT_ID_MASK;
            uint32_t unitPos = chip_id & 0x0000000f;
            chip_id >>= UNIT_ID_SHIFT;
            TARGETING::Target * proc = NULL;

            err = getHbTarget(chip_id, proc);
            if(err)
            {
                break;
            }

            PredicateCTM exFilter(CLASS_UNIT, TYPE_EX);
            PredicateAttrVal<ATTR_CHIP_UNIT> unitAttr(unitPos);
            PredicatePostfixExpr exUnitFilter;
            exUnitFilter.push(&exFilter).push(&unitAttr).And();

            TargetHandleList target_list;

            targetService().getAssociated( target_list,
                                           proc,
                                           TargetService::CHILD,
                                           TargetService::ALL,
                                           &exUnitFilter);

            //Should only be one result
            if(target_list.size())
            {
                o_target = target_list[0];
            }
            // o_target not found caught below..
        }
        else if( idType == PROC_ID_TYPE)
        {
            // assume processor chip
            // chip_id  = 'NNNCCC'b
            uint32_t fabId = i_rt_chip_id >> CHIPID_NODE_SHIFT;
            uint32_t procPos = i_rt_chip_id & 0x7;

            PredicateCTM procFilter(CLASS_CHIP, TYPE_PROC);
            PredicateAttrVal<ATTR_FABRIC_NODE_ID> nodeFilter(fabId);
            PredicateAttrVal<ATTR_FABRIC_CHIP_ID> chipFilter(procPos);

            PredicatePostfixExpr theProc, theAttrs;
            theAttrs.push(&nodeFilter).push(&chipFilter).And();
            theProc.push(&procFilter).push(&theAttrs).And();

            TargetRangeFilter procRange(targetService().begin(),
                                        targetService().end(),
                                        &theProc);

            if(procRange)
            {
                o_target = *procRange;
            }
        }

        if(!err && o_target == NULL)
        {
            TRACFCOMP( g_trac_targeting,
                       ERR_MRK"Can't find HB target for chipId 0x%lx",
                       i_rt_chip_id);
            /*@
             * @errortype
             * @moduleid     TARGETING::TARG_RT_GET_HB_TARGET
             * @reasoncode   TARGETING::TARG_RT_TARGET_TYPE_NOT_SUPPORTED
             * @userdata1    runtime procId
             * @userdata2    0
             * @devdesc      Can't find HB Target for chipId provided.
             */
            err =
                new ERRORLOG::ErrlEntry
                (
                 ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                 TARGETING::TARG_RT_GET_HB_TARGET,
                 TARGETING::TARG_RT_TARGET_TYPE_NOT_SUPPORTED,
                 i_rt_chip_id,
                 0,
                 true);

        }
    } while(0);

    return err;
}

}; // namespace
OpenPOWER on IntegriCloud