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