Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 3 | #include <analyzer/analyzer_main.hpp> |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 4 | #include <attn/attn_common.hpp> |
Ben Tyner | 188f109 | 2021-02-01 09:33:06 -0600 | [diff] [blame] | 5 | #include <attn/attn_dbus.hpp> |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 6 | #include <attn/attn_dump.hpp> |
Ben Tyner | b797b3e | 2020-06-29 10:12:05 -0500 | [diff] [blame] | 7 | #include <attn/attn_logging.hpp> |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 8 | #include <attn/pel/pel_minimal.hpp> |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 9 | #include <phosphor-logging/log.hpp> |
Ben Tyner | 1315968 | 2022-02-16 14:55:38 -0600 | [diff] [blame] | 10 | #include <util/dbus.hpp> |
Ben Tyner | faf3336 | 2022-02-16 14:04:51 -0600 | [diff] [blame] | 11 | #include <util/ffdc.hpp> |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 12 | #include <util/trace.hpp> |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 13 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 14 | namespace attn |
| 15 | { |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 16 | /** @brief Tuple containing information about ffdc files */ |
| 17 | using FFDCTuple = |
| 18 | std::tuple<util::FFDCFormat, uint8_t, uint8_t, sdbusplus::message::unix_fd>; |
| 19 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 20 | /** |
| 21 | * Create FFDCTuple objects corresponding to the specified FFDC files. |
| 22 | * |
| 23 | * The D-Bus method to create an error log requires a vector of tuples to |
| 24 | * pass in the FFDC file information. |
| 25 | * |
| 26 | * @param files - FFDC files |
| 27 | * @return vector of FFDCTuple objects |
| 28 | */ |
| 29 | std::vector<FFDCTuple> |
| 30 | createFFDCTuples(const std::vector<util::FFDCFile>& files) |
| 31 | { |
| 32 | std::vector<FFDCTuple> ffdcTuples{}; |
Zane Shelley | a79f6c8 | 2021-01-12 16:38:49 -0600 | [diff] [blame] | 33 | util::transformFFDC(files, ffdcTuples); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 34 | |
| 35 | return ffdcTuples; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @brief Create an FFDCFile object containing raw data |
| 40 | * |
| 41 | * Throws an exception if an error occurs. |
| 42 | * |
| 43 | * @param i_buffer - raw data to add to ffdc faw data file |
| 44 | * @param i_size - size of the raw data |
| 45 | * @return FFDCFile object |
| 46 | */ |
| 47 | util::FFDCFile createFFDCRawFile(void* i_buffer, size_t i_size) |
| 48 | { |
| 49 | util::FFDCFile file{util::FFDCFormat::Custom}; |
| 50 | |
| 51 | // Write buffer to file and then reset file description file offset |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 52 | int fd = file.getFileDescriptor(); |
| 53 | size_t numBytes = write(fd, static_cast<char*>(i_buffer), i_size); |
| 54 | if (i_size != numBytes) |
| 55 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 56 | trace::err("%s only %u of %u bytes written", file.getPath().c_str(), |
| 57 | numBytes, i_size); |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 58 | } |
| 59 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 60 | lseek(fd, 0, SEEK_SET); |
| 61 | |
| 62 | return file; |
| 63 | } |
| 64 | |
| 65 | /** |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 66 | * Create FFDCFile objects containing debug data to store in the error log. |
| 67 | * |
| 68 | * If an error occurs, the error is written to the journal but an exception |
| 69 | * is not thrown. |
| 70 | * |
| 71 | * @param i_buffer - raw data (if creating raw dump ffdc entry in log) |
| 72 | * @return vector of FFDCFile objects |
| 73 | */ |
| 74 | std::vector<util::FFDCFile> createFFDCFiles(char* i_buffer = nullptr, |
| 75 | size_t i_size = 0) |
| 76 | { |
| 77 | std::vector<util::FFDCFile> files{}; |
| 78 | |
| 79 | // Create raw dump file |
| 80 | if ((nullptr != i_buffer) && (0 != i_size)) |
| 81 | { |
| 82 | files.emplace_back(createFFDCRawFile(i_buffer, i_size)); |
| 83 | } |
| 84 | |
| 85 | // Create trace dump file |
Ben Tyner | faf3336 | 2022-02-16 14:04:51 -0600 | [diff] [blame] | 86 | util::createFFDCTraceFiles(files); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 87 | |
Ben Tyner | 21cc627 | 2022-10-05 18:26:36 -0500 | [diff] [blame] | 88 | // Add PRD scratch registers |
| 89 | addPrdScratchRegs(files); |
| 90 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 91 | return files; |
| 92 | } |
| 93 | |
| 94 | /** |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 95 | * Create a PEL from an existing PEL |
| 96 | * |
| 97 | * Create a new PEL based on the specified raw PEL and submit the new PEL |
| 98 | * to the backend logging code as a raw PEL. Note that additional data map |
| 99 | * here contains data to be committed to the PEL and it can also be used to |
| 100 | * create the PEL as it contains needed information. |
| 101 | * |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 102 | * @param i_rawPel - buffer containing a raw PEL |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 103 | * @param i_additional - additional data to be added to the new PEL |
| 104 | */ |
| 105 | void createPelCustom(std::vector<uint8_t>& i_rawPel, |
| 106 | std::map<std::string, std::string> i_additional) |
| 107 | { |
| 108 | // create PEL object from buffer |
| 109 | auto tiPel = std::make_unique<pel::PelMinimal>(i_rawPel); |
| 110 | |
| 111 | // The additional data contains the TI info as well as the value for the |
| 112 | // subystem that provided the TI info. Get the subystem from additional |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 113 | // data and then populate the primary SRC and SRC words for the custom PEL |
| 114 | // based on the subsystem's TI info. |
| 115 | std::map<std::string, std::string>::iterator it; |
| 116 | uint8_t subsystem; |
| 117 | |
| 118 | it = i_additional.find("Subsystem"); |
| 119 | if (it != i_additional.end()) |
| 120 | { |
| 121 | subsystem = std::stoi(it->second); |
| 122 | tiPel->setSubsystem(subsystem); |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | // The entry with key "Subsystem" does not exist in the additional map. |
| 127 | // Log the error, create failure event, and return. |
Zane Shelley | 67b8229 | 2022-03-25 09:48:40 -0500 | [diff] [blame] | 128 | trace::err("Error the key Subsystem does not exist in the map."); |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 129 | eventAttentionFail((int)AttnSection::attnLogging | ATTN_INVALID_KEY); |
| 130 | return; |
| 131 | } |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 132 | |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 133 | // If recoverable attentions are active we will call the analyzer and |
| 134 | // then link the custom pel to analyzer pel. |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 135 | it = i_additional.find("recoverables"); |
| 136 | if (it != i_additional.end() && "true" == it->second) |
| 137 | { |
| 138 | DumpParameters dumpParameters; |
Zane Shelley | ebff0d3 | 2021-11-21 10:52:07 -0600 | [diff] [blame] | 139 | auto plid = analyzer::analyzeHardware( |
| 140 | analyzer::AnalysisType::TERMINATE_IMMEDIATE, dumpParameters); |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 141 | if (0 != plid) |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 142 | { |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 143 | // Link the PLID if an attention was found and a PEL was generated. |
| 144 | tiPel->setPlid(plid); |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 148 | if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem) |
| 149 | { |
| 150 | // populate hypervisor SRC words |
| 151 | tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{ |
| 152 | (uint32_t)std::stoul(i_additional["0x10 SRC Word 12"], 0, 16), |
| 153 | (uint32_t)std::stoul(i_additional["0x14 SRC Word 13"], 0, 16), |
| 154 | (uint32_t)std::stoul(i_additional["0x18 SRC Word 14"], 0, 16), |
| 155 | (uint32_t)std::stoul(i_additional["0x1c SRC Word 15"], 0, 16), |
| 156 | (uint32_t)std::stoul(i_additional["0x20 SRC Word 16"], 0, 16), |
| 157 | (uint32_t)std::stoul(i_additional["0x24 SRC Word 17"], 0, 16), |
| 158 | (uint32_t)std::stoul(i_additional["0x28 SRC Word 18"], 0, 16), |
| 159 | (uint32_t)std::stoul(i_additional["0x2c SRC Word 19"], 0, 16)}); |
| 160 | |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 161 | // Populate phyp primary SRC |
| 162 | |
| 163 | // char array for raw pel src |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 164 | std::array<char, pel::asciiStringSize> srcChars{'0'}; |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 165 | std::string srcString; |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 166 | |
| 167 | // src from TI info |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 168 | it = i_additional.find("SrcAscii"); |
| 169 | if (it != i_additional.end()) |
| 170 | { |
| 171 | srcString = it->second; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | // The entry with key "Subsystem" does not exist in the additional |
| 176 | // map. Log the error, create failure event, and return. |
Zane Shelley | 67b8229 | 2022-03-25 09:48:40 -0500 | [diff] [blame] | 177 | trace::err("Error the key SrcAscii does not exist in the map."); |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 178 | eventAttentionFail((int)AttnSection::attnLogging | |
| 179 | ATTN_INVALID_KEY); |
| 180 | return; |
| 181 | } |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 182 | |
| 183 | // copy from string to char array |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 184 | srcString.copy(srcChars.data(), |
| 185 | std::min(srcString.size(), pel::asciiStringSize), 0); |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 186 | |
| 187 | tiPel->setAsciiString(srcChars); // pel object src is char array |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 188 | |
| 189 | // set symptom-id |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 190 | auto symptomId = (srcString.substr(0, 8) + '_'); |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 191 | |
| 192 | symptomId += (i_additional["0x10 SRC Word 12"]); |
| 193 | symptomId += (i_additional["0x14 SRC Word 13"] + '_'); |
| 194 | symptomId += (i_additional["0x18 SRC Word 14"]); |
| 195 | symptomId += (i_additional["0x1c SRC Word 15"] + '_'); |
| 196 | symptomId += (i_additional["0x20 SRC Word 16"]); |
| 197 | symptomId += (i_additional["0x24 SRC Word 17"] + '_'); |
| 198 | symptomId += (i_additional["0x28 SRC Word 18"]); |
| 199 | symptomId += (i_additional["0x2c SRC Word 19"]); |
| 200 | |
| 201 | // setSymptomId will take care of required null-terminate and padding |
| 202 | tiPel->setSymptomId(symptomId); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 203 | } |
| 204 | else |
| 205 | { |
| 206 | // Populate hostboot SRC words - note HB word 0 from the shared info |
| 207 | // data (additional data "0x10 HB Word") is reflected in the PEL as |
| 208 | // "reason code" so we zero it here. Also note that the first word |
| 209 | // in this group of words starts at word 0 and word 1 does not exits. |
| 210 | tiPel->setSrcWords(std::array<uint32_t, pel::numSrcWords>{ |
| 211 | (uint32_t)0x00000000, |
| 212 | (uint32_t)std::stoul(i_additional["0x14 HB Word 2"], 0, 16), |
| 213 | (uint32_t)std::stoul(i_additional["0x18 HB Word 3"], 0, 16), |
| 214 | (uint32_t)std::stoul(i_additional["0x1c HB Word 4"], 0, 16), |
| 215 | (uint32_t)std::stoul(i_additional["0x20 HB Word 5"], 0, 16), |
| 216 | (uint32_t)std::stoul(i_additional["0x24 HB Word 6"], 0, 16), |
| 217 | (uint32_t)std::stoul(i_additional["0x28 HB Word 7"], 0, 16), |
| 218 | (uint32_t)std::stoul(i_additional["0x2c HB Word 8"], 0, 16)}); |
| 219 | |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 220 | // Populate hostboot primary SRC |
| 221 | |
| 222 | // char array for raw pel src |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 223 | std::array<char, pel::asciiStringSize> srcChars{'0'}; |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 224 | std::string srcString; |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 225 | |
| 226 | // src from TI info |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 227 | it = i_additional.find("SrcAscii"); |
| 228 | if (it != i_additional.end()) |
| 229 | { |
| 230 | srcString = it->second; |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | // The entry with key "Subsystem" does not exist in the additional |
| 235 | // map. Log the error, create failure event, and return. |
Zane Shelley | 67b8229 | 2022-03-25 09:48:40 -0500 | [diff] [blame] | 236 | trace::err("Error the key SrcAscii does not exist in the map."); |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 237 | eventAttentionFail((int)AttnSection::attnLogging | |
| 238 | ATTN_INVALID_KEY); |
| 239 | return; |
| 240 | } |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 241 | |
| 242 | // copy from string to char array |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 243 | srcString.copy(srcChars.data(), |
| 244 | std::min(srcString.size(), pel::asciiStringSize), 0); |
Ben Tyner | 9d4f91c | 2021-02-09 08:27:58 -0600 | [diff] [blame] | 245 | |
| 246 | tiPel->setAsciiString(srcChars); // pel object src is char array |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 247 | |
| 248 | // set symptom-id |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 249 | auto symptomId = (srcString.substr(0, 8) + '_'); |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 250 | |
| 251 | symptomId += (i_additional["0x10 HB Word 0"]); // note: word 1 |
| 252 | symptomId += (i_additional["0x14 HB Word 2"] + '_'); // does not exist |
| 253 | symptomId += (i_additional["0x18 HB Word 3"]); |
| 254 | symptomId += (i_additional["0x1c HB Word 4"] + '_'); |
| 255 | symptomId += (i_additional["0x20 HB Word 5"]); |
| 256 | symptomId += (i_additional["0x24 HB Word 6"] + '_'); |
| 257 | symptomId += (i_additional["0x28 HB Word 7"]); |
| 258 | symptomId += (i_additional["0x2c HB Word 8"]); |
| 259 | |
| 260 | // setSymptomId will take care of required null-terminate and padding |
| 261 | tiPel->setSymptomId(symptomId); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | // set severity, event type and action flags |
| 265 | tiPel->setSeverity(static_cast<uint8_t>(pel::Severity::termination)); |
| 266 | tiPel->setType(static_cast<uint8_t>(pel::EventType::na)); |
Ben Tyner | ac5bd05 | 2022-03-03 14:09:13 -0600 | [diff] [blame] | 267 | |
| 268 | auto actionFlags = pel::ActionFlags::service | pel::ActionFlags::report | |
| 269 | pel::ActionFlags::call; |
| 270 | |
| 271 | it = i_additional.find("hidden"); |
| 272 | if (it != i_additional.end() && "true" == it->second) |
| 273 | { |
| 274 | trace::inf("making HB TI PEL hidden"); |
| 275 | actionFlags = actionFlags | pel::ActionFlags::hidden; |
| 276 | } |
| 277 | |
| 278 | tiPel->setAction(static_cast<uint16_t>(actionFlags)); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 279 | |
Ben Tyner | 21cc627 | 2022-10-05 18:26:36 -0500 | [diff] [blame] | 280 | // The raw PEL that we used as the basis for this custom PEL contains some |
| 281 | // user data sections that do not need to be in this PEL. However we do |
| 282 | // want to include the raw TI information. |
| 283 | int ffdcCount = 0; |
| 284 | it = i_additional.find("FFDC count"); |
| 285 | if (it != i_additional.end()) |
| 286 | { |
| 287 | // remove all sections except 1 (raw Ti info) |
| 288 | ffdcCount = std::stoi(it->second) - 1; |
| 289 | } |
| 290 | tiPel->setSectionCount(tiPel->getSectionCount() - ffdcCount); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 291 | |
| 292 | // Update the raw PEL with the new custom PEL data |
| 293 | tiPel->raw(i_rawPel); |
| 294 | |
| 295 | // create PEL from raw data |
| 296 | createPelRaw(i_rawPel); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Log an event handled by the attention handler |
| 301 | * |
| 302 | * Basic (non TI) events will generate a standard message-registry based PEL |
| 303 | * |
| 304 | * TI events will create two PEL's. One PEL will be informational and will |
| 305 | * contain trace information relevent to attention handler. The second PEL |
| 306 | * will be specific to the TI type (including the primary SRC) and will be |
| 307 | * based off of the TI information provided to the attention handler through |
| 308 | * shared TI info data area. |
| 309 | * |
| 310 | * @param i_event - The event type |
| 311 | * @param i_additional - Additional PEL data |
| 312 | * @param i_ffdc - FFDC PEL data |
Ben Tyner | 9051685 | 2022-12-14 21:04:18 -0600 | [diff] [blame] | 313 | * @param i_severity - Severity level |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 314 | * @return Event log Id (0 if no event log generated) |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 315 | */ |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 316 | uint32_t event(EventType i_event, |
| 317 | std::map<std::string, std::string>& i_additional, |
Ben Tyner | 9051685 | 2022-12-14 21:04:18 -0600 | [diff] [blame] | 318 | const std::vector<util::FFDCFile>& i_ffdc, |
| 319 | std::string i_severity = levelPelError) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 320 | { |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 321 | uint32_t pelId = 0; // assume no event log generated |
| 322 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 323 | bool eventValid = false; // assume no event created |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 324 | bool tiEvent = false; // assume not a terminate event |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 325 | |
Ben Tyner | 21cc627 | 2022-10-05 18:26:36 -0500 | [diff] [blame] | 326 | // count user data sections so we can fixup custom PEL |
| 327 | i_additional["FFDC count"] = std::to_string(i_ffdc.size()); |
| 328 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 329 | std::string eventName; |
| 330 | |
| 331 | switch (i_event) |
| 332 | { |
| 333 | case EventType::Checkstop: |
| 334 | eventName = "org.open_power.HwDiags.Error.Checkstop"; |
| 335 | eventValid = true; |
| 336 | break; |
| 337 | case EventType::Terminate: |
| 338 | eventName = "org.open_power.Attn.Error.Terminate"; |
| 339 | eventValid = true; |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 340 | tiEvent = true; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 341 | break; |
| 342 | case EventType::Vital: |
| 343 | eventName = "org.open_power.Attn.Error.Vital"; |
| 344 | eventValid = true; |
| 345 | break; |
| 346 | case EventType::HwDiagsFail: |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 347 | case EventType::AttentionFail: |
| 348 | eventName = "org.open_power.Attn.Error.Fail"; |
| 349 | eventValid = true; |
| 350 | break; |
| 351 | default: |
| 352 | eventValid = false; |
| 353 | break; |
| 354 | } |
| 355 | |
| 356 | if (true == eventValid) |
| 357 | { |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 358 | // Create PEL with additional data and FFDC data. The newly created |
| 359 | // PEL's platform log-id will be returned. |
Ben Tyner | 9051685 | 2022-12-14 21:04:18 -0600 | [diff] [blame] | 360 | pelId = util::dbus::createPel(eventName, i_severity, i_additional, |
Ben Tyner | 1315968 | 2022-02-16 14:55:38 -0600 | [diff] [blame] | 361 | createFFDCTuples(i_ffdc)); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 362 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 363 | // If this is a TI event we will create an additional PEL that is |
| 364 | // specific to the subsystem that generated the TI. |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 365 | if ((0 != pelId) && (true == tiEvent)) |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 366 | { |
| 367 | // get file descriptor and size of information PEL |
Ben Tyner | 188f109 | 2021-02-01 09:33:06 -0600 | [diff] [blame] | 368 | int pelFd = getPel(pelId); |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 369 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 370 | // if PEL found, read into buffer |
| 371 | if (-1 != pelFd) |
| 372 | { |
| 373 | auto pelSize = lseek(pelFd, 0, SEEK_END); |
| 374 | lseek(pelFd, 0, SEEK_SET); |
Ben Tyner | 1b1915e | 2020-10-23 15:13:38 -0500 | [diff] [blame] | 375 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 376 | // read information PEL into buffer |
| 377 | std::vector<uint8_t> buffer(pelSize); |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 378 | size_t numBytes = read(pelFd, buffer.data(), buffer.size()); |
| 379 | if (buffer.size() != numBytes) |
| 380 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 381 | trace::err("Error reading event log: %u of %u bytes read", |
| 382 | numBytes, buffer.size()); |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 383 | } |
| 384 | else |
| 385 | { |
| 386 | // create PEL from buffer |
| 387 | createPelCustom(buffer, i_additional); |
| 388 | } |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 389 | |
Ben Tyner | d700609 | 2021-02-05 14:55:52 -0600 | [diff] [blame] | 390 | close(pelFd); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 391 | } |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 392 | |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 393 | std::map<std::string, std::string>::iterator it; |
| 394 | uint8_t subsystem; |
| 395 | |
| 396 | it = i_additional.find("Subsystem"); |
| 397 | if (it != i_additional.end()) |
| 398 | { |
| 399 | subsystem = std::stoi(it->second); |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | // The entry with key "Subsystem" does not exist in the |
| 404 | // additional map. Log the error, create failure event, and |
| 405 | // return. |
Zane Shelley | 67b8229 | 2022-03-25 09:48:40 -0500 | [diff] [blame] | 406 | trace::err( |
| 407 | "Error the key Subsystem does not exist in the map."); |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 408 | eventAttentionFail((int)AttnSection::attnLogging | |
| 409 | ATTN_INVALID_KEY); |
| 410 | return 0; |
| 411 | } |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 412 | |
Ben Tyner | 6bc43c9 | 2021-05-27 15:08:02 -0500 | [diff] [blame] | 413 | // If not hypervisor TI |
| 414 | if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) != subsystem) |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 415 | { |
Ben Tyner | 6bc43c9 | 2021-05-27 15:08:02 -0500 | [diff] [blame] | 416 | // Request a dump and transition the host |
| 417 | if ("true" == i_additional["Dump"]) |
| 418 | { |
| 419 | // will not return until dump is complete |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 420 | requestDump(pelId, DumpParameters{0, DumpType::Hostboot}); |
Ben Tyner | 6bc43c9 | 2021-05-27 15:08:02 -0500 | [diff] [blame] | 421 | } |
Ben Tyner | 5c5db65 | 2021-02-22 18:22:35 -0600 | [diff] [blame] | 422 | } |
| 423 | } |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 424 | } |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 425 | return pelId; |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 426 | } |
| 427 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 428 | /** |
| 429 | * Commit special attention TI event to log |
| 430 | * |
| 431 | * Create a event log with provided additional information and standard |
| 432 | * FFDC data plus TI FFDC data |
| 433 | * |
| 434 | * @param i_additional - Additional log data |
| 435 | * @param i_ti_InfoData - TI FFDC data |
| 436 | */ |
| 437 | void eventTerminate(std::map<std::string, std::string> i_additionalData, |
| 438 | char* i_tiInfoData) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 439 | { |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 440 | uint32_t tiInfoSize = 0; // assume TI info was not available |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 441 | |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 442 | if (nullptr != i_tiInfoData) |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 443 | { |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 444 | tiInfoSize = 56; // assume not hypervisor TI |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 445 | |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 446 | std::map<std::string, std::string>::iterator it; |
| 447 | uint8_t subsystem; |
| 448 | |
| 449 | it = i_additionalData.find("Subsystem"); |
| 450 | if (it != i_additionalData.end()) |
| 451 | { |
| 452 | subsystem = std::stoi(it->second); |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | // The entry with key "Subsystem" does not exist in the additional |
| 457 | // map. Log the error, create failure event, and return. |
Zane Shelley | 67b8229 | 2022-03-25 09:48:40 -0500 | [diff] [blame] | 458 | trace::err("Error the key Subsystem does not exist in the map."); |
austinfcui | c49d20b | 2022-02-22 16:36:47 -0600 | [diff] [blame] | 459 | eventAttentionFail((int)AttnSection::attnLogging | |
| 460 | ATTN_INVALID_KEY); |
| 461 | return; |
| 462 | } |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 463 | |
| 464 | // If hypervisor |
| 465 | if (static_cast<uint8_t>(pel::SubsystemID::hypervisor) == subsystem) |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 466 | { |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 467 | tiInfoSize = 1024; // assume hypervisor max |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 468 | |
Ben Tyner | 29651ef | 2021-02-08 10:51:03 -0600 | [diff] [blame] | 469 | // hypervisor may just want some of the data |
| 470 | if (0 == (*(i_tiInfoData + 0x09) & 0x01)) |
| 471 | { |
| 472 | uint32_t* additionalLength = (uint32_t*)(i_tiInfoData + 0x50); |
| 473 | uint32_t tiAdditional = be32toh(*additionalLength); |
| 474 | tiInfoSize = std::min(tiInfoSize, (84 + tiAdditional)); |
| 475 | } |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 479 | trace::inf("TI info size = %u", tiInfoSize); |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 480 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 481 | event(EventType::Terminate, i_additionalData, |
Ben Tyner | b6401ed | 2021-01-11 09:08:07 -0600 | [diff] [blame] | 482 | createFFDCFiles(i_tiInfoData, tiInfoSize)); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 483 | } |
| 484 | |
Ben Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 485 | /** @brief Commit SBE vital event to log, returns event log ID */ |
Ben Tyner | 9051685 | 2022-12-14 21:04:18 -0600 | [diff] [blame] | 486 | uint32_t eventVital(std::string severity) |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 487 | { |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 488 | // Additional data for log |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 489 | std::map<std::string, std::string> additionalData; |
| 490 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 491 | // Create log event with additional data and FFDC data |
Ben Tyner | 9051685 | 2022-12-14 21:04:18 -0600 | [diff] [blame] | 492 | return event(EventType::Vital, additionalData, createFFDCFiles(nullptr, 0), |
| 493 | severity); |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 494 | } |
| 495 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 496 | /** |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 497 | * Commit attention handler failure event to log |
| 498 | * |
| 499 | * Create an event log containing the specified error code. |
| 500 | * |
| 501 | * @param i_error - Error code |
| 502 | */ |
| 503 | void eventAttentionFail(int i_error) |
| 504 | { |
| 505 | // Additional data for log |
| 506 | std::map<std::string, std::string> additionalData; |
| 507 | additionalData["ERROR_CODE"] = std::to_string(i_error); |
| 508 | |
| 509 | // Create log event with additional data and FFDC data |
| 510 | event(EventType::AttentionFail, additionalData, |
| 511 | createFFDCFiles(nullptr, 0)); |
| 512 | } |
| 513 | |
Ben Tyner | b1ebfcb | 2020-05-08 18:52:48 -0500 | [diff] [blame] | 514 | } // namespace attn |