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