summaryrefslogtreecommitdiffstats
path: root/src/usr/util/runtime/rt_fwnotify.C
blob: a96b24bba28844840de3515b41e5e5dbb9099df6 (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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/util/runtime/rt_fwnotify.C $                          */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017,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                                                     */

#include <sbeio/sbe_retry_handler.H>       // SbeRetryHandler
#include <util/runtime/rt_fwreq_helper.H>  // firmware_request_helper
#include <runtime/interface.h>             // g_hostInterfaces
#include <runtime/runtime_reasoncodes.H>   // MOD_RT_FIRMWARE_NOTIFY, etc
#include <errl/errlentry.H>                // ErrlEntry
#include <errl/errlmanager.H>              // errlCommit
#include <errl/hberrltypes.H>              // TWO_UINT32_TO_UINT64
#include <targeting/common/target.H>       // TargetHandle_t, getTargetFromHuid
#include <runtime/rt_targeting.H>          // RT_TARG::getHbTarget
#include <attributeenums.H>                // ATTRIBUTE_ID

#ifdef CONFIG_NVDIMM
#include <isteps/nvdimm/nvdimm.H>          // NVDIMM related activities
#include <targeting/common/targetUtil.H>   // makeAttribute
#include <runtime/hbrt_utilities.H>
using namespace NVDIMM;
#endif

using namespace TARGETING;
using namespace RUNTIME;
using namespace ERRORLOG;
using namespace MBOX;
using namespace SBEIO;


// Trace definition
extern trace_desc_t* g_trac_runtime;
extern trace_desc_t* g_trac_hbrt;

/**
 * @brief The lower and upper bounds for the sequence ID.
 **/
const uint16_t SEQ_ID_MIN = 0x0000;
const uint16_t SEQ_ID_MAX = 0x7FFF;

/**
 * @brief Set the sequence ID to the minimum value
 **/
uint16_t SeqId_t::SEQ_ID = SEQ_ID_MIN;

/**
 * @brief Gets the next sequence ID.
 * @return The next sequence ID value within its lower and upper bound
 * @note This code is thread safe, no need for a mutex around this because
 *       HBRT never runs in multi-thread.
 *
 **/
uint16_t SeqId_t::getNextSeqId()
{
    if (SeqId_t::SEQ_ID < SEQ_ID_MAX)
    {
        ++SeqId_t::SEQ_ID;
    }
    else
    {
        SeqId_t::SEQ_ID = SEQ_ID_MIN;
    }

    return SeqId_t::SEQ_ID;
}

/**
 *  @brief Gets the current value of the sequence ID.
 *  @return The current value of the sequence ID.
 **/
uint16_t SeqId_t::getCurrentSeqId()
{
    return SeqId_t::SEQ_ID;
}

/**
 *  @brief Attempt an SBE recovery after an SBE error
 *  @param[in] uint64_t i_data Contains a HUID (in the first 4 bytes)
 *                             and a plid (in the last 4 bytes)
 *  @platform FSP, OpenPOWER
 **/
void sbeAttemptRecovery(uint64_t i_data)
{
    // Create a useful struct to get to the data
    // The data is expected to be a HUID (in the first 4 bytes)
    // followed by a PLID (in the last 4 bytes).
    SbeRetryReqData_t *l_sbeRetryData = reinterpret_cast<SbeRetryReqData_t*>(&i_data);

    TRACFCOMP(g_trac_runtime, ENTER_MRK"sbeAttemptRecovery: plid:0x%X, "
             "HUID:0x%X", l_sbeRetryData->plid, l_sbeRetryData->huid);

    errlHndl_t l_err = nullptr;

    do
    {
        // Extract the target from the given HUID
        TargetHandle_t l_target =
                        Target::getTargetFromHuid(l_sbeRetryData->huid);

        // If HUID invalid, log error and quit
        if (nullptr == l_target)
        {
            TRACFCOMP(g_trac_runtime, ERR_MRK"sbeAttemptRecovery: "
                       "No target associated with HUID:0x%.8X",
                       l_sbeRetryData->huid);

            /*@
             * @errortype
             * @severity     ERRL_SEV_PREDICTIVE
             * @moduleid     MOD_RT_FIRMWARE_NOTIFY
             * @reasoncode   RC_SBE_RT_INVALID_HUID
             * @userdata1    HUID of target
             * @userdata2    HWSV error log id (plid)
             * @devdesc      SBE error recovery attempt failed
             */
            l_err = new ErrlEntry( ERRL_SEV_PREDICTIVE,
                                   MOD_RT_FIRMWARE_NOTIFY,
                                   RC_SBE_RT_INVALID_HUID,
                                   l_sbeRetryData->huid,
                                   l_sbeRetryData->plid,
                                   true);
            break;
        }

        // Get the SBE Retry Handler, propagating the supplied PLID
        SbeRetryHandler l_SBEobj = SbeRetryHandler(SbeRetryHandler::
                                    SBE_MODE_OF_OPERATION::ATTEMPT_REBOOT,
                                    l_sbeRetryData->plid);

        //Attempt to recover the SBE
        l_SBEobj.main_sbe_handler(l_target);


        if (nullptr == g_hostInterfaces ||
            nullptr == g_hostInterfaces->firmware_request)
        {
            TRACFCOMP(g_trac_runtime, ERR_MRK"sbeAttemptRecovery: "
                       "Hypervisor firmware_request interface not linked");

            /*@
             * @errortype
             * @severity     ERRL_SEV_PREDICTIVE
             * @moduleid     MOD_RT_FIRMWARE_NOTIFY
             * @reasoncode   RC_FW_REQUEST_RT_NULL_PTR
             * @userdata1    HUID of target
             * @userdata2    HWSV error log id (plid)
             * @devdesc      SBE error recovery attempt failed
             */
            l_err = new ErrlEntry( ERRL_SEV_PREDICTIVE,
                                   MOD_RT_FIRMWARE_NOTIFY,
                                   RC_FW_REQUEST_RT_NULL_PTR,
                                   l_sbeRetryData->huid,
                                   l_sbeRetryData->plid,
                                   true);

           break;
        }

        // Create the firmware_request request struct to send data
        hostInterfaces::hbrt_fw_msg l_req_fw_msg;
        uint64_t l_req_fw_msg_size = sizeof(l_req_fw_msg);

        // Initialize the firmware_request request struct
        l_req_fw_msg.generic_msg.initialize();

        // Populate the firmware_request request struct with given data
        l_req_fw_msg.io_type = hostInterfaces::HBRT_FW_MSG_HBRT_FSP_REQ;
        l_req_fw_msg.generic_msg.msgq = GenericFspMboxMessage_t::FSP_HBRT_MESSAGEQ;
        l_req_fw_msg.generic_msg.__req = GenericFspMboxMessage_t::REQUEST;
        l_req_fw_msg.generic_msg.data = i_data;

        // Set msgType based on recovery success or failure (If sbe made it back to runtime)
        if (l_SBEobj.isSbeAtRuntime())
        {
            TRACFCOMP(g_trac_runtime, "sbeAttemptRecovery: RECOVERY_SUCCESS");
            l_req_fw_msg.generic_msg.msgType =
                             GenericFspMboxMessage_t::MSG_SBE_RECOVERY_SUCCESS;
        }
        else
        {
            TRACFCOMP(g_trac_runtime, "sbeAttemptRecovery: RECOVERY_FAILED");
            l_req_fw_msg.generic_msg.msgType =
                              GenericFspMboxMessage_t::MSG_SBE_RECOVERY_FAILED;
        }

        // Create the firmware_request response struct to receive data
        // NOTE: For messages to the FSP the response size must match
        // the request size
        // No need to check for expected response size > request
        // size because they use the same base structure
        hostInterfaces::hbrt_fw_msg l_resp_fw_msg;
        uint64_t l_resp_fw_msg_size = sizeof(l_resp_fw_msg);
        memset(&l_resp_fw_msg, 0, l_resp_fw_msg_size);

        // Trace out the request structure
        TRACFBIN( g_trac_runtime, INFO_MRK"Sending firmware_request",
                  &l_req_fw_msg,
                  l_req_fw_msg_size);

        // Make the firmware_request call
        l_err = firmware_request_helper(l_req_fw_msg_size,
                                        &l_req_fw_msg,
                                        &l_resp_fw_msg_size,
                                        &l_resp_fw_msg);

        if (l_err)
        {
            break;
        }
    } while(0);

    if (l_err)
    {
       //Commit the error if it exists
       errlCommit(l_err, RUNTIME_COMP_ID);
    }

    TRACFCOMP(g_trac_runtime, EXIT_MRK"sbeAttemptRecovery");
}

/**
 *  @brief Attempt to notify PHYP of OCC active status change
 *  @param[in] i_data - contains a byte indicating OCC active status
 *  @platform FSP
 **/
void occActiveNotification( void * i_data )
{
    // data is one byte - 1 = OCC active, 0 = OCC not active
    uint8_t * l_active = reinterpret_cast<uint8_t*>(i_data);

    // Just a safety check
    assert(l_active != nullptr, "occActiveNotification: invalid NULL data ptr");

    TRACFCOMP(g_trac_runtime, ENTER_MRK"occActiveNotification: 0x%02X", *l_active);

#ifdef CONFIG_NVDIMM
    errlHndl_t l_err = nullptr;

    TargetHandleList l_procList;
    getAllChips(l_procList, TYPE_PROC);

    // Now send msg to PHYP notifying them if OCC is protecting the NVDIMMs
    for (auto & l_proc : l_procList)
    {
        if (*l_active)
        {
            l_err = NVDIMM::notifyNvdimmProtectionChange(l_proc,
                                                         NVDIMM::OCC_ACTIVE);
            // Arm the nvdimms
            Target* l_sys = nullptr;
            targetService().getTopLevelTarget( l_sys );
            assert(l_sys, "occActiveNotification: no TopLevelTarget");

            if (l_sys->getAttr<ATTR_NVDIMM_AUTO_ARM>())
            {
                TARGETING::TargetHandleList l_nvdimmTargetList =
                                    TARGETING::getProcNVDIMMs(l_proc);
                NVDIMM::nvdimmArm(l_nvdimmTargetList);
            }
        }
        else
        {
            l_err = NVDIMM::notifyNvdimmProtectionChange(l_proc,
                                                         NVDIMM::OCC_INACTIVE);
        }

        // commit error if it exists
        // continue notification to all functional processors
        if (l_err)
        {
            TRACFCOMP(g_trac_runtime,
                      ERR_MRK"occActiveNotification: 0x%02X - 0x%.8X processor",
                      *l_active, TARGETING::get_huid(l_proc));

            errlCommit(l_err, RUNTIME_COMP_ID);
            l_err = nullptr;
        }
    }
#endif
}

/**
 *  @brief Attempt to sync attribute setting with the FSP
 *  @param[in] void * i_data - contains a target huid, attribute id,
 *                             attribute data length, and attribute data
 *  @platform FSP
 **/
void attrSyncRequest( void * i_data)
{
    HbrtAttrSyncData_t * l_hbrtAttrData =
                                reinterpret_cast<HbrtAttrSyncData_t*>(i_data);
    TRACFCOMP(g_trac_runtime, ENTER_MRK"attrSyncRequest: Target HUID 0x%0X "
             "for AttrID: 0x%0X with AttrSize: %lld", l_hbrtAttrData->huid,
             l_hbrtAttrData->attrID, l_hbrtAttrData->sizeOfAttrData);

    TRACFBIN(g_trac_runtime, "Attribute data: ",
             &(l_hbrtAttrData->attrDataStart),
             l_hbrtAttrData->sizeOfAttrData);

    // extract the target from the given HUID
    TargetHandle_t l_target = Target::getTargetFromHuid(l_hbrtAttrData->huid);

    // Assumes the attribute is writeable
    bool attr_updated = l_target->unsafeTrySetAttr(
                                               l_hbrtAttrData->attrID,
                                               l_hbrtAttrData->sizeOfAttrData,
               reinterpret_cast<const void*>(&(l_hbrtAttrData->attrDataStart)));

    if (!attr_updated)
    {
        TRACFCOMP(g_trac_runtime,ERR_MRK"attrSyncRequest: "
                    "Unable to update attribute");

        // Copy the first couple bytes of new attribute data (up to 4 bytes)
        uint32_t l_attrData = 0;
        uint32_t l_attrSize = l_hbrtAttrData->sizeOfAttrData;
        if (l_attrSize > sizeof(l_attrData))
        {
            l_attrSize = sizeof(l_attrData);
        }
        memcpy(&l_attrData, &(l_hbrtAttrData->attrDataStart), l_attrSize);

        /*@
         * @errortype
         * @severity     ERRL_SEV_PREDICTIVE
         * @moduleid     MOD_RT_ATTR_SYNC_REQUEST
         * @reasoncode   RC_ATTR_UPDATE_FAILED
         * @userdata1[0:31]  Target HUID
         * @userdata1[32:63] Attribute ID
         * @userdata2[0:31]  Data Size
         * @userdata2[32:63] Up to 4 bytes of attribute data
         * @devdesc      Attribute failed to update on HBRT side
         */
        errlHndl_t l_err = new ErrlEntry(ERRL_SEV_PREDICTIVE,
                                         MOD_RT_ATTR_SYNC_REQUEST,
                                         RC_ATTR_UPDATE_FAILED,
                                         TWO_UINT32_TO_UINT64(
                                            l_hbrtAttrData->huid,
                                            l_hbrtAttrData->attrID),
                                         TWO_UINT32_TO_UINT64(
                                            l_hbrtAttrData->sizeOfAttrData,
                                            l_attrData),
                                         true);

        l_err->collectTrace(RUNTIME_COMP_NAME, 256);

        //Commit the error
        errlCommit(l_err, RUNTIME_COMP_ID);
    }

    TRACFCOMP(g_trac_runtime, EXIT_MRK"attrSyncRequest");
}

#ifdef CONFIG_NVDIMM
/**
 * @brief Utility function to set ATTR_NVDIMM_ENCRYPTION_ENABLE
 *        and send the value to the FSP
 */
void set_ATTR_NVDIMM_ENCRYPTION_ENABLE(
            ATTR_NVDIMM_ENCRYPTION_ENABLE_type i_val )
{
    errlHndl_t l_err = nullptr;

    Target* l_sys = nullptr;
    targetService().getTopLevelTarget( l_sys );
    assert(l_sys, "set_ATTR_NVDIMM_ENCRYPTION_ENABLE: no TopLevelTarget");
    l_sys->setAttr<ATTR_NVDIMM_ENCRYPTION_ENABLE>(i_val);

    // Send it down to the FSP
    AttributeTank::Attribute l_attr = {};
    if( !makeAttribute<ATTR_NVDIMM_ENCRYPTION_ENABLE>
        (l_sys, l_attr) )
    {
        TRACFCOMP(g_trac_runtime, ERR_MRK"set_ATTR_NVDIMM_ENCRYPTION_ENABLE() Could not create Attribute");
        /*@
         *@errortype
         *@reasoncode       RC_CANNOT_MAKE_ATTRIBUTE
         *@severity         ERRORLOG_SEV_PREDICTIVE
         *@moduleid         SET_ATTR_NVDIMM_ENCRYPTION_ENABLE
         *@devdesc          Couldn't create an Attribute to send the data
         *                  to the FSP
         *@custdesc         NVDIMM encryption error
         */
        l_err = new ERRORLOG::ErrlEntry(
                                        ERRORLOG::ERRL_SEV_PREDICTIVE,
                                        SET_ATTR_NVDIMM_ENCRYPTION_ENABLE,
                                        RC_CANNOT_MAKE_ATTRIBUTE,
                                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT );
        l_err->collectTrace(NVDIMM_COMP_NAME);
        errlCommit( l_err, NVDIMM_COMP_ID );
    }
    else
    {
        std::vector<TARGETING::AttributeTank::Attribute> l_attrList;
        l_attrList.push_back(l_attr);
        l_err = sendAttributes( l_attrList );
        if (l_err)
        {
            TRACFCOMP(g_trac_runtime, ERR_MRK"set_ATTR_NVDIMM_ENCRYPTION_ENABLE() Error sending ATTR_NVDIMM_ENCRYPTION_ENABLE down to FSP");
            l_err->setSev(ERRORLOG::ERRL_SEV_PREDICTIVE);
            l_err->collectTrace(NVDIMM_COMP_NAME);
            errlCommit( l_err, NVDIMM_COMP_ID );
        }
    }
}
#endif //CONFIG_NVDIMM

/**
 *  @brief Perform an NVDIMM operation
 *  @param[in] i_nvDimmOp - A struct that contains the operation(s) to perform
 *                          and a flag indicating whether to perform operation
 *                          on all processors or a given single processor.
 *
 *  @Note The arming/disarming operations below are in the order of which they
 *        should be performed.  If a new sequence is added to the
 *        arming/disarming sequence, make sure it is inserted in the
 *        correct order.
 *        The current order is: disarm -> disable encryption -> remove keys ->
 *                              enable encryption -> arm
 **/
int doNvDimmOperation(const hostInterfaces::nvdimm_operation_t& i_nvDimmOp)
{
    int rc = 0;
#ifndef CONFIG_NVDIMM
    TRACFCOMP(g_trac_runtime, ENTER_MRK"doNvDimmOperation: not an "
              "NVDIMM configuration, this call becomes a noop.");

#else
    TRACFCOMP(g_trac_runtime, ENTER_MRK"doNvDimmOperation: Operation(s) "
              "0x%0X, processor ID  0x%0X",
              i_nvDimmOp.opType,
              i_nvDimmOp.procId);

    // Error log handle for capturing any errors
    errlHndl_t       l_err{nullptr};
    // List of NVDIMM Targets to execute NVDIMM operation on
    TargetHandleList l_nvDimmTargetList;

    // Perform the operations requested
    do
    {
        /// Populate the NVDIMM target list
        // If requesting to perform operation on all NVDIMMs, then
        // retrieve all NVDIMMs from system
        if (HBRT_NVDIMM_OPERATION_APPLY_TO_ALL_NVDIMMS == i_nvDimmOp.procId)
        {
            nvdimm_getNvdimmList(l_nvDimmTargetList);
        }
        // Else retrieve only the NVDIMMs from given processor ID
        else
        {
            /// Get the NVDIMMs associated with procId
            // Convert the procId to a real boy, uh, I mean target
            TARGETING::TargetHandle_t l_procTarget;
            l_err = RT_TARG::getHbTarget(i_nvDimmOp.procId, l_procTarget);
            if (l_err)
            {
                TRACFCOMP(g_trac_runtime, "doNvDimmOperation: Error getting "
                                          "HB Target from processor ID 0x%0X, "
                                          "exiting ...",
                                          i_nvDimmOp.procId);
                rc = -1;
                break;
            }

            // Get the list of NVDIMMs associated with processor target
            l_nvDimmTargetList = TARGETING::getProcNVDIMMs(l_procTarget);
        }

        // No point in continuing if the list of NVDIMM Targets is empty
        if (!l_nvDimmTargetList.size())
        {
            TRACFCOMP(g_trac_runtime, "doNvDimmOperation: No NVDIMMs found, "
                                      "exiting ...");
            rc = -1;
            break;
        }

        // Perform the arming/disarming operations.  If anyone fails in the
        // sequence, no point in calling the next, if there is a next operation.
        do
        {
            // Disarm the NV logic
            if (i_nvDimmOp.opType & hostInterfaces::HBRT_FW_NVDIMM_DISARM)
            {
                // Make call to disarm
                if (!nvdimmDisarm(l_nvDimmTargetList))
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                              "Call to disarm failed. Will not perform any "
                              "more arming/disarming calls, if they exist");
                    rc = -1;
                    break;
                }
                else
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                              "Call to disarm succeeded");
                }
            }

            // Disable encryption on the NVDIMM and clear saved values from FW
            if (i_nvDimmOp.opType &
                              hostInterfaces::HBRT_FW_NVDIMM_DISABLE_ENCRYPTION)
            {
                // Make call to disable encryption
                if (!nvdimm_crypto_erase(l_nvDimmTargetList))
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                              "Call to disable encryption failed.  Will not "
                              "perform any more arming/disarming calls, if "
                              "they exist");

                    // Clear the encryption enable attribute
                    set_ATTR_NVDIMM_ENCRYPTION_ENABLE(0);

                    rc = -1;
                    break;
                }
                else
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                       "Call to disable encryption succeeded.");
                }

                // Clear the encryption enable attribute
                set_ATTR_NVDIMM_ENCRYPTION_ENABLE(0);
            }

            // Remove keys
            if (i_nvDimmOp.opType & hostInterfaces::HBRT_FW_NVDIMM_REMOVE_KEYS)
            {
                // Make call to remove keys
                if (!nvdimm_remove_keys())
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                              "Call to remove keys failed.  Will not perform "
                              "any more arming/disarming calls, if they exist");
                    rc = -1;
                    break;
                }
                else
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                              "Call to remove keys succeeded.");
                }
            }

            // Enable encryption on the NVDIMM
            if (i_nvDimmOp.opType &
                               hostInterfaces::HBRT_FW_NVDIMM_ENABLE_ENCRYPTION)
            {
                // Set the encryption enable attribute
                set_ATTR_NVDIMM_ENCRYPTION_ENABLE(1);

                // Make call to generate keys before enabling encryption
                if(!nvdimm_gen_keys())
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                              "Call to generate keys failed, unable to enable "
                              "encryption. Will not perform any more "
                              "arming/disarming calls, if they exist");
                    rc = -1;
                    break;
                }
                else
                {
                    // Make call to enable encryption
                    if (!nvdimm_encrypt_enable(l_nvDimmTargetList))
                    {
                        TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                  "Call to enable encryption failed. "
                                  "Will not perform any more arming/disarming "
                                  "calls, if they exist");
                        rc = -1;
                        break;
                    }
                    else
                    {
                        TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                        "Call to enable encryption succeeded.");
                    }
                } // end if(!nvdimm_gen_keys()) ... else ...
            }

            // Arm the NV logic
            if (i_nvDimmOp.opType & hostInterfaces::HBRT_FW_NVDIMM_ARM)
            {
                // Make call to arm
                if (!nvdimmArm(l_nvDimmTargetList))
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                              "Call to arm failed.");
                    rc = -1;
                    break;
                }
                else
                {
                    TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                              "Call to arm succeeded.");
                }
            }  // end if (nvDimmOp.opType & hostInterfaces::HBRT_FW_NVDIMM_ARM)
        }  while (0); // end Perform the arming/disarming operations.

        // Perform the health check operation
        if (i_nvDimmOp.opType & hostInterfaces::HBRT_FW_MNFG_ES_HEALTH_CHECK)
        {
            if (!nvDimmCheckHealthStatus(l_nvDimmTargetList))
            {
                TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                          "Call to do a health check failed.");
                rc = -1;
                break;
            }
            else
            {
                TRACFCOMP(g_trac_runtime, "doNvDimmOperation: "
                                        "Call to do a health check succeeded.");
            }
        }
    } while(0); // end Perform the operations requested

    if (l_err)
    {
       //Commit the error if it exists
       errlCommit(l_err, RUNTIME_COMP_ID);
    }

