summaryrefslogtreecommitdiffstats
path: root/src/usr/sbeio/runtime/rt_sbeio.C
blob: 360a144cd0034fad495d8659ebcf4bc2b406e0f8 (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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/sbeio/runtime/rt_sbeio.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 <runtime/interface.h>
#include <kernel/console.H>

#include <vmmconst.h>
#include <sys/misc.h>
#include <sbeio/runtime/sbe_msg_passing.H>
#include <sbeio/runtime/sbeio_attr_override.H>
#include <sbeio/runtime/sbeio_nvdimm_operation.H>
#include <sbeio/sbeioreasoncodes.H>
#include <errno.h>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <errl/errlreasoncodes.H>
#include <devicefw/userif.H>

//  targeting support
#include    <targeting/common/target.H>
#include    <targeting/common/commontargeting.H>
#include    <targeting/common/utilFilter.H>
#include    <runtime/rt_targeting.H>


using namespace TARGETING;
using namespace ERRORLOG;
using namespace SBE_MSG;
extern trace_desc_t* g_trac_hbrt;

// Trace
trace_desc_t* g_trac_sbeio;
TRAC_INIT(&g_trac_sbeio, SBEIO_COMP_NAME, 6*KILOBYTE, TRACE::BUFFER_SLOW);


namespace RT_SBEIO
{
    // Map of process command functions for the pass-through commands
    ProcessCmdMap_t g_processCmdMap;

    //------------------------------------------------------------------------

    /**
     *  @brief SBE message passing read pass-through command
     *
     *  @details  This is a call that will read a pass-through command
     *            from the SBE Communication buffer and copy it to a
     *            local buffer so its information is preserved during
     *            processing of the command and creation of the response
     *            in the same SBE Communication buffer.
     *
     *  @param[in]  i_proc        HB processor target
     *  @param[in]  i_sbeMessage  Pass-through command request in sbe-comm
     *  @param[out] o_request     Copied pass-through command request
     *
     *  @returns  errlHndl_t  NULL on success
     */
    errlHndl_t process_sbe_msg_read_command(TargetHandle_t i_proc,
                                            sbeMessage_t& i_sbeMessage,
                                            sbeMessage_t& o_request)
    {
        errlHndl_t errl = nullptr;

        if((!ENUM_SBEHDRVER_CHECK(i_sbeMessage.sbeHdr.version)) ||
           (!ENUM_CMDHDRVER_CHECK(i_sbeMessage.cmdHdr.version)))
        {
           TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: read "
                      "command SBE Header version 0x%08x %s, Command Header "
                      "version 0x%08x %s",
                      i_sbeMessage.sbeHdr.version,
                      (ENUM_SBEHDRVER_CHECK(i_sbeMessage.sbeHdr.version))
                          ? "valid" : "invalid",
                      i_sbeMessage.cmdHdr.version,
                      (ENUM_CMDHDRVER_CHECK(i_sbeMessage.cmdHdr.version))
                          ? "valid" : "invalid");

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_INVALID_VERSION
             * @userdata1[0:31]   SBE Header version
             * @userdata1[32:63]  Command Header version
             * @userdata2    Processor HUID
             *
             * @devdesc      SBEIO RT Read Pass-through command invalid version.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_INVALID_VERSION,
                                 TWO_UINT32_TO_UINT64(
                                     i_sbeMessage.sbeHdr.version,
                                     i_sbeMessage.cmdHdr.version),
                                 get_huid(i_proc));

            errl->addFFDC( SBE_COMP_ID,
                           &(i_sbeMessage),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                           false );           // merge
            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        else if(i_sbeMessage.sbeHdr.msgSize > SBE_MSG_SIZE)
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: read "
                      "command message size too large 0x%08x",
                      i_sbeMessage.sbeHdr.msgSize);

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_MSG_SIZE_TOO_LARGE
             * @userdata1[0:31]   Processor HUID
             * @userdata1[32:63]  Message Size
             * @userdata2    Reserved
             *
             * @devdesc      SBEIO RT Read Pass-through command message size
             *                is too large.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_MSG_SIZE_TOO_LARGE,
                                 TWO_UINT32_TO_UINT64(
                                     get_huid(i_proc),
                                     i_sbeMessage.sbeHdr.msgSize),
                                 0);

            errl->addFFDC( SBE_COMP_ID,
                           &(i_sbeMessage),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                           false );           // merge
            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        else if(i_sbeMessage.cmdHdr.dataOffset < sizeof(cmdHeader_t))
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: read "
                      "command data offset too small 0x%08x",
                      i_sbeMessage.cmdHdr.dataOffset);

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_DATA_OFFSET_TOO_SMALL
             * @userdata1[0:31]   Processor HUID
             * @userdata1[32:63]  Data Offset
             * @userdata2    Minimum Data Offset
             *
             * @devdesc      SBEIO RT Read Pass-through command data offset
             *                is too small.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_DATA_OFFSET_TOO_SMALL,
                                 TWO_UINT32_TO_UINT64(
                                     get_huid(i_proc),
                                     i_sbeMessage.cmdHdr.dataOffset),
                                 sizeof(cmdHeader_t));

            errl->addFFDC( SBE_COMP_ID,
                           &(i_sbeMessage),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                           false );           // merge
            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        else if(i_sbeMessage.cmdHdr.dataOffset + i_sbeMessage.cmdHdr.dataSize >
                i_sbeMessage.sbeHdr.msgSize - sizeof(sbeHeader_t))
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: read "
                      "command, data offset 0x%08x and data size 0x%08x "
                      "larger than msg size 0x%08x minus SBE hdr size 0x%08x",
                      i_sbeMessage.cmdHdr.dataOffset,
                      i_sbeMessage.cmdHdr.dataSize,
                      i_sbeMessage.sbeHdr.msgSize,
                      sizeof(sbeHeader_t));

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_DATA_TOO_LARGE
             * @userdata1[0:31]   Processor HUID
             * @userdata1[32:63]  Data Offset
             * @userdata2[0:31]   Message Size
             * @userdata2[32:63]  Data Size
             *
             * @devdesc      SBEIO RT Read Pass-through command data offset
             *                is too large.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_DATA_TOO_LARGE,
                                 TWO_UINT32_TO_UINT64(
                                     get_huid(i_proc),
                                     i_sbeMessage.cmdHdr.dataOffset),
                                 TWO_UINT32_TO_UINT64(
                                     i_sbeMessage.sbeHdr.msgSize,
                                     i_sbeMessage.cmdHdr.dataSize));

            errl->addFFDC( SBE_COMP_ID,
                           &(i_sbeMessage),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                           false );           // merge
            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        else
        {
            // Copy command from SBE Communication area
            memcpy(reinterpret_cast<void*>(&o_request),
                   reinterpret_cast<void*>(&i_sbeMessage),
                   i_sbeMessage.sbeHdr.msgSize);
        }

        return errl;
    }

    //------------------------------------------------------------------------

    /**
     *  @brief SBE message passing call pass-through command processor
     *
     *  @details  This is a call that will call the appropriate command
     *            processor for a pass-through command.
     *
     *  @param[in]  i_proc      HB processor target
     *  @param[in]  i_request   Pass-through command request
     *  @param[out] o_response  Pass-through command response
     *
     *  @returns  errlHndl_t  NULL on success
     */
    errlHndl_t process_sbe_msg_cmd_processor(TargetHandle_t i_proc,
                                             sbeMessage_t& i_request,
                                             sbeMessage_t& o_response)
    {
        errlHndl_t errl = nullptr;

        uint32_t l_command = i_request.cmdHdr.command;

        if(g_processCmdMap.find(l_command) == g_processCmdMap.end())
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: process "
                      "command, function pointer not found for command 0x%08x",
                      l_command);

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_FUNCTION_NOT_FOUND
             * @userdata1[0:31]   Processor HUID
             * @userdata1[32:63]  Request Command
             * @userdata2    Sequence ID
             *
             * @devdesc      SBEIO RT Process Pass-through command function not
             *                found.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_FUNCTION_NOT_FOUND,
                                 TWO_UINT32_TO_UINT64(
                                     get_huid(i_proc),
                                     l_command),
                                 i_request.sbeHdr.seqId);

            errl->addFFDC( SBE_COMP_ID,
                           &(i_request),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                                              // ^^^ @TODO RTC:172362
                           false );           // merge
            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        else if(g_processCmdMap[l_command] == nullptr)
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: process "
                      "command, function pointer not set for command 0x%08x",
                      l_command);

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_FUNCTION_NOT_SET
             * @userdata1[0:31]   Processor HUID
             * @userdata1[32:63]  Request Command
             * @userdata2    Sequence ID
             *
             * @devdesc      SBEIO RT Process Pass-through command function not
             *                set.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_FUNCTION_NOT_SET,
                                 TWO_UINT32_TO_UINT64(
                                     get_huid(i_proc),
                                     l_command),
                                 i_request.sbeHdr.seqId);

            errl->addFFDC( SBE_COMP_ID,
                           &(i_request),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                                              // ^^^ @TODO RTC:172362
                           false );           // merge
            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        else
        {
            // Trace command to be processed
            TRACFCOMP(g_trac_sbeio, "process_sbe_msg: process "
                      "command, process command 0x%08x with sequence ID 0x%08x",
                      l_command,
                      i_request.sbeHdr.seqId);

            // Check data offset
            if(o_response.cmdHdr.dataOffset > sizeof(cmdHeader_t))
            {
                TRACFCOMP(g_trac_sbeio, "process_sbe_msg: process command "
                          "adjusting response data offset");

                // Change offset to show response payload is being put
                // immediately after command header
                o_response.cmdHdr.dataOffset = sizeof(cmdHeader_t);
            }

            // Call function to process command
            errl = g_processCmdMap[l_command](i_proc,
                                              i_request.cmdHdr.dataSize,
                                              i_request.data,
                                              &o_response.cmdHdr.status,
                                              &o_response.cmdHdr.dataSize,
                                              o_response.data);

            if(errl)
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: process "
                          "command returned error log",
                          o_response.cmdHdr.dataSize);

                errl->addFFDC( SBE_COMP_ID,
                               &(i_request),
                               sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                               0,                 // Version
                               ERRL_UDT_NOFORMAT, // parser ignores data
                               false );           // merge
                errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH);
                errl->collectTrace(SBEIO_COMP_NAME);
            }
            else if(o_response.cmdHdr.dataSize > SBE_MSG_MAX_DATA)
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: process "
                          "command, response data size 0x%08x too large",
                          o_response.cmdHdr.dataSize);

                /*@
                 * @errortype
                 * @moduleid     SBEIO::SBEIO_RUNTIME
                 * @reasoncode   SBEIO::SBEIO_RT_RSP_DATA_TOO_LARGE
                 * @userdata1[0:31]   Processor HUID
                 * @userdata1[32:63]  Request Command
                 * @userdata2[0:31]   Sequence ID
                 * @userdata2[32:63]  Response Data Size
                 *
                 * @devdesc      SBEIO RT Process Pass-through command response
                 *                data size too large.
                 * @custdesc     Firmware error communicating with boot device
                 */
                errl = new ErrlEntry(ERRL_SEV_INFORMATIONAL,
                                     SBEIO::SBEIO_RUNTIME,
                                     SBEIO::SBEIO_RT_RSP_DATA_TOO_LARGE,
                                     TWO_UINT32_TO_UINT64(
                                         get_huid(i_proc),
                                         l_command),
                                     TWO_UINT32_TO_UINT64(
                                         i_request.sbeHdr.seqId,
                                         o_response.cmdHdr.dataSize));

                errl->addFFDC( SBE_COMP_ID,
                               &(i_request),
                               sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                               0,                 // Version
                               ERRL_UDT_NOFORMAT, // parser ignores data
                                                  // ^^^ @TODO RTC:172362
                               false );           // merge
                errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH);
                errl->collectTrace(SBEIO_COMP_NAME);

                // Calculate message size for response using max data
                o_response.sbeHdr.msgSize = sizeof(sbeHeader_t) +
                    sizeof(cmdHeader_t) + SBE_MSG_MAX_DATA;
            }
            else
            {
                // Calculate message size for response
                o_response.sbeHdr.msgSize = sizeof(sbeHeader_t) +
                    sizeof(cmdHeader_t) + o_response.cmdHdr.dataSize;
            }

            // Trace response to command that was processed
            TRACFCOMP(g_trac_sbeio, "process_sbe_msg: process "
                      "command, response to command 0x%08x with sequence ID "
                      "0x%08x was status 0x%08x",
                      o_response.cmdHdr.command,
                      o_response.sbeHdr.seqId,
                      o_response.cmdHdr.status);
        }

        return errl;
    }

    //------------------------------------------------------------------------

    /**
     *  @brief SBE message passing check pass-through command response
     *
     *  @details  This is a call that will check a pass-through command
     *            response that was written to the SBE Communication buffer
     *            against certain fields from the local copy of the command.
     *
     *  @param[in]  i_proc        HB processor target
     *  @param[in]  i_sbeMessage  Pass-through command response in sbe-comm
     *  @param[in]  i_request     Copied pass-through command request
     *
     *  @returns  errlHndl_t  NULL on success
     */
    errlHndl_t process_sbe_msg_check_response(TargetHandle_t i_proc,
                                              sbeMessage_t& i_sbeMessage,
                                              sbeMessage_t& i_request)
    {
        errlHndl_t errl = nullptr;

        if((i_sbeMessage.sbeHdr.version != i_request.sbeHdr.version) ||
           (i_sbeMessage.sbeHdr.seqId != i_request.sbeHdr.seqId) ||
           (i_sbeMessage.cmdHdr.version != i_request.cmdHdr.version) ||
           (i_sbeMessage.cmdHdr.command != i_request.cmdHdr.command))
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: check "
                      "response, response field was altered");

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_RSP_FIELD_ALTERED
             * @userdata1[0:31]   Processor HUID
             * @userdata1[32:63]  Request Command
             * @userdata2    Sequence ID
             *
             * @devdesc      SBEIO RT Check Pass-through command response field
             *                was altered.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_RSP_FIELD_ALTERED,
                                 TWO_UINT32_TO_UINT64(
                                     get_huid(i_proc),
                                     i_request.cmdHdr.command),
                                 i_request.sbeHdr.seqId);

            errl->addFFDC( SBE_COMP_ID,
                           &(i_request),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                           false );           // merge
            errl->addFFDC( SBE_COMP_ID,
                           &(i_sbeMessage),
                           sizeof(sbeHeader_t) + sizeof(cmdHeader_t),
                           0,                 // Version
                           ERRL_UDT_NOFORMAT, // parser ignores data
                           false );           // merge
            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }

        return errl;
    }

    //------------------------------------------------------------------------

    int process_sbe_msg(uint32_t i_procChipId)
    {
        TRACFCOMP(g_trac_hbrt, ENTER_MRK" sbe_message_passing: i_procChipId=%d", i_procChipId );
        int rc = 0;
        errlHndl_t errl = nullptr;

        TRACFCOMP(g_trac_sbeio, ENTER_MRK" process_sbe_msg: on proc %d", i_procChipId );

        // Used to store a local copy of the Pass-through command and preserve
        // it during processing (response overlays SBE Communication buffer)
        sbeMessage_t l_request;

        do
        {
            // Convert chipId to HB target
            TargetHandle_t l_proc = nullptr;
            errl = RT_TARG::getHbTarget(i_procChipId, l_proc);
            if(errl)
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: getHbTarget "
                         "returned rc=0x%04X for procChipId: %llx",
                          rc, i_procChipId);

                break;
            }

            // Set CFAM register - processing in progress
            TRACFCOMP(g_trac_sbeio, "process_sbe_msg: set CFAM register - "
                                    "processing in progress");
            errl = process_sbe_msg_update_cfam(l_proc,
                                            SBE_MESSAGE_PROCESSING_IN_PROGRESS,
                                            SBE_MESSAGE_PROCESSING_COMPLETE);
            if(errl)
            {
                break;
            }

            // Get SBE Communication Buffer for target processor
            uint64_t l_sbeCommAddr =
                l_proc->getAttr<TARGETING::ATTR_SBE_COMM_ADDR>();

            // Make sure SBE Communication Buffer is set
            if(l_sbeCommAddr == NULL)
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg: getAttr "
                          "did not get SBE Communication buffer address");

                /*@
                 * @errortype
                 * @moduleid     SBEIO::SBEIO_RUNTIME
                 * @reasoncode   SBEIO::SBEIO_RT_NO_SBE_COMM_BUFFER
                 * @userdata1    Processor HUID
                 * @userdata2    Reserved
                 *
                 * @devdesc      SBEIO RT Process Pass-through command SBE
                 *                Communication buffer not set.
                 * @custdesc     Firmware error communicating with boot device
                 */
                errl = new ErrlEntry(ERRL_SEV_INFORMATIONAL,
                                     SBEIO::SBEIO_RUNTIME,
                                     SBEIO::SBEIO_RT_NO_SBE_COMM_BUFFER,
                                     get_huid(l_proc),
                                     0);

                errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH);
                errl->collectTrace(SBEIO_COMP_NAME);

                break;
            }

            // Provide access to SBE Communication Buffer as an SBE Message
            sbeMessage_t *l_sbeMessage =
                reinterpret_cast<sbeMessage_t*>(l_sbeCommAddr);

            // Process SBE message read command
            TRACFCOMP(g_trac_sbeio, "process_sbe_msg: read command");
            errl = process_sbe_msg_read_command(l_proc,
                                                *l_sbeMessage,
                                                l_request);
            if (errl)
            {
                break;
            }

            // Call appropriate command processor
            TRACFCOMP(g_trac_sbeio, "process_sbe_msg: call command processor");
            errl = process_sbe_msg_cmd_processor(l_proc,
                                                 l_request,
                                                 *l_sbeMessage);
            if(errl)
            {
                break;
            }

            // Process SBE message check response
            TRACFCOMP(g_trac_sbeio, "process_sbe_msg: check response");
            errl = process_sbe_msg_check_response(l_proc,
                                                  *l_sbeMessage,
                                                  l_request);
            if(errl)
            {
                break;
            }

            // Set CFAM register - processing complete
            TRACFCOMP(g_trac_sbeio, "process_sbe_msg: set CFAM register - "
                                    "processing complete");
            errl = process_sbe_msg_update_cfam(l_proc,
                                            SBE_MESSAGE_PROCESSING_COMPLETE,
                                            SBE_MESSAGE_PROCESSING_IN_PROGRESS);
            if(errl)
            {
                break;
            }
        } while(0);

        if(errl)
        {
            rc = errl->reasonCode();
            if (0 == rc)
            {
                // If there was a failure, be sure to return non-zero status
                rc = -1;
            }
            errlCommit (errl, SBE_COMP_ID);
        }

        TRACFCOMP(g_trac_sbeio, EXIT_MRK" process_sbe_msg: rc=0x%X", rc );
        TRACFCOMP(g_trac_hbrt, EXIT_MRK" sbe_message_passing: rc=0x%X", rc );
        return rc;
    }

    //------------------------------------------------------------------------

