Brad Bishop | 5e5d445 | 2020-10-27 19:46:13 -0400 | [diff] [blame] | 1 | extern "C" |
| 2 | { |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 3 | #include <libpdbg.h> |
| 4 | } |
| 5 | |
| 6 | #include "create_pel.hpp" |
Jayanth Othayoth | 006641e | 2021-10-07 06:56:24 -0500 | [diff] [blame] | 7 | #include "dump_utils.hpp" |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 8 | #include "extensions/phal/common_utils.hpp" |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 9 | #include "phal_error.hpp" |
| 10 | |
| 11 | #include <attributes_info.H> |
| 12 | #include <fmt/format.h> |
| 13 | #include <libekb.H> |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 14 | #include <libphal.H> |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 15 | |
Brad Bishop | 5e5d445 | 2020-10-27 19:46:13 -0400 | [diff] [blame] | 16 | #include <nlohmann/json.hpp> |
| 17 | #include <phosphor-logging/elog.hpp> |
| 18 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 19 | #include <algorithm> |
| 20 | #include <cstdlib> |
| 21 | #include <cstring> |
| 22 | #include <iomanip> |
| 23 | #include <list> |
| 24 | #include <map> |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 25 | #include <sstream> |
| 26 | #include <string> |
| 27 | |
| 28 | namespace openpower |
| 29 | { |
| 30 | namespace phal |
| 31 | { |
| 32 | using namespace phosphor::logging; |
Jayanth Othayoth | 5d5eb31 | 2021-11-15 01:54:07 -0600 | [diff] [blame] | 33 | using namespace openpower::phal::exception; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Used to pass buffer to pdbg callback api to get required target |
| 37 | * data (attributes) based on given data (attribute). |
| 38 | */ |
| 39 | struct TargetInfo |
| 40 | { |
| 41 | ATTR_PHYS_BIN_PATH_Type physBinPath; |
| 42 | ATTR_LOCATION_CODE_Type locationCode; |
| 43 | ATTR_PHYS_DEV_PATH_Type physDevPath; |
| 44 | ATTR_MRU_ID_Type mruId; |
| 45 | |
| 46 | bool deconfigure; |
| 47 | |
| 48 | TargetInfo() |
| 49 | { |
| 50 | memset(&physBinPath, '\0', sizeof(physBinPath)); |
| 51 | memset(&locationCode, '\0', sizeof(locationCode)); |
| 52 | memset(&physDevPath, '\0', sizeof(physDevPath)); |
| 53 | mruId = 0; |
| 54 | deconfigure = false; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * Used to return in callback function which are used to get |
| 60 | * physical path value and it binary format value. |
| 61 | * |
| 62 | * The value for constexpr defined based on pdbg_target_traverse function usage. |
| 63 | */ |
| 64 | constexpr int continueTgtTraversal = 0; |
| 65 | constexpr int requireAttrFound = 1; |
| 66 | constexpr int requireAttrNotFound = 2; |
| 67 | |
| 68 | /** |
| 69 | * @brief Used to get target location code from phal device tree |
| 70 | * |
| 71 | * @param[in] target current device tree target |
| 72 | * @param[out] appPrivData used for accessing|storing from|to application |
| 73 | * |
| 74 | * @return 0 to continue traverse, non-zero to stop traverse |
| 75 | */ |
| 76 | int pdbgCallbackToGetTgtReqAttrsVal(struct pdbg_target* target, |
| 77 | void* appPrivData) |
| 78 | { |
Jayanth Othayoth | 5d5eb31 | 2021-11-15 01:54:07 -0600 | [diff] [blame] | 79 | using namespace openpower::phal::pdbg; |
| 80 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 81 | TargetInfo* targetInfo = static_cast<TargetInfo*>(appPrivData); |
| 82 | |
| 83 | ATTR_PHYS_BIN_PATH_Type physBinPath; |
| 84 | /** |
| 85 | * TODO: Issue: phal/pdata#16 |
| 86 | * Should not use direct pdbg api to read attribute. Need to use DT_GET_PROP |
| 87 | * macro for bmc app's and this will call libdt-api api but, it will print |
| 88 | * "pdbg_target_get_attribute failed" trace if attribute is not found and |
| 89 | * this callback will call recursively by using pdbg_target_traverse() until |
| 90 | * find expected attribute based on return code from this callback. Because, |
| 91 | * need to do target iteration to get actual attribute (ATTR_PHYS_BIN_PATH) |
| 92 | * value when device tree target info doesn't know to read attribute from |
| 93 | * device tree. So, Due to this error trace user will get confusion while |
| 94 | * looking traces. Hence using pdbg api to avoid trace until libdt-api |
| 95 | * provides log level setup. |
| 96 | */ |
| 97 | if (!pdbg_target_get_attribute( |
| 98 | target, "ATTR_PHYS_BIN_PATH", |
| 99 | std::stoi(dtAttr::fapi2::ATTR_PHYS_BIN_PATH_Spec), |
| 100 | dtAttr::fapi2::ATTR_PHYS_BIN_PATH_ElementCount, physBinPath)) |
| 101 | { |
| 102 | return continueTgtTraversal; |
| 103 | } |
| 104 | |
| 105 | if (std::memcmp(physBinPath, targetInfo->physBinPath, |
| 106 | sizeof(physBinPath)) != 0) |
| 107 | { |
| 108 | return continueTgtTraversal; |
| 109 | } |
| 110 | |
Jayanth Othayoth | de90925 | 2021-11-15 02:36:45 -0600 | [diff] [blame] | 111 | // Found Target, now collect the required attributes associated to the |
| 112 | // target. Incase of any attribute read failure, initialize the data with |
| 113 | // default value. |
Jayanth Othayoth | 5d5eb31 | 2021-11-15 01:54:07 -0600 | [diff] [blame] | 114 | try |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 115 | { |
Jayanth Othayoth | 5d5eb31 | 2021-11-15 01:54:07 -0600 | [diff] [blame] | 116 | // Get location code information |
| 117 | openpower::phal::pdbg::getLocationCode(target, |
| 118 | targetInfo->locationCode); |
| 119 | } |
| 120 | catch (const std::exception& e) |
| 121 | { |
Jayanth Othayoth | 5d5eb31 | 2021-11-15 01:54:07 -0600 | [diff] [blame] | 122 | log<level::ERR>(fmt::format("getLocationCode({}): Exception({})", |
| 123 | pdbg_target_path(target), e.what()) |
| 124 | .c_str()); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | if (DT_GET_PROP(ATTR_PHYS_DEV_PATH, target, targetInfo->physDevPath)) |
| 128 | { |
Jayanth Othayoth | de90925 | 2021-11-15 02:36:45 -0600 | [diff] [blame] | 129 | log<level::ERR>( |
| 130 | fmt::format("Could not read({}) PHYS_DEV_PATH attribute", |
| 131 | pdbg_target_path(target)) |
| 132 | .c_str()); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | if (DT_GET_PROP(ATTR_MRU_ID, target, targetInfo->mruId)) |
| 136 | { |
Jayanth Othayoth | de90925 | 2021-11-15 02:36:45 -0600 | [diff] [blame] | 137 | log<level::ERR>(fmt::format("Could not read({}) ATTR_MRU_ID attribute", |
| 138 | pdbg_target_path(target)) |
| 139 | .c_str()); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 140 | } |
| 141 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 142 | return requireAttrFound; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @brief Used to get target info (attributes data) |
| 147 | * |
| 148 | * To get target required attributes value using another attribute value |
| 149 | * ("PHYS_BIN_PATH" which is present in same target attributes list) by using |
| 150 | * "ipdbg_target_traverse" api because, here we have attribute value only and |
| 151 | * doesn't have respective device tree target info to get required attributes |
| 152 | * values from it attributes list. |
| 153 | * |
| 154 | * @param[in] physBinPath to pass PHYS_BIN_PATH value |
| 155 | * @param[out] targetInfo to pas buufer to fill with required attributes |
| 156 | * |
| 157 | * @return true on success otherwise false |
| 158 | */ |
| 159 | bool getTgtReqAttrsVal(const std::vector<uint8_t>& physBinPath, |
| 160 | TargetInfo& targetInfo) |
| 161 | { |
| 162 | std::memcpy(&targetInfo.physBinPath, physBinPath.data(), |
| 163 | sizeof(targetInfo.physBinPath)); |
| 164 | |
| 165 | int ret = pdbg_target_traverse(NULL, pdbgCallbackToGetTgtReqAttrsVal, |
| 166 | &targetInfo); |
| 167 | if (ret == 0) |
| 168 | { |
| 169 | log<level::ERR>(fmt::format("Given ATTR_PHYS_BIN_PATH value({}) " |
| 170 | "not found in phal device tree", |
| 171 | targetInfo.physBinPath) |
| 172 | .c_str()); |
| 173 | return false; |
| 174 | } |
| 175 | else if (ret == requireAttrNotFound) |
| 176 | { |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | return true; |
| 181 | } |
| 182 | } // namespace phal |
| 183 | |
| 184 | namespace pel |
| 185 | { |
| 186 | using namespace phosphor::logging; |
| 187 | |
| 188 | namespace detail |
| 189 | { |
| 190 | using json = nlohmann::json; |
| 191 | |
| 192 | // keys need to be unique so using counter value to generate unique key |
| 193 | static int counter = 0; |
| 194 | |
| 195 | // list of debug traces |
| 196 | static std::vector<std::pair<std::string, std::string>> traceLog; |
| 197 | |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 198 | /** |
| 199 | * @brief Process platform realted boot failure |
| 200 | * |
| 201 | * @param[in] errInfo - error details |
| 202 | */ |
| 203 | static void processPlatBootError(const ipl_error_info& errInfo); |
| 204 | |
Brad Bishop | 63508a7 | 2020-10-27 18:55:01 -0400 | [diff] [blame] | 205 | void processLogTraceCallback(void*, const char* fmt, va_list ap) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 206 | { |
| 207 | va_list vap; |
| 208 | va_copy(vap, ap); |
| 209 | std::vector<char> logData(1 + std::vsnprintf(nullptr, 0, fmt, ap)); |
| 210 | std::vsnprintf(logData.data(), logData.size(), fmt, vap); |
| 211 | va_end(vap); |
| 212 | std::string logstr(logData.begin(), logData.end()); |
| 213 | |
| 214 | log<level::INFO>(logstr.c_str()); |
| 215 | |
| 216 | char timeBuf[80]; |
| 217 | time_t t = time(0); |
| 218 | tm myTm{}; |
| 219 | gmtime_r(&t, &myTm); |
| 220 | strftime(timeBuf, 80, "%Y-%m-%d %H:%M:%S", &myTm); |
| 221 | |
| 222 | // key values need to be unique for PEL |
| 223 | // TODO #openbmc/dev/issues/1563 |
| 224 | // If written to Json no need to worry about unique KEY |
| 225 | std::stringstream str; |
| 226 | str << std::setfill('0'); |
| 227 | str << "LOG" << std::setw(3) << counter; |
| 228 | str << " " << timeBuf; |
| 229 | traceLog.emplace_back(std::make_pair(str.str(), std::move(logstr))); |
| 230 | counter++; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @brief GET PEL priority from pHAL priority |
| 235 | * |
| 236 | * The pHAL callout priority is in different format than PEL format |
| 237 | * so, this api is used to return current phal supported priority into |
| 238 | * PEL expected format. |
| 239 | * |
| 240 | * @param[in] phalPriority used to pass phal priority format string |
| 241 | * |
| 242 | * @return pel priority format string else empty if failure |
| 243 | * |
| 244 | * @note For "NONE" returning "L" (LOW) |
| 245 | */ |
| 246 | static std::string getPelPriority(const std::string& phalPriority) |
| 247 | { |
| 248 | const std::map<std::string, std::string> priorityMap = { |
| 249 | {"HIGH", "H"}, {"MEDIUM", "M"}, {"LOW", "L"}, {"NONE", "L"}}; |
| 250 | |
| 251 | auto it = priorityMap.find(phalPriority); |
| 252 | if (it == priorityMap.end()) |
| 253 | { |
| 254 | log<level::ERR>(fmt::format("Unsupported phal priority({}) is given " |
| 255 | "to get pel priority format", |
| 256 | phalPriority) |
| 257 | .c_str()); |
| 258 | return "H"; |
| 259 | } |
| 260 | |
| 261 | return it->second; |
| 262 | } |
| 263 | |
Jayanth Othayoth | 2b21170 | 2021-09-06 05:14:23 -0500 | [diff] [blame] | 264 | void processIplErrorCallback(const ipl_error_info& errInfo) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 265 | { |
Jayanth Othayoth | 2b21170 | 2021-09-06 05:14:23 -0500 | [diff] [blame] | 266 | log<level::INFO>( |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 267 | fmt::format("processIplErrorCallback: Error type({})", errInfo.type) |
Jayanth Othayoth | 2b21170 | 2021-09-06 05:14:23 -0500 | [diff] [blame] | 268 | .c_str()); |
| 269 | |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 270 | switch (errInfo.type) |
Jayanth Othayoth | 2b21170 | 2021-09-06 05:14:23 -0500 | [diff] [blame] | 271 | { |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 272 | case IPL_ERR_OK: |
| 273 | // reset trace log and exit |
| 274 | reset(); |
| 275 | break; |
| 276 | case IPL_ERR_SBE_BOOT: |
| 277 | case IPL_ERR_SBE_CHIPOP: |
| 278 | // handle SBE related failures. |
| 279 | processSbeBootError(); |
| 280 | break; |
| 281 | case IPL_ERR_HWP: |
| 282 | // Handle hwp failure |
| 283 | processBootError(false); |
| 284 | break; |
| 285 | case IPL_ERR_PLAT: |
| 286 | processPlatBootError(errInfo); |
| 287 | break; |
| 288 | default: |
| 289 | createPEL("org.open_power.PHAL.Error.Boot"); |
| 290 | // reset trace log and exit |
| 291 | reset(); |
| 292 | break; |
Jayanth Othayoth | faaef2a | 2021-10-08 06:49:36 -0500 | [diff] [blame] | 293 | } |
Jayanth Othayoth | 2b21170 | 2021-09-06 05:14:23 -0500 | [diff] [blame] | 294 | } |
| 295 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 296 | /** |
| 297 | * @brief addPlanarCallout |
| 298 | * |
| 299 | * This function will add a json for planar callout in the input json list. |
| 300 | * The caller can pass this json list into createErrorPEL to apply the callout. |
| 301 | * |
| 302 | * @param[in,out] jsonCalloutDataList - json list where callout json will be |
| 303 | * emplaced |
| 304 | * @param[in] priority - string indicating priority. |
| 305 | */ |
| 306 | static void addPlanarCallout(json& jsonCalloutDataList, |
| 307 | const std::string& priority) |
| 308 | { |
| 309 | json jsonCalloutData; |
| 310 | |
| 311 | // Inventory path for planar |
| 312 | jsonCalloutData["InventoryPath"] = |
| 313 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
| 314 | jsonCalloutData["Deconfigured"] = false; |
| 315 | jsonCalloutData["Guarded"] = false; |
| 316 | jsonCalloutData["Priority"] = priority; |
| 317 | |
| 318 | jsonCalloutDataList.emplace_back(jsonCalloutData); |
| 319 | } |
| 320 | |
| 321 | void processBootErrorHelper(FFDC* ffdc, const std::string& ffdc_prefix) |
Jayanth Othayoth | 2b21170 | 2021-09-06 05:14:23 -0500 | [diff] [blame] | 322 | { |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 323 | log<level::INFO>("processBootErrorHelper "); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 324 | try |
| 325 | { |
Ramesh Iyyar | 3af83eb | 2020-11-19 23:11:38 -0600 | [diff] [blame] | 326 | log<level::INFO>( |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 327 | fmt::format("PHAL FFDC: Return Message[{}]", ffdc->message) |
| 328 | .c_str()); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 329 | |
| 330 | // To store callouts details in json format as per pel expectation. |
| 331 | json jsonCalloutDataList; |
| 332 | jsonCalloutDataList = json::array(); |
| 333 | |
| 334 | // To store phal trace and other additional data about ffdc. |
| 335 | FFDCData pelAdditionalData; |
| 336 | |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 337 | if (ffdc->ffdc_type == FFDC_TYPE_HWP) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 338 | { |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 339 | std::string keyWithPrefix(ffdc_prefix + "RC"); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 340 | // Adding hardware procedures return code details |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 341 | pelAdditionalData.emplace_back(keyWithPrefix, |
| 342 | ffdc->hwp_errorinfo.rc); |
| 343 | keyWithPrefix = ffdc_prefix + "RC_DESC"; |
| 344 | pelAdditionalData.emplace_back(keyWithPrefix, |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 345 | ffdc->hwp_errorinfo.rc_desc); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 346 | |
| 347 | // Adding hardware procedures required ffdc data for debug |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 348 | for_each(ffdc->hwp_errorinfo.ffdcs_data.begin(), |
| 349 | ffdc->hwp_errorinfo.ffdcs_data.end(), |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 350 | [&pelAdditionalData, &ffdc_prefix]( |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 351 | std::pair<std::string, std::string>& ele) -> void { |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 352 | std::string keyWithPrefix(ffdc_prefix + "FFDC_"); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 353 | keyWithPrefix.append(ele.first); |
| 354 | |
| 355 | pelAdditionalData.emplace_back(keyWithPrefix, |
| 356 | ele.second); |
| 357 | }); |
| 358 | |
| 359 | // Adding hardware callout details |
| 360 | int calloutCount = 0; |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 361 | for_each( |
| 362 | ffdc->hwp_errorinfo.hwcallouts.begin(), |
| 363 | ffdc->hwp_errorinfo.hwcallouts.end(), |
| 364 | [&pelAdditionalData, &calloutCount, &jsonCalloutDataList, |
| 365 | &ffdc_prefix](const HWCallout& hwCallout) -> void { |
| 366 | calloutCount++; |
| 367 | std::stringstream keyPrefix; |
| 368 | keyPrefix << ffdc_prefix << "HW_CO_" << std::setfill('0') |
| 369 | << std::setw(2) << calloutCount << "_"; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 370 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 371 | pelAdditionalData.emplace_back( |
| 372 | std::string(keyPrefix.str()).append("HW_ID"), |
| 373 | hwCallout.hwid); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 374 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 375 | pelAdditionalData.emplace_back( |
| 376 | std::string(keyPrefix.str()).append("PRIORITY"), |
| 377 | hwCallout.callout_priority); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 378 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 379 | // Log target details only if entity path is |
| 380 | // available. For example target entity path will not |
| 381 | // be available for non-hwp clock failure. |
| 382 | if (!hwCallout.target_entity_path.empty()) |
| 383 | { |
| 384 | phal::TargetInfo targetInfo; |
| 385 | phal::getTgtReqAttrsVal(hwCallout.target_entity_path, |
| 386 | targetInfo); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 387 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 388 | std::string locationCode = |
| 389 | std::string(targetInfo.locationCode); |
| 390 | pelAdditionalData.emplace_back( |
| 391 | std::string(keyPrefix.str()).append("LOC_CODE"), |
| 392 | locationCode); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 393 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 394 | std::string physPath = |
| 395 | std::string(targetInfo.physDevPath); |
| 396 | pelAdditionalData.emplace_back( |
| 397 | std::string(keyPrefix.str()).append("PHYS_PATH"), |
| 398 | physPath); |
| 399 | } |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 400 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 401 | pelAdditionalData.emplace_back( |
| 402 | std::string(keyPrefix.str()).append("CLK_POS"), |
| 403 | std::to_string(hwCallout.clkPos)); |
| 404 | |
| 405 | pelAdditionalData.emplace_back( |
| 406 | std::string(keyPrefix.str()).append("CALLOUT_PLANAR"), |
| 407 | (hwCallout.isPlanarCallout == true ? "true" : "false")); |
| 408 | |
| 409 | std::string pelPriority = |
| 410 | getPelPriority(hwCallout.callout_priority); |
| 411 | |
| 412 | if (hwCallout.isPlanarCallout) |
| 413 | { |
| 414 | addPlanarCallout(jsonCalloutDataList, pelPriority); |
| 415 | } |
| 416 | }); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 417 | |
| 418 | // Adding CDG (callout, deconfigure and guard) targets details |
| 419 | calloutCount = 0; |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 420 | for_each( |
| 421 | ffdc->hwp_errorinfo.cdg_targets.begin(), |
| 422 | ffdc->hwp_errorinfo.cdg_targets.end(), |
| 423 | [&pelAdditionalData, &calloutCount, &jsonCalloutDataList, |
| 424 | &ffdc_prefix](const CDG_Target& cdg_tgt) -> void { |
| 425 | calloutCount++; |
| 426 | std::stringstream keyPrefix; |
| 427 | keyPrefix << ffdc_prefix << "CDG_TGT_" << std::setfill('0') |
| 428 | << std::setw(2) << calloutCount << "_"; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 429 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 430 | phal::TargetInfo targetInfo; |
| 431 | targetInfo.deconfigure = cdg_tgt.deconfigure; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 432 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 433 | phal::getTgtReqAttrsVal(cdg_tgt.target_entity_path, |
| 434 | targetInfo); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 435 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 436 | std::string locationCode = |
| 437 | std::string(targetInfo.locationCode); |
| 438 | pelAdditionalData.emplace_back( |
| 439 | std::string(keyPrefix.str()).append("LOC_CODE"), |
| 440 | locationCode); |
| 441 | std::string physPath = std::string(targetInfo.physDevPath); |
| 442 | pelAdditionalData.emplace_back( |
| 443 | std::string(keyPrefix.str()).append("PHYS_PATH"), |
| 444 | physPath); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 445 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 446 | pelAdditionalData.emplace_back( |
| 447 | std::string(keyPrefix.str()).append("CO_REQ"), |
| 448 | (cdg_tgt.callout == true ? "true" : "false")); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 449 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 450 | pelAdditionalData.emplace_back( |
| 451 | std::string(keyPrefix.str()).append("CO_PRIORITY"), |
| 452 | cdg_tgt.callout_priority); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 453 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 454 | pelAdditionalData.emplace_back( |
| 455 | std::string(keyPrefix.str()).append("DECONF_REQ"), |
| 456 | (cdg_tgt.deconfigure == true ? "true" : "false")); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 457 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 458 | pelAdditionalData.emplace_back( |
| 459 | std::string(keyPrefix.str()).append("GUARD_REQ"), |
| 460 | (cdg_tgt.guard == true ? "true" : "false")); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 461 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 462 | pelAdditionalData.emplace_back( |
| 463 | std::string(keyPrefix.str()).append("GUARD_TYPE"), |
| 464 | cdg_tgt.guard_type); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 465 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 466 | json jsonCalloutData; |
| 467 | jsonCalloutData["LocationCode"] = locationCode; |
| 468 | std::string pelPriority = |
| 469 | getPelPriority(cdg_tgt.callout_priority); |
| 470 | jsonCalloutData["Priority"] = pelPriority; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 471 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 472 | if (targetInfo.mruId != 0) |
| 473 | { |
| 474 | jsonCalloutData["MRUs"] = json::array({ |
| 475 | {{"ID", targetInfo.mruId}, |
| 476 | {"Priority", pelPriority}}, |
| 477 | }); |
| 478 | } |
| 479 | jsonCalloutData["Deconfigured"] = cdg_tgt.deconfigure; |
| 480 | jsonCalloutData["Guarded"] = cdg_tgt.guard; |
| 481 | jsonCalloutData["GuardType"] = cdg_tgt.guard_type; |
| 482 | jsonCalloutData["EntityPath"] = cdg_tgt.target_entity_path; |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 483 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 484 | jsonCalloutDataList.emplace_back(jsonCalloutData); |
| 485 | }); |
Jayanth Othayoth | 0ac7c38 | 2021-11-15 05:43:24 -0600 | [diff] [blame] | 486 | // Adding procedure callout |
| 487 | calloutCount = 0; |
| 488 | for_each( |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 489 | ffdc->hwp_errorinfo.procedures_callout.begin(), |
| 490 | ffdc->hwp_errorinfo.procedures_callout.end(), |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 491 | [&pelAdditionalData, &calloutCount, &jsonCalloutDataList, |
| 492 | &ffdc_prefix](const ProcedureCallout& procCallout) -> void { |
Jayanth Othayoth | 0ac7c38 | 2021-11-15 05:43:24 -0600 | [diff] [blame] | 493 | calloutCount++; |
| 494 | std::stringstream keyPrefix; |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 495 | keyPrefix << ffdc_prefix << "PROC_CO_" << std::setfill('0') |
Jayanth Othayoth | 0ac7c38 | 2021-11-15 05:43:24 -0600 | [diff] [blame] | 496 | << std::setw(2) << calloutCount << "_"; |
| 497 | |
| 498 | pelAdditionalData.emplace_back( |
| 499 | std::string(keyPrefix.str()).append("PRIORITY"), |
| 500 | procCallout.callout_priority); |
| 501 | |
| 502 | pelAdditionalData.emplace_back( |
| 503 | std::string(keyPrefix.str()).append("MAINT_PROCEDURE"), |
| 504 | procCallout.proc_callout); |
| 505 | |
| 506 | json jsonCalloutData; |
| 507 | jsonCalloutData["Procedure"] = procCallout.proc_callout; |
| 508 | std::string pelPriority = |
| 509 | getPelPriority(procCallout.callout_priority); |
| 510 | jsonCalloutData["Priority"] = pelPriority; |
| 511 | jsonCalloutDataList.emplace_back(jsonCalloutData); |
| 512 | }); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 513 | } |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 514 | else if ((ffdc->ffdc_type != FFDC_TYPE_NONE) && |
| 515 | (ffdc->ffdc_type != FFDC_TYPE_UNSUPPORTED)) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 516 | { |
| 517 | log<level::ERR>( |
| 518 | fmt::format("Unsupported phal FFDC type to create PEL. " |
| 519 | "MSG: {}", |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 520 | ffdc->message) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 521 | .c_str()); |
| 522 | } |
| 523 | |
| 524 | // Adding collected phal logs into PEL additional data |
| 525 | for_each(traceLog.begin(), traceLog.end(), |
| 526 | [&pelAdditionalData]( |
| 527 | std::pair<std::string, std::string>& ele) -> void { |
| 528 | pelAdditionalData.emplace_back(ele.first, ele.second); |
| 529 | }); |
| 530 | |
| 531 | // TODO: #ibm-openbmc/dev/issues/2595 : Once enabled this support, |
| 532 | // callout details is not required to sort in H,M and L orders which |
| 533 | // are expected by pel because, pel will take care for sorting callouts |
| 534 | // based on priority so, now adding support to send callout in order |
| 535 | // i.e High -> Medium -> Low. |
| 536 | std::sort( |
| 537 | jsonCalloutDataList.begin(), jsonCalloutDataList.end(), |
| 538 | [](const json& aEle, const json& bEle) -> bool { |
| 539 | // Considering b element having higher priority than a element |
| 540 | // or Both element will be same priorty (to keep same order |
| 541 | // which are given by phal when two callouts are having same |
| 542 | // priority) |
| 543 | if (((aEle["Priority"] == "M") && (bEle["Priority"] == "H")) || |
| 544 | ((aEle["Priority"] == "L") && |
| 545 | ((bEle["Priority"] == "H") || |
| 546 | (bEle["Priority"] == "M"))) || |
| 547 | (aEle["Priority"] == bEle["Priority"])) |
| 548 | { |
| 549 | return false; |
| 550 | } |
| 551 | |
| 552 | // Considering a element having higher priority than b element |
| 553 | return true; |
| 554 | }); |
Jayanth Othayoth | 8fe9ff9 | 2021-11-14 09:15:59 -0600 | [diff] [blame] | 555 | openpower::pel::createErrorPEL("org.open_power.PHAL.Error.Boot", |
| 556 | jsonCalloutDataList, pelAdditionalData); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 557 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 558 | catch (const std::exception& ex) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 559 | { |
| 560 | reset(); |
| 561 | throw ex; |
| 562 | } |
| 563 | reset(); |
| 564 | } |
| 565 | |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 566 | void processPlatBootError(const ipl_error_info& errInfo) |
| 567 | { |
| 568 | log<level::INFO>("processPlatBootError "); |
| 569 | |
| 570 | // Collecting ffdc details from phal |
| 571 | FFDC* ffdc = reinterpret_cast<FFDC*>(errInfo.private_data); |
| 572 | try |
| 573 | { |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 574 | processBootErrorHelper(ffdc, "PLAT_"); |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 575 | } |
| 576 | catch (const std::exception& ex) |
| 577 | { |
| 578 | log<level::ERR>( |
| 579 | fmt::format("processPlatBootError: exception({})", ex.what()) |
| 580 | .c_str()); |
| 581 | throw ex; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | void processBootError(bool status) |
| 586 | { |
| 587 | log<level::INFO>( |
| 588 | fmt::format("processBootError: status({})", status).c_str()); |
| 589 | |
| 590 | try |
| 591 | { |
| 592 | // return If no failure during hwp execution |
| 593 | if (status) |
| 594 | return; |
| 595 | |
| 596 | // Collecting ffdc details from phal |
| 597 | FFDC ffdc; |
| 598 | libekb_get_ffdc(ffdc); |
| 599 | |
rajerpp1 | db92472 | 2021-11-30 11:00:05 -0600 | [diff] [blame] | 600 | processBootErrorHelper(&ffdc, "HWP_"); |
Marri Devender Rao | 381c3e3 | 2021-12-01 06:27:55 -0600 | [diff] [blame] | 601 | } |
| 602 | catch (const std::exception& ex) |
| 603 | { |
| 604 | log<level::ERR>( |
| 605 | fmt::format("processBootError: exception({})", ex.what()).c_str()); |
| 606 | throw ex; |
| 607 | } |
| 608 | } |
| 609 | |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 610 | void processSbeBootError() |
| 611 | { |
| 612 | log<level::INFO>("processSbeBootError : Entered "); |
| 613 | |
| 614 | using namespace openpower::phal::sbe; |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 615 | |
| 616 | // To store phal trace and other additional data about ffdc. |
| 617 | FFDCData pelAdditionalData; |
| 618 | |
| 619 | // Adding collected phal logs into PEL additional data |
| 620 | for_each( |
| 621 | traceLog.begin(), traceLog.end(), |
| 622 | [&pelAdditionalData](std::pair<std::string, std::string>& ele) -> void { |
| 623 | pelAdditionalData.emplace_back(ele.first, ele.second); |
| 624 | }); |
| 625 | |
| 626 | // reset the trace log and counter |
| 627 | reset(); |
| 628 | |
| 629 | // get primary processor to collect FFDC/Dump information. |
| 630 | struct pdbg_target* procTarget; |
| 631 | pdbg_for_each_class_target("proc", procTarget) |
| 632 | { |
| 633 | if (openpower::phal::isPrimaryProc(procTarget)) |
| 634 | break; |
| 635 | procTarget = nullptr; |
| 636 | } |
| 637 | // check valid primary processor is available |
| 638 | if (procTarget == nullptr) |
| 639 | { |
| 640 | log<level::ERR>("processSbeBootError: fail to get primary processor"); |
Jayanth Othayoth | 0a516de | 2021-11-14 09:59:06 -0600 | [diff] [blame] | 641 | // Add BMC code callout and create PEL |
| 642 | json jsonCalloutDataList; |
| 643 | jsonCalloutDataList = json::array(); |
| 644 | json jsonCalloutData; |
| 645 | jsonCalloutData["Procedure"] = "BMC0001"; |
| 646 | jsonCalloutData["Priority"] = "H"; |
| 647 | jsonCalloutDataList.emplace_back(jsonCalloutData); |
| 648 | openpower::pel::createErrorPEL( |
| 649 | "org.open_power.Processor.Error.SbeBootFailure", |
| 650 | jsonCalloutDataList); |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 651 | return; |
| 652 | } |
| 653 | // SBE error object. |
| 654 | sbeError_t sbeError; |
| 655 | bool dumpIsRequired = false; |
| 656 | |
| 657 | try |
| 658 | { |
| 659 | // Capture FFDC information on primary processor |
| 660 | sbeError = captureFFDC(procTarget); |
| 661 | } |
Jayanth Othayoth | faaef2a | 2021-10-08 06:49:36 -0500 | [diff] [blame] | 662 | catch (const phalError_t& phalError) |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 663 | { |
| 664 | // Fail to collect FFDC information , trigger Dump |
| 665 | log<level::ERR>( |
Jayanth Othayoth | faaef2a | 2021-10-08 06:49:36 -0500 | [diff] [blame] | 666 | fmt::format("captureFFDC: Exception({})", phalError.what()) |
| 667 | .c_str()); |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 668 | dumpIsRequired = true; |
| 669 | } |
| 670 | |
Jayanth Othayoth | 006641e | 2021-10-07 06:56:24 -0500 | [diff] [blame] | 671 | std::string event; |
| 672 | |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 673 | if ((sbeError.errType() == SBE_FFDC_NO_DATA) || |
| 674 | (sbeError.errType() == SBE_CMD_TIMEOUT) || (dumpIsRequired)) |
| 675 | { |
Jayanth Othayoth | 006641e | 2021-10-07 06:56:24 -0500 | [diff] [blame] | 676 | event = "org.open_power.Processor.Error.SbeBootTimeout"; |
| 677 | dumpIsRequired = true; |
| 678 | } |
| 679 | else |
| 680 | { |
| 681 | event = "org.open_power.Processor.Error.SbeBootFailure"; |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 682 | } |
| 683 | // SRC6 : [0:15] chip position |
Jayanth Othayoth | 006641e | 2021-10-07 06:56:24 -0500 | [diff] [blame] | 684 | uint32_t index = pdbg_target_index(procTarget); |
| 685 | pelAdditionalData.emplace_back("SRC6", std::to_string(index << 16)); |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 686 | // Create SBE Error with FFDC data. |
Jayanth Othayoth | e5ba5fd | 2022-01-27 09:29:01 -0600 | [diff] [blame] | 687 | auto logId = |
| 688 | createSbeErrorPEL(event, sbeError, pelAdditionalData, procTarget); |
Jayanth Othayoth | 006641e | 2021-10-07 06:56:24 -0500 | [diff] [blame] | 689 | |
| 690 | if (dumpIsRequired) |
| 691 | { |
| 692 | using namespace openpower::phal::dump; |
| 693 | DumpParameters dumpParameters = {logId, index, SBE_DUMP_TIMEOUT, |
| 694 | DumpType::SBE}; |
| 695 | try |
| 696 | { |
| 697 | requestDump(dumpParameters); |
| 698 | } |
| 699 | catch (const std::runtime_error& e) |
| 700 | { |
| 701 | // Allowing call back to handle the error gracefully. |
| 702 | log<level::ERR>("Dump collection failed"); |
| 703 | // TODO revist error handling. |
| 704 | } |
| 705 | } |
Jayanth Othayoth | 4079f09 | 2021-09-20 07:36:54 -0500 | [diff] [blame] | 706 | } |
| 707 | |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 708 | void reset() |
| 709 | { |
| 710 | // reset the trace log and counter |
| 711 | traceLog.clear(); |
| 712 | counter = 0; |
| 713 | } |
| 714 | |
Brad Bishop | 63508a7 | 2020-10-27 18:55:01 -0400 | [diff] [blame] | 715 | void pDBGLogTraceCallbackHelper(int, const char* fmt, va_list ap) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 716 | { |
| 717 | processLogTraceCallback(NULL, fmt, ap); |
| 718 | } |
| 719 | } // namespace detail |
| 720 | |
| 721 | static inline uint8_t getLogLevelFromEnv(const char* env, const uint8_t dValue) |
| 722 | { |
| 723 | auto logLevel = dValue; |
| 724 | try |
| 725 | { |
| 726 | if (const char* env_p = std::getenv(env)) |
| 727 | { |
| 728 | logLevel = std::stoi(env_p); |
| 729 | } |
| 730 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 731 | catch (const std::exception& e) |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 732 | { |
| 733 | log<level::ERR>(("Conversion Failure"), entry("ENVIRONMENT=%s", env), |
| 734 | entry("EXCEPTION=%s", e.what())); |
| 735 | } |
| 736 | return logLevel; |
| 737 | } |
| 738 | |
| 739 | void addBootErrorCallbacks() |
| 740 | { |
| 741 | // Get individual phal repos log level from environment variable |
| 742 | // and update the log level. |
| 743 | pdbg_set_loglevel(getLogLevelFromEnv("PDBG_LOG", PDBG_INFO)); |
| 744 | libekb_set_loglevel(getLogLevelFromEnv("LIBEKB_LOG", LIBEKB_LOG_IMP)); |
| 745 | ipl_set_loglevel(getLogLevelFromEnv("IPL_LOG", IPL_INFO)); |
| 746 | |
| 747 | // add callback for debug traces |
| 748 | pdbg_set_logfunc(detail::pDBGLogTraceCallbackHelper); |
| 749 | libekb_set_logfunc(detail::processLogTraceCallback, NULL); |
| 750 | ipl_set_logfunc(detail::processLogTraceCallback, NULL); |
| 751 | |
| 752 | // add callback for ipl failures |
Jayanth Othayoth | 2b21170 | 2021-09-06 05:14:23 -0500 | [diff] [blame] | 753 | ipl_set_error_callback_func(detail::processIplErrorCallback); |
Brad Bishop | f6783cd | 2020-10-27 19:25:09 -0400 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | } // namespace pel |
| 757 | } // namespace openpower |