summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/plat/mem/prdfMemTdCtlr_rt.C
blob: da18cea812868c4fbaf865abd38e454857e0ebcb (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
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/plat/mem/prdfMemTdCtlr_rt.C $               */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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                                                     */

/** @file  prdfMemTdCtlr_rt.C
 *  @brief A state machine for memory Targeted Diagnostics (runtime only).
 */

#include <prdfMemTdCtlr.H>

// Framework includes
#include <prdfRegisterCache.H>
#include <UtilHash.H>

// Platform includes
#include <prdfCenMbaDataBundle.H>
#include <prdfCenMbaExtraSig.H>
#include <prdfMemCaptureData.H>
#include <prdfMemEccAnalysis.H>
#include <prdfMemScrubUtils.H>
#include <prdfMemTps.H>
#include <prdfMemUtils.H>
#include <prdfMemVcm.H>
#include <prdfP9McaDataBundle.H>
#include <prdfP9McaExtraSig.H>
#include <prdfPlatServices.H>

using namespace TARGETING;

namespace PRDF
{

using namespace PlatServices;

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

template<TARGETING::TYPE T>
void __recaptureRegs( STEP_CODE_DATA_STRUCT & io_sc, ExtensibleChip * i_chip );

template<>
void __recaptureRegs<TYPE_MCBIST>( STEP_CODE_DATA_STRUCT & io_sc,
                                   ExtensibleChip * i_chip )
{
    #define PRDF_FUNC "[__recaptureRegs<TYPE_MCBIST>] "

    RegDataCache & cache = RegDataCache::getCachedRegisters();
    CaptureData & cd = io_sc.service_data->GetCaptureData();

    // refresh and recapture the mcb registers
    const char * mcbRegs[] =
    {
        "MCBISTFIR", "MBSEC0", "MBSEC1", "MCB_MBSSYMEC0",
        "MCB_MBSSYMEC1", "MCB_MBSSYMEC2", "MCB_MBSSYMEC3",
        "MCB_MBSSYMEC4", "MCB_MBSSYMEC5", "MCB_MBSSYMEC6",
        "MCB_MBSSYMEC7", "MCB_MBSSYMEC8", "MBSMSEC", "MCBMCAT",
    };

    for ( uint32_t i = 0; i < sizeof(mcbRegs)/sizeof(char*); i++ )
    {
        SCAN_COMM_REGISTER_CLASS * reg =
            i_chip->getRegister( mcbRegs[i] );
        cache.flush( i_chip, reg );
    }

    i_chip->CaptureErrorData( cd, Util::hashString("MaintCmdRegs_mcb") );

    // refresh and recapture the mca registers
    const char * mcaRegs[] =
    {
        "MCAECCFIR",
    };

    ExtensibleChipList mcaList = getConnected( i_chip, TYPE_MCA );

    for ( auto & mca : mcaList )
    {
        for ( uint32_t i = 0; i < sizeof(mcaRegs)/sizeof(char*); i++ )
        {
            SCAN_COMM_REGISTER_CLASS * reg = mca->getRegister( mcaRegs[i] );
            cache.flush( mca, reg );
        }
        mca->CaptureErrorData( cd, Util::hashString("MaintCmdRegs_mca") );
    }

    #undef PRDF_FUNC
}

template<>
void __recaptureRegs<TYPE_OCMB_CHIP>( STEP_CODE_DATA_STRUCT & io_sc,
                                   ExtensibleChip * i_chip )
{
    #define PRDF_FUNC "[__recaptureRegs<TYPE_OCMB_CHIP>] "

    RegDataCache & cache = RegDataCache::getCachedRegisters();
    CaptureData & cd = io_sc.service_data->GetCaptureData();

    // refresh and recapture the ocmb registers
    const char * ocmbRegs[] =
    {
        "MCBISTFIR", "RDFFIR", "MBSEC0", "MBSEC1", "OCMB_MBSSYMEC0",
        "OCMB_MBSSYMEC1", "OCMB_MBSSYMEC2", "OCMB_MBSSYMEC3",
        "OCMB_MBSSYMEC4", "OCMB_MBSSYMEC5", "OCMB_MBSSYMEC6",
        "OCMB_MBSSYMEC7", "OCMB_MBSSYMEC8", "MBSMSEC", "MCBMCAT",
    };

    for ( uint32_t i = 0; i < sizeof(ocmbRegs)/sizeof(char*); i++ )
    {
        SCAN_COMM_REGISTER_CLASS * reg =
            i_chip->getRegister( ocmbRegs[i] );
        cache.flush( i_chip, reg );
    }

    i_chip->CaptureErrorData( cd, Util::hashString("MaintCmdRegs_ocmb") );

    #undef PRDF_FUNC
}

template<>
void __recaptureRegs<TYPE_MBA>( STEP_CODE_DATA_STRUCT & io_sc,
                                ExtensibleChip * i_chip )
{
    #define PRDF_FUNC "[__recaptureRegs<TYPE_MBA>] "

    RegDataCache & cache = RegDataCache::getCachedRegisters();
    ExtensibleChip * membChip = getConnectedParent( i_chip, TYPE_MEMBUF );
    TargetHandle_t mbaTrgt = i_chip->GetChipHandle();
    uint32_t mbaPos = getTargetPosition( mbaTrgt );

    const char * membRegs[2][15] =
    {
        { "MBSECCFIR_0", "MBA0_MBSECCERRPT_0","MBA0_MBSECCERRPT_1",
          "MBA0_MBSEC0", "MBA0_MBSEC1", "MBSTR_0",
          "MBA0_MBSSYMEC0", "MBA0_MBSSYMEC1", "MBA0_MBSSYMEC2",
          "MBA0_MBSSYMEC3", "MBA0_MBSSYMEC4", "MBA0_MBSSYMEC5",
          "MBA0_MBSSYMEC6", "MBA0_MBSSYMEC7", "MBA0_MBSSYMEC8", },
        { "MBSECCFIR_1", "MBA1_MBSECCERRPT_0","MBA1_MBSECCERRPT_1",
          "MBA1_MBSEC0", "MBA1_MBSEC1", "MBSTR_1",
          "MBA1_MBSSYMEC0", "MBA1_MBSSYMEC1", "MBA1_MBSSYMEC2",
          "MBA1_MBSSYMEC3", "MBA1_MBSSYMEC4", "MBA1_MBSSYMEC5",
          "MBA1_MBSSYMEC6", "MBA1_MBSSYMEC7", "MBA1_MBSSYMEC8", },
    };
    for ( uint32_t i = 0; i < 15; i++ )
    {
        SCAN_COMM_REGISTER_CLASS * reg
            = membChip->getRegister( membRegs[mbaPos][i] );
        cache.flush( membChip, reg );
    }

    const char * mbaRegs[] =
    {
        "MBASPA", "MBMCT", "MBMSR", "MBMACA", "MBMEA", "MBASCTL", "MBAECTL",
    };
    for ( uint32_t i = 0; i < sizeof(mbaRegs)/sizeof(char*); i++ )
    {
        SCAN_COMM_REGISTER_CLASS * reg = i_chip->getRegister( mbaRegs[i] );
        cache.flush( i_chip, reg );
    }

    // Now recapture those registers.

    CaptureData & cd = io_sc.service_data->GetCaptureData();

    if ( 0 == mbaPos )
    {
        membChip->CaptureErrorData(cd, Util::hashString("MaintCmdRegs_mba0") );
    }
    else
    {
        membChip->CaptureErrorData(cd, Util::hashString("MaintCmdRegs_mba1") );
    }
    i_chip->CaptureErrorData(cd, Util::hashString("MaintCmdRegs"));

    #undef PRDF_FUNC
}

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

template <TARGETING::TYPE T>
uint32_t MemTdCtlr<T>::handleTdEvent( STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[MemTdCtlr::handleTdEvent] "

    uint32_t o_rc = SUCCESS;

    do
    {
        // Make sure the TD controller is initialized.
        o_rc = initialize();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "initialize() failed on 0x%08x",
                      iv_chip->getHuid() );
            break;
        }

        // Don't interrupt a TD procedure if one is already in progress.
        if ( nullptr != iv_curProcedure ) break;

        // If the queue is empty, there is nothing to do. So there is no point
        // to stopping background scrub. This could have happen if TPS was
        // banned on a rank and the TPS request was never added to the queue. In
        // that case, mask fetch attentions temporarily to prevent flooding.
        if ( iv_queue.empty() )
        {
            o_rc = maskEccAttns();
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "maskEccAttns() failed" );
                break;
            }

            break; // Don't stop background scrub.
        }

        // Stop background scrubbing.
        o_rc = stopBgScrub<T>( iv_chip );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "stopBgScrub<T>(0x%08x) failed",
                      iv_chip->getHuid() );
            break;
        }

        // Since we had to manually stop the maintenance command, refresh all
        // relevant registers that may have changed since the initial capture.
        __recaptureRegs<T>( io_sc, iv_chip );

        collectStateCaptureData( io_sc, TD_CTLR_DATA::START );

        // It is possible that background scrub could have found an ECC error
        // before we had a chance to stop the command. Therefore, we need to
        // call analyzeCmdComplete() first so that any ECC errors found can be
        // handled. Also, analyzeCmdComplete() will initialize the variables
        // needed so we know where to restart background scrubbing.
        bool junk = false;
        o_rc = analyzeCmdComplete( junk, io_sc );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "analyzeCmdComplete(0x%08x) failed",
                      iv_chip->getHuid() );
            break;
        }

        // Move onto the next step in the state machine.
        o_rc = nextStep( io_sc );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "nextStep() failed on 0x%08x",
                      iv_chip->getHuid() );
            break;
        }

    } while (0);

    // Gather capture data even if something failed above.
    collectStateCaptureData( io_sc, TD_CTLR_DATA::END );

    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( PRDF_FUNC "Failed on 0x%08x", iv_chip->getHuid() );

        // Change signature indicating there was an error in analysis.
        io_sc.service_data->setSignature( iv_chip->getHuid(),
                                          PRDFSIG_CmdComplete_ERROR );

        // Something definitely failed, so callout 2nd level support.
        io_sc.service_data->SetCallout( LEVEL2_SUPPORT, MRU_HIGH );
        io_sc.service_data->setServiceCall();
    }

    return o_rc;

    #undef PRDF_FUNC
}

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

