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 | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 23 | void initializeIsolator(const std::vector<libhei::Chip>& i_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 | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 72 | // Returns the chip model/level of the given target. |
| 73 | libhei::ChipType_t __getChipType(pdbg_target* i_trgt) |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 74 | { |
| 75 | libhei::ChipType_t type; |
| 76 | |
| 77 | // START WORKAROUND |
| 78 | // TODO: Will need to grab the model/level from the target attributes when |
| 79 | // they are available. For now, use ATTR_TYPE to determine which |
| 80 | // currently supported value to use supported. |
Zane Shelley | a029985 | 2020-11-13 13:38:04 -0600 | [diff] [blame^] | 81 | uint8_t attrType = util::pdbg::getTrgtType(i_trgt); |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 82 | switch (attrType) |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 83 | { |
| 84 | case 0x05: // PROC |
| 85 | type = 0x120DA049; |
| 86 | break; |
| 87 | |
| 88 | case 0x4b: // OCMB_CHIP |
| 89 | type = 0x160D2000; |
| 90 | break; |
| 91 | |
| 92 | default: |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 93 | trace::err("Unsupported ATTR_TYPE value: 0x%02x", attrType); |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 94 | assert(0); |
| 95 | } |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 96 | // END WORKAROUND |
| 97 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 98 | return type; |
| 99 | } |
| 100 | |
| 101 | //------------------------------------------------------------------------------ |
| 102 | |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 103 | // Gathers list of active chips to analyze. |
| 104 | void __getActiveChips(std::vector<libhei::Chip>& o_chips) |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 105 | { |
| 106 | // Iterate each processor. |
| 107 | pdbg_target* procTrgt; |
| 108 | pdbg_for_each_class_target("proc", procTrgt) |
| 109 | { |
| 110 | // Active processors only. |
| 111 | if (PDBG_TARGET_ENABLED != pdbg_target_probe(procTrgt)) |
| 112 | continue; |
| 113 | |
| 114 | // Add the processor to the list. |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 115 | o_chips.emplace_back(procTrgt, __getChipType(procTrgt)); |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 116 | |
| 117 | // Iterate the connected OCMBs, if they exist. |
| 118 | pdbg_target* ocmbTrgt; |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 119 | pdbg_for_each_target("ocmb", procTrgt, ocmbTrgt) |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 120 | { |
| 121 | // Active OCMBs only. |
| 122 | if (PDBG_TARGET_ENABLED != pdbg_target_probe(ocmbTrgt)) |
| 123 | continue; |
| 124 | |
| 125 | // Add the OCMB to the list. |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 126 | o_chips.emplace_back(ocmbTrgt, __getChipType(ocmbTrgt)); |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 127 | } |
| 128 | } |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | //------------------------------------------------------------------------------ |
| 132 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 133 | // Takes a signature list that will be filtered and sorted. The first entry in |
| 134 | // the returned list will be the root cause. If the returned list is empty, |
| 135 | // analysis failed. |
| 136 | void __filterRootCause(std::vector<libhei::Signature>& io_list) |
| 137 | { |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 138 | // For debug, trace out the original list of signatures before filtering. |
| 139 | for (const auto& sig : io_list) |
| 140 | { |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 141 | trace::inf("Signature: %s 0x%0" PRIx32 " %s", |
| 142 | util::pdbg::getPath(sig.getChip()), __sig(sig), |
| 143 | __attn(sig.getAttnType())); |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 146 | // Special and host attentions are not supported by this user application. |
| 147 | auto newEndItr = |
| 148 | std::remove_if(io_list.begin(), io_list.end(), [&](const auto& t) { |
| 149 | return (libhei::ATTN_TYPE_SP_ATTN == t.getAttnType() || |
| 150 | libhei::ATTN_TYPE_HOST_ATTN == t.getAttnType()); |
| 151 | }); |
| 152 | |
| 153 | // Shrink the vector, if needed. |
| 154 | io_list.resize(std::distance(io_list.begin(), newEndItr)); |
| 155 | |
| 156 | // START WORKAROUND |
| 157 | // TODO: Filtering should be determined by the RAS Data Files provided by |
| 158 | // the host firmware via the PNOR (similar to the Chip Data Files). |
| 159 | // Until that support is available, use a rudimentary filter that |
| 160 | // first looks for any recoverable attention, then any unit checkstop, |
| 161 | // and then any system checkstop. This is built on the premise that |
| 162 | // recoverable errors could be the root cause of an system checkstop |
| 163 | // attentions. Fortunately, we just need to sort the list by the |
| 164 | // greater attention type value. |
| 165 | std::sort(io_list.begin(), io_list.end(), |
| 166 | [&](const auto& a, const auto& b) { |
| 167 | return a.getAttnType() > b.getAttnType(); |
| 168 | }); |
| 169 | // END WORKAROUND |
| 170 | } |
| 171 | |
| 172 | //------------------------------------------------------------------------------ |
| 173 | |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 174 | bool __logError(const std::vector<libhei::Signature>& i_sigList, |
| 175 | const libhei::IsolationData& i_isoData) |
| 176 | { |
| 177 | bool attnFound = false; |
| 178 | |
| 179 | // Get numerical values for the root cause. |
| 180 | uint32_t word6 = 0; // [ 0: 7]: chip target type |
| 181 | // [ 8:31]: chip FAPI position |
| 182 | // uint32_t word7 = 0; // TODO: chip target info |
| 183 | uint32_t word8 = 0; // [ 0:15]: node ID |
| 184 | // [16:23]: node instance |
| 185 | // [24:31]: bit position |
| 186 | // uint32_t word9 = 0; // [ 0: 7]: attention type |
| 187 | |
| 188 | if (i_sigList.empty()) |
| 189 | { |
| 190 | trace::inf("No active attentions found"); |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | attnFound = true; |
| 195 | |
| 196 | // The root cause attention is the first in the filtered list. |
| 197 | libhei::Signature root = i_sigList.front(); |
| 198 | |
| 199 | word6 = __trgt(root); |
| 200 | word8 = __sig(root); |
| 201 | |
| 202 | trace::inf("Root cause attention: %s 0x%0" PRIx32 " %s", |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 203 | util::pdbg::getPath(root.getChip()), word8, |
| 204 | __attn(root.getAttnType())); |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // Get the log data. |
| 208 | std::map<std::string, std::string> logData; |
| 209 | logData["_PID"] = std::to_string(getpid()); |
| 210 | logData["CHIP_ID"] = std::to_string(word6); |
| 211 | logData["SIGNATURE"] = std::to_string(word8); |
| 212 | |
| 213 | // Get access to logging interface and method for creating log. |
| 214 | auto bus = sdbusplus::bus::new_default_system(); |
| 215 | |
| 216 | // Using direct create method (for additional data) |
| 217 | auto method = bus.new_method_call( |
| 218 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 219 | "xyz.openbmc_project.Logging.Create", "Create"); |
| 220 | |
| 221 | // Attach additional data |
| 222 | method.append("org.open_power.HwDiags.Error.Checkstop", |
| 223 | "xyz.openbmc_project.Logging.Entry.Level.Error", logData); |
| 224 | |
| 225 | // Log the event. |
| 226 | // TODO: Should the reply be handled? |
| 227 | bus.call(method); |
| 228 | |
| 229 | return attnFound; |
| 230 | } |
| 231 | |
| 232 | //------------------------------------------------------------------------------ |
| 233 | |
| 234 | bool analyzeHardware() |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 235 | { |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 236 | bool attnFound = false; |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 237 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 238 | trace::inf(">>> enter analyzeHardware()"); |
| 239 | |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 240 | // Get the active chips to be analyzed. |
| 241 | std::vector<libhei::Chip> chips; |
| 242 | __getActiveChips(chips); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 243 | |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 244 | // Initialize the isolator for all chips. |
| 245 | trace::inf("Initializing the isolator..."); |
| 246 | initializeIsolator(chips); |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 247 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 248 | // Isolate attentions. |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 249 | trace::inf("Isolating errors: # of chips=%u", chips.size()); |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 250 | libhei::IsolationData isoData{}; |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 251 | libhei::isolate(chips, isoData); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 252 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 253 | // Filter signatures to determine root cause. We'll need to make a copy of |
| 254 | // the list so that the original list is maintained for the log. |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 255 | std::vector<libhei::Signature> sigList{isoData.getSignatureList()}; |
| 256 | __filterRootCause(sigList); |
| 257 | |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 258 | // Create and commit a log. |
| 259 | attnFound = __logError(sigList, isoData); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 260 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 261 | // All done, clean up the isolator. |
Zane Shelley | f4bd5ff | 2020-11-05 22:26:04 -0600 | [diff] [blame] | 262 | trace::inf("Uninitializing isolator..."); |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 263 | libhei::uninitialize(); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 264 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 265 | trace::inf("<<< exit analyzeHardware()"); |
| 266 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 267 | return attnFound; |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | } // namespace analyzer |