summaryrefslogtreecommitdiffstats
path: root/src/usr/initservice/istepdispatcher/istepWorker.C
blob: f14651e4154f7aa392cf4d5d2e0cd889ddeb1123 (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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/initservice/istepdispatcher/istepWorker.C $           */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2013              */
/*                                                                        */
/* 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                                                     */
/**
 *  @file istepWorker.C
 *
 *  IStep Dispatcher worker thread.
 *
 */

/******************************************************************************/
// Includes
/******************************************************************************/
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <sys/msg.h>
#include <vfs/vfs.H>

#include <errl/errlentry.H>

#include <isteps/istepmasterlist.H>
#include <hwpf/istepreasoncodes.H>
#include <hwas/common/deconfigGard.H>
#include <hwas/hwasPlat.H>

#include    "../baseinitsvc/initservice.H"

#include <diag/attn/attn.H>

//#include <initservice/initsvcudistep.H>  //  InitSvcUserDetailsIstep

#include <targeting/attrsync.H>

#include <targeting/common/attributes.H>

#include <fapiAttributeService.H>

#include "istep_mbox_msgs.H"
#include "istepWorker.H"
#include "istepdispatcher.H"

//  -----   namespace   INITSERVICE -------------------------------------------
namespace   INITSERVICE
{
/******************************************************************************/
// Globals/Constants
/******************************************************************************/
extern trace_desc_t *g_trac_initsvc;

bool getSyncEnabledAttribute();
void loadModules( uint32_t istep );
void unLoadModules( uint32_t istep );

// ----------------------------------------------------------------------------
// startIStepWorkerThread
// ----------------------------------------------------------------------------
void* startIStepWorkerThread ( void * io_args )
{
    TRACFCOMP( g_trac_initsvc,
               ENTER_MRK"startIStepWorkerThread()" );

    // detach from main istep dispatcher thread
    task_detach();

    // Worker thread entry
    iStepWorkerThread( io_args );

    TRACDCOMP( g_trac_initsvc,
               EXIT_MRK"startIStepWorkerThread()" );

    // Shutdown.
    return NULL;
}


// ----------------------------------------------------------------------------
// iStepWorkerThread()
// ----------------------------------------------------------------------------
void iStepWorkerThread ( void * i_msgQ )
{
    errlHndl_t err          =   NULL;
    msg_q_t theQ            =   static_cast<msg_q_t>( i_msgQ );
    msg_t * theMsg          =   NULL;
    uint32_t istep          =   0x0;
    uint32_t substep        =   0x0;
    uint32_t prevStep       =   0x0;
    uint64_t progressCode   =   0x0;
    bool first              =   true;

    TRACDCOMP( g_trac_initsvc,
               ENTER_MRK"iStepWorkerThread()" );

    // cache the value, it wont change during ipl.
    bool step_mode = IStepDispatcher::getTheInstance().getIStepMode();

    while( 1 )
    {
        // Send More Work Needed msg to the main thread.
        theMsg = msg_allocate();
        theMsg->type = MORE_WORK_NEEDED;
        theMsg->data[0] = first ? 1 : 0x0;
        if ( err )
        {
            // The size of the errorlog (data[1]) is intentionally left at 0;
            //  the main thread will commit this errorlog.  We do not really
            //  need to send the size of the errorlog.
            theMsg->data[1] = 0;
            TRACFCOMP( g_trac_initsvc,
                       "istepWorker:  send errlog back to main, PLID = 0x%x",
                       err->plid()  );
        }

        theMsg->extra_data = err;
        err = NULL;
        TRACDCOMP( g_trac_initsvc,
        INFO_MRK"istepWorker: sendmsg t=0x%08x, d0=0x%016x, d1=0x%016x, x=%p",
                   theMsg->type,
                   theMsg->data[0],
                   theMsg->data[1],
                   theMsg->extra_data );

        // Wait here until the main thread has work for us.
        msg_sendrecv( theQ,
                      theMsg );

        TRACDCOMP( g_trac_initsvc,
        INFO_MRK"istepWorker: rcvmsg t=0x%08x, d0=0x%016x, d1=0x%016x, x=%p",
                   theMsg->type,
                   theMsg->data[0],
                   theMsg->data[1],
                   theMsg->extra_data );

        first = false;

        // Got a response...  The step/substep to execute are in data[0]
        istep = ((theMsg->data[0] & 0xFF00) >> 8);
        substep = (theMsg->data[0] & 0xFF);


        // Get the Task Info for this step
        const TaskInfo * theStep = findTaskInfo( istep,
                                                 substep );

        if( NULL != theStep )
        {
            TRACFCOMP( g_trac_initsvc,
                    "IStepDispatcher (worker): "
                    "Run Istep (%d), substep(%d), - %s",
                       istep, substep, theStep->taskname );

            // Post the Progress Code
            InitService::getTheInstance().setProgressCode( progressCode );

            if( prevStep != istep )
            {
                // unload the modules from the previous step
                unLoadModules( prevStep );
                // load modules for this step
                loadModules( istep );
                prevStep = istep;
            }

            err = InitService::getTheInstance().executeFn( theStep,
                                                           NULL );

            //  flush contTrace immediately after each istep/substep  returns
            TRAC_FLUSH_BUFFERS();

            // sync the attributes to fsp in single step mode but only
            // after step 6 is complete to allow discoverTargets() to
            // run before the sync is done.
            if( step_mode && istep > 6 )
            {
                // this value can change between steps, so read now
                if( getSyncEnabledAttribute() )
                {
                    TRACFCOMP( g_trac_initsvc, "sync attributes to FSP");

                    errlHndl_t l_errl = TARGETING::syncAllAttributesToFsp();

                    if(l_errl)
                    {
                        TRACFCOMP(g_trac_initsvc,
                        "Attribute sync between steps failed"
                        "see %x for details",
                        l_errl->eid());

                        errlCommit(l_errl, INITSVC_COMP_ID);
                    }
                }
            }

            bool callouts = false;
            // check to see if there were any deferred deconfigure callouts
            // IF there wasn't a PLD detected.
            if (HWAS::hwasPLDDetection())
            {
                TRACFCOMP(g_trac_initsvc,
                    "hwasPLDDetection return true - clear deconfig records");
                HWAS::theDeconfigGard().clearDeconfigureRecords(NULL);
            }
            else
            {
                // call HWAS to have this processed
                callouts = HWAS::processDeferredDeconfig();
            }

            // force a TI if there were callouts
            if (callouts)
            {
                TRACFCOMP(g_trac_initsvc,
                    INFO_MRK"HWAS has deferred deconfigs!");

                // we are going to return an errl so that we TI
                //  but if there is an error already (and it's very likely,
                //  since that's how deconfigure callouts happen) we want
                //  go send that one along
                if (err)
                {
                    TRACFCOMP( g_trac_initsvc,
                       "istepDispatcher, committing errorlog, PLID = 0x%x",
                       err->plid() );
                    errlCommit( err, INITSVC_COMP_ID );
                    // err is now NULL
                }

                /*@
                 * @errortype
                 * @reasoncode       ISTEP_DELAYED_DECONFIG
                 * @severity         ERRORLOG::ERRL_SEV_UNRECOVERABLE
                 * @moduleid         ISTEP_INITSVC_MOD_ID
                 * @userdata1        Current Istep
                 * @userdata2        Current SubStep
                 * @devdesc          a deferred deconfigure callup was
                 *                   encountered;
                 */
                err = new ERRORLOG::ErrlEntry(
                            ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                            ISTEP_INITSVC_MOD_ID,
                            ISTEP_DELAYED_DECONFIG,
                            istep ,
                            substep );

                // add procedure callout
                err->addProcedureCallout(HWAS::EPUB_PRC_FIND_DECONFIGURED_PART,
                        HWAS::SRCI_PRIORITY_HIGH);
            }

            if( err )
            {
                TRACFCOMP( g_trac_initsvc,
                           "IStepDipspatcher (worker): "
                           "Istep %s return PLID=0x%x",
                           theStep->taskname,
                           err->plid() );
            }
            // Check for any attentions and invoke PRD for analysis
            else if ( true == theStep->taskflags.check_attn )
            {
                TRACDCOMP( g_trac_initsvc,
                           INFO_MRK"Check for attentions and invoke PRD" );

                err = ATTN::checkForIplAttentions();

                if ( err )
                {
                    TRACFCOMP( g_trac_initsvc,
                               "IStepDipspatcher (worker): "
                               "ERROR return from PRD analysis after Istep %s",
                               theStep->taskname);
                }
            }

        }
        else
        {
#if 1
            TRACFCOMP( g_trac_initsvc,
                       "istepWorker: Empty Istep, nothing to do!" );
#else
            //  @TODO reopen issue 70657
            //  Invalid istep sent from FSP or spless, return error.
            TRACFCOMP( g_trac_initsvc,
                       "istepWorker: ERROR: "
                       "Invalid Istep %d, substep %d ",
                       istep,
                       substep );
            //  This istep should have not been sent here to run, make up
            //  an errorlog and return it.
            /*@
             * @errortype
             * @reasoncode       ISTEP_INVALID_ISTEP
             * @severity         ERRORLOG::ERRL_SEV_UNRECOVERABLE
             * @moduleid         ISTEP_INITSVC_MOD_ID
             * @userdata1        Current Istep
             * @userdata2        Current SubStep
             * @devdesc          An invalid istep or substep was passed.
             */
            err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                           ISTEP_INITSVC_MOD_ID,
                                           ISTEP_INVALID_ISTEP,
                                           istep,
                                           substep  );

            TRACFCOMP( g_trac_initsvc,
                       ERR_MRK"istepWorker ERROR:"
                       "Invalid Istep %d.%d, returned errlog PLID=0x%x",
                       istep,
                       substep,
                       err->plid()  );
#endif

        }


        msg_free( theMsg );
        theMsg = NULL;
    }   // end while(1)

    // Something bad happened...  this thread should never exit once started
    assert( false, "istepWorker:  should never get here." );
}


// load module routine used in simple temp solution
// for module management
void loadModules( uint32_t istepNumber )
{
    errlHndl_t l_errl = NULL;
    do
    {
        //  if no dep modules then just exit out, let the call to
        //  executeFN load the module based on the function being
        //  called.
        if( g_isteps[istepNumber].depModules == NULL)
        {
            TRACDCOMP( g_trac_initsvc,
                    "g_isteps[%d].depModules == NULL",
                    istepNumber );
            break;
        }
        uint32_t i = 0;

        while( ( l_errl == NULL ) &&
                ( g_isteps[istepNumber].depModules->modulename[i][0] != 0) )
        {
            TRACFCOMP( g_trac_initsvc,
                    "loading [%s]",
                    g_isteps[istepNumber].depModules->modulename[i]);

            l_errl = VFS::module_load(
                    g_isteps[istepNumber].depModules->modulename[i] );
            i++;
        }

        if( l_errl )
        {
            errlCommit( l_errl, ISTEP_COMP_ID );
            assert(0);
        }

    }while(0);
}


// unload module routine used in simple temp solution
// for module management
void unLoadModules( uint32_t istepNumber )
{
    errlHndl_t l_errl = NULL;

    do
    {
        //  if no dep modules then just exit out
        if( g_isteps[istepNumber].depModules == NULL)
        {
            TRACDCOMP( g_trac_initsvc,
                    "g_isteps[%d].depModules == NULL",
                    istepNumber );
            break;
        }
        uint32_t i = 0;

        while( ( l_errl == NULL ) &&
                ( g_isteps[istepNumber].depModules->modulename[i][0] != 0) )
        {
            TRACFCOMP( g_trac_initsvc,
                    "unloading [%s]",
                    g_isteps[istepNumber].depModules->modulename[i]);

            l_errl = VFS::module_unload(
                    g_isteps[istepNumber].depModules->modulename[i] );

            i++;
        }

        if( l_errl )
        {
            TRACFCOMP( g_trac_initsvc,
                    " failed to unload module, commit error and move on");
            errlCommit(l_errl, INITSVC_COMP_ID );
            l_errl = NULL;
        }

    }while(0);
}

// ----------------------------------------------------------------------------
// findTaskInfo()
// ----------------------------------------------------------------------------
const TaskInfo * findTaskInfo( const uint32_t i_IStep,
                               const uint32_t i_SubStep )
{
    //  default return is NULL
    const TaskInfo *l_pistep = NULL;

    // Cache the ipl mode since it doesn't change during an IPL
    static bool l_mpipl_mode = IStepDispatcher::getTheInstance().isMpiplMode();

    //  apply filters
    do
    {
        //  Sanity check / dummy IStep
        if( g_isteps[i_IStep].pti == NULL)
        {
            TRACDCOMP( g_trac_initsvc,
                       "g_isteps[%d].pti == NULL (substep=%d)",
                       i_IStep,
                       i_SubStep );
            break;
        }

        // check input range - IStep
        if( i_IStep >= INITSERVICE::MaxISteps )
        {
            TRACDCOMP( g_trac_initsvc,
                       "IStep %d out of range. (substep=%d) ",
                       i_IStep,
                       i_SubStep );
            break;      // break out with l_pistep set to NULL
        }

        //  check input range - ISubStep
        if( i_SubStep >= g_isteps[i_IStep].numitems )
        {
            TRACDCOMP( g_trac_initsvc,
                       "IStep %d Substep %d out of range.",
                       i_IStep,
                       i_SubStep );
            break;      // break out with l_pistep set to NULL
        }

        //   check for end of list.
        if( g_isteps[i_IStep].pti[i_SubStep].taskflags.task_type
            == END_TASK_LIST )
        {
            TRACDCOMP( g_trac_initsvc,
                       "IStep %d SubStep %d task_type==END_TASK_LIST.",
                       i_IStep,
                       i_SubStep );
            break;
        }

        //  check to see if the pointer to the function is NULL.
        //  This is possible if some of the substeps aren't working yet
        //  and are just placeholders.
        if( g_isteps[i_IStep].pti[i_SubStep].taskfn == NULL )
        {
            TRACDCOMP( g_trac_initsvc,
                       "IStep %d SubStep %d fn ptr is NULL.",
                       i_IStep,
                       i_SubStep );
            break;
        }

        //  check to see if we should skip this istep
        //  This is possible depending on which IPL mode we're in
        uint8_t l_ipl_op = g_isteps[i_IStep].pti[i_SubStep].taskflags.ipl_op;
        if (true == l_mpipl_mode)
        {
            if (!(l_ipl_op & MPIPL_OP))
            {
                TRACDCOMP( g_trac_initsvc,
                           "Skipping IStep %d SubStep %d for MPIPL mode",
                           i_IStep,
                           i_SubStep );
                break;
            }
        }
        else
        {
            if (!(l_ipl_op & NORMAL_IPL_OP))
            {
                TRACDCOMP( g_trac_initsvc,
                           "Skipping IStep %d SubStep %d for non MPIPL mode",
                           i_IStep,
                           i_SubStep );
                break;
            }
        }

        //  we're good, set the istep & return it to caller
        l_pistep = &( g_isteps[i_IStep].pti[i_SubStep] );
    } while( 0 );

    return  l_pistep;
}

bool getSyncEnabledAttribute()
{
    using namespace TARGETING;

    Target* l_pTopLevel = NULL;

    uint8_t l_syncEnabled = 0;

    TargetService& l_targetService = targetService();

    l_targetService.getTopLevelTarget( l_pTopLevel );

    if( l_pTopLevel == NULL )
    {
        TRACFCOMP( g_trac_initsvc,
                "Top level handle was NULL, default sync not enabled" );
        /*@
         * @errortype
         * @reasoncode       ISTEP::ISTEP_TOP_LEVEL_TARGET_NULL
         * @severity         ERRORLOG::ERRL_SEV_UNRECOVERABLE
         * @moduleid         ISTEP_INITSVC_MOD_ID
         * @userdata1        N/A
         * @userdata2        N/A
         * @devdesc          call to get top level targeting handle
         *                   returned null.
         */

        errlHndl_t err = new ERRORLOG::ErrlEntry(
                                ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                ISTEP::ISTEP_INITSVC_MOD_ID,
                                ISTEP::ISTEP_TOP_LEVEL_TARGET_NULL );

        errlCommit( err, ISTEP_COMP_ID );
    }
    else
    {
        l_syncEnabled = l_pTopLevel->getAttr<ATTR_SYNC_BETWEEN_STEPS> ();
    }

    return  ( (l_syncEnabled) ? true : false );

}
} // namespace
OpenPOWER on IntegriCloud