summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/istep16/call_host_activate_master.C
blob: 63a882886ac32ec59e19a7f179c7c24babd8100f (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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/istep16/call_host_activate_master.C $          */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,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                                                     */


// Error Handling
#include    <errl/errlentry.H>
#include    <errl/errlmanager.H>
#include    <initservice/isteps_trace.H>
#include    <isteps/hwpisteperror.H>
#include    <errl/errludtarget.H>
#include    <intr/interrupt.H>
#include    <console/consoleif.H>
#include <arch/pirformat.H>
#include <arch/pvrformat.H>
#include <sys/task.h>
#include <sys/mmio.h>
#include <arch/ppc.H>


//  targeting support
#include    <targeting/namedtarget.H>
#include    <targeting/attrsync.H>
#include    <fapi2/target.H>

//SBE interfacing
#include    <sbeio/sbeioif.H>
#include    <sys/misc.h>
#include    <pm/pm_common.H>

//Import directory (EKB)
#include    <p9_block_wakeup_intr.H>

#include <scom/scomif.H>

//HWP invoker
#include    <fapi2/plat_hwp_invoker.H>

using   namespace   ERRORLOG;
using   namespace   TARGETING;
using   namespace   ISTEP;
using   namespace   ISTEP_ERROR;


namespace ISTEP_16
{
void* call_host_activate_master (void *io_pArgs)
{
    IStepError  l_stepError;

    TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_host_activate_master entry" );

    errlHndl_t  l_errl  =   NULL;

    do  {
        bool l_isFusedMode = is_fused_mode();
        // find the master core, i.e. the one we are running on
        TRACDCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "call_host_activate_master: Find master core: " );
                   //Determine top-level system target
        TARGETING::Target* l_sys = NULL;
        TARGETING::targetService().getTopLevelTarget(l_sys);
        assert( l_sys != NULL );


        const TARGETING::Target*  l_masterCore  = getMasterCore( );
        assert( l_masterCore != NULL );

        TARGETING::Target* l_proc_target = const_cast<TARGETING::Target *>
                                          ( getParentChip( l_masterCore ) );

        // Cast OUR type of target to a FAPI2 type of target.
        const fapi2::Target<fapi2::TARGET_TYPE_CORE> l_fapi2_coreTarget(
                                const_cast<TARGETING::Target*> (l_masterCore));

        bool l_isDD1 = false;
        PVR_t l_pvr( mmio_pvr_read() & 0xFFFFFFFF );
        if( l_pvr.isNimbusDD1() )
        {
            l_isDD1 = true;
        }

        fapi2::Target<fapi2::TARGET_TYPE_CORE> l_fapi2_fusedTarget = NULL;
        const TARGETING::Target* l_fusedCore = NULL;

        if(l_isFusedMode && !l_isDD1)
        {
            uint64_t cpuid = task_getcpuid();
            uint64_t l_masterCoreID = PIR_t::coreFromPir(cpuid);
            uint64_t l_fusedCoreID = l_masterCoreID + 1;

            // get the list of core targets for this proc chip
            TARGETING::TargetHandleList l_coreTargetList;
            TARGETING::getChildChiplets( l_coreTargetList,
                                         l_proc_target,
                                         TARGETING::TYPE_CORE,
                                         false);

            //Find the core that matched with the fusedCoreID we
            //calculated above. This core is the core that will
            //be fused with the master.
            for( const auto & l_core:l_coreTargetList)
            {
                TARGETING::ATTR_CHIP_UNIT_type l_coreId =
                (l_core)->getAttr<TARGETING::ATTR_CHIP_UNIT>();
                if( l_coreId == l_fusedCoreID )
                {
                    l_fusedCore = (l_core);
                    break;
                }
            }

            if( l_fusedCore == NULL )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                        "Could not find a target for core %d",
                        l_fusedCoreID );
                /*@
                * @errortype
                * @moduleid     ISTEP::MOD_HOST_ACTIVATE_MASTER
                * @reasoncode   ISTEP::RC_NO_FUSED_CORE_TARGET
                * @userdata1    Master-fused core id
                * @userdata2    Master-fused processor chip huid
                * @devdesc      activate_master> Could not find a target
                *               for the master-fused core
                * @custdesc     A problem occurred during the IPL
                *               of the system.
                */
                l_errl = new ERRORLOG::ErrlEntry(
                                    ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                    ISTEP::MOD_HOST_ACTIVATE_MASTER,
                                    ISTEP::RC_NO_FUSED_CORE_TARGET,
                                    l_fusedCoreID,
                                    TARGETING::get_huid(l_proc_target));
                l_errl->collectTrace("TARG",256);
                l_errl->collectTrace(FAPI_TRACE_NAME,256);
                l_errl->collectTrace(FAPI_IMP_TRACE_NAME,256);

                break;
            }

            // Cast OUR type of target to a FAPI2 type of target.
            l_fapi2_fusedTarget = const_cast<TARGETING::Target*> (l_fusedCore);
        }

        //Because of a bug in how the SBE injects the IPI used to wake
        //up the master core, need to ensure no mailbox traffic
        //or even an interrupt in the interrupt presenter
        // 1) Reclaim all DMA bfrs from the FSP
        // 2) suspend the mailbox with interrupt disable
        // 3) tell the SBE to start the deadman timer
        // 4) ensure that interrupt presenter is drained
        l_errl = MBOX::reclaimDmaBfrsFromFsp();
        if (l_errl)
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "call_host_activate_master ERROR : "
                       "MBOX::reclaimDmaBfrsFromFsp");

            //  if it not complete then thats okay, but we want to store the
            //   log away somewhere. Since we didn't get all the DMA buffers
            //   back its not a big deal to commit a log, even if we lose a
            //   DMA buffer because of it it doesn't matter that much.
            //  this will generate more traffic to the FSP
            l_errl->setSev(ERRORLOG::ERRL_SEV_INFORMATIONAL);
            errlCommit( l_errl, HWPF_COMP_ID );

            // (do not break.   keep going to suspend)
        }

        l_errl = MBOX::suspend(true, true);
        if (l_errl)
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "call_host_activate_master ERROR : MBOX::suspend");
            break;
        }

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "call_host_activate_master: About to start deadman loop... "
                   "Target HUID %.8X",
                    TARGETING::get_huid(l_proc_target));

        //In the future possibly move default "waitTime" value to SBEIO code
        uint64_t waitTime = 10500; // wait time 10.5 sec, anything larger than 10737 ms can cause
                                   // overflow on SBE side of the tiemout calculations
        l_errl = SBEIO::startDeadmanLoop(waitTime);

        if ( l_errl )
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
            "startDeadmanLoop ERROR : Returning errorlog, reason=0x%x",
                l_errl->reasonCode() );

            // capture the target data in the elog
            ErrlUserDetailsTarget(l_proc_target).addToLog( l_errl );

            break;
        }
        else
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "startDeadManLoop SUCCESS"  );
        }

        //Need to indicate to PHYP to save HRMOR and other SPR Data to be
        // applied during wakeup
        MAGIC_INSTRUCTION(MAGIC_SIMICS_CORESTATESAVE);

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace, "draining interrupt Q");
        INTR::drainQueue();

        // Call p9_block_wakeup_intr to prevent stray interrupts from
        // popping core out of winkle before SBE sees it.

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "call_host_activated_master: call p9_block_wakeup_intr(SET) "
                   "Target HUID %.8x",
                   TARGETING::get_huid(l_fapi2_coreTarget) );


        FAPI_INVOKE_HWP( l_errl,
                        p9_block_wakeup_intr,
                        l_fapi2_coreTarget,
                        p9pmblockwkup::SET );

        if ( l_errl )
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
            "p9_block_wakeup_intr ERROR : Returning errorlog, reason=0x%x",
                l_errl->reasonCode() );

            // capture the target data in the elog
            ErrlUserDetailsTarget(l_masterCore).addToLog( l_errl );

            break;
        }
        else
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "p9_block_wakeup_intr SUCCESS"  );
        }

        if(l_fusedCore != NULL)
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
            "call_host_activated_master: call p9_block_wakeup_intr(SET) "
            "Target HUID %.8x",
            TARGETING::get_huid(l_fapi2_fusedTarget) );

            FAPI_INVOKE_HWP( l_errl,
                            p9_block_wakeup_intr,
                             l_fapi2_fusedTarget,
                            p9pmblockwkup::SET );

            if ( l_errl )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                "p9_block_wakeup_intr ERROR : Returning errorlog, reason=0x%x",
                    l_errl->reasonCode() );

                // capture the target data in the elog
                ErrlUserDetailsTarget(l_fusedCore).addToLog( l_errl );

                break;
            }
            else
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                        "p9_block_wakeup_intr SUCCESS"  );
            }
        }

        //  put the master into winkle.
        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "call_host_activate_master: put master into winkle..." );

        // Flush any lingering console traces first
        CONSOLE::flush();

        int l_rc    =   cpu_master_winkle(l_isFusedMode);
        if ( l_rc )
        {
            TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace,
                      "ERROR : failed to winkle master, rc=0x%x",
                      l_rc  );
            /*@
             * @errortype
             * @reasoncode  RC_FAIL_MASTER_WINKLE
             * @severity    ERRORLOG::ERRL_SEV_UNRECOVERABLE
             * @moduleid    MOD_HOST_ACTIVATE_MASTER
             * @userdata1   return code from cpu_master_winkle
             * @userdata2   Fused core indicator
             *
             * @devdesc cpu_master_winkle returned an error
             */
            l_errl =
            new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                    MOD_HOST_ACTIVATE_MASTER,
                                    RC_FAIL_MASTER_WINKLE,
                                    l_rc, l_isFusedMode );
            break;
        }


        //  --------------------------------------------------------
        //  should return from Winkle at this point
        //  --------------------------------------------------------
        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "Returned from Winkle." );

        l_errl = SBEIO::stopDeadmanLoop();
        if ( l_errl )
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "stopDeadmanLoop ERROR : "
                       "Returning errorlog, reason=0x%x",
                       l_errl->reasonCode() );

            // capture the target data in the elog
            ErrlUserDetailsTarget(l_proc_target).addToLog( l_errl );

            break;
        }
        else
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "stopDeadmanLoop SUCCESS"  );
        }

        //Re-enable the mailbox
        l_errl = MBOX::resume();
        if (l_errl)
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "call_host_activate_master ERROR : MBOX::resume");
            break;
        }

        TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                   "Call proc_stop_deadman_timer. Target %.8X",
                   TARGETING::get_huid(l_proc_target) );


        // Save off original checkstop values and override them
        // to disable core xstops and enable sys xstops.
        l_errl = HBPM::core_checkstop_helper_hwp(l_masterCore, true);

        if( l_errl )
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "core_checkstop_helper_hwp on master ERROR: returning.");
            break;
        }

        // We want to make sure the fused pair is also setting the
        // core firs to handle checkstops at system level and not
        // at the local level
        if(l_fusedCore != NULL)
        {
            l_errl = HBPM::core_checkstop_helper_hwp(l_fusedCore, true);

            if ( l_errl )
            {
                TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                           "core_checkstop_helper_hwp on fused pair ERROR: returning.");
                break;
            }
        }

        // Take new checkstop values and insert them into the homer image
        l_errl = HBPM::core_checkstop_helper_homer();

        if( l_errl )
        {
            TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
                       "core_checkstop_helper_homer ERROR: returning.");
            break;
        }

    }   while ( 0 );

    if( l_errl )
    {
        // Create IStep error log and cross reference error that occurred
        l_stepError.addErrorDetails( l_errl );

        // Commit Error
        errlCommit( l_errl, HWPF_COMP_ID );
    }

    // Flush the console to correct the timestamp on istep 16.2
    CONSOLE::flush();

    TRACFCOMP( ISTEPS_TRACE::g_trac_isteps_trace,
               "call_host_activate_master exit" );
    // end task, returning any errorlogs to IStepDisp
    return l_stepError.getErrorHandle();

}



};
OpenPOWER on IntegriCloud