template <TARGETING::TYPE T>
uint32_t MemTdCtlr<T>::defaultStep( STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[MemTdCtlr::defaultStep] "

    uint32_t o_rc = SUCCESS;

    if ( iv_resumeBgScrub )
    {
        // Background scrubbing paused for FFDC collection only. Resume the
        // current command.

        iv_resumeBgScrub = false;

        PRDF_TRAC( PRDF_FUNC "Calling resumeBgScrub<T>(0x%08x)",
                   iv_chip->getHuid() );

        o_rc = resumeBgScrub<T>( iv_chip );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "resumeBgScrub<T>(0x%08x) failed",
                      iv_chip->getHuid() );
        }
    }
    else
    {

        // Unmask the ECC attentions that were explicitly masked during the
        // TD procedure.
        o_rc = unmaskEccAttns();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "unmaskEccAttns() failed" );
        }

        // A TD procedure has completed. Restart background scrubbing on the
        // next rank.

        TdRankListEntry nextRank = iv_rankList.getNext( iv_stoppedRank );

        PRDF_TRAC( PRDF_FUNC "Calling startBgScrub<T>(0x%08x, m%ds%d)",
                   nextRank.getChip()->getHuid(),
                   nextRank.getRank().getMaster(),
                   nextRank.getRank().getSlave() );

        o_rc = startBgScrub<T>( nextRank.getChip(), nextRank.getRank() );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "startBgScrub<T>(0x%08x,m%ds%d) failed",
                      nextRank.getChip()->getHuid(),
                      nextRank.getRank().getMaster(),
                      nextRank.getRank().getSlave() );
        }
    }

    return o_rc;

    #undef PRDF_FUNC
}

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

template<TARGETING::TYPE T>
uint32_t __handleNceEte( ExtensibleChip * i_chip,
                         const MemAddr & i_addr, STEP_CODE_DATA_STRUCT & io_sc,
                         bool i_isHard = false )
{
    #define PRDF_FUNC "[__handleNceEte] "

    uint32_t o_rc = SUCCESS;

    MemRank rank = i_addr.getRank();

    do
    {
        // Query the per-symbol counters for the CE symbol(s).
        MemUtils::MaintSymbols symData; MemSymbol junk;
        o_rc = MemUtils::collectCeStats<T>( i_chip, rank, symData, junk );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "MemUtils::collectCeStats(0x%08x,m%ds%d) "
                      "failed", i_chip->getHuid(), rank.getMaster(),
                      rank.getSlave() );
            break;
        }

        // Make sure the list size is correct. Note that Nimbus has two symbol
        // correction. So it is possible to have two symbols in the counters
        // even though the threshold is set to 1.
        uint32_t count = symData.size();
        switch ( T )
        {
            case TYPE_MCA:       PRDF_ASSERT( 1 <= count && count <= 2 ); break;
            case TYPE_MBA:       PRDF_ASSERT( 1 == count               ); break;
            case TYPE_OCMB_CHIP: PRDF_ASSERT( 1 <= count && count <= 2 ); break;
            default: PRDF_ASSERT( false );
        }

        for ( auto & d : symData )
        {
            // Add the symbol(s) to the callout list and CE table.
            bool doTps;
            o_rc = MemEcc::handleMemCe<T>( i_chip, i_addr, d.symbol, doTps,
                                           io_sc, i_isHard );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "handleMemCe(0x%08x) failed",
                          i_chip->getHuid() );
                break;
            }

            // Add a TPS procedure to the queue, if needed.
            if ( doTps )
            {
                TdEntry * e = new TpsEvent<T>{ i_chip, rank };
                MemDbUtils::pushToQueue<T>( i_chip, e );
            }
        }
        if ( SUCCESS != o_rc ) break;

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

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

