summaryrefslogtreecommitdiffstats
path: root/src/usr/mbox/ipcSp.C
blob: d0110db9879cf24b55d8c75c964196f4695b4a31 (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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/mbox/ipcSp.C $                                        */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2013,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                                                     */
#include <mbox/ipc_msg_types.H>
#include "ipcSp.H"
#include <runtime/runtime.H>
#include <vfs/vfs.H>
#include <mbox/ipc_reasoncodes.H>
#include <mbox/mboxif.H>
#include <errl/errlmanager.H>
#include <mbox/mbox_reasoncodes.H>
#include <intr/interrupt.H>
#include <initservice/initserviceif.H>
#include <sbeio/sbeioif.H>
#include <util/utiltce.H>
#include <targeting/targplatutil.H>

namespace ISTEP_21
{
    extern errlHndl_t callShutdown ( uint64_t i_hbInstance,
                                     bool i_masterInstance,
                                     const uint64_t i_commBase );

    extern errlHndl_t callCheckFreqAttrData(uint64_t freqData1, uint64_t freqData2);
};

trace_desc_t* g_trac_ipc = NULL;
TRAC_INIT(&g_trac_ipc, IPC_TRACE_NAME, KILOBYTE);

using namespace IPC;
using namespace ERRORLOG;
using namespace TARGETING;

IpcSp::IpcSp()
    :
        iv_msgQ()
{
}

IpcSp::~IpcSp()
{
    msg_q_destroy(iv_msgQ);
}

void IpcSp::init(errlHndl_t & o_errl)
{
    o_errl = Singleton<IpcSp>::instance()._init();
}

void* IpcSp::msg_handler(void *unused)
{
    Singleton<IpcSp>::instance().msgHandler();
    return NULL;
}

errlHndl_t IpcSp::_init()
{
    errlHndl_t err = NULL;

    iv_msgQ = msg_q_create();
    err = MBOX::msgq_register(MBOX::HB_IPC_MSGQ,iv_msgQ);


    if(!err)
    {
        task_create(IpcSp::msg_handler, NULL);
    }

    return err;
}

void IpcSp::msgHandler()
{
    errlHndl_t err = NULL;
    bool mod_loaded = false;

    while(1)
    {
        msg_t* msg = msg_wait(iv_msgQ);

        switch(msg->type)
        {
            case IPC_POPULATE_TPM_INFO_BY_NODE:
            {
                // make sure runtime module is loaded
                if ( !VFS::module_is_loaded( "libruntime.so" ) )
                {
                    err = VFS::module_load( "libruntime.so" );

                    if ( err )
                    {
                        TRACFCOMP( g_trac_ipc,
                                   "Could not load runtime module - must shutdown now!!!" );
                    }
                    else
                    {
                        mod_loaded = true;
                    }
                }

                if(!err)
                {
                    // msg->extra_data contains PAYLOAD Base
                    RUNTIME::setPayloadBaseAddress(
                               reinterpret_cast<uint64_t>(msg->extra_data));

                    // msg->data[0] contains the HDAT TPM info instance
                    // to populate
                    err = RUNTIME::populate_TpmInfoByNode(msg->data[0]);
                    if(err)
                    {
                        TRACFCOMP( g_trac_ipc, ERR_MRK"IpcSp::msgHandler: populate_TpmInfoByNode errored - must shutdown now!!!");
                    }
                }

                if (err)
                {
                    const auto l_errPlid = err->plid();
                    errlCommit(err, IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }

                if(mod_loaded)
                {
                    err = VFS::module_unload( "libruntime.so" );

                    if (err)
                    {
                        errlCommit(err, IPC_COMP_ID);
                    }
                    mod_loaded = false;
                }

                // give a response back to the sender
                err = MBOX::send(MBOX::HB_POP_TPM_INFO_MSGQ, msg, msg->data[1]);
                if (err)
                {
                    const auto l_errPlid = err->plid();
                    errlCommit(err,IPC_COMP_ID);
                    msg_free(msg);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }
                break;
            }

            case IPC_POPULATE_ATTRIBUTES:
                // make sure runtime module is loaded
                if ( !VFS::module_is_loaded( "libruntime.so" ) )
                {
                    err = VFS::module_load( "libruntime.so" );

                    if ( err )
                    {
                        TRACFCOMP( g_trac_ipc,
                                   "Could not load runtime module" );
                    }
                    else
                    {
                        mod_loaded = true;
                    }
                }

                if(!err)
                {
                    // msg->extra_data contains PAYLOAD Base
                    RUNTIME::setPayloadBaseAddress(
                        reinterpret_cast<uint64_t>(msg->extra_data));

                    // msg->data[0] contains the node number
                    err = RUNTIME::populate_HbRsvMem( msg->data[0] );
                }

                if (err)
                {
                    TRACFCOMP( g_trac_ipc, "In ipcSp: populate_node_attribute errored - must shutdown now!!!");
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err, IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }

                if(mod_loaded)
                {
                    err = VFS::module_unload( "libruntime.so" );

                    if (err)
                    {
                        errlCommit(err, IPC_COMP_ID);
                    }
                    mod_loaded = false;
                }

                // Respond
                err = MBOX::send(MBOX::HB_POP_ATTR_MSGQ, msg, msg->data[1] );
                if (err)
                {
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err,IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }
                break;

            case IPC_TEST_CONNECTION:

                TRACFCOMP( g_trac_ipc,
                           "IPC received the test connection msg - %d:%d",
                            msg->data[0], msg->data[1] );

                // Tell this HB node about the other HB node
                err = INTR::addHbNode(msg->data[1]);
                if( err)
                {
                    errlCommit(err,IPC_COMP_ID);
                }

                //Send a response to indicate the connection has been
                //established
                err = MBOX::send(MBOX::HB_COALESCE_MSGQ, msg, msg->data[1] );

                if (err)
                {
                    errlCommit(err,IPC_COMP_ID);
                }
                break;

            case IPC_QUERY_CHIPINFO:
            {
                TARGETING::TargetHandleList l_procChips;
                getAllChips( l_procChips, TARGETING::TYPE_PROC , true);
                uint64_t l_systemFabricConfigurationMap = 0x0;
                for(auto l_proc : l_procChips)
                {
                    //Get fabric info from proc
                    uint8_t l_fabricChipId =
                      l_proc->getAttr<TARGETING::ATTR_FABRIC_CHIP_ID>();
                    uint8_t l_fabricGroupId =
                      l_proc->getAttr<TARGETING::ATTR_FABRIC_GROUP_ID>();
                    //Calculate what bit position this will be
                    uint8_t l_bitPos = l_fabricChipId + (RUNTIME::MAX_PROCS_PER_NODE * l_fabricGroupId);

                    //Set the bit @ l_bitPos to be 1 because this is a functional proc
                    l_systemFabricConfigurationMap |= (0x8000000000000000 >> l_bitPos);
                }

                TRACFCOMP( g_trac_ipc,
                           "IPC Query ChipInfo 0x%lx", l_systemFabricConfigurationMap);

                //Send a response with this HB instances chip info
                msg->extra_data = reinterpret_cast<uint64_t*>(l_systemFabricConfigurationMap);
                err = MBOX::send(MBOX::HB_SBE_SYSCONFIG_MSGQ, msg, msg->data[1] );
                if (err)
                {
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err,IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }
                break;
             }
             case IPC_SET_SBE_CHIPINFO:
             {
                //Need to send System Configuration down to SBE
                //Master sends info to set into SBE via msg->extra_data
                uint64_t l_systemFabricConfigurationMap =
                        reinterpret_cast<uint64_t>(msg->extra_data);

                TRACFCOMP( g_trac_ipc,
                           "sending systemConfig[0x%lx] to SBEs",
                           l_systemFabricConfigurationMap);

                TARGETING::TargetHandleList l_procChips;
                getAllChips( l_procChips, TARGETING::TYPE_PROC , true);
                for(auto l_proc : l_procChips)
                {
                    TRACDCOMP( g_trac_ipc,
                               "calling sendSystemConfig on proc 0x%x",
                               TARGETING::get_huid(l_proc));
                    err = SBEIO::sendSystemConfig(l_systemFabricConfigurationMap,
                                                    l_proc);
                    if ( err )
                    {
                        TRACFCOMP( g_trac_ipc,
                                   "sendSystemConfig ERROR : Error sending sbe chip-op to proc 0x%.8X. Returning errorlog, reason=0x%x",
                                   TARGETING::get_huid(l_proc),
                                   err->reasonCode() );
                        break;
                    }
                }

                //If error terminate here
                if(err)
                {
                    TRACFCOMP( g_trac_ipc, "In ipcSp: SBEIO::sendSystemConfig errored - must shutdown now!!!");
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err, IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }
                else
                {
                    TRACFCOMP( g_trac_ipc,
                               "Successfully sent all system configs to procs via SBE chip op !!");
                }

                //Send response back to the master HB to indicate successful configuration down to SBE
                err = MBOX::send(MBOX::HB_SBE_SYSCONFIG_MSGQ, msg, msg->data[1] );
                if (err)
                {
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err,IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }
                break;
             }

            case IPC_FREQ_ATTR_DATA:
            {

                TRACFCOMP( g_trac_ipc,
                           "IPC received the IPC_FREQ_ATTR_DATA msg - %u:%u",
                            msg->data[0]>>32, (msg->data[0]& 0xFFFFFFFF));

                const int NUM_MOD = 2;
                const char * mods[NUM_MOD] =
                   { "libistep21.so","libruntime.so"};
                bool loaded_mods[NUM_MOD] = {false, false};
                for (auto cnt = 0; cnt < NUM_MOD; ++cnt)
                {
                    if ( !VFS::module_is_loaded( mods[cnt] ) )
                    {
                        err = VFS::module_load( mods[cnt] );

                        if ( err )
                        {
                            TRACFCOMP( g_trac_ipc,
                                       "Could not load %s module", mods[cnt] );
                            break;
                        }
                        else
                        {
                            loaded_mods[cnt] = true;
                        }
                    }
                }

                if(!err)
                {
                    uint64_t l_freqData1 =
                        reinterpret_cast<uint64_t>(msg->data[1]);

                    uint64_t l_freqData2 =
                        reinterpret_cast<uint64_t>(msg->extra_data);

                    //  Function checks frequency attribute data. Returns an error
                    //  if there is a mismatch with that of HB master data
                    err = ISTEP_21::callCheckFreqAttrData(l_freqData1, l_freqData2);
                }

                if (err)
                {
                   uint32_t l_errPlid = err->plid();
                   errlCommit(err,IPC_COMP_ID);
                   INITSERVICE::doShutdown(l_errPlid, true);
                }

                for (auto cnt = 0; cnt < NUM_MOD; ++cnt)
                {
                    if ( loaded_mods[cnt] )
                    {
                        err = VFS::module_unload( mods[cnt] );

                        if (err)
                        {
                            errlCommit(err, IPC_COMP_ID);
                        }
                        loaded_mods[cnt] = false;
                    }

                }

                 //Send response back to the master HB to indicate set freq attr successful
                 err = MBOX::send(MBOX::HB_FREQ_ATTR_DATA_MSGQ, msg, (msg->data[0]& 0xFFFFFFFF) );

                 if (err)
                 {
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err,IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                 }



             break;

            }

             case IPC_START_PAYLOAD:
            {
                const int NUM_MOD = 4;
                const char * mods[NUM_MOD] =
                   {"libp9_cpuWkup.so", "libistep21.so", "libpm.so",
                   "libruntime.so"};
                bool loaded_mods[NUM_MOD] = {false, false, false};
                for (auto cnt = 0; cnt < NUM_MOD; ++cnt)
                {
                    if ( !VFS::module_is_loaded( mods[cnt] ) )
                    {
                        err = VFS::module_load( mods[cnt] );

                        if ( err )
                        {
                            TRACFCOMP( g_trac_ipc,
                                       "Could not load %s module", mods[cnt] );
                            break;
                        }
                        else
                        {
                            loaded_mods[cnt] = true;
                        }
                    }
                }

                if (err) break;

                if(!err)
                {
                    //  Function will not return unless error
                    err = ISTEP_21::callShutdown(msg->data[0],false,
                                                                  msg->data[1]);
                }

                if(err)
                {
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err, IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }

                for (auto cnt = 0; cnt < NUM_MOD; ++cnt)
                {
                    if ( loaded_mods[cnt] )
                    {
                        err = VFS::module_unload( mods[cnt] );

                        if (err)
                        {
                            errlCommit(err, IPC_COMP_ID);
                        }
                        loaded_mods[cnt] = false;
                    }

                }

                msg_free(msg);

                break;
            }

            case IPC_CLOSE_TCES:
            {
               TRACFCOMP( g_trac_ipc,
                          "Closing TCEs on this node (%d)",
                          TARGETING::UTIL::getCurrentNodePhysId());

                // make sure util module is loaded
                const char * libutil = "libutil.so";
                if ( !VFS::module_is_loaded( libutil ) )
                {
                    err = VFS::module_load( libutil );

                    if ( err )
                    {
                        TRACFCOMP( g_trac_ipc,
                                   "Could not load util module" );
                    }
                    else
                    {
                        mod_loaded = true;
                    }
                }

                if(!err)
                {
                    err = TCE::utilClosePayloadTces();
                }

                if(!err)
                {
                    err = TCE::utilDisableTces();
                }

                if(err)
                {
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err, IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }

                if(mod_loaded)
                {
                    err = VFS::module_unload( libutil );

                    if (err)
                    {
                        errlCommit(err, IPC_COMP_ID);
                    }
                    else
                    {
                        mod_loaded = false;
                    }
                }

                // Respond
                err = MBOX::send(MBOX::HB_CLOSE_TCES_MSGQ, msg, msg->data[1] );
                if (err)
                {
                    uint32_t l_errPlid = err->plid();
                    errlCommit(err,IPC_COMP_ID);
                    INITSERVICE::doShutdown(l_errPlid, true);
                }

                break;
            }

            default:

                TRACFCOMP( g_trac_ipc,
                           "IPC received an unexpected message type of %d",
                           msg->type);

                /*@ errorlog tag
                 * @errortype  ERRL_SEV_INFORMATIONAL
                 * @moduleid   IPC::MOD_IPCSP_MSGHDLR
                 * @reasoncode IPC::RC_INVALID_MSG_TYPE
                 * @userdata1  Message type
                 * @userdata2  Data word 0 of message
                 *
                 * @devdesc    IPC service provider received an unexpected
                 *             message.
                 *
                 */
                err = new ERRORLOG::ErrlEntry
                    (
                     ERRORLOG::ERRL_SEV_INFORMATIONAL,    // severity
                     IPC::MOD_IPCSP_MSGHDLR,              // moduleid
                     IPC::RC_INVALID_MSG_TYPE,            // reason code
                     msg->type,
                     msg->data[0],
                     true //Add HB Software Callout
                    );
                //@todo: RTC:93750 Create real parseable FFDC class
                err->addFFDC(MBOX_COMP_ID,
                             msg,
                             sizeof(msg_t),
                             1,//version
                             MBOX::MBOX_UDT_MSG_DATA);//subsect

                err->collectTrace(MBOXMSG_TRACE_NAME);
                err->collectTrace(IPC_TRACE_NAME);

                errlCommit(err, IPC_COMP_ID);

                msg_free(msg);

                break;
        }
    }
}


OpenPOWER on IntegriCloud