Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 1 | #include <libpdbg.h> |
| 2 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 3 | #include <hei_main.hpp> |
| 4 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 5 | #include <fstream> |
| 6 | #include <iostream> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 7 | #include <map> |
| 8 | #include <string> |
| 9 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 10 | namespace analyzer |
| 11 | { |
| 12 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 13 | /** @brief Chip types that coorelate device tree nodes to chip data files */ |
| 14 | static constexpr uint8_t chipTypeOcmb[4] = {0x00, 0x20, 0x0d, 0x16}; |
| 15 | static 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 | */ |
| 29 | bool initWithFile(const char* i_filePath) |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 30 | { |
Ben Tyner | b859d79 | 2020-05-06 21:29:47 -0500 | [diff] [blame] | 31 | using namespace libhei; |
| 32 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 33 | bool rc = true; // assume success |
Ben Tyner | b859d79 | 2020-05-06 21:29:47 -0500 | [diff] [blame] | 34 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 35 | // open the file and seek to the end to get length |
| 36 | std::ifstream fileStream(i_filePath, std::ios::binary | std::ios::ate); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 37 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 38 | if (!fileStream) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 39 | { |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 40 | std::cout << "could not open file" << std::endl; |
| 41 | rc = false; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 42 | } |
| 43 | else |
| 44 | { |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 45 | // 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 Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 62 | } |
Ben Tyner | b859d79 | 2020-05-06 21:29:47 -0500 | [diff] [blame] | 63 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 64 | return rc; |
| 65 | } |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 66 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 67 | /** |
| 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 | */ |
| 80 | bool analyzeHardware(std::map<std::string, std::string>& o_errors) |
| 81 | { |
| 82 | using namespace libhei; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 83 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 84 | 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 Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | } // namespace analyzer |