template<TARGETING::TYPE T>
uint32_t __handleSoftInterCeEte( ExtensibleChip * i_chip,
                                 const MemAddr & i_addr,
                                 STEP_CODE_DATA_STRUCT & io_sc );

template<>
uint32_t __handleSoftInterCeEte<TYPE_MCA>( ExtensibleChip * i_chip,
                                           const MemAddr & i_addr,
                                           STEP_CODE_DATA_STRUCT & io_sc )
{
    return __handleNceEte<TYPE_MCA>( i_chip, i_addr, io_sc );
}

template<>
uint32_t __handleSoftInterCeEte<TYPE_OCMB_CHIP>( ExtensibleChip * i_chip,
                                                 const MemAddr & i_addr,
                                                 STEP_CODE_DATA_STRUCT & io_sc )
{
    return __handleNceEte<TYPE_OCMB_CHIP>( i_chip, i_addr, io_sc );
}

template<>
uint32_t __handleSoftInterCeEte<TYPE_MBA>( ExtensibleChip * i_chip,
                                           const MemAddr & i_addr,
                                           STEP_CODE_DATA_STRUCT & io_sc )
{
    // Due to workarounds on the Centaur we are unable to stop on each
    // occurrence of the soft or intermittent CEs like we do for Nimbus.
    // Instead, the threshold is set much higher. If the threshold is hit we
    // simply want to add the rank to the callout list and trigger TPS.

    MemoryMru mm { i_chip->getTrgt(), i_addr.getRank(),
                   MemoryMruData::CALLOUT_RANK };
    io_sc.service_data->SetCallout( mm );

    TdEntry * e = new TpsEvent<TYPE_MBA>{ i_chip, i_addr.getRank() };
    MemDbUtils::pushToQueue<TYPE_MBA>( i_chip, e );

    return SUCCESS;
}

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

template<TARGETING::TYPE T>
uint32_t __handleRceEte( ExtensibleChip * i_chip,
                         const MemRank & i_rank, bool & o_errorsFound,
                         STEP_CODE_DATA_STRUCT & io_sc );

template<>
uint32_t __handleRceEte<TYPE_MCA>( ExtensibleChip * i_chip,
                                   const MemRank & i_rank, bool & o_errorsFound,
                                   STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[__handleRceEte] "

    uint32_t o_rc = SUCCESS;

    // Should only get this attention in MNFG mode.
    PRDF_ASSERT( mfgMode() );

    do
    {
        // The RCE ETE attention could be from IUE, IMPE, or IRCD. Need to check
        // MCAECCFIR[37] to determine if there was at least one IUE.
        SCAN_COMM_REGISTER_CLASS * fir = i_chip->getRegister( "MCAECCFIR" );
        o_rc = fir->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MCAECCFIR: i_chip=0x%08x",
                      i_chip->getHuid() );
            break;
        }
        if ( !fir->IsBitSet(37) ) break; // nothing else to do

        // Handle the IUE.
        o_errorsFound = true;
        io_sc.service_data->AddSignatureList( i_chip->getTrgt(),
                                              PRDFSIG_MaintIUE );
        o_rc = MemEcc::handleMemIue<TYPE_MCA>( i_chip, i_rank, io_sc );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "analyzeMaintIue(0x%08x) failed",
                      i_chip->getHuid() );
            break;
        }

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t __handleRceEte<TYPE_OCMB_CHIP>( ExtensibleChip * i_chip,
                                         const MemRank & i_rank,
                                         bool & o_errorsFound,
                                         STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[__handleRceEte] "

    uint32_t o_rc = SUCCESS;

    // Should only get this attention in MNFG mode.
    PRDF_ASSERT( mfgMode() );

    do
    {
        // The RCE ETE attention could be from IUE, IMPE, or IRCD. Need to check
        // RDFFIR[37] to determine if there was at least one IUE.
        SCAN_COMM_REGISTER_CLASS * fir = i_chip->getRegister( "RDFFIR" );
        o_rc = fir->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on RDFFIR: i_chip=0x%08x",
                      i_chip->getHuid() );
            break;
        }
        if ( !fir->IsBitSet(37) ) break; // nothing else to do

        // Handle the IUE.
        o_errorsFound = true;
        io_sc.service_data->AddSignatureList( i_chip->getTrgt(),
                                              PRDFSIG_MaintIUE );
        o_rc = MemEcc::handleMemIue<TYPE_OCMB_CHIP>( i_chip, i_rank, io_sc );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "analyzeMaintIue(0x%08x) failed",
                      i_chip->getHuid() );
            break;
        }

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t __handleRceEte<TYPE_MBA>( ExtensibleChip * i_chip,
                                   const MemRank & i_rank, bool & o_errorsFound,
                                   STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[__handleRceEte] "

    uint32_t o_rc = SUCCESS;

    TargetHandle_t trgt = i_chip->getTrgt();

    o_errorsFound = true;
    io_sc.service_data->AddSignatureList( trgt, PRDFSIG_MaintRETRY_CTE );

    // Add the rank to the callout list.
    MemoryMru mm { trgt, i_rank, MemoryMruData::CALLOUT_RANK };
    io_sc.service_data->SetCallout( mm );

    do
    {
        bool doTps = true;

        if ( mfgMode() )
        {
            ExtensibleChip * membChip = getConnectedParent(i_chip, TYPE_MEMBUF);

            // Get the current RCE count from hardware.
            const char * reg_str = (0 == i_chip->getPos()) ? "MBA0_MBSEC1"
                                                           : "MBA1_MBSEC1";
            SCAN_COMM_REGISTER_CLASS * reg = membChip->getRegister( reg_str );
            o_rc = reg->Read();
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "Read() failed on %s", reg_str );
                break;
            }
            uint16_t count = reg->GetBitFieldJustified( 0, 12 );

            // Add the count to RCE table.
            doTps = getMbaDataBundle(i_chip)->iv_rceTable.addEntry( i_rank,
                                                                    io_sc,
                                                                    count );
        }
        else
        {
            // The RCE threshold was set to the maximum. If we hit this then
            // there is definitely a problem.
            io_sc.service_data->setServiceCall();
        }

        // Add a TPS procedure to the queue, if needed.
        if ( doTps )
        {
            TdEntry * e = new TpsEvent<TYPE_MBA>{ i_chip, i_rank };
            MemDbUtils::pushToQueue<TYPE_MBA>( i_chip, e );
        }

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

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

