summaryrefslogtreecommitdiffstats
path: root/src/usr/scom/scom.C
blob: 22567fb49b2edb89f89f13cc6f426bd04d09e204 (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
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/scom/scom.C $                                         */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,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                                                     */
/**
 *  @file scom.C
 *
 *  @brief Implementation of SCOM operations
 */

/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/
#include <assert.h>
#include <devicefw/driverif.H>
#include <trace/interface.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include "scom.H"
#include "postopchecks.H"
#include <scom/scomreasoncodes.H>
#include <scom/errlud_pib.H>
#include <ibscom/ibscomreasoncodes.H>
#include <sys/time.h>
#include <xscom/piberror.H>
#include <errl/errludtarget.H>
#include <errl/errludlogregister.H>
#include <hw_access_def.H>
#include <p9_scom_addr.H>
#include <targeting/common/utilFilter.H>
#include <targeting/namedtarget.H>

#include <config.h>

#ifndef __HOSTBOOT_RUNTIME
#ifdef CONFIG_SECUREBOOT
#include <secureboot/service.H>
#include <scom/centaurScomCache.H>
#endif
#endif

// Trace definition
trace_desc_t* g_trac_scom = NULL;
TRAC_INIT(&g_trac_scom, SCOM_COMP_NAME, KILOBYTE, TRACE::BUFFER_SLOW); //1K


namespace SCOM
{
#ifndef __HOSTBOOT_RUNTIME
/**
 * Keep track of system state to handle the multicast workaround
 *  more cleanly
 */
bool g_useSlaveCores = false;
bool g_useMemChiplets = false;

/**
 * @brief Enable scoms to all cores for multicast workaround
 */
void enableSlaveCoreMulticast( void )
{
    g_useSlaveCores = true;
};

/**
 * @brief Enable scoms to the memory chiplets for multicast workaround
 */
void enableMemChipletMulticast( void )
{
    g_useMemChiplets = true;
};
#endif

/**
 * @brief Add any additional FFDC for this specific type of scom
 *
 * @param[in] i_err  Log to add FFDC to
 * @param[in] i_target  Target of SCOM operation
 * @param[in] i_addr  SCOM address
 */
void addScomFailFFDC( errlHndl_t i_err,
                      TARGETING::Target* i_target,
                       uint64_t i_addr );

/**
 * @brief Perform a manual multicast operation if appropriate
 *
 * @param[in] i_opType  Read/Write
 * @param[in] i_target  Processor target
 * @param[in] o_buffer  Output buffer
 * @param[inout] io_buflen  Size of buffer (must be 8 bytes)
 * @param[in] i_addr  SCOM address
 * @param[out] o_didWorkaround  true if the manual workaround was
 *             performed
 * @return nullptr for success
 */
errlHndl_t doMulticastWorkaround( DeviceFW::OperationType i_opType,
                                  TARGETING::Target* i_target,
                                  void* io_buffer,
                                  size_t& io_buflen,
                                  uint64_t i_addr,
                                  bool& o_didWorkaround );


// Register Scom access functions to DD framework
DEVICE_REGISTER_ROUTE(DeviceFW::WILDCARD,
                      DeviceFW::SCOM,
                      TARGETING::TYPE_PROC,
                      scomPerformOp);

DEVICE_REGISTER_ROUTE(DeviceFW::WILDCARD,
                      DeviceFW::SCOM,
                      TARGETING::TYPE_MEMBUF,
                      scomMemBufPerformOp);

DEVICE_REGISTER_ROUTE(DeviceFW::WILDCARD,
                      DeviceFW::SCOM,
                      TARGETING::TYPE_OCMB_CHIP,
                      scomPerformOp);

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t scomPerformOp(DeviceFW::OperationType i_opType,
                         TARGETING::Target* i_target,
                         void* io_buffer,
                         size_t& io_buflen,
                         int64_t i_accessType,
                         va_list i_args)
{
    errlHndl_t l_err = NULL;


    uint64_t l_scomAddr = va_arg(i_args,uint64_t);

    l_err = checkIndirectAndDoScom(i_opType,
                                   i_target,
                                   io_buffer,
                                   io_buflen,
                                   i_accessType,
                                   l_scomAddr);

    return l_err;
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t scomMemBufPerformOp(DeviceFW::OperationType i_opType,
                               TARGETING::Target* i_target,
                               void* io_buffer,
                               size_t& io_buflen,
                               int64_t i_accessType,
                               va_list i_args)
{
    errlHndl_t l_err = NULL;

    uint64_t l_scomAddr = va_arg(i_args,uint64_t);

    l_err = checkIndirectAndDoScom(i_opType,
                                   i_target,
                                   io_buffer,
                                   io_buflen,
                                   i_accessType,
                                   l_scomAddr);

    // Check for ATTR_CENTAUR_EC_ENABLE_RCE_WITH_OTHER_ERRORS_HW246685
    // if ATTR set and MBSECCQ being read then set bit 16
    // See RTC 97286
    //
    if(!l_err && (i_opType == DeviceFW::READ))
    {
        const uint64_t MBS_ECC0_MBSECCQ_0x0201144A = 0x000000000201144Aull;
        const uint64_t MBS_ECC1_MBSECCQ_0x0201148A = 0x000000000201148Aull;

        uint64_t addr = l_scomAddr & 0x000000007FFFFFFFull;
        if(addr == MBS_ECC0_MBSECCQ_0x0201144A ||
           addr == MBS_ECC1_MBSECCQ_0x0201148A)
        {
            uint8_t enabled = 0;
            //FAPI_ATTR_GET      @todo RTC 101877 - access FAPI attributes
            //    (ATTR_CENTAUR_EC_ENABLE_RCE_WITH_OTHER_ERRORS_HW246685,
            //     i_target,
            //     enabled);
            //   For now use:   if ec >= 0x20
            if(i_target->getAttr<TARGETING::ATTR_EC>() >= 0x20)
            {
                enabled = true;
            }

            if(enabled)
            {
                uint64_t * data = reinterpret_cast<uint64_t *>(io_buffer);
                *data |= 0x0000800000000000ull; // Force on bit 16
            }
        }
    }

    return l_err;
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t checkIndirectAndDoScom(DeviceFW::OperationType i_opType,
                                  TARGETING::Target* i_target,
                                  void* io_buffer,
                                  size_t& io_buflen,
                                  int64_t i_accessType,
                                  uint64_t i_addr)
{

    errlHndl_t l_err = NULL;

    do {

#ifndef __HOSTBOOT_RUNTIME
#ifdef CONFIG_SECUREBOOT
    if(   (i_opType == DeviceFW::READ)
       && (i_target != TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
       && SECUREBOOT::enabled()
       && SECUREBOOT::CENTAUR_SECURITY::ScomCache::getInstance().cacheEnabled()
       && (i_target->getAttr<TARGETING::ATTR_TYPE>()==TARGETING::TYPE_MEMBUF))
    {
        bool skipScom=true;
        uint64_t cacheData=0;
        l_err=SECUREBOOT::CENTAUR_SECURITY::ScomCache::getInstance().
            read(i_target,i_addr,skipScom,cacheData);
        if(l_err)
        {
            TRACFCOMP(g_trac_scom, ERR_MRK
                "checkIndirectAndDoScom: failed in call to ScomCache::read() "
                "for HUID = 0x%08X, address = 0x%016llX",
                TARGETING::get_huid(i_target),
                i_addr);
            break;
        }

        if(skipScom)
        {
            *reinterpret_cast<uint64_t*>(io_buffer) = cacheData;
            io_buflen=sizeof(cacheData);
            break;
        }
    }
#endif
#endif

        // Do we need to do the indirect logic or not?
        bool l_runIndirectLogic = true;

        // If the indirect scom bit is 0, then doing a regular scom
        if( (i_addr & 0x8000000000000000) == 0)
        {
            l_runIndirectLogic = false;
        }

        // In HOSTBOOT_RUNTIME we always defer indirect scoms to
        //   Sapphire, but PHYP wants us to do it ourselves
#ifdef __HOSTBOOT_RUNTIME
        if( TARGETING::is_sapphire_load() )
        {
            l_runIndirectLogic = false;
        }
#endif // __HOSTBOOT_RUNTIME

        // Not indirect (or skipping that) so just do regular scom
        if( l_runIndirectLogic == false )
        {
            l_err = doScomOp(i_opType,
                             i_target,
                             io_buffer,
                             io_buflen,
                             i_accessType,
                             i_addr);
            //all done
            break;
        }

        //----------------------------------------------
        //---  Below here is the indirect scom logic ---

        uint64_t l_io_buffer = 0;
        uint64_t temp_scomAddr = 0;
        uint8_t form = 0;

        memcpy(&l_io_buffer, io_buffer, 8);
        memcpy(&temp_scomAddr, &i_addr, 8);

        // Bits 0:3 of the address hold the indirect and form bits
        // We shift out 60 bits to read the form bit here
        form = (i_addr >> 60) & 1;

        // If the form is 0, we are using the "old" indirect scom method
        if (form == 0)
        {
            // setupForm0ScomRegs sets up the registers for form0 scom op
            l_err = doForm0IndirectScom(i_opType,
                                        i_target,
                                        io_buffer,
                                        io_buflen,
                                        i_accessType,
                                        i_addr);

            if (l_err)
            {
                TRACFCOMP(g_trac_scom,
                    "checkIndirectAndDoScom: Error from doForm0IndirectScom");
                break;
            }
        }

        // If form is equal to 1, we are using new FBC method
        else if (form == 1)
        {
            l_err = doForm1IndirectScom(i_opType,
                                        i_target,
                                        io_buffer,
                                        io_buflen,
                                        i_accessType,
                                        i_addr);

            if (l_err)
            {
                TRACFCOMP(g_trac_scom,
                    "checkIndirectAndDoScom: Error from doForm1IndirectScom");
                break;

            }
        }

        // Unsupported form, break out
        else
        {
            TRACFCOMP(g_trac_scom, "Unsupported indirect scom form %d", form);

            /*@
             * @errortype
             * @moduleid     SCOM::SCOM_CHECK_INDIRECT_AND_DO_SCOM
             * @reasoncode   SCOM::SCOM_INVALID_FORM
             * @userdata1    Address
             * @userdata2    HUID of Target
             * @devdesc      Unsupported indirect scom form
             * @custdesc     A problem occurred during the IPL of the system.
             */
            l_err = new ERRORLOG::ErrlEntry(
                                  ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                  SCOM_CHECK_INDIRECT_AND_DO_SCOM,
                                  SCOM_INVALID_FORM,
                                  i_addr,
                                  get_huid(i_target),
                                  ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

            break;
        }

    } while(0);

#ifndef __HOSTBOOT_RUNTIME
#ifdef CONFIG_SECUREBOOT
    if(   !l_err
       && (i_opType == DeviceFW::WRITE)
       && (i_target!=TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
       && SECUREBOOT::enabled()
       && SECUREBOOT::CENTAUR_SECURITY::ScomCache::getInstance().cacheEnabled()
       && (i_target->getAttr<TARGETING::ATTR_TYPE>()==TARGETING::TYPE_MEMBUF) )
    {
        l_err = SECUREBOOT::CENTAUR_SECURITY::ScomCache::getInstance().
            write(i_target,i_addr,
            *reinterpret_cast<uint64_t*>(io_buffer));
        if(l_err)
        {
            TRACFCOMP(g_trac_scom, ERR_MRK
                "checkIndirectAndDoScom: failed in call to ScomCache::write() "
                "for HUID = 0x%08X, address = 0x%016llX",
                TARGETING::get_huid(i_target),
                i_addr);
        }
    }
#endif
#endif

    return l_err;
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t doForm0IndirectScom(DeviceFW::OperationType i_opType,
                               TARGETING::Target* i_target,
                               void* io_buffer,
                               size_t& io_buflen,
                               int64_t i_accessType,
                               uint64_t i_addr)
{
    errlHndl_t l_err = NULL;

    enum { MAX_INDSCOM_TIMEOUT_NS = 10000000 }; //=10ms

    mutex_t* l_mutex = NULL;
    bool need_unlock = false;
    uint64_t elapsed_indScom_time_ns = 0;
    uint64_t l_io_buffer = 0;
    uint64_t temp_scomAddr = 0;

    memcpy(&l_io_buffer, io_buffer, 8);
    memcpy(&temp_scomAddr, &i_addr, 8);

    do {
        // Get the 20bit indirect scom address
        temp_scomAddr = temp_scomAddr & 0x001FFFFF00000000;

        // Zero out the indirect address location.. leave the 16bits of data
        l_io_buffer = l_io_buffer & 0x000000000000FFFF;

        // OR in the 20bit indirect address
        l_io_buffer = l_io_buffer | temp_scomAddr;

        // zero out the indirect address from the buffer..
        // bit 0-31 - indirect area..
        // bit 32 - always 0
        // bit 33-47 - bcast/chipletID/port
        // bit 48-63 - local addr
        i_addr = i_addr & 0x000000007FFFFFFF;

        // If we are doing a read. We need to do a write first..
        if(i_opType == DeviceFW::READ)
        {
            // use the chip-specific mutex attribute
            l_mutex =
              i_target->getHbMutexAttr<TARGETING::ATTR_SCOM_IND_MUTEX>();

            mutex_lock(l_mutex);
            need_unlock = true;

            // turn the read bit on.
            l_io_buffer = l_io_buffer | 0x8000000000000000;

            // perform write before the read with the new
            // IO_buffer with the imbedded indirect scom addr.
            l_err = doScomOp(DeviceFW::WRITE,
                             i_target,
                             & l_io_buffer,
                             io_buflen,
                             i_accessType,
                             i_addr);

            if (l_err != NULL)
            {
                break;
            }

            // Need to check loop on read until we see done, error,
            //  or we timeout
            IndirectScom_t scomout;
            scomout.data64 = 0;
            do
            {
                // Now perform the op requested using the passed in
                // IO_Buffer to pass the read data back to caller.
                l_err = doScomOp(i_opType,
                                 i_target,
                                 &(scomout.data64),
                                 io_buflen,
                                 i_accessType,
                                 i_addr);

                if (l_err != NULL)
                {
                    break;
                }

                // if bit 32 is on indicating a complete bit
                //  or we saw an error, then we're done
                if (scomout.done || scomout.piberr)
                {
                    // there is a small chance for a race if we check the
                    //  status very quickly, the hardware sets the status
                    //  to 001=Resource Occupied when the command first
                    //  starts so keep polling
                    if( scomout.piberr != PIB::PIB_RESOURCE_OCCUPIED )
                    {
                        break;
                    }
                }

                nanosleep( 0, 10000 ); //sleep for 10,000 ns
                elapsed_indScom_time_ns += 10000;

            }while ( elapsed_indScom_time_ns <= MAX_INDSCOM_TIMEOUT_NS);

            mutex_unlock(l_mutex);
            need_unlock = false;

            if (l_err) { break; }

            // Check for a PCB/PIB Error
            if( scomout.piberr != 0 )
            {
                // got an indirect read error
                // the data buffer is in tempIoData
                TRACFCOMP(g_trac_scom,
                          "INDIRECT SCOM READ: PIB Error=%d (reg=0x%.16X)",
                          scomout.piberr, scomout.data64);

                /*@
                 * @errortype
                 * @moduleid     SCOM::SCOM_CHECK_INDIRECT_AND_DO_SCOM
                 * @reasoncode   SCOM::SCOM_INDIRECT_READ_FAIL
                 * @userdata1    Address
                 * @userdata2    Indirect Scom Status Register
                 * @devdesc      Indirect SCOM Read error
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                      ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      SCOM_CHECK_INDIRECT_AND_DO_SCOM,
                                      SCOM_INDIRECT_READ_FAIL,
                                      i_addr,
                                      scomout.data64);

                // we should never hit this so if we do we are going
                //  to blame hardware
                if( scomout.piberr == PIB::PIB_RESOURCE_OCCUPIED )
                {
                    SCOM::UdPibInfo(scomout.piberr).addToLog(l_err);
                    l_err->addHwCallout( i_target,
                                         HWAS::SRCI_PRIORITY_HIGH,
                                         HWAS::NO_DECONFIG,
                                         HWAS::GARD_NULL );
                }
                else
                {
                    //Add the callouts for the specific PCB/PIB error
                    PIB::addFruCallouts( i_target,
                                         scomout.piberr,
                                         i_addr,
                                         l_err );
                }

                //Add this target to the FFDC
                ERRORLOG::ErrlUserDetailsTarget(i_target,"IndSCOM Target")
                  .addToLog(l_err);

                l_err->collectTrace( SCOM_COMP_NAME, 256);
            }
            // if we got a timeout, create an errorlog.
            else if( scomout.done == 0 )
            {
                // got an indirect read timeout
                TRACFCOMP(g_trac_scom,
                          "INDIRECT SCOM READ: Timeout, reg=0x%.16X",
                          scomout.data64);

                /*@
                 * @errortype
                 * @moduleid     SCOM::SCOM_CHECK_INDIRECT_AND_DO_SCOM
                 * @reasoncode   SCOM::SCOM_INDIRECT_READ_TIMEOUT
                 * @userdata1    Address
                 * @userdata2    Indirect Scom Status Register
                 * @devdesc      Indirect SCOM complete bit did not come on
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                      ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      SCOM_CHECK_INDIRECT_AND_DO_SCOM,
                                      SCOM_INDIRECT_READ_TIMEOUT,
                                      i_addr,
                                      scomout.data64);

                //Best guess is the chip
                l_err->addHwCallout( i_target,
                                     HWAS::SRCI_PRIORITY_HIGH,
                                     HWAS::DELAYED_DECONFIG,
                                     HWAS::GARD_Predictive );

                //Add this target to the FFDC
                ERRORLOG::ErrlUserDetailsTarget(i_target,"IndSCOM Target")
                  .addToLog(l_err);

                l_err->collectTrace( SCOM_COMP_NAME, 256);
            }
            else // It worked
            {
                uint64_t tmp = static_cast<uint64_t>(scomout.data);
                memcpy( io_buffer, &tmp, sizeof(uint64_t) );
            }
        }
        else //write
        {
            // Turn the read bit off.
            l_io_buffer = l_io_buffer & 0x7FFFFFFFFFFFFFFF;

            // Now perform the op requested using the
            // local io_buffer with the indirect addr imbedded.
            l_err = doScomOp(i_opType,
                             i_target,
                             & l_io_buffer,
                             io_buflen,
                             i_accessType,
                             i_addr);

            if (l_err != NULL)
            {
                break;
            }

            // Need to check loop on read until we see done, error,
            //  or we timeout
            IndirectScom_t scomout;
            scomout.data64 = 0;
            do
            {
                // Now look for status
                l_err = doScomOp(DeviceFW::READ,
                                 i_target,
                                 &(scomout.data64),
                                 io_buflen,
                                 i_accessType,
                                 i_addr);

                if (l_err != NULL)
                {
                    break;
                }

                // if bit 32 is on indicating a complete bit
                //  or we saw an error, then we're done
                if (scomout.done || scomout.piberr)
                {
                    // there is a small chance for a race if we check the
                    //  status very quickly, the hardware sets the status
                    //  to 001=Resource Occupied when the command first
                    //  starts so keep polling
                    if( scomout.piberr != PIB::PIB_RESOURCE_OCCUPIED )
                    {
                        break;
                    }
                }

                nanosleep( 0, 10000 ); //sleep for 10,000 ns
                elapsed_indScom_time_ns += 10000;

            }while ( elapsed_indScom_time_ns <= MAX_INDSCOM_TIMEOUT_NS);

            if (l_err) { break; }

            // Check for a PCB/PIB Error
            if( scomout.piberr != 0 )
            {
                // got an indirect write error
                TRACFCOMP(g_trac_scom,
                        "INDIRECT SCOM PIB Error=%d (reg=0x%.16X)",
                        scomout.piberr, scomout.data64);

                /*@
                 * @errortype
                 * @moduleid    SCOM::SCOM_CHECK_INDIRECT_AND_DO_SCOM
                 * @reasoncode  SCOM::SCOM_INDIRECT_WRITE_FAIL
                 * @userdata1   Address
                 * @userdata2   Indirect Scom Status Register
                 * @devdesc     Indirect SCOM Write failed for this address
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                      ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      SCOM_CHECK_INDIRECT_AND_DO_SCOM,
                                      SCOM_INDIRECT_WRITE_FAIL,
                                      i_addr,
                                      scomout.data64);

                // we should never hit this so if we do we are going
                //  to blame hardware
                if( scomout.piberr == PIB::PIB_RESOURCE_OCCUPIED )
                {
                    SCOM::UdPibInfo(scomout.piberr).addToLog(l_err);
                    l_err->addHwCallout( i_target,
                                         HWAS::SRCI_PRIORITY_HIGH,
                                         HWAS::NO_DECONFIG,
                                         HWAS::GARD_NULL );
                }
                else
                {
                    //Add the callouts for the specific PCB/PIB error
                    PIB::addFruCallouts( i_target,
                                         scomout.piberr,
                                         i_addr,
                                         l_err );
                }

                //Add this target to the FFDC
                ERRORLOG::ErrlUserDetailsTarget(i_target,"IndSCOM Target")
                  .addToLog(l_err);

                l_err->collectTrace( SCOM_COMP_NAME, 256);
            }
            // if we got a timeout, create an errorlog.
            else if( scomout.done == 0 )
            {
                // got an indirect read timeout
                TRACFCOMP(g_trac_scom,
                          "INDIRECT SCOM WRITE: Timeout, reg=0x%.16X",
                          scomout.data64);

                /*@
                 * @errortype
                 * @moduleid     SCOM::SCOM_CHECK_INDIRECT_AND_DO_SCOM
                 * @reasoncode   SCOM::SCOM_INDIRECT_WRITE_TIMEOUT
                 * @userdata1    Address
                 * @userdata2    Indirect Scom Status Register
                 * @devdesc      Indirect SCOM complete bit did not come on
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                      ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      SCOM_CHECK_INDIRECT_AND_DO_SCOM,
                                      SCOM_INDIRECT_WRITE_TIMEOUT,
                                      i_addr,
                                      scomout.data64);

                //Best guess is the chip
                l_err->addHwCallout( i_target,
                                     HWAS::SRCI_PRIORITY_HIGH,
                                     HWAS::DELAYED_DECONFIG,
                                     HWAS::GARD_Predictive );

                //Add this target to the FFDC
                ERRORLOG::ErrlUserDetailsTarget(i_target,"IndSCOM Target")
                  .addToLog(l_err);

                l_err->collectTrace( SCOM_COMP_NAME, 256);
            }
        } // end of write
    } while(0);

    if( need_unlock )
    {
        mutex_unlock(l_mutex);
    }

    return l_err;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t doForm1IndirectScom(DeviceFW::OperationType i_opType,
                               TARGETING::Target* i_target,
                               void* io_buffer,
                               size_t& io_buflen,
                               int64_t i_accessType,
                               uint64_t i_addr)
{
    errlHndl_t l_err = NULL;

    uint64_t l_io_buffer = 0;
    uint64_t temp_scomAddr = 0;
    uint64_t l_data_from_addr = 0;

    memcpy(&l_io_buffer, io_buffer, 8);
    memcpy(&temp_scomAddr, &i_addr, 8);

    do {
        if(i_opType == DeviceFW::READ)
        {
            TRACFCOMP(g_trac_scom, "doForm1IndirectScom: Indirect Scom Form 1"
                " does not support read op");

            /*@
             * @errortype
             * @moduleid     SCOM::SCOM_DO_FORM_1_INDIRECT_SCOM
             * @reasoncode   SCOM::SCOM_FORM_1_READ_REQUEST
             * @userdata1    Address
             * @userdata2    Operation Type
             * @devdesc      No read op on form 1 indirect scom.
             */
            l_err = new ERRORLOG::ErrlEntry(
                                  ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                  SCOM_DO_FORM_1_INDIRECT_SCOM,
                                  SCOM_FORM_1_READ_REQUEST,
                                  i_addr,
                                  i_opType,
                                  ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

            break;
        }
        // We want to make sure the user inputted data bits 0:11 are zero
        // so we can push addr(20:31) in it.
        if ((l_io_buffer & 0xFFF0000000000000) != 0)
        {
            TRACFCOMP(g_trac_scom, "doForm1IndirectScom> User supplied "
                "data(0:11) is not Zero: data out of range");

            /*@
             * @errortype
             * @moduleid     SCOM::SCOM_DO_FORM_1_INDIRECT_SCOM
             * @reasoncode   SCOM::SCOM_FORM_1_INVALID_DATA
             * @userdata1    Address
             * @userdata2    User supplied data
             * @devdesc      Bits 0:11 in user supplied data is not zero
             */
            l_err = new ERRORLOG::ErrlEntry(
                                  ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                  SCOM_DO_FORM_1_INDIRECT_SCOM,
                                  SCOM_FORM_1_INVALID_DATA,
                                  i_addr,
                                  l_io_buffer,
                                  ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

            break;
        }

        // Set up Address reg
        // cmdreg = addr(32:63)
        temp_scomAddr = i_addr & 0x00000000FFFFFFFF;

        // Set up data regs
        // data(0:11) = addr(20:31)
        l_data_from_addr = i_addr & 0x00000FFF00000000;
        // Do some bit shifting so things line up nicely
        l_data_from_addr = (l_data_from_addr << 20 );

        // data(12:63) = data(12:63)
        // Set Data reg
        l_io_buffer = l_io_buffer | l_data_from_addr;

        // Now perform the op requested using the
        // local io_buffer with the indirect addr imbedded.
        l_err = doScomOp(i_opType,
                         i_target,
                         & l_io_buffer,
                         io_buflen,
                         i_accessType,
                         temp_scomAddr);

        if (l_err != NULL)
        {
            TRACFCOMP(g_trac_scom, "doForm1IndirectScom: Write op fail");
            break;
        }

    }while(0);

    return l_err;
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
errlHndl_t doScomOp(DeviceFW::OperationType i_opType,
                    TARGETING::Target* i_target,
                    void* io_buffer,
                    size_t& io_buflen,
                    int64_t i_accessType,
                    uint64_t i_addr)
{
    errlHndl_t l_err = NULL;

    uint32_t l_remainingAttempts{2};
    uint32_t l_retryCount{0};

    // P9 has a bug in the multicast logic that causes it to return a
    //  'chiplet offline' error if there are any chiplets in the multicast
    //  group that are offline.  If the scom is performed via the PIB
    //  we will see a pib error but the data will be valid.  If the scom
    //  is performed via the ADU we will see an error but the data we
    //  get returned will be all FFs.
    bool l_multicastBugError = false;

    do
    {
        //number of max remaining attempts after the current attempt.
        --l_remainingAttempts;

        do{
            TARGETING::ScomSwitches scomSetting;
            // We start by assuming target = MASTER_PROCESSOR_CHIP_TARGET_SENTINEL
            // so following that assumption default l_targetType to PROC_CHIP
            TARGETING::ATTR_TYPE_type l_targetType = TARGETING::TYPE_PROC;
            scomSetting.useXscom = true;  //Default to Xscom supported.
            if(TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL != i_target)
            {
                scomSetting =
                  i_target->getAttr<TARGETING::ATTR_SCOM_SWITCHES>();

                l_targetType = i_target->getAttr<TARGETING::ATTR_TYPE>();

                if( l_targetType == TARGETING::TYPE_PROC )
                {
                    l_multicastBugError = true;
                }
            }

            //Always XSCOM the Master Sentinel
            if((TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL == i_target) ||
                (scomSetting.useXscom))
            {  //do XSCOM
                // xscom uses ADU so we'll do a workaround instead of ignoring
                //  the error code
                l_multicastBugError = false;

                //Check to see if we need to do the multicast bug workaround
                // and do it, returns true if the workaround was performed
                // which means we skip the regular call
                bool l_didWorkaround = false;
                l_err = doMulticastWorkaround(i_opType,
                                              i_target,
                                              io_buffer,
                                              io_buflen,
                                              i_addr,
                                              l_didWorkaround);
                if( !l_didWorkaround && !l_err )
                {
                    l_err = deviceOp(i_opType,
                                     i_target,
                                     io_buffer,
                                     io_buflen,
                                     DEVICE_XSCOM_ADDRESS(i_addr));
                }
                else if( l_didWorkaround && !l_err )
                {
                    //Since this is a pre-workaround, don't
                    //test for a retry if successful.
                    l_remainingAttempts = 0;
                }
                break;
            }
            else if(scomSetting.useI2cScom)
            {
                //do I2CSCOM
                l_err = deviceOp(i_opType,
                                i_target,
                                io_buffer,
                                io_buflen,
                                DEVICE_I2CSCOM_ADDRESS(i_addr));
                if( l_err ) { break; }

            }
            else if(scomSetting.useSbeScom)
            {   //do SBESCOM
                l_err = deviceOp(i_opType,
                                 i_target,
                                 io_buffer,
                                 io_buflen,
                                 DEVICE_SBEFIFOSCOM_ADDRESS(i_addr));
                if( l_err ) { break; }
            }
            else if(scomSetting.useInbandScom)
            {   //do IBSCOM
                l_err = deviceOp(i_opType,
                                 i_target,
                                 io_buffer,
                                 io_buflen,
                                 DEVICE_IBSCOM_ADDRESS(i_addr));
                if( l_err ) { break; }
            }
            else if(scomSetting.useFsiScom)
            {   //do FSISCOM
                l_err = deviceOp(i_opType,
                                 i_target,
                                 io_buffer,
                                 io_buflen,
                                 DEVICE_FSISCOM_ADDRESS(i_addr));
                if( l_err ) { break; }
            }
            else
            {
                assert(0,"SCOM::scomPerformOp> ATTR_SCOM_SWITCHES does not "
                        "indicate Xscom, SBESCOM, Ibscom, or FSISCOM is "
                        "supported. i_target=0x%.8x", get_huid(i_target));
                l_remainingAttempts = 0;
                break;
            }

        }while(0);

        //Check if any retry workaround's are needed.
        if(l_remainingAttempts > 0)
        {
            bool l_doRetry{false};
            const PostOpChecks* l_postOpPtr = PostOpChecks::theInstance();
            if(nullptr != l_postOpPtr)
            {
                l_doRetry = l_postOpPtr->requestRetry(
                                                      l_err,
                                                      l_retryCount,
                                                      i_opType,
                                                      i_target,
                                                      io_buffer,
                                                      io_buflen,
                                                      i_accessType,
                                                      i_addr
                                                     );
            }

            if(l_doRetry)
            {
                delete l_err;
                l_err = nullptr;

                TRACFCOMP(g_trac_scom,
                          "Forcing retry of Scom to 0x%016X on 0x%08X",
                          i_addr,
                (TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL == i_target ?
                        0xFFFFFFFF : TARGETING::get_huid(i_target)));

            }
            else
            {
                //no retries are needed.
                l_remainingAttempts = 0;
                break;
            }
        }

        //keep track of attempts.
        ++l_retryCount;
    }
    while(l_remainingAttempts > 0);


    if( l_err && p9_scom_addr(i_addr).is_multicast() && l_multicastBugError )
    {
        //Delete the error if the mask matches the pib err
        for(auto data : l_err->getUDSections(SCOM_COMP_ID, SCOM::SCOM_UDT_PIB))
        {
            //We get the raw data from the userdetails section, which in this
            //case is the pib_err itself so just check it.
            if(*reinterpret_cast<uint8_t *>(data) == PIB::PIB_CHIPLET_OFFLINE)
            {
                TRACFCOMP(g_trac_scom, "Ignoring error %.8X because it is a"
                          " multicast scom with a PIB_CHIPLET_OFFLINE error,"
                          " and this is expected",
                          l_err->plid() );
                delete l_err;
                l_err = NULL;
                break;
            }
        }
    }

    //Add some additional FFDC based on the specific operation
    if( l_err )
    {
        addScomFailFFDC( l_err, i_target, i_addr );
    }

    return l_err;
}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void addScomFailFFDC( errlHndl_t i_err,
                      TARGETING::Target* i_chipTarg,
                      uint64_t i_addr )
{
    // Read some error regs from scom
    ERRORLOG::ErrlUserDetailsLogRegister l_scom_data(i_chipTarg);
    bool addit = false;
    TARGETING::TYPE l_type = TARGETING::TYPE_NA;
    uint32_t l_badChiplet = 0x00;

    static bool l_insideFFDC = false;
    if( l_insideFFDC )
    {
        TRACDCOMP( g_trac_scom, "Already gathering FFDC..." );
        return;
    }
    l_insideFFDC = true;

    if( i_chipTarg == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL )
    {
        l_type = TARGETING::TYPE_PROC;
    }
    else
    {
        l_type = i_chipTarg->getAttr<TARGETING::ATTR_TYPE>();
    }

    //Multicast scoms on the processor
    if( p9_scom_addr(i_addr).is_multicast()
        && (TARGETING::TYPE_PROC == l_type) )
    {
        addit = true;
        uint64_t ffdc_regs1[] = {
            0x000F001E, // PCBMS.FIRST_ERR_REG
            0x000F001F, // PCBMS.ERROR_REG
        };
        for( size_t x = 0;
             x < (sizeof(ffdc_regs1)/sizeof(ffdc_regs1[0]));
             x++ )
        {
            l_scom_data.addData(DEVICE_SCOM_ADDRESS(ffdc_regs1[x]));
        }

        uint64_t ffdc_regs2[] = {
            0x000F0011, // PCBMS.REC_ERR_REG0
            0x000F0012, // PCBMS.REC_ERR_REG1
            0x000F0013, // PCBMS.REC_ERR_REG2
            0x000F0014, // PCBMS.REC_ERR_REG3
        };

        // save off the responses to figure out which chiplet failed
        uint8_t l_responses[(sizeof(ffdc_regs2)/sizeof(ffdc_regs2[0]))
                            *sizeof(uint64_t)];
        uint8_t* l_respPtr = l_responses;

        for( size_t x = 0;
             x < (sizeof(ffdc_regs2)/sizeof(ffdc_regs2[0]));
             x++ )
        {
            // going to read these manually because we want to look at the data
            uint64_t l_scomdata = 0;
            size_t l_scomsize = sizeof(l_scomdata);
            errlHndl_t l_ignored = doScomOp( DeviceFW::READ,
                                             i_chipTarg,
                                             &l_scomdata,
                                             l_scomsize,
                                             DeviceFW::SCOM,
                                             ffdc_regs2[x] );
            if( l_ignored )
            {
                delete l_ignored;
                l_ignored = nullptr;
                l_scomdata = 0;
            }
            else
            {
                l_scom_data.addDataBuffer( &l_scomdata,
                                        l_scomsize,
                                        DEVICE_SCOM_ADDRESS(ffdc_regs2[x]) );
            }

            // copy the error data into our big buffer
            memcpy( l_respPtr, &l_scomdata, l_scomsize );
            l_respPtr += l_scomsize; // move to the next chunk
        }

        // find the bad chiplet
        //   4-bits per chiplet : 1-bit response, 3-bit error code
        for( size_t x = 0; x < sizeof(l_responses); x++ )
        {
            // look for the first non-zero pib error code
            if( l_responses[x] & 0x70 ) //front nibble
            {
                l_badChiplet = x*2;
            }
            else if( l_responses[x] & 0x07 ) //back nibble
            {
                l_badChiplet = x*2 + 1;
            }
        }

        uint64_t ffdc_regs3[] = {
            0x0F0001, // multicast group1
            0x0F0002, // multicast group2
            0x0F0003, // multicast group3
            0x0F0004, // multicast group4
        };
        for( size_t x = 0;
             x < (sizeof(ffdc_regs3)/sizeof(ffdc_regs3[0]));
             x++ )
        {
            p9_scom_addr l_scom(ffdc_regs3[x]);
            l_scom.set_chiplet_id(l_badChiplet);
            l_scom_data.addData(DEVICE_SCOM_ADDRESS(l_scom.get_addr()));
        }
    }

    //Any non-PCB Slave and non TP reg on the processor
    if( ((i_addr & 0x00FF0000) != 0x000F0000) //PCB slave
        && (p9_scom_addr(i_addr).get_chiplet_id() != 0x00) //TP
        && (TARGETING::TYPE_PROC == l_type) )
    {
        addit = true;
        if( l_badChiplet == 0x00 )
        {
            l_badChiplet = p9_scom_addr(i_addr).get_chiplet_id();
        }
        //grab some data related to the PCB slave state
        uint64_t ffdc_regs[] = {
            0x0F001F, // PCBSL<cplt>.ERROR_REG
            0x03000F, // CC.<chiplet>.ERROR_STATUS
            0x010001, // <chiplet>.PSC.PSCOM_STATUS_ERROR_REG
            0x010002, // <chiplet>.PSC.PSCOM_ERROR_MASK
        };
        for( size_t x = 0; x < (sizeof(ffdc_regs)/sizeof(ffdc_regs[0])); x++ )
        {
            p9_scom_addr l_scom(ffdc_regs[x]);
            l_scom.set_chiplet_id(l_badChiplet);
            l_scom_data.addData(DEVICE_SCOM_ADDRESS(l_scom.get_addr()));
        }

        //Osc Switch Sense 1 register
        l_scom_data.addData(DEVICE_SCOM_ADDRESS(0x0005001D));
        //Osc Switch Sense 2 register
        l_scom_data.addData(DEVICE_SCOM_ADDRESS(0x0005001E));

        //grab the clock regs via FSI too, just in case
        if (i_chipTarg != TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
        {
            TARGETING::Target* mproc = NULL;
            TARGETING::targetService().masterProcChipTargetHandle(mproc);
            if (i_chipTarg != mproc)
            {
                l_scom_data.addData(DEVICE_FSI_ADDRESS(0x2874));//==281D
                l_scom_data.addData(DEVICE_FSI_ADDRESS(0x2878));//==281E
            }
        }
    }

    //PBA scoms on the processor
    if( ((i_addr & 0xFFFFF000) == 0x00068000)
        && (TARGETING::TYPE_PROC == l_type) )
    {
        addit = true;
        //look for hung operations on the PBA
        uint64_t ffdc_regs[] = {
            //grab the PBA buffers in case something is hung
            0x05012850, //PBARBUFVAL0
            0x05012851, //PBARBUFVAL1
            0x05012852, //PBARBUFVAL2
            0x05012853, //PBARBUFVAL3
            0x05012854, //PBARBUFVAL4
            0x05012855, //PBARBUFVAL5
            0x05012858, //PBAWBUFVAL0
            0x05012859, //PBAWBUFVAL1
        };
        for( size_t x = 0; x < (sizeof(ffdc_regs)/sizeof(ffdc_regs[0])); x++ )
        {
            l_scom_data.addData(DEVICE_SCOM_ADDRESS(ffdc_regs[x]));
        }
    }
    //Core/EX/EQ scoms on the processor (not including PCB slave regs)
    else if( (((i_addr & 0xF0000000) == 0x10000000) //CACHE
              || ((i_addr & 0xF0000000) == 0x20000000)) //CORE
             && ((i_addr & 0x00FF0000) != 0x000F0000) //PCB slave
             && (TARGETING::TYPE_PROC == l_type) )
    {
        addit = true;
        uint8_t l_badChiplet = p9_scom_addr(i_addr).get_chiplet_id();
        //grab some data related to the PCB slave state
        uint64_t ffdc_regs[] = {
            0x0F010A, //Special Wakeup Other
            0x0F010B, //Special Wakeup FSP
            0x0F010C, //Special Wakeup OCC
            0x0F010D, //Special Wakeup HYP
            0x0F0111, //PM State History FSP
        };
        for( size_t x = 0; x < (sizeof(ffdc_regs)/sizeof(ffdc_regs[0])); x++ )
        {
            p9_scom_addr l_scom(ffdc_regs[x]);
            l_scom.set_chiplet_id(l_badChiplet);
            l_scom_data.addData(DEVICE_SCOM_ADDRESS(l_scom.get_addr()));
        }
    }


    if( addit )
    {
        l_scom_data.addToLog(i_err);
    }

    l_insideFFDC = false;
}


/**
 * @brief Perform a manual multicast operation if appropriate
 */
errlHndl_t doMulticastWorkaround( DeviceFW::OperationType i_opType,
                                  TARGETING::Target* i_target,
                                  void* io_buffer,
                                  size_t& io_buflen,
                                  uint64_t i_addr,
                                  bool& o_didWorkaround )
{
    errlHndl_t l_err = nullptr;
    uint64_t* l_summaryReg = reinterpret_cast<uint64_t*>(io_buffer);

    // Some masks for parsing the address
    constexpr uint64_t IS_MULTICAST         = 0x40000000;
    constexpr uint64_t MULTICAST_GROUP      = 0x07000000;
    constexpr uint64_t GROUP_ZERO           = 0x00000000;
    constexpr uint64_t GROUP_ONE            = 0x01000000;
    constexpr uint64_t IS_PCBSLAVE          = 0x000F0000;
    constexpr uint64_t CHIPLET_BYTE         = 0xFF000000;
    constexpr uint64_t MULTICAST_OP         = 0x38000000;
    constexpr uint64_t MULTICAST_OP_BITWISE = 0x10000000;
    constexpr uint64_t MULTICAST_OP_OR      = 0x00000000;

#ifndef __HOSTBOOT_RUNTIME
    // Some P9-specific chiplet values to make things more efficient
    constexpr uint64_t P9_FIRST_MC   = 0x07;
    constexpr uint64_t P9_LAST_MC    = 0x08;
    constexpr uint64_t P9_FIRST_EQ   = 0x10;
    constexpr uint64_t P9_LAST_EQ    = 0x1F;
    constexpr uint64_t P9_FIRST_EC   = 0x20;
    constexpr uint64_t P9_LAST_EC    = 0x3F;
#endif

    o_didWorkaround = false;

    do
    {

        // Skip calls to the SENTINEL since we don't have the
        //  ability to find its children
        if( TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL == i_target )
        {
            break;
        }

        bool l_opIsBitwise = false;
        bool l_opIsOr      = false;
        bool l_groupIsZero = false;
        bool l_groupIsOne  = false;

        // Only perform this workaround for:
        //  - reads
        //  - multicast registers
        //  - scom is not part of pcb slave
        if( (DeviceFW::READ == i_opType)
            && ((IS_MULTICAST & i_addr) == IS_MULTICAST)
            && ((IS_PCBSLAVE & i_addr) != IS_PCBSLAVE) )
        {
            l_opIsBitwise = ((MULTICAST_OP & i_addr) == MULTICAST_OP_BITWISE);
            l_opIsOr      = ((MULTICAST_OP & i_addr) == MULTICAST_OP_OR);
            l_groupIsZero = ((MULTICAST_GROUP & i_addr) == GROUP_ZERO);
            l_groupIsOne  = ((MULTICAST_GROUP & i_addr) == GROUP_ONE);

            //  - multicast read option XXX 'bit-wise'
            //  - multicast read option XXX 'or'
            //  - multicast group0 'all functional chiplets'
            //  - multicast group1 'all functional cores'
            if( (l_opIsBitwise || l_opIsOr) &&
                (l_groupIsZero || l_groupIsOne) )
            {
                TRACFCOMP( g_trac_scom, "doMulticastWorkaround on %.8X for %.8X", TARGETING::get_huid(i_target), i_addr );
            }
            // Not a supported multicast op
            else
            {
                TRACFCOMP(g_trac_scom, "doMulticastWorkaround Multicast op has unsupported group 0x%X",(MULTICAST_OP & i_addr));

                /*@
                * @errortype
                * @moduleid     SCOM::SCOM_DO_MULTICAST_WORKAROUND
                * @reasoncode   SCOM::SCOM_UNSUPPORTED_MULTICAST_OP
                * @userdata1    Address
                * @userdata1    Target huid
                * @devdesc      Unsupported multicast op
                */
                l_err = new ERRORLOG::ErrlEntry(
                                    ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                    SCOM_DO_MULTICAST_WORKAROUND,
                                    SCOM_UNSUPPORTED_MULTICAST_OP,
                                    i_addr,
                                    get_huid(i_target),
                                    ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);

                break;
            }
        }
        // Common path when not a multicast op
        else
        {
            break;
        }

        TARGETING::TargetHandleList l_chiplets;
        if( l_groupIsZero )
        {
            // Get every functional pervasive target
            TARGETING::getChildChiplets( l_chiplets,
                                        i_target,
                                        TARGETING::TYPE_PERV,
                                        true );
        }
        else if( l_groupIsOne )
        {
            // Get every functional core target
            TARGETING::getChildChiplets( l_chiplets,
                                        i_target,
                                        TARGETING::TYPE_CORE,
                                        true );
        }

        // Loop through the chiplets, perform the xscom reads, combine results
        for( auto l_chiplet : l_chiplets )
        {
            uint64_t l_data = 0;
            uint64_t l_addr = (i_addr & ~CHIPLET_BYTE);
            // Use CHIPLET_ID for unit, is equal to CHIP_UNIT for TYPE_PERV
            uint64_t l_unit = l_chiplet->getAttr<TARGETING::ATTR_CHIPLET_ID>();

#ifndef __HOSTBOOT_RUNTIME
            // filter out some chiplets that aren't running yet
            if( !g_useSlaveCores
                && (((l_unit >= P9_FIRST_EQ) && (l_unit <= P9_LAST_EQ))
                    || ((l_unit >= P9_FIRST_EC) && (l_unit <= P9_LAST_EC))
                    )
                )
            {
                // Only access the master ec/eq
                static const TARGETING::Target* l_masterCore =
                TARGETING::getMasterCore();
                uint64_t l_ecNum =
                l_masterCore->getAttr<TARGETING::ATTR_CHIP_UNIT>();
                bool l_fused = TARGETING::is_fused_mode();
                if( !((l_unit == l_ecNum)  //master
                    || (l_fused && (l_unit == l_ecNum+1))) )  //fused-pair
                {
                    continue;
                }
                auto l_eqNum = 0x10 + l_ecNum/4;
                if( l_unit == l_eqNum )
                {
                    continue;
                }
            }
            if( !g_useMemChiplets
                && ((l_unit >= P9_FIRST_MC) && (l_unit <= P9_LAST_MC)) )
            {
                // Only access the mem chiplets if we're not in async mode
                //  because we don't start clocks until later on in that case
                auto l_syncMode =
                i_target->getAttr<TARGETING::ATTR_MC_SYNC_MODE>();
                if( l_syncMode == TARGETING::MC_SYNC_MODE_NOT_IN_SYNC )
                {
                    continue;
                }
            }
#endif

            l_addr |= (l_unit << 24);
            io_buflen = sizeof(uint64_t);
            l_err = deviceOp(i_opType,
                            i_target,
                            &l_data,
                            io_buflen,
                            DEVICE_XSCOM_ADDRESS_NO_ERROR(l_addr));
            // just ignore any errors, we expect they will happen
            if( l_err )
            {
                delete l_err;
                l_err = nullptr;
                continue;
            }

            if( l_opIsBitwise )
            {
                // if any bits are set, set this unit's bit in summary reg
                //   note: this is good enough for the use-case we have now
                //         but a better implementation would be to actually
                //         check the select regs as well so we know which bit(s)
                //         are the trigger
                if( l_data & 0x8000000000000000 )
                {
                    *l_summaryReg |= (0x8000000000000000 >> l_unit);
                }
            }
            else if( l_opIsOr )
            {
                *l_summaryReg |= l_data;
            }
        }

        o_didWorkaround = true;

    } while (0);


    return l_err;
}

} // end namespace
OpenPOWER on IntegriCloud