summaryrefslogtreecommitdiffstats
path: root/src/usr/errl/errlentry.C
blob: 370df7091dedd4998948e9c8a76a1316ad55aa68 (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
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/errl/errlentry.C $                                    */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2019                        */
/* [+] Google Inc.                                                        */
/* [+] 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 errlentry.C
 *
 *  @brief Implementation of ErrlEntry class
 */

/*****************************************************************************/
// I n c l u d e s
/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <algorithm>
#include <hbotcompid.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <errl/errludbacktrace.H>
#include <errl/errludcallout.H>
#include <errl/errlreasoncodes.H>
#include <errl/errludstring.H>
#include <errl/errluserdetails.H>
#include <errl/errludattribute.H>
#include <errl/errludstate.H>
#include <errl/errli2c.H>
#include <trace/interface.H>
#include <config.h>

#include "../trace/entry.H"
#include <util/align.H>

#include <arch/ppc.H>
#include <hwas/common/hwasCallout.H>
#include <hwas/common/deconfigGard.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/utilFilter.H>
#include <targeting/common/commontargeting.H>
#include <config.h>
#include <initservice/initserviceif.H>
#include <attributeenums.H>
#include "errlentry_consts.H"
#include <util/misc.H>

#ifdef CONFIG_BMC_IPMI
#include <ipmi/ipmisensor.H>
#include <errl/errludsensor.H>
#endif

#include <util/utillidmgr.H>

// Hostboot Image ID string
extern char hbi_ImageId;

using namespace ERRORLOG;
using namespace HWAS;

namespace ERRORLOG
{

// Trace definition
trace_desc_t* g_trac_errl = NULL;
TRAC_INIT(&g_trac_errl, "ERRL", KILOBYTE, TRACE::BUFFER_SLOW);

// std::map to trace severity in trace
// NOTE: must be kept in sync with enum definition in hberrltypes.H
std::map<uint8_t, const char *> errl_sev_str_map {
    {ERRL_SEV_INFORMATIONAL,     "INFORMATIONAL"},
    {ERRL_SEV_RECOVERED,         "RECOVERED"},
    {ERRL_SEV_PREDICTIVE,        "PREDICTIVE"},
    {ERRL_SEV_UNRECOVERABLE,     "UNRECOVERABLE"},
    {ERRL_SEV_CRITICAL_SYS_TERM, "CRITICAL_SYS_TERM"},
    {ERRL_SEV_UNKNOWN,           "UNKNOWN"},
};

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
ErrlEntry::ErrlEntry(const errlSeverity_t i_sev,
                     const uint8_t i_modId,
                     const uint16_t i_reasonCode,
                     const uint64_t i_user1,
                     const uint64_t i_user2,
                     const bool i_hbSwError,
                     const bool i_hbDump ) :
    iv_Private( static_cast<compId_t>(i_reasonCode & 0xFF00)),
    iv_User( i_sev ),
    // The SRC_ERR_INFO becomes part of the SRC; example, B1 in SRC B180xxxx
    // iv_Src assigns the epubSubSystem_t; example, 80 in SRC B180xxxx
    iv_Src( SRC_ERR_INFO, i_modId, i_reasonCode, i_user1, i_user2 ),
    iv_termState(TERM_STATE_UNKNOWN),
    iv_sevFinal(false),
    iv_skipShowingLog(true),
    iv_eselCallhomeInfoEvent(false),
    iv_doHbDump(i_hbDump)
{
    #ifdef CONFIG_ERRL_ENTRY_TRACE
    TRACFCOMP( g_trac_errl, ERR_MRK"Error created : PLID=%.8X, RC=%.4X, Mod=%.2X, Userdata=%.16llX %.16llX, Sev=%s", plid(), i_reasonCode, i_modId, i_user1, i_user2, errl_sev_str_map.at(i_sev) );
    #else
    TRACDCOMP( g_trac_errl, ERR_MRK"Error created : PLID=%.8X, RC=%.4X, Mod=%.2X, Userdata=%.16llX %.16llX, Sev=%s", plid(), i_reasonCode, i_modId, i_user1, i_user2, errl_sev_str_map.at(i_sev) );
    #endif
    // Collect the Backtrace and add it to the error log
    iv_pBackTrace = new ErrlUserDetailsBackTrace();

#ifndef __HOSTBOOT_RUNTIME
    // Add the istep data to the vector of sections for this error log
    ErrlUserDetailsSysState l_UserDetailsSysState;

    l_UserDetailsSysState.addToLog( this );
#endif

    // Automatically add a software callout if asked
    if( i_hbSwError )
    {
        addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                             HWAS::SRCI_PRIORITY_HIGH );
    }
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
ErrlEntry::~ErrlEntry()
{
    // Free memory of all sections
    for (std::vector<ErrlUD*>::const_iterator l_itr = iv_SectionVector.begin();
         l_itr != iv_SectionVector.end(); ++l_itr)
    {
        delete (*l_itr);
    }

    delete iv_pBackTrace;
    iv_pBackTrace = NULL;
}

///////////////////////////////////////////////////////////////////////////////
// add a new UD section to the list of optional sections

ErrlUD * ErrlEntry::addFFDC(const compId_t i_compId,
             const void * i_dataPtr,
             const uint32_t i_ffdcLen,
             const uint8_t i_ffdcVer,
             const uint8_t i_ffdcSubSect,
             bool i_merge)
{
    ErrlUD * l_ffdcSection = NULL;

    if ( (i_dataPtr != NULL) && (i_ffdcLen != 0) )
    {
        TRACDCOMP( g_trac_errl, INFO_MRK"addFFDC(): %x %d %d - %s merge",
                      i_compId, i_ffdcVer,
                      i_ffdcSubSect, i_merge == true ? "DO" : "NO" );

        // if we're to try to merge, AND there's at least 1 section
        if ((i_merge) && (iv_SectionVector.size() > 0))
        {   // look at the last one to see if it's a match or not.
            // this is done to preserve the order of the errlog - we
            // only merge like sections if they are being put in at the
            // 'same time'.
            ErrlUD *pErrlUD = iv_SectionVector.back();

            if ((i_compId       == pErrlUD->iv_header.iv_compId) &&
                (i_ffdcVer      == pErrlUD->iv_header.iv_ver) &&
                (i_ffdcSubSect  == pErrlUD->iv_header.iv_sst))
            {
                TRACDCOMP( g_trac_errl, INFO_MRK"appending to matched %p",
                            pErrlUD);
                appendToFFDC(pErrlUD, i_dataPtr, i_ffdcLen);
                l_ffdcSection = pErrlUD;
            }
        } // i_merge && >0 section

        // i_merge == false, or it was true but we didn't find a match
        if (l_ffdcSection == NULL)
        {
            // Create a user-defined section.
            l_ffdcSection = new ErrlUD(  i_dataPtr,
                                         i_ffdcLen,
                                         i_compId,
                                         i_ffdcVer,
                                         i_ffdcSubSect );

            // Add to the vector of sections for this error log.
            iv_SectionVector.push_back( l_ffdcSection );
        }
    }
    else
    {
        TRACFCOMP( g_trac_errl,
        ERR_MRK"addFFDC(): Invalid FFDC data pointer or size, no add");
    }

    return l_ffdcSection;
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void ErrlEntry::appendToFFDC(ErrlUD * i_pErrlUD,
                  const void *i_dataPtr,
                  const uint32_t i_dataLen)
{
    uint64_t l_rc;
    TRACDCOMP( g_trac_errl, ENTER_MRK"appendToFFDC(%p, %p, %d)",
                i_pErrlUD, i_dataPtr, i_dataLen);

    l_rc = i_pErrlUD->addData( i_dataPtr, i_dataLen );
    if( 0 == l_rc )
    {
        TRACFCOMP( g_trac_errl, ERR_MRK"ErrlEntry::appendToFFDC() rets zero" );
    }
    return;
}

///////////////////////////////////////////////////////////////////////////////
// Return a Boolean indication of success.

bool ErrlEntry::collectTrace(const char i_name[], const uint64_t i_max)
{
    bool l_rc = false;  // assume a problem.
    char * l_pBuffer = NULL;
    uint64_t l_cbOutput = 0;
    uint64_t l_cbBuffer = 0;

    do
    {
        // By passing nil arguments 2 and 3, obtain the size of the buffer.
        // Besides getting buffer size, it validates i_name.
        uint64_t l_cbFull = TRACE::getBuffer( i_name, NULL,0 );
        if( 0 == l_cbFull )
        {
            // Problem, likely unknown trace buffer name.
            TRACFCOMP( g_trac_errl,
                ERR_MRK"ErrlEntry::collectTrace(): getBuffer(%s) rets zero.",i_name);
            break;
        }

        if(( 0 == i_max ) || ( i_max >= l_cbFull ))
        {
            // Full trace buffer desired
            l_cbBuffer = l_cbFull;
        }
        else
        {
            // Partial buffer desired
            l_cbBuffer = i_max;
        }

        // allocate the buffer
        l_pBuffer = new char[ l_cbBuffer ];

        // Get the data into the buffer.
        l_cbOutput = TRACE::getBuffer( i_name, l_pBuffer, l_cbBuffer );

        if( 0 == l_cbOutput )
        {
            // Problem.
            TRACFCOMP( g_trac_errl,
                ERR_MRK"ErrlEntry::collectTrace(): getBuffer(%s,%ld) rets zero.",
                i_name,
                l_cbBuffer );
            break;
        }

        // Save the trace buffer as a UD section on this.
        ErrlUD * l_udSection = new ErrlUD( l_pBuffer,
                                           l_cbOutput,
                                           FIPS_ERRL_COMP_ID,
                                           FIPS_ERRL_UDV_DEFAULT_VER_1,
                                           FIPS_ERRL_UDT_HB_TRACE );

        // Add the trace section to the vector of sections
        // for this error log.
        iv_SectionVector.push_back( l_udSection );

        l_rc = true;
    }
    while(0);

    delete[] l_pBuffer;

    return l_rc;
}

/////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void ErrlEntry::removeBackTrace()
{
    delete iv_pBackTrace;
    iv_pBackTrace = NULL;
}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/*
 * @brief  Safely retrieves the EntityPath for the target or the SENTINEL
 *         pointer if appropriate
 * @param[in]  i_target  Target to evaluate
 * @param[out]  o_ePath  Pointer to new EntityPath if applicable, if this
 *     comes back non-NULL, caller must delete the memory
 * @param[out]  o_dataPtr  Pointer to target data
 * @param[out]  o_dataSize  Size of target data
 */
void getTargData( const TARGETING::Target *i_target,
                  TARGETING::EntityPath*& o_ePath,
                  const void*& o_dataPtr,
                  uint32_t& o_dataSize )
{
    o_ePath = nullptr;
    o_dataPtr = nullptr;
    o_dataSize = 0;
    if (i_target == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
    {
        o_dataSize = sizeof(HWAS::TARGET_IS_SENTINEL);
        o_dataPtr = &HWAS::TARGET_IS_SENTINEL;
    }
    else
    {   // we got a non MASTER_SENTINEL target, therefore the targeting
        // module is loaded, therefore we can make this call.
        o_ePath = new TARGETING::EntityPath;
        *o_ePath = i_target->getAttr<TARGETING::ATTR_PHYS_PATH>();
        // size is total EntityPath size minus unused path elements
        o_dataSize = sizeof(*o_ePath) -
          (TARGETING::EntityPath::MAX_PATH_ELEMENTS - o_ePath->size()) *
          sizeof(TARGETING::EntityPath::PathElement);
        o_dataPtr = o_ePath;
    }
}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void ErrlEntry::addClockCallout(const TARGETING::Target *i_target,
                        const HWAS::clockTypeEnum i_clockType,
                        const HWAS::callOutPriority i_priority,
                        const HWAS::DeconfigEnum i_deconfigState,
                        const HWAS::GARD_ErrorType i_gardErrorType)
{
    TRACFCOMP(g_trac_errl, ENTER_MRK"addClockCallout(%p, %d, 0x%x)",
                i_target, i_clockType, i_priority);

    const void* pData = nullptr;
    uint32_t size = 0;
    TARGETING::EntityPath* ep = nullptr;
    getTargData( i_target, ep, pData, size );

    ErrlUserDetailsCallout( pData, size, i_clockType,
            i_priority, i_deconfigState, i_gardErrorType).addToLog(this);

    if (i_gardErrorType != GARD_NULL)
    {
        setGardBit();
    }
    if (i_deconfigState != NO_DECONFIG)
    {
        setDeconfigBit();
    }

    if( ep )
    {
        delete ep;
    }
} // addClockCallout


void ErrlEntry::addSensorCallout(const uint32_t i_sensorID,
                            const HWAS::sensorTypeEnum i_sensorType,
                            const HWAS::callOutPriority i_priority)
{
    TRACFCOMP(g_trac_errl, ENTER_MRK"addSensorCallout(0x%X, %d, 0x%x)",
                i_sensorID, i_sensorType, i_priority);

    ErrlUserDetailsCallout(i_sensorID, i_sensorType, i_priority).addToLog(this);
}

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void ErrlEntry::addPartCallout(const TARGETING::Target *i_target,
                        const HWAS::partTypeEnum i_partType,
                        const HWAS::callOutPriority i_priority,
                        const HWAS::DeconfigEnum i_deconfigState,
                        const HWAS::GARD_ErrorType i_gardErrorType)
{
    TRACFCOMP(g_trac_errl, ENTER_MRK"addPartCallout(%p, %d, 0x%x, %d, 0x%x)",
                i_target, i_partType, i_priority,
                i_deconfigState, i_gardErrorType);

    const void* pData = nullptr;
    uint32_t size = 0;
    TARGETING::EntityPath* ep = nullptr;
    getTargData( i_target, ep, pData, size );

    ErrlUserDetailsCallout( pData, size, i_partType,
            i_priority, i_deconfigState, i_gardErrorType).addToLog(this);

    if (i_gardErrorType != GARD_NULL)
    {
        setGardBit();
    }
    if (i_deconfigState != NO_DECONFIG)
    {
        setDeconfigBit();
    }

    if( ep )
    {
        delete ep;
    }
} // addPartCallout

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void ErrlEntry::addBusCallout(const TARGETING::Target *i_target_endp1,
                        const TARGETING::Target *i_target_endp2,
                        const HWAS::busTypeEnum i_busType,
                        const HWAS::callOutPriority i_priority,
                        const HWAS::CalloutFlag_t i_flag)
{
    TRACFCOMP(g_trac_errl, ENTER_MRK"addBusCallout(%p, %p, %d, 0x%x)",
                i_target_endp1, i_target_endp2, i_busType, i_priority);

    const void* pData1 = nullptr;
    uint32_t size1 = 0;
    TARGETING::EntityPath* ep1 = nullptr;
    getTargData( i_target_endp1, ep1, pData1, size1 );

    const void* pData2 = nullptr;
    uint32_t size2 = 0;
    TARGETING::EntityPath* ep2 = nullptr;
    getTargData( i_target_endp2, ep2, pData2, size2 );


    ErrlUserDetailsCallout( pData1, size1, pData2, size2, i_busType,
                            i_priority, i_flag).addToLog(this);

    if( ep1 )
    {
        delete ep1;
    }
    if( ep2 )
    {
        delete ep2;
    }
} // addBusCallout

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void ErrlEntry::addBusCallout(const TARGETING::EntityPath & i_target_endp1,
                              const TARGETING::EntityPath & i_target_endp2,
                              const HWAS::busTypeEnum i_busType,
                              const HWAS::callOutPriority i_priority,
                              const HWAS::CalloutFlag_t i_flag)
{
    char * l_target_endp1_path_str = nullptr;
    char * l_target_endp2_path_str = nullptr;

    do
    {

    // Need targeting module loaded before calculating the size of the
    // EntityPaths.  If not loaded, don't make error callout, which
    // shouldn't be an issue as without targeting only 1 target is
    // available in the system: TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL
    if(Util::isTargetingLoaded() && TARGETING::targetService().isInitialized())
    {

        l_target_endp1_path_str = i_target_endp1.toString();
        l_target_endp2_path_str = i_target_endp2.toString();

        TRACFCOMP(g_trac_errl, ENTER_MRK"addBusCallout(%s, %s, %d, 0x%x)",
                  l_target_endp1_path_str, l_target_endp2_path_str,
                  i_busType, i_priority);

        auto size1 = sizeof(i_target_endp1) -
          (TARGETING::EntityPath::MAX_PATH_ELEMENTS - i_target_endp1.size()) *
          sizeof(TARGETING::EntityPath::PathElement);

        auto size2 = sizeof(i_target_endp2) -
          (TARGETING::EntityPath::MAX_PATH_ELEMENTS - i_target_endp2.size()) *
          sizeof(TARGETING::EntityPath::PathElement);

        ErrlUserDetailsCallout(&i_target_endp1,
                               size1,
                               &i_target_endp2,
                               size2,
                               i_busType,
                               i_priority,
                               i_flag).addToLog(this);

    }
    else
    {
        TRACFCOMP(g_trac_errl, ERR_MRK"addBusCallout(ep1, ep2, %d, 0x%x): "
                  "Can't process because targeting isn't loaded",
                  i_busType, i_priority);
    }

    } while (0);

    if (l_target_endp1_path_str != nullptr)
    {
        free(l_target_endp1_path_str);
        l_target_endp1_path_str = nullptr;
    }

    if (l_target_endp2_path_str != nullptr)
    {
        free(l_target_endp2_path_str);
        l_target_endp2_path_str = nullptr;
    }

    return;

} // addBusCallout (with EntityPath inputs)

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void ErrlEntry::addHwCallout(const TARGETING::Target *i_target,
                        const HWAS::callOutPriority i_priority,
                        const HWAS::DeconfigEnum i_deconfigState,
                        const HWAS::GARD_ErrorType i_gardErrorType)
{
    if (i_target == nullptr)
    {
        TRACFCOMP(g_trac_errl, ENTER_MRK
                  "addHwCallout called with NULL target");
        addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                             HWAS::SRCI_PRIORITY_HIGH);
        return;
    }

    if (i_target == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
    {
        #ifdef CONFIG_ERRL_ENTRY_TRACE
        TRACFCOMP(g_trac_errl, ENTER_MRK
                "addHwCallout(\"MASTER_PROC_SENTINEL\" 0x%x 0x%x 0x%x)",
                i_priority, i_deconfigState, i_gardErrorType);
        #else
        TRACDCOMP(g_trac_errl, ENTER_MRK
                "addHwCallout(\"MASTER_PROC_SENTINEL\" 0x%x 0x%x 0x%x)",
                i_priority, i_deconfigState, i_gardErrorType);
        #endif

        //need to override deconfig value to avoid possible deadlocks
        // in pnor
        HWAS::DeconfigEnum l_deconfigState = i_deconfigState;
        if( i_deconfigState == HWAS::DELAYED_DECONFIG )
        {
            TRACFCOMP( g_trac_errl, "addHwCallout> Forcing delayed deconfig to standard deconfig on sentinel" );
            l_deconfigState = HWAS::DECONFIG;
        }

        ErrlUserDetailsCallout(
                &HWAS::TARGET_IS_SENTINEL, sizeof(HWAS::TARGET_IS_SENTINEL),
                i_priority, l_deconfigState, i_gardErrorType).addToLog(this);
    }
    else
    {   // we got a non MASTER_SENTINEL target, therefore the targeting
        // module is loaded, therefore we can make this call.
        #ifdef CONFIG_ERRL_ENTRY_TRACE
        TRACFCOMP(g_trac_errl, ENTER_MRK"addHwCallout(0x%.8x 0x%x 0x%x 0x%x)",
                get_huid(i_target), i_priority,
                i_deconfigState, i_gardErrorType);
        #else
        TRACDCOMP(g_trac_errl, ENTER_MRK"addHwCallout(0x%.8x 0x%x 0x%x 0x%x)",
                get_huid(i_target), i_priority,
                i_deconfigState, i_gardErrorType);
        #endif
        TARGETING::EntityPath ep;
        TARGETING::TYPE l_type = i_target->getAttr<TARGETING::ATTR_TYPE>();

        TARGETING::TYPE l_type_ecid = l_type;
        const TARGETING::Target* l_parentTarget = i_target;
        if((l_type_ecid != TARGETING::TYPE_MEMBUF) &&
              (l_type_ecid != TARGETING::TYPE_PROC) &&
              (l_type_ecid != TARGETING::TYPE_NODE)
             )
        {
            //since this returns NULL if the parent is not found,
            // we need a placeholder
            const TARGETING::Target* l_tempParentTarget =
                    getParentChip(l_parentTarget);
            if(l_tempParentTarget != NULL)
            {
                l_parentTarget = l_tempParentTarget;
                l_type_ecid = l_parentTarget->getAttr<TARGETING::ATTR_TYPE>();
            }
        }
        //if we have found a type_membuf or type_proc, store the ecid
        //otherwise, (type_node), do nothing.
        if(l_type_ecid == TARGETING::TYPE_MEMBUF ||
           l_type_ecid == TARGETING::TYPE_PROC)
        {
            ErrlUserDetailsAttribute(l_parentTarget,
                                     TARGETING::ATTR_ECID).addToLog(this);
        }

        ep = i_target->getAttr<TARGETING::ATTR_PHYS_PATH>();

        // size is total EntityPath size minus unused path elements
        uint32_t size1 = sizeof(ep) -
                    (TARGETING::EntityPath::MAX_PATH_ELEMENTS - ep.size()) *
                        sizeof(TARGETING::EntityPath::PathElement);

        ErrlUserDetailsCallout(&ep, size1,
                i_priority, i_deconfigState, i_gardErrorType).addToLog(this);

    }
    if (i_gardErrorType != GARD_NULL)
    {
        setGardBit();
    }
    if (i_deconfigState != NO_DECONFIG)
    {
        setDeconfigBit();
    }
} // addHwCallout


////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void ErrlEntry::addProcedureCallout(const HWAS::epubProcedureID i_procedure,
                            const HWAS::callOutPriority i_priority)
{
    #ifdef CONFIG_ERRL_ENTRY_TRACE
    TRACFCOMP( g_trac_errl, ENTER_MRK"addProcedureCallout(0x%x, 0x%x)",
                i_procedure, i_priority);
    #else
    TRACDCOMP( g_trac_errl, ENTER_MRK"addProcedureCallout(0x%x, 0x%x)",
                i_procedure, i_priority);
    #endif

    ErrlUserDetailsCallout(i_procedure, i_priority).addToLog(this);

} // addProcedureCallout

///////////////////////////////////////////////////////////////////////////////
// Function to add a UD section containing the Hostboot Build ID to the
// current error log being committed
void ErrlEntry::addHbBuildId()
{
    // Title string
    const char * const l_title = "Hostboot Build ID: ";
    // Char[] based on title + Hostboot image ID
    char l_pString[strlen(l_title) + strlen(&hbi_ImageId) + 1];
    // Set beginning of string
    strcpy(l_pString, l_title);
    // Concatenate the Hostboot Image ID
    strcat(l_pString, &hbi_ImageId);
    // Create UD section and add string
    ErrlUserDetailsString(l_pString).addToLog(this);
}

void ErrlEntry::addVersionInfo()
{

    TRACDCOMP(g_trac_errl, ENTER_MRK"addVersionInfo()");

// Start of IPL only block; runtime does not support secure loading of
// partitions
#ifndef __HOSTBOOT_RUNTIME

    // Version section of PNOR is only available to OpenPOWER systems.
    if (   !INITSERVICE::spBaseServicesEnabled()
        && PNOR::isSectionAvailable(PNOR::VERSION))
    {
        bool l_secureSectionLoaded = false;
        errlHndl_t l_errl = nullptr, l_errl_loadSecureSection = nullptr;

        do
        {

#ifdef CONFIG_SECUREBOOT
            l_errl_loadSecureSection = PNOR::loadSecureSection(PNOR::VERSION);
            if (l_errl_loadSecureSection)
            {
                TRACFCOMP( g_trac_errl,
                          "addVersionInfo: Failed to load secure VERSION");
                // Since an error occurred while attempting to add version info
                // to another error log there is nothing that can be done with
                // this error since attempting to commit it will lead to an
                // infinite loop of committing the error and then recalling this
                // function. If this error occurred then the VERSION partition
                // is not added and the error log commit continues.
                delete l_errl_loadSecureSection;
                l_errl_loadSecureSection = nullptr;
                break;
            }
            else
            {
                l_secureSectionLoaded = true;
            }
#endif

            // Get PNOR Version
            PNOR::SectionInfo_t l_pnorVersionInfo;
            l_errl = getSectionInfo(PNOR::VERSION, l_pnorVersionInfo);

            if (l_errl)
            {
                TRACFCOMP( g_trac_errl,
                          "addVersionInfo: Failed to getSectionInfo");
                // Since an error occurred while attempting to add version info
                // to another error log there is nothing that can be done with
                // this error since attempting to commit it will lead to an
                // infinite loop of committing the error and then recalling this
                // function. If this error occurred then the VERSION partition
                // is not added and the error log commit continues.
                delete l_errl;
                l_errl = nullptr;
                break;
            }

            const uint8_t* l_versionData =
                reinterpret_cast<uint8_t*>(l_pnorVersionInfo.vaddr);

            size_t l_numberOfBytes = 0;

            // Determine the size of the version data. The max size is the given
            // size in the SectionInfo but can be less.
            while ((static_cast<char>(l_versionData[l_numberOfBytes]) != '\0')
                  && l_numberOfBytes < l_pnorVersionInfo.size)
            {
                ++l_numberOfBytes;
            }

            char l_pVersionString[l_numberOfBytes + 1]={0};

            memcpy(l_pVersionString, l_versionData, l_numberOfBytes);

            ErrlUserDetailsString(l_pVersionString).addToLog(this);
        } while(0);

#ifdef CONFIG_SECUREBOOT
        if (l_secureSectionLoaded)
        {
            l_errl_loadSecureSection = PNOR::unloadSecureSection(PNOR::VERSION);
            if(l_errl_loadSecureSection)
            {
                TRACFCOMP( g_trac_errl,
                          "addVersionInfo: Failed to unload secure VERSION");
                // Since an error occurred while attempting to add version info
                // to another error log there is nothing that can be done with
                // this error since attempting to commit it will lead to an
                // infinite loop of committing the error and then recalling this
                // function. If this error occurred then the VERSION partition
                // is not added and the error log commit continues.
                delete l_errl_loadSecureSection;
                l_errl_loadSecureSection = nullptr;
            }
        }
#endif

    }

// End of IPL only block
#else
// Start of runtime block. Since runtime doesn't support securing load of PNOR
// sections, we load the version info from reserved memory.

    // Version section of PNOR is only available to OpenPOWER systems.
    if (!INITSERVICE::spBaseServicesEnabled())
    {
        errlHndl_t l_errl = nullptr;

        do
        {

            // Get PNOR Version
            UtilLidMgr l_lidMgr(Util::VERSION_LIDID);
            size_t l_lidSize = 0;
            l_errl = l_lidMgr.getLidSize(l_lidSize);

            if (l_errl)
            {
                TRACFCOMP( g_trac_errl,
                          "addVersionInfo: Failed to getLidSize() - error");
                // Since an error occurred while attempting to add version info
                // to another error log there is nothing that can be done with
                // this error since attempting to commit it will lead to an
                // infinite loop of committing the error and then recalling this
                // function. If this error occurred then the VERSION partition
                // is not added and the error log commit continues.
                delete l_errl;
                l_errl = nullptr;
                break;
            }

            TRACDCOMP(g_trac_errl,
                      "addVersionInfo: l_lidSize = %d",
                      l_lidSize);

            char* l_versionData = new char[l_lidSize]();
            l_errl = l_lidMgr.getLid(l_versionData, l_lidSize);


            if (l_errl)
            {
                TRACFCOMP( g_trac_errl,
                          "addVersionInfo: Failed to getLid() - error");
                // Since an error occurred while attempting to add version info
                // to another error log there is nothing that can be done with
                // this error since attempting to commit it will lead to an
                // infinite loop of committing the error and then recalling this
                // function. If this error occurred then the VERSION partition
                // is not added and the error log commit continues.
                delete l_errl;
                l_errl = nullptr;
                delete[] l_versionData;
                l_versionData = nullptr;
                break;
            }

            size_t l_numberOfBytes = 0;

            // Determine the size of the version data. The max size is the
            // lidSize but can be less.
            while ((static_cast<char>(l_versionData[l_numberOfBytes]) != '\0')
                  && l_numberOfBytes < l_lidSize)
            {
                ++l_numberOfBytes;
            }

            TRACDCOMP(g_trac_errl,
                      "addVersionInfo: l_numberOfBytes = %d",
                      l_numberOfBytes);

            char l_pVersionString[l_numberOfBytes + 1]={0};

            memcpy(l_pVersionString, l_versionData, l_numberOfBytes);

            ErrlUserDetailsString(l_pVersionString).addToLog(this);

            delete[] l_versionData;
            l_versionData = nullptr;

        } while(0);


    }
#endif

    TRACFCOMP(g_trac_errl, EXIT_MRK"addVersionInfo()");

}

enum {
    SKIP_INFO_RECOVERABLE_LOGS =
        TARGETING::HIDDEN_ERRLOGS_ENABLE_NO_HIDDEN_LOGS,
    ENABLE_INFORMATIONAL_LOGS =
        TARGETING::HIDDEN_ERRLOGS_ENABLE_ALLOW_INFORMATIONAL,
    ENABLE_RECOVERABLE_LOGS =
        TARGETING::HIDDEN_ERRLOGS_ENABLE_ALLOW_RECOVERED,
    ENABLE_ALL_LOGS =
        TARGETING::HIDDEN_ERRLOGS_ENABLE_ALLOW_ALL_LOGS
};

void ErrlEntry::checkHiddenLogsEnable( )
{

    // Note: iv_skipShowingLog is set to True by default
    //0 = Prevent INFORMATIONAL/RECOVERED error logs from being processed.
    //1 = Send only INFORMATIONAL error logs.
    //2 = Send only RECOVERED error logs.
    //3 = Allow all hidden error logs to be processed.

    uint8_t l_enableLogs = getHiddenLogsEnable();

    // enable all logs to be displayed
    if( l_enableLogs == ENABLE_ALL_LOGS )
    {
        iv_skipShowingLog = false;
    }
    else
    {
        // need to check based on severity
        switch( sev() )
        {
            case ERRL_SEV_INFORMATIONAL:

                if(l_enableLogs & ENABLE_INFORMATIONAL_LOGS )
                {
                    iv_skipShowingLog = false;
                }
                break;

            case ERRL_SEV_RECOVERED:

                if(l_enableLogs & ENABLE_RECOVERABLE_LOGS )
                {
                    iv_skipShowingLog = false;
                }
                break;

            default:
                // For any error log that is not INFORMATIONAL
                // or RECOVERED, we want to show the log
                iv_skipShowingLog = false;
        }
    }
}

///////////////////////////////////////////////////////////////////////////////
// Called by addHwCallout to get the part and serial numbers from the current
// target so that it can be appended to the error log
#ifdef CONFIG_BMC_IPMI
    void ErrlEntry::addPartAndSerialNumbersToErrLog
(const TARGETING::Target * i_target)
{
    TRACDCOMP(g_trac_errl, ENTER_MRK"ErrlEntry::addPartAndSerialNumbersToErrLog()");


    // Get the type of the target
    const TARGETING::Target * l_target = i_target;
    TARGETING::TYPE l_type = l_target->getAttr<TARGETING::ATTR_TYPE>();

    do
    {
        if((l_type != TARGETING::TYPE_PROC ) &&
                (l_type != TARGETING::TYPE_DIMM ) &&
                (l_type != TARGETING::TYPE_MEMBUF ))
        {
            TARGETING::PredicatePostfixExpr l_procDimmMembuf;
            TARGETING::TargetHandleList l_pList;

            TARGETING::PredicateCTM l_procs(TARGETING::CLASS_CHIP,
                    TARGETING::TYPE_PROC);

            TARGETING::PredicateCTM l_dimms(TARGETING::CLASS_CARD,
                    TARGETING::TYPE_DIMM);

            TARGETING::PredicateCTM l_membufs(TARGETING::CLASS_CHIP,
                    TARGETING::TYPE_MEMBUF);

            l_procDimmMembuf.push(&l_procs).push(&l_dimms).Or()
                .push(&l_membufs).Or();

            // Search for any parents with TYPE_PROC, TYPE_DIMM, or TYPE_MEMBUF
            TARGETING::targetService().getAssociated( l_pList, l_target,
                    TARGETING::TargetService::PARENT,
                    TARGETING::TargetService::ALL,
                    &l_procDimmMembuf);
            // If no parent of desired type is present, break
            if(!l_pList.size())
            {
                TRACFCOMP(g_trac_errl, "Error! errlentry.C::addPartAndSerialNumbersToErrLog - No parent containing Serial/Part numbers found.");
                break;
            }
            else
            {
                // We have found the parent
                l_target = l_pList[0];
            }

        }
        // We have made it here so we have found a target that contains
        // ATTR_SERIAL_NUMBER and ATTR_PART_NUMBER
        //Add the part number to the error log.
        ErrlUserDetailsAttribute( l_target,
                          TARGETING::ATTR_PART_NUMBER).addToLog(this);

        //Add the serial number to the error log.
        ErrlUserDetailsAttribute( l_target,
                          TARGETING::ATTR_SERIAL_NUMBER).addToLog(this);


    }while( 0 );

    TRACDCOMP(g_trac_errl, EXIT_MRK"ErrlEntry::addPartAndSerialNumbersToErrLog()");
}


// Find the FRU ID associated with target.
// Returns first FRU ID found as it navigates the target's parent hierarchy
TARGETING::ATTR_FRU_ID_type getFRU_ID(TARGETING::Target * i_target)
{
    TARGETING::ATTR_FRU_ID_type l_fruid = 0;  // set to invalid FRU ID
    TARGETING::TargetHandleList l_parentList;
    TARGETING::Target * l_target = i_target;

    uint16_t level = 0; // just a basic parent level counter

    TRACDCOMP(g_trac_errl,"Looking for FRU ID starting at HUID 0x%X target",
        TARGETING::get_huid(i_target));

    bool foundFru = i_target->tryGetAttr<TARGETING::ATTR_FRU_ID>(l_fruid);
    while (!foundFru)
    {
        level++;

        // Get immediate parent
        TARGETING::targetService().getAssociated(
                                        l_parentList,
                                        l_target,
                                        TARGETING::TargetService::PARENT,
                                        TARGETING::TargetService::IMMEDIATE);

        if (l_parentList.size() != 1)
        {
            TRACDCOMP(g_trac_errl,"%d No Parent for HUID 0x%X target",
                level, TARGETING::get_huid(l_target));
            break;
        }

        l_target = l_parentList[0];

        if (l_target->tryGetAttr<TARGETING::ATTR_FRU_ID>(l_fruid))
        {
            // Found 1st parent with a FRU ID
            foundFru = true;
        }

        l_parentList.clear();  // clear out old entry

    } // end while

    if (foundFru)
    {
        TRACDCOMP(g_trac_errl,"level %d FRU ID 0x%X found for target HUID 0x%X",
                    level, l_fruid, TARGETING::get_huid(l_target));
    }
    else
    {
        TRACFCOMP(g_trac_errl,"Failed to find a FRU ID for target HUID 0x%X. Looked at %d levels.",
            TARGETING::get_huid(i_target), level);
    }

    return l_fruid;
}

void ErrlEntry::addSensorDataToErrLog(TARGETING::Target * i_target,
                                      HWAS::callOutPriority i_priority )
{
    TRACDCOMP(g_trac_errl,
        ENTER_MRK"ErrlEntry::addSensorDataToErrLog(HUID 0x%X, priority %d)",
        TARGETING::get_huid(i_target), i_priority);

    uint8_t l_sensorNum = SENSOR::getFaultSensorNumber(i_target);
    TARGETING::ATTR_FRU_ID_type l_fru_id = getFRU_ID(i_target);

    // Add the sensor details to the error log
    ErrlUserDetailsSensor(l_fru_id, l_sensorNum, i_priority).addToLog(this);

    TRACDCOMP(g_trac_errl, EXIT_MRK"ErrlEntry::addSensorDataToErrLog()");
}


#endif

///////////////////////////////////////////////////////////////////////////////
// for use by ErrlManager
void ErrlEntry::commit( compId_t  i_committerComponent )
{
    // TODO RTC 35258 need a better timepiece, or else apply a transform onto
    // timebase for an approximation of real time.
    iv_Private.iv_committed = getTB();

    // User header contains the component ID of the committer.
    iv_User.setComponentId( i_committerComponent );

    // Avoid adding a callout to informational callhome "error"
    if (!getEselCallhomeInfoEvent())
    {
        setSubSystemIdBasedOnCallouts();
    }

    // Add the captured backtrace to the error log
    if (iv_pBackTrace)
    {
        iv_pBackTrace->addToLog(this);
        delete iv_pBackTrace;
        iv_pBackTrace = NULL;
    }

    // Add the Hostboot Build ID to the error log
    addHbBuildId();

    // check to see if we should skip info and recoverable errors?
    checkHiddenLogsEnable();

    // Check to make sure targeting is initialized. If so, collect part and
    // serial numbers
    if(Util::isTargetingLoaded() && TARGETING::targetService().isInitialized())
    {
        // Add the version info to the error log for OpenPOWER systems
        addVersionInfo();

        // If this error was a hardware callout, add the serial and part numbers
        // to the log. FSP provides this data so if there is no FSP, get them here.
        if(!INITSERVICE::spBaseServicesEnabled())
        {
            for(size_t i = 0; i < iv_SectionVector.size(); i++)
            {
                ErrlUD * l_udSection = iv_SectionVector[i];
                HWAS::callout_ud_t * l_ud =
                    reinterpret_cast<HWAS::callout_ud_t*>(l_udSection->iv_pData);

                if((ERRL_COMP_ID     == (l_udSection)->iv_header.iv_compId) &&
                   (1                == (l_udSection)->iv_header.iv_ver) &&
                   (ERRL_UDT_CALLOUT == (l_udSection)->iv_header.iv_sst) &&
                   (HWAS::HW_CALLOUT == l_ud->type))
                {
                    uint8_t * l_uData = (uint8_t *)(l_ud + 1);
                    TARGETING::Target * l_target = NULL;

                    bool l_err = HWAS::retrieveTarget(l_uData,
                                                      l_target,
                                                      this);
                    if(!l_err)
                    {
#ifdef CONFIG_BMC_IPMI
                        addPartAndSerialNumbersToErrLog( l_target );
                        addSensorDataToErrLog( l_target, l_ud->priority);
#endif
                    }
                    else
                    {
                        TRACFCOMP(g_trac_errl, "ErrlEntry::commit() - Error retrieving target");
                    }
                }
            }
        }
    }
    else
    {
        TRACFCOMP(g_trac_errl,
                "TARGETING has not been initialized yet! Skipping serial/part "
                "number collection!");
    }
}

///////////////////////////////////////////////////////////////////////////////
// Function to set the correct subsystem ID based on callout priorities
void ErrlEntry::setSubSystemIdBasedOnCallouts()
{
    TRACDCOMP(g_trac_errl, INFO_MRK
            "ErrlEntry::getSubSystemIdBasedOnCallouts()");

    HWAS::callout_ud_t *    pData = NULL;

    HWAS::callout_ud_t *  highestPriorityCallout = NULL;

    // look thru the errlog for any Callout UserDetail sections
    for( std::vector<ErrlUD*>::const_iterator it = iv_SectionVector.begin();
            it != iv_SectionVector.end();
            it++ )
    {
        // look for a CALLOUT section
        if ((ERRL_COMP_ID     == (*it)->iv_header.iv_compId) &&
                (1                == (*it)->iv_header.iv_ver) &&
                (ERRL_UDT_CALLOUT == (*it)->iv_header.iv_sst))
        {
            // its a callout, grab the priority
            pData = reinterpret_cast<HWAS::callout_ud_t *>
                ( (*it)->iv_pData );

            // figure out the highest priority callout, just grab
            // the first one if there are several with the same
            // priority.
            if( (highestPriorityCallout == NULL) ||
                (pData->priority > highestPriorityCallout->priority) )
            {
                highestPriorityCallout = pData;
            }
        }
    } // for each SectionVector

    // if this pointer is not null it will be pointing to the
    // highest priority entry
    if((highestPriorityCallout == NULL) ||
       (highestPriorityCallout->priority == HWAS::SRCI_PRIORITY_NONE) )
    {
        // no callouts in log, add default callout for hb code and
        // add trace
        TRACFCOMP(g_trac_errl, "WRN>> No callouts in elog %.8X", eid());
        TRACFCOMP(g_trac_errl, "Adding default callout EPUB_PRC_HB_CODE ");
        addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                             HWAS::SRCI_PRIORITY_LOW);

        iv_User.setSubSys( EPUB_FIRMWARE_HOSTBOOT );

    }
    else
    {
        pData = highestPriorityCallout;

        if( pData->type ==  HWAS::HW_CALLOUT )
        {
            // rebuild the target from the entity path, then use
            // the target type to determine the ssid
            if (*((uint8_t *)(pData + 1)) != TARGET_IS_SENTINEL)
            {
                // copy the entity path from the data buffer
                TARGETING::EntityPath ep;
                memcpy(&ep, ( pData + 1), sizeof(ep));

                // convert the EntityPath to a Target pointer
                TARGETING::Target *pTarget =
                            TARGETING::targetService().toTarget(ep);

                TRACDCOMP(g_trac_errl, INFO_MRK
                        "mapping highest priority target 0x%x "
                        "callout to determine SSID",
                        pTarget->getAttr<TARGETING::ATTR_TYPE>() );

                // use the target type to get the failing ssid.
                iv_User.setSubSys( getSubSystem(
                        pTarget->getAttr<TARGETING::ATTR_TYPE>()));
            }
            else
            {
                // it was the sentinel -- so just use the proc ssid
                iv_User.setSubSys( EPUB_PROCESSOR_SUBSYS );
            }
        }
        else if ( pData->type == HWAS::PROCEDURE_CALLOUT )
        {
            // for procedures, map the procedure to a subsystem
            TRACDCOMP(g_trac_errl, INFO_MRK
                    "mapping highest priority procedure 0x%x "
                    "callout to determine SSID",  pData->procedure);
            iv_User.setSubSys(getSubSystem( pData->procedure));

        }
        else if ( pData->type == HWAS::BUS_CALLOUT )
        {
            TRACFCOMP(g_trac_errl, INFO_MRK
                    "mapping highest priority bus 0x%x "
                    "callout to determine SSID",  pData->busType);
            iv_User.setSubSys(getSubSystem(pData->busType));
        }
        else if ( pData->type == HWAS::CLOCK_CALLOUT )
        {
            TRACFCOMP(g_trac_errl, INFO_MRK
                    "mapping highest priority clock 0x%x "
                    "callout to determine SSID", pData->clockType);
            iv_User.setSubSys(getSubSystem(pData->clockType));
        }
        else if ( pData->type == HWAS::PART_CALLOUT )
        {
            TRACFCOMP(g_trac_errl, INFO_MRK
                    "mapping highest priority part 0x%x "
                    "callout to determine SSID", pData->partType);
            iv_User.setSubSys(getSubSystem(pData->partType));
        }
        else if ( pData->type == HWAS::SENSOR_CALLOUT )
        {
            TRACFCOMP(g_trac_errl, INFO_MRK
                    "mapping highest priority sensor type 0x%x "
                    "callout to determine SSID", pData->sensorType);
            iv_User.setSubSys(getSubSystem(pData->sensorType));
        }
        else if (pData->type == HWAS::I2C_DEVICE_CALLOUT)
        {
            TRACFCOMP(g_trac_errl, INFO_MRK
                    "setting subsystem for type 0x%x "
                    "callout to I2C Device", pData->type);

            iv_User.setSubSys(EPUB_CEC_HDW_I2C_DEVS);
        }
        else
        {
            TRACFCOMP(g_trac_errl, ERR_MRK
                    "Unknown callout type 0x%x, setting subsys to unknown",
                    pData->type);
            iv_User.setSubSys(EPUB_UNKNOWN);
        }
    }
    // add ssid to the SRC too, it is defined in the ErrlUH in FSP land
    // in hb code it has been defined in both places and is also used
    // in both places.
    iv_Src.setSubSys( iv_User.getSubSys() );

    TRACDCOMP(g_trac_errl, INFO_MRK
                "ErrlEntry::setSubSystemIdBasedOnCallouts() "
                "ssid selected 0x%X", iv_Src.getSubSys() );

}
///////////////////////////////////////////////////////////////////////////////
// Determine if this log should cause a termination
bool ErrlEntry::isTerminateLog() const
{
    bool l_terminate = false;

    switch( iv_termState )
    {
        case TERM_STATE_MNFG:
            l_terminate = true;
            break;

        case TERM_STATE_SOFT:
            l_terminate = true;
            break;

        default:
            l_terminate = false;
            break;

    }

    return l_terminate;

}

///////////////////////////////////////////////////////////////////////////////
// Map the target type to correct subsystem ID using a binary search
epubSubSystem_t ErrlEntry::getSubSystem( TARGETING::TYPE i_target ) const
{

    TRACDCOMP(g_trac_errl, ENTER_MRK"getSubSystem()"
            " i_target = 0x%x", i_target );

    // local variables
    epubSubSystem_t subsystem = EPUB_MISC_UNKNOWN;

    uint32_t TARGET_TO_SUBSYS_TABLE_ENTRIES =
                    sizeof(TARGET_TO_SUBSYS_TABLE)/
                    sizeof(TARGET_TO_SUBSYS_TABLE[0]);

    uint32_t low = 0;
    uint32_t high = TARGET_TO_SUBSYS_TABLE_ENTRIES - 1;
    uint32_t mid  = 0;

    while( low <= high )
    {
        mid = low + (( high - low)/2);

        if ( TARGET_TO_SUBSYS_TABLE[mid].xType > i_target )
        {
            high = mid -1;
        }
        else if ( TARGET_TO_SUBSYS_TABLE[mid].xType < i_target )
        {
            low = mid + 1;
        }
        else
        {
            // found it
           subsystem = TARGET_TO_SUBSYS_TABLE[mid].xSubSys;
           break;
        }
    }

    if( subsystem == EPUB_MISC_UNKNOWN )
    {
        TRACFCOMP(g_trac_errl,"WRN>> Failed to find subsystem ID for "
                               "target type 0x%x", i_target);
    }

    TRACDCOMP(g_trac_errl, EXIT_MRK"getSubSystem()  ssid  0x%x", subsystem );

    return (subsystem);

}

///////////////////////////////////////////////////////////////////////////////
// Map the procedure type to correct subsystem ID using a binary search
epubSubSystem_t ErrlEntry::getSubSystem( epubProcedureID i_procedure  ) const
{
    TRACDCOMP(g_trac_errl, ENTER_MRK"getSubSystem()"
                " from procedure  0x%x", i_procedure );

    // local variables
    epubSubSystem_t subsystem = EPUB_MISC_UNKNOWN;

    uint32_t PROCEDURE_TO_SUBSYS_TABLE_ENTRIES =
                        sizeof(PROCEDURE_TO_SUBSYS_TABLE)/
                        sizeof(PROCEDURE_TO_SUBSYS_TABLE[0]);

    uint32_t low = 0;
    uint32_t high = PROCEDURE_TO_SUBSYS_TABLE_ENTRIES -1;
    uint32_t mid  = 0;

    while( low <= high )
    {
        mid = low + (( high - low)/2);

        if ( PROCEDURE_TO_SUBSYS_TABLE[mid].xProc > i_procedure )
        {
            high = mid -1;
        }
        else if ( PROCEDURE_TO_SUBSYS_TABLE[mid].xProc < i_procedure )
        {
            low = mid + 1;
        }
        else
        {
           subsystem = PROCEDURE_TO_SUBSYS_TABLE[mid].xSubSys;
           break;
        }
    }

    if( subsystem == EPUB_MISC_UNKNOWN )
    {
        TRACFCOMP(g_trac_errl,"WRN>> Failed to find subsystem ID for "
                               "procedure 0x%x", i_procedure);
    }

    TRACDCOMP(g_trac_errl, EXIT_MRK"getSubSystem()"
                " ssid  0x%x", subsystem );

    return (subsystem);
}

///////////////////////////////////////////////////////////////////////////////
// Map a bus type to a subsystem ID
epubSubSystem_t ErrlEntry::getSubSystem( HWAS::busTypeEnum i_busType ) const
{
    TRACDCOMP(g_trac_errl, ENTER_MRK"getSubSystem() from bus type 0x%x",
              i_busType);

    epubSubSystem_t subsystem = EPUB_MISC_UNKNOWN;

    const uint32_t BUS_TO_SUBSYS_TABLE_ENTRIES =
        sizeof(BUS_TO_SUBSYS_TABLE)/sizeof(BUS_TO_SUBSYS_TABLE[0]);

    for (uint32_t i = 0; i < BUS_TO_SUBSYS_TABLE_ENTRIES; i++)
    {
        if (BUS_TO_SUBSYS_TABLE[i].xType == i_busType)
        {
            subsystem = BUS_TO_SUBSYS_TABLE[i].xSubSys;
            break;
        }
    }

    if(subsystem == EPUB_MISC_UNKNOWN)
    {
        TRACFCOMP(g_trac_errl,"WRN>> Failed to find subsystem ID for bus type 0x%x",
                  i_busType);
    }

    TRACDCOMP(g_trac_errl, EXIT_MRK"getSubSystem() ssid 0x%x", subsystem);
    return subsystem;
}

///////////////////////////////////////////////////////////////////////////////
// Map a clock type to a subsystem ID
epubSubSystem_t ErrlEntry::getSubSystem( HWAS::clockTypeEnum i_clockType ) const
{
    TRACDCOMP(g_trac_errl, ENTER_MRK"getSubSystem() from clock type 0x%x",
              i_clockType);

    epubSubSystem_t subsystem = EPUB_MISC_UNKNOWN;

    const uint32_t CLOCK_TO_SUBSYS_TABLE_ENTRIES =
        sizeof(CLOCK_TO_SUBSYS_TABLE)/sizeof(CLOCK_TO_SUBSYS_TABLE[0]);

    for (uint32_t i = 0; i < CLOCK_TO_SUBSYS_TABLE_ENTRIES; i++)
    {
        if (CLOCK_TO_SUBSYS_TABLE[i].xType == i_clockType)
        {
            subsystem = CLOCK_TO_SUBSYS_TABLE[i].xSubSys;
            break;
        }
    }

    if(subsystem == EPUB_MISC_UNKNOWN)
    {
        TRACFCOMP(g_trac_errl,"WRN>> Failed to find subsystem ID for clock type 0x%x",
                  i_clockType);
    }

    TRACDCOMP(g_trac_errl, EXIT_MRK"getSubSystem() ssid 0x%x", subsystem);
    return subsystem;
}

///////////////////////////////////////////////////////////////////////////////
// Map a Sensor type to a subsystem ID
epubSubSystem_t ErrlEntry::getSubSystem(HWAS::sensorTypeEnum i_sensorType) const
{
    TRACDCOMP(g_trac_errl, ENTER_MRK"getSubSystem() from sensor type 0x%x",
              i_sensorType);

    epubSubSystem_t subsystem = EPUB_MISC_UNKNOWN;

    const uint32_t SENSOR_TO_SUBSYS_TABLE_ENTRIES =
        sizeof(SENSOR_TO_SUBSYS_TABLE)/sizeof(SENSOR_TO_SUBSYS_TABLE[0]);

    for (uint32_t i = 0; i < SENSOR_TO_SUBSYS_TABLE_ENTRIES; i++)
    {
        if (SENSOR_TO_SUBSYS_TABLE[i].xType == i_sensorType)
        {
            subsystem = SENSOR_TO_SUBSYS_TABLE[i].xSubSys;
            break;
        }
    }

    if(subsystem == EPUB_MISC_UNKNOWN)
    {
        TRACFCOMP(g_trac_errl,"WRN>> Failed to find subsystem ID for sensor type 0x%x",
                  i_sensorType);
    }

    TRACDCOMP(g_trac_errl, EXIT_MRK"getSubSystem() ssid 0x%x", subsystem);
    return subsystem;
}

///////////////////////////////////////////////////////////////////////////////
// Map a Part type to a subsystem ID
epubSubSystem_t ErrlEntry::getSubSystem( HWAS::partTypeEnum i_partType ) const
{
    TRACDCOMP(g_trac_errl, ENTER_MRK"getSubSystem() from part type 0x%x",
              i_partType);

    epubSubSystem_t subsystem = EPUB_MISC_UNKNOWN;

    const uint32_t PART_TO_SUBSYS_TABLE_ENTRIES =
        sizeof(PART_TO_SUBSYS_TABLE)/sizeof(PART_TO_SUBSYS_TABLE[0]);

    for (uint32_t i = 0; i < PART_TO_SUBSYS_TABLE_ENTRIES; i++)
    {
        if (PART_TO_SUBSYS_TABLE[i].xType == i_partType)
        {
            subsystem = PART_TO_SUBSYS_TABLE[i].xSubSys;
            break;
        }
    }

    if(subsystem == EPUB_MISC_UNKNOWN)
    {
        TRACFCOMP(g_trac_errl,"WRN>> Failed to find subsystem ID for part type 0x%x",
                  i_partType);
    }

    TRACDCOMP(g_trac_errl, EXIT_MRK"getSubSystem() ssid 0x%x", subsystem);
    return subsystem;
}


///////////////////////////////////////////////////////////////////////////////
// for use by ErrlManager
void ErrlEntry::processCallout()
{
    TRACDCOMP(g_trac_errl, INFO_MRK"errlEntry::processCallout");

    // Skip all callouts if this is a non-visible log
    if( !isSevVisible() )
    {
        TRACDCOMP(g_trac_errl, "Error log is non-visible - skipping callouts");
        return;
    }

    // see if HWAS has been loaded and has set the processCallout function
    HWAS::processCalloutFn pFn =
            ERRORLOG::theErrlManager::instance().getHwasProcessCalloutFn();
    if (pFn != NULL)
    {
        // look thru the errlog for any Callout UserDetail sections
        for(std::vector<ErrlUD*>::const_iterator it = iv_SectionVector.begin();
                it != iv_SectionVector.end();
                it++ )
        {
            // if this is a CALLOUT
            if ((ERRL_COMP_ID     == (*it)->iv_header.iv_compId) &&
                (1                == (*it)->iv_header.iv_ver) &&
                (ERRL_UDT_CALLOUT == (*it)->iv_header.iv_sst))
            {
                // call HWAS to have this processed
                errlHndl_t l_errl = this;
                (*pFn)(l_errl,(*it)->iv_pData, (*it)->iv_Size, false);
                assert((this == l_errl), "processCallout changed the errl");
            }
        } // for each SectionVector
    } // if HWAS module loaded
    else
    {
        TRACDCOMP(g_trac_errl, INFO_MRK"hwas processCalloutFn not set!");
    }

    TRACDCOMP(g_trac_errl, INFO_MRK"errlEntry::processCallout returning");
}


///////////////////////////////////////////////////////////////////////////////
// for use by ErrlManager
void ErrlEntry::deferredDeconfigure()
{
    // NOTE:
    // This function is called in the calling process of errl->commit.  Since
    // processes that are not allowed to touch swappable memory may call
    // errl->commit, we need to be very careful about what we do in this
    // function.
    //
    // The getHwasProcessCalloutFn is only enabled when the HWAS module is
    // loaded, but this does not ensure that the HWAS code pages are
    // physically present in memory.  Processes like the PnorRP cannot call
    // into the HWAS module, but can make callouts (using MASTER_..SENTINEL).
    //
    // Currently we're using the fact that non-swappable tasks do not make
    // deferred deconfig requests as the indicator that it is safe to call
    // the HWAS functionality.

    TRACDCOMP(g_trac_errl, INFO_MRK"errlEntry::deferredDeconfigure");

    // Skip all callouts if this is a non-visible log
    if( !isSevVisible() )
    {
        TRACDCOMP(g_trac_errl, "Error log is non-visible - skipping callouts");
        return;
    }

    // see if HWAS has been loaded and has set the processCallout function
    HWAS::processCalloutFn pFn =
            ERRORLOG::theErrlManager::instance().getHwasProcessCalloutFn();
    if (pFn != NULL)
    {
        //check for deferred deconfigure callouts
        // look thru the errlog for any Callout UserDetail sections
        for(std::vector<ErrlUD*>::const_iterator it = iv_SectionVector.begin();
                it != iv_SectionVector.end();
                it++ )
        {
            // if this is a CALLOUT and DELAYED_DECONFIG.
            if ((ERRL_COMP_ID     == (*it)->iv_header.iv_compId) &&
                (1                == (*it)->iv_header.iv_ver) &&
                (ERRL_UDT_CALLOUT == (*it)->iv_header.iv_sst) &&
                (HWAS::HW_CALLOUT ==
                    reinterpret_cast<HWAS::callout_ud_t*>(
                        (*it)->iv_pData)->type) &&
#if  __HOSTBOOT_RUNTIME
                ((HWAS::DELAYED_DECONFIG ==
                    reinterpret_cast<HWAS::callout_ud_t*>(
                        (*it)->iv_pData)->deconfigState) ||
                 (HWAS::DECONFIG ==
                    reinterpret_cast<HWAS::callout_ud_t*>(
                        (*it)->iv_pData)->deconfigState))
#else
                (HWAS::DELAYED_DECONFIG ==
                    reinterpret_cast<HWAS::callout_ud_t*>(
                        (*it)->iv_pData)->deconfigState)
#endif
               )
            {
                // call HWAS function to register this action,
                //  put it on a queue and will be processed separately,
                //  when the time is right.
                errlHndl_t l_errl = this;
                (*pFn)(l_errl,(*it)->iv_pData, (*it)->iv_Size, true);
                assert((this == l_errl), "processCallout changed the errl");
            }
        } // for each SectionVector
    } // if HWAS module loaded
    else
    {
        TRACDCOMP(g_trac_errl, INFO_MRK"hwas processCalloutFn not set!");
    }

    TRACDCOMP(g_trac_errl, INFO_MRK"errlEntry::deferredDeconfigure returning");
}

//////////////////////////////////////////////////////////////////////////////
// for use by ErrlManager

uint64_t ErrlEntry::flattenedSize()
{
    uint64_t l_bytecount = iv_Private.flatSize() +
                           iv_User.flatSize() +
                           iv_Src.flatSize();

    // plus the sizes of the other optional sections

    std::vector<ErrlUD*>::const_iterator it;
    for( it = iv_SectionVector.begin(); it != iv_SectionVector.end(); it++ )
    {
        l_bytecount += (*it)->flatSize();
    }
    return l_bytecount;
}


/////////////////////////////////////////////////////////////////////////////
// Flatten this object and all its sections into PEL
// for use by ErrlManager. Return how many bytes flattened to the output
// buffer, or else zero on error.

uint64_t ErrlEntry::flatten( void * o_pBuffer,
            const uint64_t i_bufsize,
            const bool i_truncate)
{
    uint64_t l_flatSize = 0;
    uint64_t l_cb = 0;
    uint64_t l_sizeRemaining = i_bufsize;

    // The CPPASSERT() macro will cause the compile to abend
    // when the expression given evaluates to false.  If ever
    // these cause the compile to fail, then perhaps the size
    // of enum'ed types has grown unexpectedly.
    CPPASSERT( 2 == sizeof(iv_Src.iv_reasonCode));
    CPPASSERT( 2 == sizeof(compId_t));
    CPPASSERT( 1 == sizeof(iv_Src.iv_modId));

    do
    {
        // check if the input buffer needs to be and is big enough
        l_flatSize = flattenedSize();
        if (( l_sizeRemaining < l_flatSize ) && (!i_truncate))
        {
            TRACFCOMP( g_trac_errl,
                    ERR_MRK"Buffer (%d) < flatSize (%d), aborting flatten",
                    l_sizeRemaining, l_flatSize);
            l_flatSize = 0; // return zero
            break;
        }


        // Inform the private header how many sections there are,
        // counting the PH, UH, PS, and the optionals.
        const auto startingSectionCount = iv_SectionVector.size();
        iv_Private.iv_sctns = 3 + startingSectionCount;

        // Flatten the PH private header section
        char * pBuffer = static_cast<char *>(o_pBuffer);
        l_cb = iv_Private.flatten( pBuffer, l_sizeRemaining );
        if( 0 == l_cb )
        {
            TRACFCOMP( g_trac_errl, ERR_MRK"ph.flatten error");
            l_flatSize = 0;
            // don't check i_truncate - this section MUST fit.
            break;
        }

        // save this location - if the number of sections that we flatten is
        // reduced, we need to update this PH section.
        char *pPHBuffer = pBuffer;

        pBuffer += l_cb;
        l_sizeRemaining -= l_cb;

        // flatten the UH user header section
        l_cb = iv_User.flatten( pBuffer,  l_sizeRemaining );
        if( 0 == l_cb )
        {
            TRACFCOMP( g_trac_errl, ERR_MRK"uh.flatten error");
            l_flatSize = 0;
            // don't check i_truncate - this section MUST fit.
            break;
        }
        pBuffer += l_cb;
        l_sizeRemaining -= l_cb;

        // flatten the PS primary SRC section
        l_cb = iv_Src.flatten( pBuffer, l_sizeRemaining );
        if( 0 == l_cb )
        {
            TRACFCOMP( g_trac_errl, ERR_MRK"ps.flatten error");
            l_flatSize = 0;
            // don't check i_truncate - this section MUST fit.
            break;
        }
        pBuffer += l_cb;
        l_sizeRemaining -= l_cb;


        // flatten the optional user-defined sections
        // Flattens in the following order: 1. Hardware Callouts
        //                                  2. Other UD sections (non-trace)
        //                                  3. Traces
        // When the user-defined sections exceed 16kB, FSP ERRL discards
        // any remaining user-defined sections.  Therefore this order
        // preserves the callouts, and then gives priority to other
        // non-trace sections.
        //
        // for saving errorlogs into PNOR, i_truncate will be set to true
        // and sections which don't fit are not saved.
        size_t flattenedSections = 0;

        std::vector<ErrlUD*>::const_iterator it;
        for(it = iv_SectionVector.begin();
            (it != iv_SectionVector.end()) && (l_flatSize != 0);
            it++)
        {
            // If UD section is a hardware callout.
            if( (ERRL_COMP_ID     == (*it)->iv_header.iv_compId) &&
                (ERRL_UDT_CALLOUT == (*it)->iv_header.iv_sst) )
            {
                l_cb = (*it)->flatten( pBuffer, l_sizeRemaining );
                if( 0 == l_cb )
                {
                    if (i_truncate)
                    {
                        // TODO: RTC 77560 - error if this happens during test
                        TRACFCOMP( g_trac_errl,
                                INFO_MRK"ud.flatten error, skipping");
                        continue;
                    }
                    else
                    {
                        TRACFCOMP( g_trac_errl,
                                ERR_MRK"ud.flatten error, aborting");
                        l_flatSize = 0; // return zero
                        break;
                    }
                }
                ++flattenedSections;
                pBuffer += l_cb;
                l_sizeRemaining -= l_cb;
            }
        } // for

        for(it = iv_SectionVector.begin();
            (it != iv_SectionVector.end()) && (l_flatSize != 0);
            it++)
        {
            // If UD section is not a hardware callout and not a trace.
            if( !(((ERRL_COMP_ID        == (*it)->iv_header.iv_compId) &&
                   (ERRL_UDT_CALLOUT    == (*it)->iv_header.iv_sst)) ||
                  ((FIPS_ERRL_COMP_ID   == (*it)->iv_header.iv_compId) &&
                   (FIPS_ERRL_UDT_HB_TRACE == (*it)->iv_header.iv_sst))) )
            {
                l_cb = (*it)->flatten( pBuffer, l_sizeRemaining );
                if( 0 == l_cb )
                {
                    if (i_truncate)
                    {
                        // TODO: RTC 77560 - error if this happens during test
                        TRACFCOMP( g_trac_errl,
                                INFO_MRK"ud.flatten error, skipping");
                        continue;
                    }
                    else
                    {
                        TRACFCOMP( g_trac_errl,
                                ERR_MRK"ud.flatten error, aborting");
                        l_flatSize = 0; // return zero
                        break;
                    }
                }
                ++flattenedSections;
                pBuffer += l_cb;
                l_sizeRemaining -= l_cb;
            }
        } // for

        // Before the trace UD sections are flattened, make sure there are no
        // duplicates.
        removeDuplicateTraces();

        for(it = iv_SectionVector.begin();
           (it != iv_SectionVector.end()) && (l_flatSize != 0);
            it++)
        {
            // If UD section is a trace.
            if( (FIPS_ERRL_COMP_ID   == (*it)->iv_header.iv_compId) &&
                (FIPS_ERRL_UDT_HB_TRACE == (*it)->iv_header.iv_sst) )
            {

                l_cb = (*it)->flatten( pBuffer, l_sizeRemaining );
                if( 0 == l_cb )
                {
                    if (i_truncate)
                    {
                        // TODO: RTC 77560 - error if this happens during test
                        TRACFCOMP( g_trac_errl,
                                INFO_MRK"ud.flatten error, skipping");
                        continue;
                    }
                    else
                    {
                        TRACFCOMP( g_trac_errl,
                                ERR_MRK"ud.flatten error, aborting");
                        l_flatSize = 0; // return zero
                        break;
                    }
                }
                ++flattenedSections;
                pBuffer += l_cb;
                l_sizeRemaining -= l_cb;
            }
        } // for

        if( 0 == l_flatSize )
        {
          break;
        }

        if (flattenedSections != startingSectionCount)
        {
            // some section was too big and didn't get flatten - update the
            // section count in the PH section and re-flatten it.
            // count is the PH, UH, PS, and the optionals.
            iv_Private.iv_sctns = 3 + flattenedSections;
            // use ph size, since this is overwriting flattened data
            l_cb = iv_Private.flatten( pPHBuffer, iv_Private.flatSize() );
            if( 0 == l_cb )
            {
                TRACFCOMP( g_trac_errl, ERR_MRK"ph.flatten error");
                l_flatSize = 0;
                // don't check i_truncate - this section MUST fit.
                break;
            }
        }
    }
    while( 0 );

    // if l_flatSize == 0, there was an error, return 0.
    //  else return actual size that we flattened into the buffer.
    return (l_flatSize == 0) ? 0 : (i_bufsize - l_sizeRemaining);
} // flatten


uint64_t ErrlEntry::unflatten( const void * i_buffer,  uint64_t i_len )
{
    const uint8_t * l_buf = static_cast<const uint8_t *>(i_buffer);
    uint64_t consumed = 0;
    uint64_t bytes_used = 0;
    uint64_t rc = 0;

    TRACDCOMP(g_trac_errl, INFO_MRK"Unflatten Private section...");
    bytes_used = iv_Private.unflatten(l_buf);
    consumed    += bytes_used;
    l_buf       += bytes_used;

    TRACDCOMP(g_trac_errl, INFO_MRK"Unflatten User Header section...");
    bytes_used = iv_User.unflatten(l_buf);
    consumed    += bytes_used;
    l_buf       += bytes_used;

    TRACDCOMP(g_trac_errl, INFO_MRK"Unflatten SRC section...");
    bytes_used = iv_Src.unflatten(l_buf);
    consumed    += bytes_used;
    l_buf       += bytes_used;

    iv_SectionVector.clear();
    iv_btAddrs.clear();
    removeBackTrace();

    // loop thru the User Data sections (after already doing 3: Private, User
    // Header, SRC sections) while there's still data to process
    for (int32_t l_sc = 3;
            (l_sc < iv_Private.iv_sctns) && (consumed < i_len);
            l_sc++)
    {
        TRACDCOMP(g_trac_errl, INFO_MRK"Unflatten User data section...");
        const ERRORLOG::pelSectionHeader_t * p =
            reinterpret_cast<const ERRORLOG::pelSectionHeader_t *>(l_buf);

        if(p->sid != ERRORLOG::ERRL_SID_USER_DEFINED) // 'UD'
        {
            // yikes - bad section
            TRACFCOMP(g_trac_errl, ERR_MRK"Bad UserData section found while "
                      "importing flattened data into error log. plid=%08x",
                      iv_Private.iv_plid);
            rc = -1;
            break;
        }
        const void * data = l_buf + sizeof(p);
        uint64_t d_size = p->len - sizeof(p);

        ErrlUD * ud = new ErrlUD(data,d_size,p->compId,p->ver,p->sst);
        consumed    += p->len;
        l_buf       += p->len;

        iv_SectionVector.push_back(ud);
    }

    // if we didn't get as many User Detail sections as the Private header says
    // we should have, then we have an error
    if ((iv_SectionVector.size() + 3) != iv_Private.iv_sctns)
    {
        rc = -1;
    }

    return rc;
}

//@brief Return the list of User Detail sections
//NOTE: You can pass COMP_ID or subsect 0 into this function for wildcard
std::vector<void*> ErrlEntry::getUDSections(compId_t i_compId,
                                            uint8_t i_subSect)
{
    std::vector<void *> copy_vector;

    for(auto const & section : iv_SectionVector)
    {
        if((section->compId() == i_compId) || (i_compId == 0))
        {
            if((section->subSect() == i_subSect) || (i_subSect == 0))
            {
                copy_vector.push_back(section->iv_pData);
            }
        }
    }

    return copy_vector;
}

void ErrlEntry::removeDeconfigure()
{
    //Loop through each section of the errorlog
    for(auto & section : iv_SectionVector)
    {
        if (section->compId() == ERRL_COMP_ID && section->subSect() == ERRORLOG::ERRL_UDT_CALLOUT)
        {
            //Looking at hwasCallout.H only the HW, CLOCK, and PART Callouts have deconfigure entries,
            //  so only update those to ensure the ErrorType is GARD_NULL
            if (reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->type == HWAS::HW_CALLOUT)
            {
                reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->gardErrorType = HWAS::GARD_NULL;
                reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->deconfigState = HWAS::NO_DECONFIG;
            }
            else if (reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->type == HWAS::CLOCK_CALLOUT)
            {
                reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->clkGardErrorType = HWAS::GARD_NULL;
                reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->clkDeconfigState = HWAS::NO_DECONFIG;
            }
            else if (reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->type == HWAS::PART_CALLOUT)
            {
                reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->partGardErrorType = HWAS::GARD_NULL;
                reinterpret_cast<HWAS::callout_ud_t*>(section->iv_pData)->partDeconfigState = HWAS::NO_DECONFIG;
            }
        }
    }
}

void ErrlEntry::removeDuplicateTraces()
{
    // Define a custom comparator function for std::map.find()
    struct mapComparator
    {
        bool operator()(const char* a, const char * b) const
        {
            return strcmp(a, b) < 0;
        }
    };

    // map of component id and corresponding trace entries.
    std::map<const char *, std::vector<TRACE::trace_bin_entry_t*>*,
             mapComparator> traceUD_map;
    auto it = traceUD_map.end();

    uint64_t l_flatSize = flattenedSize();

    // vector that will hold all of the trace UD sections
    // that are free of duplicates.
    std::vector<ErrlUD*> l_uniqueTraceUDVector;


    // Iterate through iv_SectionVector and create a map of all unique
    // component ids and their corresponding trace entries.
    for(auto sectionVectorIt = iv_SectionVector.begin();
       (sectionVectorIt != iv_SectionVector.end()) && (l_flatSize != 0);
        ++sectionVectorIt)
    {
        // If UD section is a trace.
        if( (FIPS_ERRL_COMP_ID   == (*sectionVectorIt)->iv_header.iv_compId)
          && (FIPS_ERRL_UDT_HB_TRACE == (*sectionVectorIt)->iv_header.iv_sst) )
        {
            char* l_data = static_cast<char*>((*sectionVectorIt)->data());

            TRACE::trace_buf_head_t* l_trace_buf_head =
                reinterpret_cast<TRACE::trace_buf_head_t*>(l_data);

            // Look for the component id in the map to insert trace entries
            // or insert a new component id into the map to insert trace entries
            const char* l_compName = l_trace_buf_head->comp;

            it = traceUD_map.find(l_compName);

            if (traceUD_map.end() == it)
            {
                traceUD_map[l_compName] =
                    new std::vector<TRACE::trace_bin_entry_t*>;
                it = traceUD_map.find(l_compName);
            }

            // Add all trace entries to map for the current component id.
            l_data += l_trace_buf_head->hdr_len;

            for (size_t traceCount = 0; traceCount < l_trace_buf_head->te_count;
                 traceCount++)
            {
                TRACE::trace_bin_entry_t* l_trace_entry =
                    reinterpret_cast<TRACE::trace_bin_entry_t*>(l_data);

                it->second->push_back(l_trace_entry);

                // fsp-trace entries have an extra 4 bytes at the end of them
                // hence the sizeof(uint32_t)
                l_data += sizeof(TRACE::trace_bin_entry_t)
                        + ALIGN_8(l_trace_entry->head.length)
                        + sizeof(uint32_t);
            }
        }
    }

    // Iterate through the map to apply duplicate pruning to all component ids
    // found in iv_SectionVector
    for (auto const& it : traceUD_map)
    {
        // Sort the vector by timestamp and hash
        std::sort(it.second->begin(), it.second->end(),
                  // Define a lambda comparator function for sorting criteria
                  [](const TRACE::trace_bin_entry_t* a,
                      const TRACE::trace_bin_entry_t* b)
                    {
                        // a goes before b if a's timestamp is less than b's.
                        // If they are equal then compare the hash values.
                        bool result = false;
                        if (a->stamp.tbh < b->stamp.tbh)
                        {
                            result = true;
                        }
                        else if ((a->stamp.tbh == b->stamp.tbh)
                                 && (a->stamp.tbl < b->stamp.tbl))
                        {
                            result = true;
                        }
                        else if ((a->stamp.tbh == b->stamp.tbh)
                                && (a->stamp.tbl == b->stamp.tbl)
                                && (a->head.hash < b->head.hash))
                        {
                            result = true;
                        }
                        return result;
                    });

        // Call unique to prune the duplicate trace entries
        auto newEndIt = std::unique(it.second->begin(), it.second->end(),
                    // Define a lambda predicate function for duplicate criteria
                    [](const TRACE::trace_bin_entry_t* a,
                       const TRACE::trace_bin_entry_t* b)
                    {
                        // a is equivalent to b if a's timestamp is the same as
                        // b's and their hashes are the same.
                        bool result = false;
                        if ((a->stamp.tbh == b->stamp.tbh)
                            && (a->stamp.tbl == b->stamp.tbl)
                            && (a->head.hash == b->head.hash))
                        {
                            result = true;
                        }
                        return result;
                    });

        it.second->resize(std::distance(it.second->begin(), newEndIt));

        // Calculate the size of the buffer that will hold all remaining
        // trace entries in the new UD section
        size_t uniqueSize = sizeof(TRACE::trace_buf_head_t);

        for (auto uniqueIt = it.second->begin(); uniqueIt != it.second->end();
             ++uniqueIt)
        {
            uniqueSize += sizeof(TRACE::trace_bin_entry_t)
                          + ALIGN_8((*uniqueIt)->head.length)
                          + sizeof(uint32_t);
        }


        // Create a new buffer for the new UD section from the vector of traces
        // for this component id.
        TRACE::trace_buf_head_t* header = nullptr;
        char* l_pBuffer = new char[ uniqueSize ]();
        size_t l_pos = 0;

        // Write the header info to the buffer.
        // This header info was chosen based on the code that is found in
        // Buffer::getTrace() if that code is changed in the future those
        // changes will need to be reflected here.
        header = reinterpret_cast<TRACE::trace_buf_head_t*>(&l_pBuffer[l_pos]);

        memset(header, '\0', sizeof(TRACE::trace_buf_head_t));

        header->ver = TRACE::TRACE_BUF_VERSION;
        header->hdr_len = sizeof(TRACE::trace_buf_head_t);
        header->time_flg = TRACE::TRACE_TIME_REAL;
        header->endian_flg = 'B';
        memcpy(&header->comp[0], it.first, TRAC_COMP_SIZE);
        header->times_wrap = 0;
        header->te_count = it.second->size();
        header->size = uniqueSize;
        header->next_free = uniqueSize;

        l_pos += header->hdr_len;

        // Copy the trace entries to the buffer
        for (auto uniqueIt = it.second->begin(); uniqueIt != it.second->end();
                ++uniqueIt)
        {
            // fsp-traces have an extra 4 bytes. Hence the sizeof(uint32_t)
            size_t entrySize = sizeof(TRACE::trace_bin_entry_t)
                             + ALIGN_8((*uniqueIt)->head.length)
                             + sizeof(uint32_t);

            memcpy(&l_pBuffer[l_pos], (*uniqueIt), entrySize);

            l_pos += entrySize;

        }

        ErrlUD* l_udSection = new ErrlUD( l_pBuffer,
                                          uniqueSize,
                                          FIPS_ERRL_COMP_ID,
                                          FIPS_ERRL_UDV_DEFAULT_VER_1,
                                          FIPS_ERRL_UDT_HB_TRACE );

        l_uniqueTraceUDVector.push_back(l_udSection);

        delete[] l_pBuffer;
        delete it.second;
    }

    // Remove old trace UD sections
    auto sectionVectorIt = iv_SectionVector.begin();
    while(sectionVectorIt != iv_SectionVector.end())
    {
        // If UD section is a trace.
        if( (FIPS_ERRL_COMP_ID   == (*sectionVectorIt)->iv_header.iv_compId)
          && (FIPS_ERRL_UDT_HB_TRACE == (*sectionVectorIt)->iv_header.iv_sst))
        {
            // Remove the ErrlUD* at this position
            delete (*sectionVectorIt);
            // Erase this entry from the vector
            sectionVectorIt = iv_SectionVector.erase(sectionVectorIt);
        }
        else
        {
            ++sectionVectorIt;
        }

    }

    // Add new trace UD sections
    for(auto it = l_uniqueTraceUDVector.begin();
        it != l_uniqueTraceUDVector.end();
        ++it)
    {
        iv_SectionVector.push_back((*it));
    }

}



/**
 * @brief Check if the severity of this log indicates it is
 *   customer visible, note this ignores any override flags that
 *   might change standard behavior
 * @return true if log is visible
 */
bool ErrlEntry::isSevVisible( void )
{
    bool l_vis = true;
    switch( sev() )
    {
        // Hidden logs
        case( ERRL_SEV_INFORMATIONAL ): l_vis = false; break;
        case( ERRL_SEV_RECOVERED ): l_vis = false; break;

        // Visible logs
        case( ERRL_SEV_PREDICTIVE ): l_vis = true; break;
        case( ERRL_SEV_UNRECOVERABLE ): l_vis = true; break;
        case( ERRL_SEV_CRITICAL_SYS_TERM ): l_vis = true; break;

        // Error case, shouldn't happen so make it show up
        case( ERRL_SEV_UNKNOWN ): l_vis = true; break;
    }
    return l_vis;
}

void ErrlEntry::addI2cDeviceCallout(const TARGETING::Target *i_i2cMaster,
                                    const uint8_t i_engine,
                                    const uint8_t i_port,
                                    const uint8_t i_address,
                                    const HWAS::callOutPriority i_priority)
{
    do {

    if (i_i2cMaster == nullptr ||
        i_i2cMaster == TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL)
    {

        TRACFCOMP(g_trac_errl, ERR_MRK
                  "addI2cDeviceCallout mistakenly called with %s target. "
                  "Adding high priority callout to the error log.",
                  i_i2cMaster? "MASTER_SENTINEL": "nullptr");
        addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                             HWAS::SRCI_PRIORITY_HIGH);
        collectTrace(ERRL_COMP_NAME);
        break;
    }

    #ifdef CONFIG_ERRL_ENTRY_TRACE
    TRACFCOMP(g_trac_errl, ENTER_MRK
            "addI2cDeviceCallout(i2cm=0x%.8x e=0x%x p=0x%x devAddr=0x%x pri=0x%x)",
            get_huid(i_i2cMaster), i_engine, i_port, i_address, i_priority);
    #else
    TRACDCOMP(g_trac_errl, ENTER_MRK
            "addI2cDeviceCallout(i2cm=0x%.8x e=0x%x p=0x%x devAddr=0x%x pri=0x%x)",
            get_huid(i_i2cMaster), i_engine, i_port, i_address, i_priority);
    #endif

    const void* pData = nullptr;
    uint32_t size = 0;
    TARGETING::EntityPath* ep = nullptr;
    getTargData( i_i2cMaster, ep, pData, size );


    ErrlUserDetailsCallout(pData, size,
            i_engine, i_port, i_address, i_priority).addToLog(this);

    if (ep)
    {
        delete ep;
        ep = nullptr;
    }

    handleI2cDeviceCalloutWithinHostboot(this, i_i2cMaster, i_engine, i_port, i_address, i_priority);

    } while (0);

} // addI2cDeviceCallout


} // End namespace

OpenPOWER on IntegriCloud