template <TARGETING::TYPE T>
uint32_t __checkEcc( ExtensibleChip * i_chip,
                     const MemAddr & i_addr, bool & o_errorsFound,
                     STEP_CODE_DATA_STRUCT & io_sc )
{
    #define PRDF_FUNC "[__checkEcc] "

    PRDF_ASSERT( nullptr != i_chip );
    PRDF_ASSERT( T == i_chip->getType() );

    uint32_t o_rc = SUCCESS;

    o_errorsFound = false;

    TargetHandle_t trgt = i_chip->getTrgt();
    HUID           huid = i_chip->getHuid();

    MemRank rank = i_addr.getRank();

    do
    {
        // Check for ECC errors.
        uint32_t eccAttns = 0;
        o_rc = checkEccFirs<T>( i_chip, eccAttns );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "checkEccFirs<T>(0x%08x) failed", huid );
            break;
        }

        if ( 0 != (eccAttns & MAINT_INT_NCE_ETE) )
        {
            o_errorsFound = true;
            io_sc.service_data->AddSignatureList( trgt, PRDFSIG_MaintINTER_CTE);

            o_rc = __handleSoftInterCeEte<T>( i_chip, i_addr, io_sc );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "__handleSoftInterCeEte<T>(0x%08x) failed",
                          huid );
                break;
            }
        }

        if ( 0 != (eccAttns & MAINT_SOFT_NCE_ETE) )
        {
            o_errorsFound = true;
            io_sc.service_data->AddSignatureList( trgt, PRDFSIG_MaintSOFT_CTE );

            o_rc = __handleSoftInterCeEte<T>( i_chip, i_addr, io_sc );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "__handleSoftInterCeEte<T>(0x%08x) failed",
                          huid );
                break;
            }
        }

        if ( 0 != (eccAttns & MAINT_HARD_NCE_ETE) )
        {
            o_errorsFound = true;
            io_sc.service_data->AddSignatureList( trgt, PRDFSIG_MaintHARD_CTE );

            o_rc = __handleNceEte<T>( i_chip, i_addr, io_sc, true );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "__handleNceEte<T>(0x%08x) failed",
                          huid );
                break;
            }

            // Any hard CEs in MNFG should be immediately reported.
            // NOTE: We will only use the MNFG thresholds if DRAM repairs is
            //       disabled. This is for a Nimbus DD2.0.1 workaround, but the
            //       change will be permanent for all P9 DD levels.
            if ( areDramRepairsDisabled() )
            {
                io_sc.service_data->setSignature( huid, PRDFSIG_MaintHARD_CTE );
                io_sc.service_data->setServiceCall();
            }
        }

        if ( 0 != (eccAttns & MAINT_MPE) )
        {
            o_errorsFound = true;
            io_sc.service_data->AddSignatureList( trgt, PRDFSIG_MaintMPE );

            o_rc = MemEcc::handleMpe<T>( i_chip, i_addr, UE_TABLE::SCRUB_MPE,
                                         io_sc );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "handleMpe<T>(0x%08x, 0x%02x) failed",
                          i_chip->getHuid(), rank.getKey() );
                break;
            }
        }

        if ( 0 != (eccAttns & MAINT_RCE_ETE) )
        {
            o_rc = __handleRceEte<T>( i_chip, rank, o_errorsFound,
                                      io_sc );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "__handleRceEte<T>(0x%08x) failed", huid );
                break;
            }
        }

        if ( 0 != (eccAttns & MAINT_UE) )
        {
            o_errorsFound = true;
            io_sc.service_data->AddSignatureList( trgt, PRDFSIG_MaintUE );

            // Since this will be a predictive callout, change the primary
            // signature as well.
            io_sc.service_data->setSignature( huid, PRDFSIG_MaintUE );

            // Add the rank to the callout list.
            o_rc = MemEcc::handleMemUe<T>( i_chip, i_addr, UE_TABLE::SCRUB_UE,
                                           io_sc );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "handleMemUe<T>(0x%08x) failed",
                          i_chip->getHuid() );
                break;
            }

            // Add a TPS request to the TD queue for additional analysis. It is
            // unlikely the procedure will result in a repair because of the UE.
            // However, we want to run TPS once just to see how bad the rank is.
            TdEntry * e = new TpsEvent<T>{ i_chip, rank };
            MemDbUtils::pushToQueue<T>( i_chip, e );

            // Because of the UE, any further TPS requests will likely have no
            // effect. So ban all subsequent requests.
            MemDbUtils::banTps<T>( i_chip, rank );
        }

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

template
uint32_t __checkEcc<TYPE_MCA>( ExtensibleChip * i_chip,
                               const MemAddr & i_addr, bool & o_errorsFound,
                               STEP_CODE_DATA_STRUCT & io_sc );
template
uint32_t __checkEcc<TYPE_MBA>( ExtensibleChip * i_chip,
                               const MemAddr & i_addr, bool & o_errorsFound,
                               STEP_CODE_DATA_STRUCT & io_sc );
template
uint32_t __checkEcc<TYPE_OCMB_CHIP>( ExtensibleChip * i_chip,
                                     const MemAddr & i_addr,
                                     bool & o_errorsFound,
                                     STEP_CODE_DATA_STRUCT & io_sc );

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

