blob: 6a4754099574729c88f4f77c42a3d70896dc46af [file] [log] [blame]
Ben Tyner87eabc62020-05-14 17:56:54 -05001#include <libpdbg.h>
2
Ben Tyner0205f3b2020-02-24 10:24:47 -06003#include <hei_main.hpp>
4
Ben Tyner87eabc62020-05-14 17:56:54 -05005#include <fstream>
6#include <iostream>
Ben Tynerb1ebfcb2020-05-08 18:52:48 -05007#include <map>
8#include <string>
9
Ben Tyner0205f3b2020-02-24 10:24:47 -060010namespace analyzer
11{
12
Ben Tyner87eabc62020-05-14 17:56:54 -050013/** @brief Chip types that coorelate device tree nodes to chip data files */
14static constexpr uint8_t chipTypeOcmb[4] = {0x00, 0x20, 0x0d, 0x16};
15static constexpr uint8_t chipTypeProc[4] = {0x49, 0xa0, 0x0d, 0x12};
16
17/**
18 * @brief send chip data file to isolator
19 *
20 * Read a chip data file into memory and then send it to the isolator via
21 * the initialize interface.
22 *
23 * @param i_filePath The file path and name to read into memory
24 *
25 * @return Returns true if the isolator was successfully initialized with
26 * a single chip data file. Returns false otherwise.
27 *
28 */
29bool initWithFile(const char* i_filePath)
Ben Tyner0205f3b2020-02-24 10:24:47 -060030{
Ben Tynerb859d792020-05-06 21:29:47 -050031 using namespace libhei;
32
Ben Tyner87eabc62020-05-14 17:56:54 -050033 bool rc = true; // assume success
Ben Tynerb859d792020-05-06 21:29:47 -050034
Ben Tyner87eabc62020-05-14 17:56:54 -050035 // open the file and seek to the end to get length
36 std::ifstream fileStream(i_filePath, std::ios::binary | std::ios::ate);
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050037
Ben Tyner87eabc62020-05-14 17:56:54 -050038 if (!fileStream)
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050039 {
Ben Tyner87eabc62020-05-14 17:56:54 -050040 std::cout << "could not open file" << std::endl;
41 rc = false;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050042 }
43 else
44 {
Ben Tyner87eabc62020-05-14 17:56:54 -050045 // get file size based on seek position
46 std::ifstream::pos_type fileSize = fileStream.tellg();
47
48 // create a buffer large enough to hold the entire file
49 std::vector<char> fileBuffer(fileSize);
50
51 // seek to the beginning of the file
52 fileStream.seekg(0, std::ios::beg);
53
54 // read the entire file into the buffer
55 fileStream.read(fileBuffer.data(), fileSize);
56
57 // done with the file
58 fileStream.close();
59
60 // intialize the isolator with the chip data
61 initialize(fileBuffer.data(), fileSize); // hei initialize
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050062 }
Ben Tynerb859d792020-05-06 21:29:47 -050063
Ben Tyner87eabc62020-05-14 17:56:54 -050064 return rc;
65}
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050066
Ben Tyner87eabc62020-05-14 17:56:54 -050067/**
68 * @brief Analyze using the hardware error isolator
69 *
70 * Query the hardware for each active chip that is a valid candidate for
71 * error analyses. Based on the list of active chips initialize the
72 * isolator with the associated chip data files. Finally request analyses
73 * from the hardware error isolator and log the results.
74 *
75 * @param o_errors A map for storing information about erros that were
76 * detected by the hardware error isolator.
77 *
78 * @return True if hardware error analyses was successful, false otherwise
79 */
80bool analyzeHardware(std::map<std::string, std::string>& o_errors)
81{
82 using namespace libhei;
Ben Tynerb1ebfcb2020-05-08 18:52:48 -050083
Ben Tyner87eabc62020-05-14 17:56:54 -050084 bool rc = true;
85
86 std::vector<Chip> chipList; // chips that need to be analyzed
87
88 IsolationData isoData{}; // data from isolato
89
90 pdbg_target *targetProc, *targetOcmb; // P10 and explorer targets
91
92 /** @brief gather list of chips to analyze */
93 pdbg_for_each_class_target("proc", targetProc)
94 {
95 if (PDBG_TARGET_ENABLED == pdbg_target_probe(targetProc))
96 {
97 // add each processor chip to the chip list
98 chipList.emplace_back(Chip(targetProc, *(uint32_t*)chipTypeProc));
99
100 pdbg_for_each_target("ocmb_chip", targetProc, targetOcmb)
101 {
102 if (PDBG_TARGET_ENABLED == pdbg_target_probe(targetOcmb))
103 {
104 // add each explorer chip (ocmb) to the chip list
105 chipList.emplace_back(
106 Chip(targetOcmb, *(uint32_t*)chipTypeOcmb));
107 }
108 }
109 }
110 }
111
112 // TODO select chip data files based on chip types detected
113 do
114 {
115 // TODO for now chip data files are local
116 // hei initialize
117 if (false ==
118 initWithFile("/usr/share/openpower-hw-diags/chip_data_ocmb.cdb"))
119 {
120 rc = false;
121 break;
122 }
123
124 // TODO for now chip data files are local
125 // hei initialize
126 if (false ==
127 initWithFile("/usr/share/openpower-hw-diags/chip_data_proc.cdb"))
128 {
129 rc = false;
130 break;
131 }
132
133 // hei isolate
134 isolate(chipList, isoData);
135
136 if (!(isoData.getSignatureList().empty()))
137 {
138 // TODO parse signature list
139 int numErrors = isoData.getSignatureList().size();
140
141 std::cout << "isolated: " << numErrors << std::endl;
142 }
143
144 // hei uninitialize
145 uninitialize();
146
147 } while (0);
148
149 return rc;
Ben Tyner0205f3b2020-02-24 10:24:47 -0600150}
151
152} // namespace analyzer