#ifdef CONFIG_HTMGT
    /**
     * @brief Function to process pass-through command from SBE message
     *
     * @param[in]  i_procTgt      HB processor target
     * @param[in]  i_reqDataSize  Pass-through command request data size
     * @param[in]  i_reqData      Pass-through command request data
     * @param[out] o_rspStatus    Pass-through command response status
     * @param[out] o_rspDataSize  Pass-through command response data size
     * @param[out] o_rspData      Pass-through command response data
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t htmgt_pass_thru_wrapper(TARGETING::TargetHandle_t i_procTgt,
                                       uint32_t i_reqDataSize,
                                       uint8_t* i_reqData,
                                       uint32_t* o_rspStatus,
                                       uint32_t* o_rspDataSize,
                                       uint8_t* o_rspData)
    {
        errlHndl_t errl = nullptr;
        uint16_t l_rspDataSize = 0;

        runtimeInterfaces_t *rt_intf = getRuntimeInterfaces();

        // Check runtime interface pointer
        if(nullptr == rt_intf)
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"htmgt_pass_thru_wrapper: NULL "
                      "runtime interface pointer from getRuntimeInterfaces");

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_NO_INTERFACE_POINTER
             * @userdata1    Processor HUID
             * @userdata2    Reserved
             *
             * @devdesc      SBEIO RT Process Pass-through command Runtime
             *                Interface pointer not set.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_INFORMATIONAL,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_NO_INTERFACE_POINTER,
                                 get_huid(i_procTgt),
                                 0);

            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        // Check runtime interface function pointer
        else if(nullptr == rt_intf->mfg_htmgt_pass_thru)
        {
            TRACFCOMP(g_trac_sbeio, ERR_MRK"htmgt_pass_thru_wrapper: function "
                      "pointer for mfg_htmgt_pass_thru not set");

            /*@
             * @errortype
             * @moduleid     SBEIO::SBEIO_RUNTIME
             * @reasoncode   SBEIO::SBEIO_RT_NO_INTERFACE_FUNCTION
             * @userdata1    Processor HUID
             * @userdata2    Reserved
             *
             * @devdesc      SBEIO RT Process Pass-through command Runtime
             *                Interface function pointer not set.
             * @custdesc     Firmware error communicating with boot device
             */
            errl = new ErrlEntry(ERRL_SEV_INFORMATIONAL,
                                 SBEIO::SBEIO_RUNTIME,
                                 SBEIO::SBEIO_RT_NO_INTERFACE_FUNCTION,
                                 get_huid(i_procTgt),
                                 0);

            errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                      HWAS::SRCI_PRIORITY_HIGH);
            errl->collectTrace(SBEIO_COMP_NAME);
        }
        else
        {
            *o_rspStatus = rt_intf->mfg_htmgt_pass_thru(i_reqDataSize,
                                                        i_reqData,
                                                        &l_rspDataSize,
                                                        o_rspData);
        }

        *o_rspDataSize = l_rspDataSize;

        return errl;
    }