template<>
uint32_t MemTdCtlr<TYPE_MCBIST>::maskEccAttns()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MCBIST>::maskEccAttns] "

    uint32_t o_rc = SUCCESS;

    // Loop through all MCAs.
    for ( auto mcaChip : getConnected(iv_chip, TYPE_MCA) )
    {
        SCAN_COMM_REGISTER_CLASS * mask =
            mcaChip->getRegister( "MCAECCFIR_MASK_OR" );

        mask->clearAllBits();
        mask->SetBit(8); // Mainline read NCE
        mask->SetBit(9); // Mainline read TCE

        o_rc = mask->Write();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Write() failed on MCAECCFIR_MASK_OR" );
            break;
        }
    }

    return o_rc;

    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_MCBIST>::unmaskEccAttns()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MCBIST>::unmaskEccAttns] "

    uint32_t o_rc = SUCCESS;

    // Memory CEs were masked at the beginning of the TD procedure, so
    // clear and unmask them. Also, it is possible that memory UEs have
    // thresholded so clear and unmask them as well.

    // Loop through all MCAs.
    for ( auto mcaChip : getConnected(iv_chip, TYPE_MCA) )
    {
        SCAN_COMM_REGISTER_CLASS * fir =
            mcaChip->getRegister( "MCAECCFIR_AND" );
        SCAN_COMM_REGISTER_CLASS * mask =
            mcaChip->getRegister( "MCAECCFIR_MASK_AND" );

        fir->setAllBits(); mask->setAllBits();

        // Do not unmask NCE and TCE attentions if they have been permanently
        // masked due to certain TPS conditions.
        if ( !(getMcaDataBundle(mcaChip)->iv_maskMainlineNceTce) )
        {
            fir->ClearBit(8);  mask->ClearBit(8);  // Mainline read NCE
            fir->ClearBit(9);  mask->ClearBit(9);  // Mainline read TCE
        }
        fir->ClearBit(14); mask->ClearBit(14); // Mainline read UE

        o_rc = fir->Write();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Write() failed on MCAECCFIR_AND" );
            break;
        }

        o_rc = mask->Write();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Write() failed on MCAECCFIR_MASK_AND" );
            break;
        }
    }

    return o_rc;

    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_OCMB_CHIP>::maskEccAttns()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_OCMB_CHIP>::maskEccAttns] "

    uint32_t o_rc = SUCCESS;

    SCAN_COMM_REGISTER_CLASS * mask = iv_chip->getRegister( "RDFFIR_MASK_OR" );

    mask->clearAllBits();
    mask->SetBit(8); // Mainline read NCE
    mask->SetBit(9); // Mainline read TCE

    o_rc = mask->Write();
    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( PRDF_FUNC "Write() failed on RDFFIR_MASK_OR" );
    }

    return o_rc;

    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_OCMB_CHIP>::unmaskEccAttns()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_OCMB_CHIP>::unmaskEccAttns] "

    uint32_t o_rc = SUCCESS;

    // Memory CEs were masked at the beginning of the TD procedure, so
    // clear and unmask them. Also, it is possible that memory UEs have
    // thresholded so clear and unmask them as well.

    SCAN_COMM_REGISTER_CLASS * fir  = iv_chip->getRegister( "RDFFIR_AND" );
    SCAN_COMM_REGISTER_CLASS * mask = iv_chip->getRegister( "RDFFIR_MASK_AND" );

    fir->setAllBits(); mask->setAllBits();

    // Do not unmask NCE and TCE attentions if they have been permanently
    // masked due to certain TPS conditions.
    if ( !(getOcmbDataBundle(iv_chip)->iv_maskMainlineNceTce) )
    {
        fir->ClearBit(8);  mask->ClearBit(8);  // Mainline read NCE
        fir->ClearBit(9);  mask->ClearBit(9);  // Mainline read TCE
    }
    fir->ClearBit(14); mask->ClearBit(14); // Mainline read UE

    o_rc = fir->Write();
    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( PRDF_FUNC "Write() failed on RDFFIR_AND" );
    }

    o_rc = mask->Write();
    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( PRDF_FUNC "Write() failed on RDFFIR_MASK_AND" );
    }

    return o_rc;

    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_MBA>::maskEccAttns()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MBA>::maskEccAttns] "

    uint32_t o_rc = SUCCESS;

    do
    {
        // Don't want to handle memory CEs during any TD procedures, so
        // mask them.

        const char * reg_str = (0 == iv_chip->getPos())
            ? "MBSECCFIR_0_MASK_OR" : "MBSECCFIR_1_MASK_OR";

        ExtensibleChip * membChip = getConnectedParent( iv_chip, TYPE_MEMBUF );

        SCAN_COMM_REGISTER_CLASS * reg = membChip->getRegister(reg_str);

        reg->clearAllBits();
        reg->SetBit(16); // fetch NCE
        reg->SetBit(17); // fetch RCE
        reg->SetBit(43); // prefetch UE

        o_rc = reg->Write();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Write() failed on %s", reg_str );
            break;
        }

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_MBA>::unmaskEccAttns()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MBA>::unmaskEccAttns] "

    uint32_t o_rc = SUCCESS;

    do
    {
        // Memory CEs where masked at the beginning of the TD procedure, so
        // clear and unmask them. Also, it is possible that memory UEs have
        // thresholded so clear and unmask them as well.

        const char * fir_str = (0 == iv_chip->getPos())
            ? "MBSECCFIR_0_AND" : "MBSECCFIR_1_AND";
        const char * msk_str = (0 == iv_chip->getPos())
            ? "MBSECCFIR_0_MASK_AND" : "MBSECCFIR_1_MASK_AND";

        ExtensibleChip * membChip = getConnectedParent( iv_chip, TYPE_MEMBUF );

        SCAN_COMM_REGISTER_CLASS * fir = membChip->getRegister( fir_str );
        SCAN_COMM_REGISTER_CLASS * msk = membChip->getRegister( msk_str );

        fir->setAllBits(); msk->setAllBits();
        fir->ClearBit(16); msk->ClearBit(16); // fetch NCE
        fir->ClearBit(17); msk->ClearBit(17); // fetch RCE
        fir->ClearBit(19); msk->ClearBit(19); // fetch UE
        fir->ClearBit(43); msk->ClearBit(43); // prefetch UE

        o_rc = fir->Write();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Write() failed on %s", fir_str );
            break;
        }

        o_rc = msk->Write();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Write() failed on %s", msk_str );
            break;
        }

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

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

template<TARGETING::TYPE T>
SCAN_COMM_REGISTER_CLASS * __getEccFirAnd( ExtensibleChip * i_chip );

template<>
SCAN_COMM_REGISTER_CLASS * __getEccFirAnd<TYPE_MCA>( ExtensibleChip * i_chip )
{
    return i_chip->getRegister( "MCAECCFIR_AND" );
}

template<>
SCAN_COMM_REGISTER_CLASS * __getEccFirAnd<TYPE_OCMB_CHIP>(
                                                ExtensibleChip * i_chip )
{
    return i_chip->getRegister( "RDFFIR_AND" );
}

template<>
SCAN_COMM_REGISTER_CLASS * __getEccFirAnd<TYPE_MBA>( ExtensibleChip * i_chip )
{
    ExtensibleChip * membChip = getConnectedParent( i_chip, TYPE_MEMBUF );
    return membChip->getRegister( (0 == i_chip->getPos()) ? "MBSECCFIR_0_AND"
                                                          : "MBSECCFIR_1_AND" );
}