#endif

    TRACFCOMP(g_trac_runtime, EXIT_MRK"doNvDimmOperation")
    return rc;
}

/**
 * @see  src/include/runtime/interface.h for definition of call
 *
 */
void firmware_notify( uint64_t i_len, void *i_data )
{
    TRACFCOMP(g_trac_hbrt, ENTER_MRK"firmware_notify: "
             "i_len:%d", i_len );

    TRACFBIN(g_trac_runtime, "firmware_notify: i_data", i_data, i_len);

    errlHndl_t l_err = nullptr;

    // Flag to detect an invalid/unknown/not used message
    bool l_badMessage = false;

    // Capture the unique message data associated with errant message
    uint64_t l_userData1(0), l_userData2(0);

    do
    {
        // make sure the length of the data is not less than the
        // data necessary to determine type of message
        if (i_len < hostInterfaces::HBRT_FW_MSG_BASE_SIZE)
        {
            l_badMessage = true;

            TRACFCOMP(g_trac_runtime, ERR_MRK"firmware_notify: Received "
                      "a non hostInterfaces::hbrt_fw_msg data stream" );

            break;
        }

        // Cast the data to an hbrt_fw_msg to extract the input type
        hostInterfaces::hbrt_fw_msg* l_hbrt_fw_msg =
                       static_cast<hostInterfaces::hbrt_fw_msg*>(i_data);
        switch (l_hbrt_fw_msg->io_type)
        {
            case hostInterfaces::HBRT_FW_MSG_HBRT_FSP_REQ:
            {
                // Distinguish based on msgType and msgq
                if ( (l_hbrt_fw_msg->generic_msg.msgType ==
                         GenericFspMboxMessage_t::MSG_ATTR_SYNC_REQUEST) &&
                        (l_hbrt_fw_msg->generic_msg.msgq ==
                         MBOX::HB_ATTR_SYNC_MSGQ) )
                {
                    attrSyncRequest((void*)&(l_hbrt_fw_msg->generic_msg.data));
                }
                else if ((l_hbrt_fw_msg->generic_msg.msgType ==
                          GenericFspMboxMessage_t::MSG_OCC_ACTIVE) &&
                         (l_hbrt_fw_msg->generic_msg.msgq ==
                          MBOX::FSP_OCC_MSGQ_ID) )
                {
                    occActiveNotification((void*)&(l_hbrt_fw_msg->generic_msg.data));
                }
                // Placing this at end as it does not have a msgq specified
                // Want to match msgType & msgq combos first
                else if (l_hbrt_fw_msg->generic_msg.msgType ==
                         GenericFspMboxMessage_t::MSG_SBE_ERROR)
                {
                    sbeAttemptRecovery(l_hbrt_fw_msg->generic_msg.data);
                }
                else
                {
                    l_badMessage = true;

                    TRACFCOMP(g_trac_runtime, ERR_MRK"firmware_notify: "
                              "Unknown FSP message type:0x%.8X, "
                              "message queue id:0x%.8X, seqNum:%d ",
                              l_hbrt_fw_msg->generic_msg.msgType,
                              l_hbrt_fw_msg->generic_msg.msgq,
                              l_hbrt_fw_msg->generic_msg.seqnum);

                    // Pack user data 1 with message input type and
                    // firmware request message sequence number
                    l_userData1 = TWO_UINT32_TO_UINT64(
                                    l_hbrt_fw_msg->io_type,
                                    l_hbrt_fw_msg->generic_msg.seqnum);

                    // Pack user data 2 with message queue and message type
                    l_userData2 = TWO_UINT32_TO_UINT64(
                                    l_hbrt_fw_msg->generic_msg.msgq,
                                    l_hbrt_fw_msg->generic_msg.msgType);
                } // END if ( (l_hbrt_fw_msg->generic_msg.msgType ... else ...
            } // END case hostInterfaces::HBRT_FW_MSG_HBRT_FSP_REQ:
            break;

            case hostInterfaces::HBRT_FW_MSG_TYPE_NVDIMM_OPERATION:
            {
                uint64_t l_minMsgSize = hostInterfaces::HBRT_FW_MSG_BASE_SIZE +
                sizeof(hostInterfaces::hbrt_fw_msg::nvdimm_operation);
                if (i_len < l_minMsgSize)
                {
                    l_badMessage = true;

                    TRACFCOMP(g_trac_runtime, ERR_MRK"firmware_notify: "
                     "Received message HBRT_FW_MSG_TYPE_NVDIMM_OPERATION, "
                     "but size of message data(%d) is not adequate for a "
                     "complete message of this type, with size requirement of "
                     "%d", i_len, l_minMsgSize );

                    // Pack user data 1 with the message input type, the only
                    // data that can be safely retrieved
                    l_userData1 = l_hbrt_fw_msg->io_type;

                    break;
                }

                doNvDimmOperation(l_hbrt_fw_msg->nvdimm_operation);
            } // END case hostInterfaces::HBRT_FW_MSG_TYPE_NVDIMM_OPERATION:
            break;

            default:
            {
                l_badMessage = true;

                TRACFCOMP(g_trac_runtime, ERR_MRK"firmware_notify: "
                          "Unknown firmware request input type:0x%.8X ",
                          l_hbrt_fw_msg->io_type);

                l_userData1 = l_hbrt_fw_msg->io_type;
            }  // END default
            break;

        };  // END switch (l_hbrt_fw_msg->io_type)

    } while(0);

    if (l_badMessage)
    {
        /*@
         * @errortype
         * @severity     ERRL_SEV_PREDICTIVE
         * @moduleid     MOD_RT_FIRMWARE_NOTIFY
         * @reasoncode   RC_FW_NOTIFY_RT_INVALID_MSG
         * @userdata1[0:31]  Firmware Request type
         * @userdata1[32:63] Sequence number (FSP msg)
         * @userdata2[0:31]  MBOX message type (FSP msg)
         * @userdata2[32:63] Message Type (FSP msg)
         * @devdesc      Error with Firmware Notify request
         */
        l_err = new ErrlEntry(ERRL_SEV_PREDICTIVE,
                              MOD_RT_FIRMWARE_NOTIFY,
                              RC_FW_NOTIFY_RT_INVALID_MSG,
                              l_userData1,
                              l_userData2,
                              true);

        if (i_len > 0)
        {
            l_err->addFFDC(RUNTIME_COMP_ID,
                           i_data,
                           i_len,
                           0, 0, false );
        }

        l_err->collectTrace(RUNTIME_COMP_NAME, 256);
    }

    if (l_err)
    {
        //Commit the error if it exists
        errlCommit(l_err, RUNTIME_COMP_ID);
    }

    TRACFCOMP(g_trac_hbrt, EXIT_MRK"firmware_notify");
};

struct registerFwNotify
{
    registerFwNotify()
    {
        getRuntimeInterfaces()->firmware_notify = &firmware_notify;
    }
};

registerFwNotify g_registerFwNotify;
OpenPOWER on IntegriCloud