#endif

    //------------------------------------------------------------------------

    struct registerSbeio
    {
        registerSbeio()
        {
            runtimeInterfaces_t * rt_intf = getRuntimeInterfaces();
            rt_intf->sbe_message_passing = &process_sbe_msg;

            TargetHandleList procChips;
            getAllChips(procChips, TYPE_PROC, true);
            for (const auto & l_procChip: procChips)
            {
                // Note: the instance we use to retrieve the data must
                //   match the value we used to populate HDAT originally
                uint64_t l_instance = l_procChip->getAttr<ATTR_HBRT_HYP_ID>();
                uint64_t l_sbeCommAddr = g_hostInterfaces->get_reserved_mem(
                                         HBRT_RSVD_MEM__SBE_COMM,
                                         l_instance);
                l_procChip->setAttr<ATTR_SBE_COMM_ADDR>(l_sbeCommAddr);
                TRACFCOMP( g_trac_sbeio, INFO_MRK" COMM_ADDR=0x%.llX for %.8X",
                           l_sbeCommAddr,
                           TARGETING::get_huid(l_procChip) );
            }

#ifdef CONFIG_HTMGT
            SBE_MSG::setProcessCmdFunction(PASSTHRU_HTMGT_GENERIC,
                                           htmgt_pass_thru_wrapper);
#endif
           SBE_MSG::setProcessCmdFunction(PASSTHRU_HBRT_OVERRIDE_ATTR,
                                          sbeApplyAttrOverrides);
#ifdef CONFIG_NVDIMM
           SBE_MSG::setProcessCmdFunction(PASSTHRU_HBRT_NVDIMM_OP,
                                          sbeNvdimmOperation);
#endif
        }
    };

    registerSbeio g_registerSbeio;
} // namespace RT_SBEIO