template <TARGETING::TYPE TP, TARGETING::TYPE TC>
uint32_t __findChipMarks( TdRankList<TC> & i_rankList )
{
    #define PRDF_FUNC "[__findChipMarks] "

    uint32_t o_rc = SUCCESS;

    for ( auto & entry : i_rankList.getList() )
    {
        ExtensibleChip * chip = entry.getChip();
        MemRank          rank = entry.getRank();

        // Call readChipMark to get MemMark.
        MemMark chipMark;
        o_rc = MarkStore::readChipMark<TP>( chip, rank, chipMark );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "readChipMark(0x%08x,0x%02x) failed",
                      chip->getHuid(), rank.getKey() );
            break;
        }

        if ( !chipMark.isValid() ) continue; // no chip mark present

        // Get the DQ Bitmap data.
        MemDqBitmap dqBitmap;
        o_rc = getBadDqBitmap( chip->getTrgt(), rank, dqBitmap );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "getBadDqBitmap(0x%08x,0x%02x)",
                      chip->getHuid(), rank.getKey() );
            break;
        }

        // Check if the chip mark is verified or not.
        bool cmVerified = false;
        o_rc = dqBitmap.isChipMark( chipMark.getSymbol(), cmVerified );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "dqBitmap.isChipMark() failed on 0x%08x "
                      "0x%02x", chip->getHuid(), rank.getKey() );
            break;
        }

        // If the chip mark is unverified, add a VcmEvent to the TD queue.
        if ( !cmVerified )
        {
            // Chip mark is not present in VPD. Add it to queue.
            TdEntry * e = new VcmEvent<TP>{ chip, rank, chipMark };
            MemDbUtils::pushToQueue<TP>( chip, e );

            // We will want to clear the MPE attention for the unverified chip
            // mark so we don't get any redundant attentions for chip marks that
            // are already in the queue. This is reset/reload safe because
            // initialize() will be called again and we can redetect the
            // unverified chip marks.
            SCAN_COMM_REGISTER_CLASS * reg = __getEccFirAnd<TP>( chip );
            reg->setAllBits();
            reg->ClearBit(  0 + rank.getMaster() ); // fetch
            reg->ClearBit( 20 + rank.getMaster() ); // scrub
            o_rc = reg->Write();
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "Write() failed on ECC FIR AND: 0x%08x",
                          chip->getHuid() );
                break;
            }
        }
    }

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t MemTdCtlr<TYPE_MCBIST>::initialize()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MCBIST>::initialize] "

    uint32_t o_rc = SUCCESS;

    do
    {
        if ( iv_initialized ) break; // nothing to do

        // Unmask the fetch attentions just in case there were masked during a
        // TD procedure prior to a reset/reload.
        o_rc = unmaskEccAttns();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "unmaskEccAttns() failed" );
            break;
        }

        // Find all unverified chip marks.
        o_rc = __findChipMarks<TYPE_MCA>( iv_rankList );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "__findChipMarks() failed on 0x%08x",
                      iv_chip->getHuid() );
            break;
        }

        // At this point, the TD controller is initialized.
        iv_initialized = true;

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t MemTdCtlr<TYPE_OCMB_CHIP>::initialize()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_OCMB_CHIP>::initialize] "

    uint32_t o_rc = SUCCESS;

    do
    {
        if ( iv_initialized ) break; // nothing to do

        // Unmask the fetch attentions just in case there were masked during a
        // TD procedure prior to a reset/reload.
        o_rc = unmaskEccAttns();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "unmaskEccAttns() failed" );
            break;
        }

        // Find all unverified chip marks.
        o_rc = __findChipMarks<TYPE_OCMB_CHIP>( iv_rankList );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "__findChipMarks() failed on 0x%08x",
                      iv_chip->getHuid() );
            break;
        }

        // At this point, the TD controller is initialized.
        iv_initialized = true;

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t MemTdCtlr<TYPE_MBA>::initialize()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MBA>::initialize] "

    uint32_t o_rc = SUCCESS;

    do
    {
        if ( iv_initialized ) break; // nothing to do

        // Unmask the fetch attentions just in case there were masked during a
        // TD procedure prior to a reset/reload.
        o_rc = unmaskEccAttns();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "unmaskEccAttns() failed" );
            break;
        }

        // Find all unverified chip marks.
        o_rc = __findChipMarks<TYPE_MBA>( iv_rankList );
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "__findChipMarks() failed on 0x%08x",
                      iv_chip->getHuid() );
            break;
        }

        // At this point, the TD controller is initialized.
        iv_initialized = true;

    } while (0);

    return o_rc;

    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_MCBIST>::handleRrFo()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MCBIST>::handleRrFo] "

    uint32_t o_rc = SUCCESS;

    do
    {
        // Check if maintenance command complete attention is set.
        SCAN_COMM_REGISTER_CLASS * mcbistfir =
                                iv_chip->getRegister("MCBISTFIR");
        o_rc = mcbistfir->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MCBISTFIR");
            break;
        }

        // If there is a command complete attention, nothing to do, break out.
        if ( mcbistfir->IsBitSet(10) ||  mcbistfir->IsBitSet(12) )
            break;


        // Check if a command is not running.
        // If bit 0 of MCB_CNTLSTAT is on, a mcbist run is in progress.
        SCAN_COMM_REGISTER_CLASS * mcb_cntlstat =
            iv_chip->getRegister("MCB_CNTLSTAT");
        o_rc = mcb_cntlstat->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MCB_CNTLSTAT" );
            break;
        }

        // If a command is not running, set command complete attn, break.
        if ( !mcb_cntlstat->IsBitSet(0) )
        {
            SCAN_COMM_REGISTER_CLASS * mcbistfir_or =
                iv_chip->getRegister("MCBISTFIR_OR");
            mcbistfir_or->SetBit( 10 );

            mcbistfir_or->Write();
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "Write() failed on MCBISTFIR_OR" );
            }
            break;
        }

        // Check if there are unverified chip marks.
        std::vector<TdRankListEntry> vectorList = iv_rankList.getList();

        for ( auto & entry : vectorList )
        {
            ExtensibleChip * mcaChip = entry.getChip();
            MemRank rank = entry.getRank();

            // Get the chip mark
            MemMark chipMark;
            o_rc = MarkStore::readChipMark<TYPE_MCA>( mcaChip, rank, chipMark );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "readChipMark<TYPE_MCA>(0x%08x,%d) "
                        "failed", mcaChip->getHuid(), rank.getMaster() );
                break;
            }

            if ( !chipMark.isValid() ) continue; // no chip mark present

            // Get the DQ Bitmap data.
            TargetHandle_t mcaTrgt = mcaChip->GetChipHandle();
            MemDqBitmap dqBitmap;

            o_rc = getBadDqBitmap( mcaTrgt, rank, dqBitmap );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "getBadDqBitmap(0x%08x, %d)",
                          getHuid(mcaTrgt), rank.getMaster() );
                break;
            }

            // Check if the chip mark is verified or not.
            bool cmVerified = false;
            o_rc = dqBitmap.isChipMark( chipMark.getSymbol(), cmVerified );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "dqBitmap.isChipMark failed." );
                break;
            }

            // If there are any unverified chip marks, stop the command, break.
            if ( !cmVerified )
            {
                o_rc = stopBgScrub<TYPE_MCBIST>( iv_chip );
                if ( SUCCESS != o_rc )
                {
                    PRDF_ERR( PRDF_FUNC "stopBgScrub<TYPE_MCBIST>(0x%08x) "
                              "failed", iv_chip->getHuid() );
                }
                break;
            }
        }

    } while (0);

    return o_rc;
    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_OCMB_CHIP>::handleRrFo()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_OCMB_CHIP>::handleRrFo] "

    uint32_t o_rc = SUCCESS;

    do
    {
        // Check if maintenance command complete attention is set.
        SCAN_COMM_REGISTER_CLASS * mcbistfir =
                                iv_chip->getRegister("MCBISTFIR");
        o_rc = mcbistfir->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MCBISTFIR");
            break;
        }

        // If there is a command complete attention, nothing to do, break out.
        if ( mcbistfir->IsBitSet(10) )
            break;


        // Check if a command is not running.
        // If bit 0 of MCB_CNTLSTAT is on, a mcbist run is in progress.
        SCAN_COMM_REGISTER_CLASS * mcb_cntlstat =
            iv_chip->getRegister("MCB_CNTLSTAT");
        o_rc = mcb_cntlstat->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MCB_CNTLSTAT" );
            break;
        }

        // If a command is not running, set command complete attn, break.
        if ( !mcb_cntlstat->IsBitSet(0) )
        {
            SCAN_COMM_REGISTER_CLASS * mcbistfir_or =
                iv_chip->getRegister("MCBISTFIR_OR");
            mcbistfir_or->SetBit( 10 );

            mcbistfir_or->Write();
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "Write() failed on MCBISTFIR_OR" );
            }
            break;
        }

        // Check if there are unverified chip marks.
        std::vector<TdRankListEntry> vectorList = iv_rankList.getList();

        for ( auto & entry : vectorList )
        {
            ExtensibleChip * ocmbChip = entry.getChip();
            MemRank rank = entry.getRank();

            // Get the chip mark
            MemMark chipMark;
            o_rc = MarkStore::readChipMark<TYPE_OCMB_CHIP>( ocmbChip, rank,
                                                            chipMark );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "readChipMark<TYPE_OCMB_CHIP>(0x%08x,%d) "
                          "failed", ocmbChip->getHuid(), rank.getMaster() );
                break;
            }

            if ( !chipMark.isValid() ) continue; // no chip mark present

            // Get the DQ Bitmap data.
            MemDqBitmap dqBitmap;

            o_rc = getBadDqBitmap( ocmbChip->getTrgt(), rank, dqBitmap );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "getBadDqBitmap(0x%08x, %d)",
                          ocmbChip->getHuid(), rank.getMaster() );
                break;
            }

            // Check if the chip mark is verified or not.
            bool cmVerified = false;
            o_rc = dqBitmap.isChipMark( chipMark.getSymbol(), cmVerified );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "dqBitmap.isChipMark failed." );
                break;
            }

            // If there are any unverified chip marks, stop the command, break.
            if ( !cmVerified )
            {
                o_rc = stopBgScrub<TYPE_OCMB_CHIP>( iv_chip );
                if ( SUCCESS != o_rc )
                {
                    PRDF_ERR( PRDF_FUNC "stopBgScrub<TYPE_OCMB_CHIP>(0x%08x) "
                              "failed", iv_chip->getHuid() );
                }
                break;
            }
        }

    } while (0);

    return o_rc;
    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_MBA>::handleRrFo()
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MBA>::handleRrFo] "

     uint32_t o_rc = SUCCESS;

    do
    {
        // Check if maintenance command complete attention is set.
        SCAN_COMM_REGISTER_CLASS * mbaspa =
                                iv_chip->getRegister("MBASPA");
        o_rc = mbaspa->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MBASPA");
            break;
        }

        // If there is a command complete attention, nothing to do, break out.
        if ( mbaspa->IsBitSet(0) ||  mbaspa->IsBitSet(8) )
            break;

        // Check if a maintenance command is running currently.
        SCAN_COMM_REGISTER_CLASS * mbmsr =
                                iv_chip->getRegister("MBMSR");

        o_rc = mbmsr->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MBMSR");
            break;
        }

        // If a command is not running, set command complete attn, break.
        if ( !mbmsr->IsBitSet(0) )
        {
            SCAN_COMM_REGISTER_CLASS * mbaspa_or =
                iv_chip->getRegister("MBASPA_OR");
            mbaspa_or->SetBit( 0 );

            mbaspa_or->Write();
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "Write() failed on MBASPA_OR" );
            }
            break;
        }

        // Check if there are unverified chip marks.
        std::vector<TdRankListEntry> vectorList = iv_rankList.getList();

        for ( auto & entry : vectorList )
        {
            ExtensibleChip * mbaChip = entry.getChip();
            MemRank rank = entry.getRank();

            // Get the chip mark
            MemMark chipMark;
            o_rc = MarkStore::readChipMark<TYPE_MBA>( mbaChip, rank, chipMark );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "readChipMark<TYPE_MBA>(0x%08x,%d) "
                        "failed", mbaChip->getHuid(), rank.getMaster() );
                break;
            }

            if ( !chipMark.isValid() ) continue; // no chip mark present

            // Get the DQ Bitmap data.
            TargetHandle_t mbaTrgt = mbaChip->GetChipHandle();
            MemDqBitmap dqBitmap;

            o_rc = getBadDqBitmap( mbaTrgt, rank, dqBitmap );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "getBadDqBitmap(0x%08x, %d)",
                          getHuid(mbaTrgt), rank.getMaster() );
                break;
            }

            // Check if the chip mark is verified or not.
            bool cmVerified = false;
            o_rc = dqBitmap.isChipMark( chipMark.getSymbol(), cmVerified );
            if ( SUCCESS != o_rc )
            {
                PRDF_ERR( PRDF_FUNC "dqBitmap.isChipMark failed." );
                break;
            }

            // If there are any unverified chip marks, stop the command, break.
            if ( !cmVerified )
            {
                o_rc = stopBgScrub<TYPE_MBA>( iv_chip );
                if ( SUCCESS != o_rc )
                {
                    PRDF_ERR( PRDF_FUNC "stopBgScrub<TYPE_MBA>(0x%08x) failed",
                            iv_chip->getHuid() );
                }

                // The HWP that stops the command apparently clears the command
                // complete attention, which we were not expecting. Therefore,
                // we must manually set the attention.
                SCAN_COMM_REGISTER_CLASS * mbaspa_or =
                                            iv_chip->getRegister("MBASPA_OR");
                mbaspa_or->SetBit( 0 );

                mbaspa_or->Write();
                if ( SUCCESS != o_rc )
                {
                    PRDF_ERR( PRDF_FUNC "Write() failed on MBASPA_OR" );
                }

                // There is now a command complete attention for this MBA. So
                // break out of the for-loop.
                break;
            }
        }

    } while (0);

    return o_rc;
    #undef PRDF_FUNC
}

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

