summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/tod/TodDrawer.C
blob: 567e30b5e16e52b636940e7c28a4db672d33b0f9 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/tod/TodDrawer.C $                              */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,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 TodDrawer.C
 *
 *  @brief The file implements methods of TodDrawer class
 */

//------------------------------------------------------------------------------
//Includes
//------------------------------------------------------------------------------
//Targeting support
#include <targeting/common/commontargeting.H>
#include <targeting/common/util.H>
#include <attributeenums.H>

#include "TodControls.H"
#include "TodProc.H"
#include "TodDrawer.H"
#include "TodUtils.H"
#include <hwas/common/deconfigGard.H>
//Standard library
#include <list>
#include "TodUtils.H"
#include <isteps/tod_init_reasoncodes.H>

namespace TOD
{

//******************************************************************************
// TodDrawer::TodDrawer
//******************************************************************************
TodDrawer::TodDrawer(const uint8_t i_drawerId,
                             const TARGETING::Target* i_parentNode):
    iv_todDrawerId(i_drawerId),
    iv_isTodMaster(false),
    iv_parentNodeTarget(i_parentNode)
{
    do
    {
      if (!iv_parentNodeTarget)
      {
          TOD_ERR_ASSERT(0, "Error creating TOD drawer with id 0x%.2X,"
          "parent node pointer passed as NULL",
          i_drawerId);
          break;
      }
      TOD_ENTER("Created TOD drawer with id 0x%.2X, parent node 0x%.8X",
                 i_drawerId,
                 i_parentNode->getAttr<TARGETING::ATTR_HUID>());
    } while (0);
    TOD_EXIT();
}

//******************************************************************************
// TodDrawer::~TodDrawer
//******************************************************************************
TodDrawer::~TodDrawer()
{
    TOD_ENTER();

    for(TodProcContainer::iterator l_itr = iv_todProcList.begin();
        l_itr != iv_todProcList.end();
        ++l_itr)
    {
        delete (*l_itr);
    }
    iv_todProcList.clear();
    TOD_EXIT();
}

//******************************************************************************
// TodDrawer::getProcWithMaxCores
//******************************************************************************
void TodDrawer::getProcWithMaxCores(
                const TodProc* i_procToIgnore,
                TodProc*& o_pTodProc,
                uint32_t& o_coreCount,
                TodProcContainer* i_pProcList) const
{
    TOD_ENTER("getProcWithMaxCores");
    o_pTodProc =  NULL;
    o_coreCount = 0;

    do{
        //List of functional cores
        TARGETING::TargetHandleList l_funcCoreTargetList;
        TARGETING::PredicateCTM
            l_coreCTM(TARGETING::CLASS_UNIT,TARGETING::TYPE_CORE);

        TARGETING::PredicateHwas l_funcPred;
        l_funcPred.functional(true);
        TARGETING::PredicatePostfixExpr l_funcCorePostfixExpr;
        l_funcCorePostfixExpr.push(&l_coreCTM).push(&l_funcPred).And();

        TodProc* l_pSelectedTarget = NULL;
        uint32_t l_maxCores = 0;

        const TodProcContainer &l_procList =
            i_pProcList ? *i_pProcList : iv_todProcList;
        for(TodProcContainer::const_iterator l_procIter =
            l_procList.begin();
            l_procIter != l_procList.end();
            ++l_procIter)
        {
            if((NULL != i_procToIgnore) &&
               (i_procToIgnore->getTarget()->getAttr<TARGETING::ATTR_HUID>() ==
               (*l_procIter)->getTarget()->getAttr<TARGETING::ATTR_HUID>()))
            {
                continue;
            }
            l_funcCoreTargetList.clear();
            //Find the funcational core targets on this proc
            TARGETING::targetService().getAssociated(l_funcCoreTargetList,
                    (*l_procIter)->getTarget(),
                    TARGETING::TargetService::CHILD,
                    TARGETING::TargetService::ALL,
                    &l_funcCorePostfixExpr);

            if ( l_funcCoreTargetList.size() > l_maxCores )
            {
                l_pSelectedTarget = *l_procIter;
                l_maxCores = l_funcCoreTargetList.size();
            }
        }
        if ( l_maxCores > 0 )
        {
            o_pTodProc = l_pSelectedTarget;
            o_coreCount = l_maxCores;
            TOD_INF("getProcWithMaxCores,On drawer 0x%2X, processor 0x%08X "
            "has maximum cores count = %d ",
            iv_todDrawerId,
            l_pSelectedTarget->getTarget()->getAttr<TARGETING::ATTR_HUID>(),
            l_maxCores);
        }

    }while(0);

    TOD_EXIT();
}


//******************************************************************************
// TodDrawer::findMasterProc
//******************************************************************************
errlHndl_t TodDrawer::findMasterProc(TodProc*& o_drawerMaster) const
{
    TOD_ENTER();

    errlHndl_t l_errHdl = NULL;

    TodProc* l_pMasterProc = NULL;

    do{
        TodProcContainer::const_iterator l_procIter = iv_todProcList.begin();
        for (; l_procIter != iv_todProcList.end(); ++l_procIter)
        {
            if(((*l_procIter)->getMasterType() == TodProc::TOD_MASTER)
               ||
               ((*l_procIter)->getMasterType() == TodProc::DRAWER_MASTER))
               {
                   l_pMasterProc = (*l_procIter);
                   break;
               }
        }
        if(iv_todProcList.end() == l_procIter)
        {
            TOD_ERR("No master proc for drawer 0x%.2X",iv_todDrawerId);
            /*@
             * @errortype
             * @moduleid     TOD_FIND_MASTER_PROC
             * @reasoncode   TOD_NO_MASTER_PROC
             * @userdata1    TOD drawer id
             * @devdesc      No master proc set for this drawer
             * @custdesc     Service Processor Firmware couldn't detect any
             *               functional master processor required to boot the
             *               host
             */

            const bool hbSwError = true;
            l_errHdl = new ERRORLOG::ErrlEntry(
                           ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                           TOD_FIND_MASTER_PROC,
                           TOD_NO_MASTER_PROC,
                           iv_todDrawerId,
                           hbSwError);
        }
    }while(0);

    o_drawerMaster = l_pMasterProc;

    TOD_EXIT();

    return l_errHdl;
}

//******************************************************************************
// TodDrawer::addProc
//******************************************************************************
void TodDrawer::addProc(TodProc* i_proc)
{
    if(i_proc)
    {
        iv_todProcList.push_back(i_proc);
    }
    else
    {
        TOD_ERR_ASSERT("Code bug! Null Proc Target passed!");
    }
}

//******************************************************************************
// TodDrawer::getPotentialMdmts
//******************************************************************************
void TodDrawer::getPotentialMdmts(
        TodProcContainer& o_procList) const
{
    TOD_ENTER("TodDrawer::getPotentialMdmts");
    bool l_isGARDed = false;
    errlHndl_t l_errHdl = NULL;

    const TARGETING::Target* l_procTarget = NULL;

    for(const auto & l_procItr : iv_todProcList)
    {

        l_procTarget = l_procItr->getTarget();

        //Check if the target is not black listed
        if ( !(TOD::isProcBlackListed(l_procTarget)) )
        {
            //Check if the target is not garded
            l_errHdl = TOD::checkGardStatusOfTarget(l_procTarget,
                        l_isGARDed);

            if(l_errHdl)
            {
                TOD_ERR("Failed in checkGardStatusOfTarget() to get the "
                        " GARD state for the target 0x%.8x",
                        GETHUID(l_procTarget));

                errlCommit(l_errHdl, TOD_COMP_ID);

                //Ignore this target as the gard status for this target
                //could not be obtained.
                continue;
            }

            TARGETING::ATTR_HWAS_STATE_type l_state =
                l_procTarget->getAttr<TARGETING::ATTR_HWAS_STATE>();

            if ( (!l_isGARDed) ||
                 (l_state.deconfiguredByEid ==
                  HWAS::DeconfigGard::CONFIGURED_BY_RESOURCE_RECOVERY) )
            {
                o_procList.push_back(l_procItr);
            }
            else
            {
                TOD_INF("PROC target 0x%.8x cannot be choosen as MDMT as"
                "its garded",GETHUID(l_procTarget));
            }
        }
        else
        {
            TOD_INF("PROC target 0x%.8x cannot be choosen as MDMT as it"
            "is backlisted",GETHUID(l_procTarget));
        }
        l_isGARDed = false;

    }//End of for loop
    TOD_EXIT();
}

}//end of namespace
OpenPOWER on IntegriCloud