namespace SBE_MSG
{
    // Set an entry in map of process command functions
    int setProcessCmdFunction(enum passThruCmds    i_command,
                              processCmdFunction_t i_function)
    {
        int rc = 0;

        do
        {
            RT_SBEIO::g_processCmdMap[i_command] = i_function;

            if(RT_SBEIO::g_processCmdMap[i_command] != i_function)
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"setProcessCmdFunction: "
                          "process command function not set for command 0x%08x",
                          i_command);

                rc = -1;

                break;
            }
        } while(0);

        return rc;
    }

    // Erase an entry in map of process command functions
    int eraseProcessCmdFunction(enum passThruCmds i_command)
    {
        int rc = 0;

        do
        {
            RT_SBEIO::g_processCmdMap.erase(i_command);

            if(RT_SBEIO::g_processCmdMap.find(i_command) !=
               RT_SBEIO::g_processCmdMap.end())
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"eraseProcessCmdFunction: "
                          "process command function not erased for command "
                          "0x%08x",
                          i_command);

                rc = -1;

                break;
            }
        } while(0);

        return rc;
    }


    /**
     *  @brief SBE message update bit(s) in CFAM register
     *
     *  @details  This is a call that will update bit(s) in CFAM register 0x283B
     *            or SCOM_ADDR_5003B.
     *
     *  @param[in]  i_proc        HB processor target
     *  @param[in]  i_set_mask    CFAM register mask (mark bits to set)
     *  @param[in]  i_clear_mask  CFAM register mask (mark bits to clear)
     *
     *  @returns  errlHndl_t  NULL on success
     */
    errlHndl_t process_sbe_msg_update_cfam(TargetHandle_t i_proc,
                                        const uint32_t i_set_mask,
                                        const uint32_t i_clear_mask)
    {
        errlHndl_t errl = nullptr;


        uint32_t l_read_reg = 0;
        size_t l_size = sizeof(uint64_t);

        do{
            // Read SCOM_ADDR_5003B for target proc
            errl = deviceRead(i_proc,
                              &l_read_reg,
                              l_size,
                              DEVICE_SCOM_ADDRESS(SCOM_ADDR_5003B));

            if(errl)
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg_update_cfam: "
                    "CFAM read failed for target 0x%llX SCOM addr 0x%llX",
                    get_huid(i_proc),
                    SCOM_ADDR_5003B);

                errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH);
                errl->collectTrace(SBEIO_COMP_NAME);

                break;
            }

            TRACFCOMP(g_trac_sbeio, "process_sbe_msg_update_cfam: CFAM read "
                "returned 0x%llX for target 0x%llX",
                l_read_reg, get_huid(i_proc) );

            // Set/clear bit(s) in CFAM reg SCOM_ADDR_5003B based on masks
            l_read_reg |= i_set_mask;
            l_read_reg &= (~i_clear_mask);

            TRACFCOMP(g_trac_sbeio, "process_sbe_msg_update_cfam: "
                "CFAM write 0x%llX to SCOM addr 0x%llX for target 0x%llX",
                l_read_reg, SCOM_ADDR_5003B, get_huid(i_proc) );

            // Write SCOM_ADDR_5003B for target proc
            errl = deviceWrite(i_proc,
                               &l_read_reg,
                               l_size,
                               DEVICE_SCOM_ADDRESS(SCOM_ADDR_5003B));

            if(errl)
            {
                TRACFCOMP(g_trac_sbeio, ERR_MRK"process_sbe_msg_update_cfam: "
                    "write CFAM failed for target 0x%llX SCOM addr 0x%llX",
                    get_huid(i_proc),
                    SCOM_ADDR_5003B);

                errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH);
                errl->collectTrace(SBEIO_COMP_NAME);

                break;
            }
        }while(0);

        return errl;
     }

} // namespace SBE_MSG
OpenPOWER on IntegriCloud