template<>
uint32_t MemTdCtlr<TYPE_MCBIST>::canResumeBgScrub( bool & o_canResume )
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MCBIST>::canResumeBgScrub] "

    uint32_t o_rc = SUCCESS;

    o_canResume = false;

    // It is possible that we were running a TD procedure and the PRD service
    // was reset. Therefore, we must check if background scrubbing was actually
    // configured. There really is not a good way of doing this. A scrub command
    // is a scrub command the only difference is the speed. Unfortunately, that
    // speed can change depending on how the hardware team tunes it. For now, we
    // can use the stop conditions, which should be unique for background scrub,
    // to determine if it has been configured.

    do
    {
        SCAN_COMM_REGISTER_CLASS * reg = iv_chip->getRegister( "MBSTR" );
        o_rc = reg->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MBSTR: iv_chip=0x%08x",
                    iv_chip->getHuid() );
            break;
        }
        // Note: The stop conditions for background scrubbing can now be
        // variable depending on whether we have hit threshold for the number
        // of UEs or CEs that we have stopped on on a rank.

        // If we haven't hit CE or UE threshold, check the CE stop conditions
        if ( !getMcbistDataBundle(iv_chip)->iv_ceScrubStopCounter.atTh() &&
             !getMcbistDataBundle(iv_chip)->iv_ueScrubStopCounter.atTh() )
        {
            // If the stop conditions aren't set, just break out.
            if ( !(0xf != reg->GetBitFieldJustified(0,4) && // NCE int TH
                   0xf != reg->GetBitFieldJustified(4,4) && // NCE soft TH
                   0xf != reg->GetBitFieldJustified(8,4)) ) // NCE hard TH
            {
                break;
            }

        }

        // If we haven't hit UE threshold yet, check the UE stop condition
        if ( !getMcbistDataBundle(iv_chip)->iv_ueScrubStopCounter.atTh() )
        {
            // If the stop condition isn't set, just break out
            if ( !reg->IsBitSet(35) ) // pause on UE
            {
                break;
            }
        }

        // Need to check the stop on mpe stop condition regardless of whether
        // we hit the UE or CE threshold.
        if ( reg->IsBitSet(34) ) // pause on MPE
        {
            // If we reach here, all the stop conditions are set for background
            // scrub, so we can resume.
            o_canResume = true;
        }
    }while(0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t MemTdCtlr<TYPE_OCMB_CHIP>::canResumeBgScrub( bool & o_canResume )
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_OCMB_CHIP>::canResumeBgScrub] "

    uint32_t o_rc = SUCCESS;

    o_canResume = false;

    // It is possible that we were running a TD procedure and the PRD service
    // was reset. Therefore, we must check if background scrubbing was actually
    // configured. There really is not a good way of doing this. A scrub command
    // is a scrub command the only difference is the speed. Unfortunately, that
    // speed can change depending on how the hardware team tunes it. For now, we
    // can use the stop conditions, which should be unique for background scrub,
    // to determine if it has been configured.

    do
    {
        SCAN_COMM_REGISTER_CLASS * reg = iv_chip->getRegister( "MBSTR" );
        o_rc = reg->Read();
        if ( SUCCESS != o_rc )
        {
            PRDF_ERR( PRDF_FUNC "Read() failed on MBSTR: iv_chip=0x%08x",
                    iv_chip->getHuid() );
            break;
        }
        // Note: The stop conditions for background scrubbing can now be
        // variable depending on whether we have hit threshold for the number
        // of UEs or CEs that we have stopped on on a rank.

        // If we haven't hit CE or UE threshold, check the CE stop conditions
        if ( !getOcmbDataBundle(iv_chip)->iv_ceScrubStopCounter.atTh() &&
             !getOcmbDataBundle(iv_chip)->iv_ueScrubStopCounter.atTh() )
        {
            // If the stop conditions aren't set, just break out.
            if ( !(0xf != reg->GetBitFieldJustified(0,4) && // NCE int TH
                   0xf != reg->GetBitFieldJustified(4,4) && // NCE soft TH
                   0xf != reg->GetBitFieldJustified(8,4)) ) // NCE hard TH
            {
                break;
            }

        }

        // If we haven't hit UE threshold yet, check the UE stop condition
        if ( !getOcmbDataBundle(iv_chip)->iv_ueScrubStopCounter.atTh() )
        {
            // If the stop condition isn't set, just break out
            if ( !reg->IsBitSet(35) ) // pause on UE
            {
                break;
            }
        }

        // Need to check the stop on mpe stop condition regardless of whether
        // we hit the UE or CE threshold.
        if ( reg->IsBitSet(34) ) // pause on MPE
        {
            // If we reach here, all the stop conditions are set for background
            // scrub, so we can resume.
            o_canResume = true;
        }
    }while(0);

    return o_rc;

    #undef PRDF_FUNC
}

