Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 1 | #include <assert.h> |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 2 | #include <libpdbg.h> |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 3 | #include <unistd.h> |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 4 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 5 | #include <hei_main.hpp> |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/log.hpp> |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 7 | #include <util/pdbg.hpp> |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 8 | #include <util/trace.hpp> |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 9 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 10 | #include <algorithm> |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 11 | #include <fstream> |
| 12 | #include <iostream> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 13 | #include <map> |
| 14 | #include <string> |
| 15 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 16 | namespace analyzer |
| 17 | { |
| 18 | |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 19 | //------------------------------------------------------------------------------ |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 20 | |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 21 | // Forward references for externally defined functions. |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 22 | |
Zane Shelley | 171a2e0 | 2020-11-13 13:56:13 -0600 | [diff] [blame] | 23 | void initializeIsolator(std::vector<libhei::Chip>& o_chips); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 24 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 25 | //------------------------------------------------------------------------------ |
| 26 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 27 | const char* __attn(libhei::AttentionType_t i_attnType) |
| 28 | { |
| 29 | const char* str = ""; |
| 30 | switch (i_attnType) |
| 31 | { |
| 32 | case libhei::ATTN_TYPE_CHECKSTOP: |
| 33 | str = "CHECKSTOP"; |
| 34 | break; |
| 35 | case libhei::ATTN_TYPE_UNIT_CS: |
| 36 | str = "UNIT_CS"; |
| 37 | break; |
| 38 | case libhei::ATTN_TYPE_RECOVERABLE: |
| 39 | str = "RECOVERABLE"; |
| 40 | break; |
| 41 | case libhei::ATTN_TYPE_SP_ATTN: |
| 42 | str = "SP_ATTN"; |
| 43 | break; |
| 44 | case libhei::ATTN_TYPE_HOST_ATTN: |
| 45 | str = "HOST_ATTN"; |
| 46 | break; |
| 47 | default: |
| 48 | trace::err("Unsupported attention type: %u", i_attnType); |
| 49 | assert(0); |
| 50 | } |
| 51 | return str; |
| 52 | } |
| 53 | |
| 54 | uint32_t __trgt(const libhei::Signature& i_sig) |
| 55 | { |
Zane Shelley | a029985 | 2020-11-13 13:38:04 -0600 | [diff] [blame] | 56 | uint8_t type = util::pdbg::getTrgtType(i_sig.getChip()); |
| 57 | uint32_t pos = util::pdbg::getChipPos(i_sig.getChip()); |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 58 | |
| 59 | // Technically, the FapiPos attribute is 32-bit, but not likely to ever go |
| 60 | // over 24-bit. |
| 61 | |
| 62 | return type << 24 | (pos & 0xffffff); |
| 63 | } |
| 64 | |
| 65 | uint32_t __sig(const libhei::Signature& i_sig) |
| 66 | { |
| 67 | return i_sig.getId() << 16 | i_sig.getInstance() << 8 | i_sig.getBit(); |
| 68 | } |
| 69 | |
| 70 | //------------------------------------------------------------------------------ |
| 71 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 72 | // Takes a signature list that will be filtered and sorted. The first entry in |
| 73 | // the returned list will be the root cause. If the returned list is empty, |
| 74 | // analysis failed. |
| 75 | void __filterRootCause(std::vector<libhei::Signature>& io_list) |
| 76 | { |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 77 | // For debug, trace out the original list of signatures before filtering. |
| 78 | for (const auto& sig : io_list) |
| 79 | { |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 80 | trace::inf("Signature: %s 0x%0" PRIx32 " %s", |
| 81 | util::pdbg::getPath(sig.getChip()), __sig(sig), |
| 82 | __attn(sig.getAttnType())); |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 85 | // Special and host attentions are not supported by this user application. |
| 86 | auto newEndItr = |
| 87 | std::remove_if(io_list.begin(), io_list.end(), [&](const auto& t) { |
| 88 | return (libhei::ATTN_TYPE_SP_ATTN == t.getAttnType() || |
| 89 | libhei::ATTN_TYPE_HOST_ATTN == t.getAttnType()); |
| 90 | }); |
| 91 | |
| 92 | // Shrink the vector, if needed. |
| 93 | io_list.resize(std::distance(io_list.begin(), newEndItr)); |
| 94 | |
| 95 | // START WORKAROUND |
| 96 | // TODO: Filtering should be determined by the RAS Data Files provided by |
| 97 | // the host firmware via the PNOR (similar to the Chip Data Files). |
| 98 | // Until that support is available, use a rudimentary filter that |
| 99 | // first looks for any recoverable attention, then any unit checkstop, |
| 100 | // and then any system checkstop. This is built on the premise that |
| 101 | // recoverable errors could be the root cause of an system checkstop |
| 102 | // attentions. Fortunately, we just need to sort the list by the |
| 103 | // greater attention type value. |
| 104 | std::sort(io_list.begin(), io_list.end(), |
| 105 | [&](const auto& a, const auto& b) { |
| 106 | return a.getAttnType() > b.getAttnType(); |
| 107 | }); |
| 108 | // END WORKAROUND |
| 109 | } |
| 110 | |
| 111 | //------------------------------------------------------------------------------ |
| 112 | |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 113 | bool __logError(const std::vector<libhei::Signature>& i_sigList, |
| 114 | const libhei::IsolationData& i_isoData) |
| 115 | { |
| 116 | bool attnFound = false; |
| 117 | |
| 118 | // Get numerical values for the root cause. |
| 119 | uint32_t word6 = 0; // [ 0: 7]: chip target type |
| 120 | // [ 8:31]: chip FAPI position |
| 121 | // uint32_t word7 = 0; // TODO: chip target info |
| 122 | uint32_t word8 = 0; // [ 0:15]: node ID |
| 123 | // [16:23]: node instance |
| 124 | // [24:31]: bit position |
| 125 | // uint32_t word9 = 0; // [ 0: 7]: attention type |
| 126 | |
| 127 | if (i_sigList.empty()) |
| 128 | { |
| 129 | trace::inf("No active attentions found"); |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | attnFound = true; |
| 134 | |
| 135 | // The root cause attention is the first in the filtered list. |
| 136 | libhei::Signature root = i_sigList.front(); |
| 137 | |
| 138 | word6 = __trgt(root); |
| 139 | word8 = __sig(root); |
| 140 | |
| 141 | trace::inf("Root cause attention: %s 0x%0" PRIx32 " %s", |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 142 | util::pdbg::getPath(root.getChip()), word8, |
| 143 | __attn(root.getAttnType())); |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | // Get the log data. |
| 147 | std::map<std::string, std::string> logData; |
| 148 | logData["_PID"] = std::to_string(getpid()); |
| 149 | logData["CHIP_ID"] = std::to_string(word6); |
| 150 | logData["SIGNATURE"] = std::to_string(word8); |
| 151 | |
| 152 | // Get access to logging interface and method for creating log. |
| 153 | auto bus = sdbusplus::bus::new_default_system(); |
| 154 | |
| 155 | // Using direct create method (for additional data) |
| 156 | auto method = bus.new_method_call( |
| 157 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 158 | "xyz.openbmc_project.Logging.Create", "Create"); |
| 159 | |
| 160 | // Attach additional data |
| 161 | method.append("org.open_power.HwDiags.Error.Checkstop", |
| 162 | "xyz.openbmc_project.Logging.Entry.Level.Error", logData); |
| 163 | |
| 164 | // Log the event. |
| 165 | // TODO: Should the reply be handled? |
| 166 | bus.call(method); |
| 167 | |
| 168 | return attnFound; |
| 169 | } |
| 170 | |
| 171 | //------------------------------------------------------------------------------ |
| 172 | |
| 173 | bool analyzeHardware() |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 174 | { |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 175 | bool attnFound = false; |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 176 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 177 | trace::inf(">>> enter analyzeHardware()"); |
| 178 | |
Zane Shelley | 171a2e0 | 2020-11-13 13:56:13 -0600 | [diff] [blame] | 179 | // Initialize the isolator and get all of the chips to be analyzed. |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 180 | trace::inf("Initializing the isolator..."); |
Zane Shelley | 171a2e0 | 2020-11-13 13:56:13 -0600 | [diff] [blame] | 181 | std::vector<libhei::Chip> chips; |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 182 | initializeIsolator(chips); |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 183 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 184 | // Isolate attentions. |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 185 | trace::inf("Isolating errors: # of chips=%u", chips.size()); |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 186 | libhei::IsolationData isoData{}; |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 187 | libhei::isolate(chips, isoData); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 188 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 189 | // Filter signatures to determine root cause. We'll need to make a copy of |
| 190 | // the list so that the original list is maintained for the log. |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 191 | std::vector<libhei::Signature> sigList{isoData.getSignatureList()}; |
| 192 | __filterRootCause(sigList); |
| 193 | |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 194 | // Create and commit a log. |
| 195 | attnFound = __logError(sigList, isoData); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 196 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 197 | // All done, clean up the isolator. |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 198 | trace::inf("Uninitializing isolator..."); |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 199 | libhei::uninitialize(); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 200 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 201 | trace::inf("<<< exit analyzeHardware()"); |
| 202 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 203 | return attnFound; |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | } // namespace analyzer |