Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "power_sequencer_monitor.hpp" |
| 18 | |
| 19 | #include <fmt/format.h> |
| 20 | |
| 21 | #include <phosphor-logging/elog.hpp> |
| 22 | #include <phosphor-logging/log.hpp> |
| 23 | |
| 24 | #include <exception> |
| 25 | #include <map> |
| 26 | |
| 27 | namespace phosphor::power::sequencer |
| 28 | { |
| 29 | |
| 30 | using namespace phosphor::logging; |
| 31 | |
| 32 | PowerSequencerMonitor::PowerSequencerMonitor(sdbusplus::bus::bus& bus) : |
| 33 | bus(bus) |
| 34 | {} |
| 35 | |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 36 | void PowerSequencerMonitor::createBmcDump() |
| 37 | { |
| 38 | try |
| 39 | { |
| 40 | auto method = bus.new_method_call( |
| 41 | "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump/bmc", |
| 42 | "xyz.openbmc_project.Dump.Create", "CreateDump"); |
| 43 | method.append( |
| 44 | std::vector< |
| 45 | std::pair<std::string, std::variant<std::string, uint64_t>>>()); |
| 46 | bus.call_noreply(method); |
| 47 | } |
| 48 | catch (const sdbusplus::exception::exception& e) |
| 49 | { |
| 50 | log<level::ERR>( |
| 51 | fmt::format("Unable to create dump, error {}", e.what()).c_str()); |
| 52 | } |
| 53 | } |
| 54 | |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 55 | void PowerSequencerMonitor::logError( |
| 56 | const std::string& message, |
| 57 | std::map<std::string, std::string>& additionalData) |
| 58 | { |
| 59 | try |
| 60 | { |
| 61 | auto method = bus.new_method_call( |
| 62 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 63 | "xyz.openbmc_project.Logging.Create", "Create"); |
| 64 | |
| 65 | // Add PID to AdditionalData |
| 66 | additionalData.emplace("_PID", std::to_string(getpid())); |
Jim Wright | 7f20c5d | 2022-02-28 20:49:39 -0600 | [diff] [blame] | 67 | // Set as system terminating |
| 68 | additionalData.emplace("SEVERITY_DETAIL", "SYSTEM_TERM"); |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 69 | |
| 70 | method.append(message, |
| 71 | sdbusplus::xyz::openbmc_project::Logging::server::Entry:: |
| 72 | Level::Critical, |
| 73 | additionalData); |
| 74 | bus.call_noreply(method); |
| 75 | } |
| 76 | catch (const std::exception& e) |
| 77 | { |
| 78 | log<level::ERR>( |
| 79 | fmt::format("Unable to log error, message: {}, error {}", message, |
| 80 | e.what()) |
| 81 | .c_str()); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void PowerSequencerMonitor::onFailure(bool timeout, |
| 86 | const std::string& powerSupplyError) |
| 87 | { |
| 88 | std::map<std::string, std::string> additionalData{}; |
| 89 | if (!powerSupplyError.empty()) |
| 90 | { |
| 91 | // Default to power supply error |
| 92 | logError(powerSupplyError, additionalData); |
| 93 | } |
| 94 | else if (timeout) |
| 95 | { |
| 96 | // Default to timeout error |
| 97 | logError("xyz.openbmc_project.Power.Error.PowerOnTimeout", |
| 98 | additionalData); |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | // Default to generic pgood error |
| 103 | logError("xyz.openbmc_project.Power.Error.Shutdown", additionalData); |
| 104 | } |
Jim Wright | 213ffe9 | 2022-06-03 08:54:30 -0500 | [diff] [blame] | 105 | if (!timeout) |
| 106 | { |
| 107 | createBmcDump(); |
| 108 | } |
Jim Wright | 930458c | 2022-01-24 14:37:27 -0600 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | } // namespace phosphor::power::sequencer |