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 | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 7 | #include <util/trace.hpp> |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 8 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 9 | #include <algorithm> |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 10 | #include <fstream> |
| 11 | #include <iostream> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 12 | #include <map> |
| 13 | #include <string> |
| 14 | |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 15 | namespace analyzer |
| 16 | { |
| 17 | |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 18 | /** |
| 19 | * @brief send chip data file to isolator |
| 20 | * |
| 21 | * Read a chip data file into memory and then send it to the isolator via |
| 22 | * the initialize interface. |
| 23 | * |
| 24 | * @param i_filePath The file path and name to read into memory |
| 25 | * |
| 26 | * @return Returns true if the isolator was successfully initialized with |
| 27 | * a single chip data file. Returns false otherwise. |
| 28 | * |
| 29 | */ |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 30 | void initWithFile(const char* i_filePath) |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 31 | { |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 32 | // open the file and seek to the end to get length |
| 33 | std::ifstream fileStream(i_filePath, std::ios::binary | std::ios::ate); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 34 | |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 35 | if (!fileStream.good()) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 36 | { |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 37 | trace::err("Unable to open file: %s", i_filePath); |
| 38 | assert(0); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 39 | } |
| 40 | else |
| 41 | { |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 42 | // get file size based on seek position |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 43 | fileStream.seekg(0, std::ios::end); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 44 | std::ifstream::pos_type fileSize = fileStream.tellg(); |
| 45 | |
| 46 | // create a buffer large enough to hold the entire file |
| 47 | std::vector<char> fileBuffer(fileSize); |
| 48 | |
| 49 | // seek to the beginning of the file |
| 50 | fileStream.seekg(0, std::ios::beg); |
| 51 | |
| 52 | // read the entire file into the buffer |
| 53 | fileStream.read(fileBuffer.data(), fileSize); |
| 54 | |
| 55 | // done with the file |
| 56 | fileStream.close(); |
| 57 | |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 58 | // initialize the isolator with the chip data |
| 59 | libhei::initialize(fileBuffer.data(), fileSize); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 60 | } |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 61 | } |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 62 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 63 | //------------------------------------------------------------------------------ |
| 64 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 65 | uint8_t __attrType(pdbg_target* i_trgt) |
| 66 | { |
| 67 | uint8_t attr = 0; |
| 68 | pdbg_target_get_attribute(i_trgt, "ATTR_TYPE", 1, 1, &attr); |
| 69 | return attr; |
| 70 | } |
| 71 | |
| 72 | uint32_t __attrFapiPos(pdbg_target* i_trgt) |
| 73 | { |
| 74 | uint32_t attr = 0; |
| 75 | pdbg_target_get_attribute(i_trgt, "ATTR_FAPI_POS", 4, 1, &attr); |
| 76 | return attr; |
| 77 | } |
| 78 | |
| 79 | //------------------------------------------------------------------------------ |
| 80 | |
| 81 | const char* __path(const libhei::Chip& i_chip) |
| 82 | { |
| 83 | return pdbg_target_path((pdbg_target*)i_chip.getChip()); |
| 84 | } |
| 85 | |
| 86 | const char* __attn(libhei::AttentionType_t i_attnType) |
| 87 | { |
| 88 | const char* str = ""; |
| 89 | switch (i_attnType) |
| 90 | { |
| 91 | case libhei::ATTN_TYPE_CHECKSTOP: |
| 92 | str = "CHECKSTOP"; |
| 93 | break; |
| 94 | case libhei::ATTN_TYPE_UNIT_CS: |
| 95 | str = "UNIT_CS"; |
| 96 | break; |
| 97 | case libhei::ATTN_TYPE_RECOVERABLE: |
| 98 | str = "RECOVERABLE"; |
| 99 | break; |
| 100 | case libhei::ATTN_TYPE_SP_ATTN: |
| 101 | str = "SP_ATTN"; |
| 102 | break; |
| 103 | case libhei::ATTN_TYPE_HOST_ATTN: |
| 104 | str = "HOST_ATTN"; |
| 105 | break; |
| 106 | default: |
| 107 | trace::err("Unsupported attention type: %u", i_attnType); |
| 108 | assert(0); |
| 109 | } |
| 110 | return str; |
| 111 | } |
| 112 | |
| 113 | uint32_t __trgt(const libhei::Signature& i_sig) |
| 114 | { |
| 115 | auto trgt = (pdbg_target*)i_sig.getChip().getChip(); |
| 116 | |
| 117 | uint8_t type = __attrType(trgt); |
| 118 | uint32_t pos = __attrFapiPos(trgt); |
| 119 | |
| 120 | // Technically, the FapiPos attribute is 32-bit, but not likely to ever go |
| 121 | // over 24-bit. |
| 122 | |
| 123 | return type << 24 | (pos & 0xffffff); |
| 124 | } |
| 125 | |
| 126 | uint32_t __sig(const libhei::Signature& i_sig) |
| 127 | { |
| 128 | return i_sig.getId() << 16 | i_sig.getInstance() << 8 | i_sig.getBit(); |
| 129 | } |
| 130 | |
| 131 | //------------------------------------------------------------------------------ |
| 132 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 133 | // Returns the chip model/level of the given target. Also, adds the chip |
| 134 | // model/level to the list of type types needed to initialize the isolator. |
| 135 | libhei::ChipType_t __getChipType(pdbg_target* i_trgt, |
| 136 | std::vector<libhei::ChipType_t>& o_types) |
| 137 | { |
| 138 | libhei::ChipType_t type; |
| 139 | |
| 140 | // START WORKAROUND |
| 141 | // TODO: Will need to grab the model/level from the target attributes when |
| 142 | // they are available. For now, use ATTR_TYPE to determine which |
| 143 | // currently supported value to use supported. |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 144 | uint8_t attrType = __attrType(i_trgt); |
| 145 | switch (attrType) |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 146 | { |
| 147 | case 0x05: // PROC |
| 148 | type = 0x120DA049; |
| 149 | break; |
| 150 | |
| 151 | case 0x4b: // OCMB_CHIP |
| 152 | type = 0x160D2000; |
| 153 | break; |
| 154 | |
| 155 | default: |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 156 | trace::err("Unsupported ATTR_TYPE value: 0x%02x", attrType); |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 157 | assert(0); |
| 158 | } |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 159 | // END WORKAROUND |
| 160 | |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 161 | // Make sure the model/level list contains unique values only. |
| 162 | // This is O(n*n), but the list size will likely be very low, probably |
| 163 | // maxing around a half dozen. So, opting for simplicity. |
| 164 | if (o_types.end() == std::find(o_types.begin(), o_types.end(), type)) |
| 165 | { |
| 166 | o_types.push_back(type); |
| 167 | } |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 168 | |
| 169 | return type; |
| 170 | } |
| 171 | |
| 172 | //------------------------------------------------------------------------------ |
| 173 | |
| 174 | // Gathers list of active chips to analyze. Also, returns the list of chip types |
| 175 | // needed to initialize the isolator. |
| 176 | void __getActiveChips(std::vector<libhei::Chip>& o_chips, |
| 177 | std::vector<libhei::ChipType_t>& o_types) |
| 178 | { |
| 179 | // Iterate each processor. |
| 180 | pdbg_target* procTrgt; |
| 181 | pdbg_for_each_class_target("proc", procTrgt) |
| 182 | { |
| 183 | // Active processors only. |
| 184 | if (PDBG_TARGET_ENABLED != pdbg_target_probe(procTrgt)) |
| 185 | continue; |
| 186 | |
| 187 | // Add the processor to the list. |
| 188 | o_chips.emplace_back(procTrgt, __getChipType(procTrgt, o_types)); |
| 189 | |
| 190 | // Iterate the connected OCMBs, if they exist. |
| 191 | pdbg_target* ocmbTrgt; |
Zane Shelley | 06e10f9 | 2020-08-10 20:35:08 -0500 | [diff] [blame] | 192 | pdbg_for_each_target("ocmb", procTrgt, ocmbTrgt) |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 193 | { |
| 194 | // Active OCMBs only. |
| 195 | if (PDBG_TARGET_ENABLED != pdbg_target_probe(ocmbTrgt)) |
| 196 | continue; |
| 197 | |
| 198 | // Add the OCMB to the list. |
| 199 | o_chips.emplace_back(ocmbTrgt, __getChipType(ocmbTrgt, o_types)); |
| 200 | } |
| 201 | } |
| 202 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 203 | // For debug, trace out all of the chips found. |
| 204 | for (const auto& chip : o_chips) |
| 205 | { |
| 206 | trace::inf("chip:%s type:0x%0" PRIx32, __path(chip), chip.getType()); |
| 207 | } |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | //------------------------------------------------------------------------------ |
| 211 | |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 212 | // Initializes the isolator for each specified chip type. |
| 213 | void __initializeIsolator(const std::vector<libhei::ChipType_t>& i_types) |
| 214 | { |
| 215 | // START WORKAROUND |
| 216 | // TODO: The chip data will eventually come from the CHIPDATA section of the |
| 217 | // PNOR. Until that support is available, we'll use temporary chip |
| 218 | // data files. |
| 219 | for (const auto& type : i_types) |
| 220 | { |
| 221 | switch (type) |
| 222 | { |
| 223 | case 0x120DA049: // PROC |
| 224 | initWithFile( |
| 225 | "/usr/share/openpower-hw-diags/chip_data_proc.cdb"); |
| 226 | break; |
| 227 | |
| 228 | case 0x160D2000: // OCMB_CHIP |
| 229 | initWithFile( |
| 230 | "/usr/share/openpower-hw-diags/chip_data_ocmb.cdb"); |
| 231 | break; |
| 232 | |
| 233 | default: |
| 234 | trace::err("Unsupported ChipType_t value: 0x%0" PRIx32, type); |
| 235 | assert(0); |
| 236 | } |
| 237 | } |
| 238 | // END WORKAROUND |
| 239 | } |
| 240 | |
| 241 | //------------------------------------------------------------------------------ |
| 242 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 243 | // Takes a signature list that will be filtered and sorted. The first entry in |
| 244 | // the returned list will be the root cause. If the returned list is empty, |
| 245 | // analysis failed. |
| 246 | void __filterRootCause(std::vector<libhei::Signature>& io_list) |
| 247 | { |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 248 | // For debug, trace out the original list of signatures before filtering. |
| 249 | for (const auto& sig : io_list) |
| 250 | { |
| 251 | trace::inf("Signature: %s 0x%0" PRIx32 " %s", __path(sig.getChip()), |
| 252 | __sig(sig), __attn(sig.getAttnType())); |
| 253 | } |
| 254 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 255 | // Special and host attentions are not supported by this user application. |
| 256 | auto newEndItr = |
| 257 | std::remove_if(io_list.begin(), io_list.end(), [&](const auto& t) { |
| 258 | return (libhei::ATTN_TYPE_SP_ATTN == t.getAttnType() || |
| 259 | libhei::ATTN_TYPE_HOST_ATTN == t.getAttnType()); |
| 260 | }); |
| 261 | |
| 262 | // Shrink the vector, if needed. |
| 263 | io_list.resize(std::distance(io_list.begin(), newEndItr)); |
| 264 | |
| 265 | // START WORKAROUND |
| 266 | // TODO: Filtering should be determined by the RAS Data Files provided by |
| 267 | // the host firmware via the PNOR (similar to the Chip Data Files). |
| 268 | // Until that support is available, use a rudimentary filter that |
| 269 | // first looks for any recoverable attention, then any unit checkstop, |
| 270 | // and then any system checkstop. This is built on the premise that |
| 271 | // recoverable errors could be the root cause of an system checkstop |
| 272 | // attentions. Fortunately, we just need to sort the list by the |
| 273 | // greater attention type value. |
| 274 | std::sort(io_list.begin(), io_list.end(), |
| 275 | [&](const auto& a, const auto& b) { |
| 276 | return a.getAttnType() > b.getAttnType(); |
| 277 | }); |
| 278 | // END WORKAROUND |
| 279 | } |
| 280 | |
| 281 | //------------------------------------------------------------------------------ |
| 282 | |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 283 | bool __logError(const std::vector<libhei::Signature>& i_sigList, |
| 284 | const libhei::IsolationData& i_isoData) |
| 285 | { |
| 286 | bool attnFound = false; |
| 287 | |
| 288 | // Get numerical values for the root cause. |
| 289 | uint32_t word6 = 0; // [ 0: 7]: chip target type |
| 290 | // [ 8:31]: chip FAPI position |
| 291 | // uint32_t word7 = 0; // TODO: chip target info |
| 292 | uint32_t word8 = 0; // [ 0:15]: node ID |
| 293 | // [16:23]: node instance |
| 294 | // [24:31]: bit position |
| 295 | // uint32_t word9 = 0; // [ 0: 7]: attention type |
| 296 | |
| 297 | if (i_sigList.empty()) |
| 298 | { |
| 299 | trace::inf("No active attentions found"); |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | attnFound = true; |
| 304 | |
| 305 | // The root cause attention is the first in the filtered list. |
| 306 | libhei::Signature root = i_sigList.front(); |
| 307 | |
| 308 | word6 = __trgt(root); |
| 309 | word8 = __sig(root); |
| 310 | |
| 311 | trace::inf("Root cause attention: %s 0x%0" PRIx32 " %s", |
| 312 | __path(root.getChip()), word8, __attn(root.getAttnType())); |
| 313 | } |
| 314 | |
| 315 | // Get the log data. |
| 316 | std::map<std::string, std::string> logData; |
| 317 | logData["_PID"] = std::to_string(getpid()); |
| 318 | logData["CHIP_ID"] = std::to_string(word6); |
| 319 | logData["SIGNATURE"] = std::to_string(word8); |
| 320 | |
| 321 | // Get access to logging interface and method for creating log. |
| 322 | auto bus = sdbusplus::bus::new_default_system(); |
| 323 | |
| 324 | // Using direct create method (for additional data) |
| 325 | auto method = bus.new_method_call( |
| 326 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 327 | "xyz.openbmc_project.Logging.Create", "Create"); |
| 328 | |
| 329 | // Attach additional data |
| 330 | method.append("org.open_power.HwDiags.Error.Checkstop", |
| 331 | "xyz.openbmc_project.Logging.Entry.Level.Error", logData); |
| 332 | |
| 333 | // Log the event. |
| 334 | // TODO: Should the reply be handled? |
| 335 | bus.call(method); |
| 336 | |
| 337 | return attnFound; |
| 338 | } |
| 339 | |
| 340 | //------------------------------------------------------------------------------ |
| 341 | |
| 342 | bool analyzeHardware() |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 343 | { |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 344 | bool attnFound = false; |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 345 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 346 | trace::inf(">>> enter analyzeHardware()"); |
| 347 | |
Zane Shelley | d84ed6e | 2020-06-08 13:41:48 -0500 | [diff] [blame] | 348 | // Get the active chips to be analyzed and their types. |
| 349 | std::vector<libhei::Chip> chipList; |
| 350 | std::vector<libhei::ChipType_t> chipTypes; |
| 351 | __getActiveChips(chipList, chipTypes); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 352 | |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 353 | // Initialize the isolator for all chip types. |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 354 | trace::inf("Initializing isolator: # of types=%u", chipTypes.size()); |
Zane Shelley | 2e994bc | 2020-06-08 14:38:14 -0500 | [diff] [blame] | 355 | __initializeIsolator(chipTypes); |
| 356 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 357 | // Isolate attentions. |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 358 | trace::inf("Isolating errors: # of chips=%u", chipList.size()); |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 359 | libhei::IsolationData isoData{}; |
| 360 | libhei::isolate(chipList, isoData); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 361 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 362 | // Filter signatures to determine root cause. We'll need to make a copy of |
| 363 | // the list so that the original list is maintained for the log. |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 364 | std::vector<libhei::Signature> sigList{isoData.getSignatureList()}; |
| 365 | __filterRootCause(sigList); |
| 366 | |
Zane Shelley | 9fb7393 | 2020-09-15 13:34:57 -0500 | [diff] [blame] | 367 | // Create and commit a log. |
| 368 | attnFound = __logError(sigList, isoData); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 369 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 370 | // All done, clean up the isolator. |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 371 | trace::inf("Uninitializing isolator"); |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 372 | libhei::uninitialize(); |
Ben Tyner | 87eabc6 | 2020-05-14 17:56:54 -0500 | [diff] [blame] | 373 | |
Zane Shelley | 2f26318 | 2020-07-10 21:41:21 -0500 | [diff] [blame] | 374 | trace::inf("<<< exit analyzeHardware()"); |
| 375 | |
Zane Shelley | 097a71a | 2020-06-08 15:55:29 -0500 | [diff] [blame] | 376 | return attnFound; |
Ben Tyner | 0205f3b | 2020-02-24 10:24:47 -0600 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | } // namespace analyzer |