template<>
uint32_t MemTdCtlr<TYPE_MBA>::canResumeBgScrub( bool & o_canResume )
{
    #define PRDF_FUNC "[MemTdCtlr<TYPE_MBA>::canResumeBgScrub] "

    uint32_t o_rc = SUCCESS;

    o_canResume = false;

    // It is possible that we were running a TD procedure and the PRD service
    // was reset. Assuming the command did not stop on the last address of the
    // current slave rank, we will simply "resume" the command from the next
    // address to the end of the rank. The MBA resume actually starts a new
    // command, unlike MCBIST. Therefore, we can get away with blindly starting
    // the command without trying to assess what type of command was actually
    // running.

    bool lastAddr = false;
    o_rc = didCmdStopOnLastAddr<TYPE_MBA>( iv_chip, SLAVE_RANK, lastAddr );
    if ( SUCCESS != o_rc )
    {
        PRDF_ERR( PRDF_FUNC "didCmdStopOnLastAddr(0x%08x) failed",
                  iv_chip->getHuid() );
    }
    else
    {
        o_canResume = !lastAddr;
    }

    return o_rc;

    #undef PRDF_FUNC
}

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

// Avoid linker errors with the template.
template class MemTdCtlr<TYPE_MCBIST>;
template class MemTdCtlr<TYPE_MBA>;
template class MemTdCtlr<TYPE_OCMB_CHIP>;

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

} // end namespace PRDF


OpenPOWER on IntegriCloud