Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
| 5 | #include "timer.hpp" |
| 6 | |
| 7 | #include <functional> |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/server/object.hpp> |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Control/Host/server.hpp> |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Ipmi/Internal/SoftPowerOff/server.hpp> |
| 12 | namespace phosphor |
| 13 | { |
| 14 | namespace ipmi |
| 15 | { |
| 16 | |
| 17 | namespace Base = sdbusplus::xyz::openbmc_project::Ipmi::Internal::server; |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 18 | using namespace sdbusplus::xyz::openbmc_project::Control::server; |
| 19 | |
| 20 | namespace sdbusRule = sdbusplus::bus::match::rules; |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 21 | |
| 22 | /** @class SoftPowerOff |
| 23 | * @brief Responsible for coordinating Host SoftPowerOff operation |
| 24 | */ |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 25 | class SoftPowerOff |
| 26 | : public sdbusplus::server::object::object<Base::SoftPowerOff> |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 27 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 28 | public: |
| 29 | /** @brief Constructs SoftPowerOff object. |
| 30 | * |
| 31 | * @param[in] bus - system dbus handler |
| 32 | * @param[in] event - sd_event handler |
| 33 | * @param[in] objPath - The Dbus path hosting SoftPowerOff function |
| 34 | */ |
| 35 | SoftPowerOff(sdbusplus::bus::bus& bus, sd_event* event, |
| 36 | const char* objPath) : |
| 37 | sdbusplus::server::object::object<Base::SoftPowerOff>(bus, objPath, |
| 38 | false), |
| 39 | bus(bus), timer(event), |
| 40 | hostControlSignal( |
| 41 | bus, |
| 42 | sdbusRule::type::signal() + sdbusRule::member("CommandComplete") + |
| 43 | sdbusRule::path("/xyz/openbmc_project/control/host0") + |
| 44 | sdbusRule::interface(CONTROL_HOST_BUSNAME) + |
| 45 | sdbusRule::argN(0, convertForMessage(Host::Command::SoftOff)), |
| 46 | std::bind(std::mem_fn(&SoftPowerOff::hostControlEvent), this, |
| 47 | std::placeholders::_1)) |
| 48 | { |
| 49 | // Need to announce since we may get the response |
| 50 | // very quickly on host shutdown command |
| 51 | emit_object_added(); |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 52 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 53 | // The whole purpose of this application is to send a host shutdown |
| 54 | // command and watch for the soft power off to go through. We need |
| 55 | // the interface added signal emitted before we send the shutdown |
| 56 | // command just to attend to lightning fast response from host |
| 57 | sendHostShutDownCmd(); |
| 58 | } |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 59 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 60 | /** @brief Tells if the objective of this application is completed */ |
| 61 | inline auto isCompleted() |
| 62 | { |
| 63 | return completed; |
| 64 | } |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 65 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 66 | /** @brief Tells if the referenced timer is expired or not */ |
| 67 | inline auto isTimerExpired() |
| 68 | { |
| 69 | return timer.isExpired(); |
| 70 | } |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 71 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 72 | /** @brief overloaded property setter function |
| 73 | * |
| 74 | * @param[in] value - One of SoftOffReceived / HostShutdown |
| 75 | * |
| 76 | * @return Success or exception thrown |
| 77 | */ |
| 78 | HostResponse responseReceived(HostResponse value) override; |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 79 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 80 | /** @brief Using the base class's getter method */ |
| 81 | using Base::SoftPowerOff::responseReceived; |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 82 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 83 | /** @brief Calls to start a timer |
| 84 | * |
| 85 | * @param[in] usec - Time in microseconds |
| 86 | * |
| 87 | * @return Success or exception thrown |
| 88 | */ |
| 89 | int startTimer(const std::chrono::microseconds& usec); |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 90 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 91 | private: |
| 92 | // Need this to send SMS_ATTN |
| 93 | // TODO : Switch over to using mapper service in a different patch |
| 94 | static constexpr auto HOST_IPMI_BUS = "org.openbmc.HostIpmi"; |
| 95 | static constexpr auto HOST_IPMI_OBJ = "/org/openbmc/HostIpmi/1"; |
| 96 | static constexpr auto HOST_IPMI_INTF = "org.openbmc.HostIpmi"; |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 97 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 98 | /* @brief sdbusplus handle */ |
| 99 | sdbusplus::bus::bus& bus; |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 100 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 101 | /** @brief Reference to Timer object */ |
| 102 | Timer timer; |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 103 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 104 | /** @brief Marks the end of life of this application. |
| 105 | * |
| 106 | * This is set to true if host gives appropriate responses |
| 107 | * for the sequence of commands. |
| 108 | */ |
| 109 | bool completed = false; |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 110 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 111 | /** @brief Subscribe to host control signals |
| 112 | * |
| 113 | * Protocol is to send the host power off request to the host |
| 114 | * control interface and then wait for a signal indicating pass/fail |
| 115 | **/ |
| 116 | sdbusplus::bus::match_t hostControlSignal; |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 117 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 118 | /** @brief Sends host control command to tell host to shut down |
| 119 | * |
| 120 | * After sending the command, wait for a signal indicating the status |
| 121 | * of the command. |
| 122 | * |
| 123 | * After receiving the initial response, start a timer for 30 minutes |
| 124 | * to let host do a clean shutdown of partitions. When the response is |
| 125 | * received from the host, it indicates that BMC can do a power off. |
| 126 | * If BMC fails to get any response, then a hard power off would |
| 127 | * be forced. |
| 128 | * |
| 129 | * @return - Does not return anything. Error will result in exception |
| 130 | * being thrown |
| 131 | */ |
| 132 | void sendHostShutDownCmd(); |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 133 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 134 | /** @brief Callback function on host control signals |
| 135 | * |
| 136 | * @param[in] msg - Data associated with subscribed signal |
| 137 | * |
| 138 | */ |
| 139 | void hostControlEvent(sdbusplus::message::message& msg); |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 140 | }; |
| 141 | } // namespace ipmi |
| 142 | } // namespace phosphor |