Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2016 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 | */ |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 16 | #include <chrono> |
| 17 | #include <phosphor-logging/log.hpp> |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/elog.hpp> |
| 19 | #include <xyz/openbmc_project/Control/Host/server.hpp> |
| 20 | #include <utils.hpp> |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 21 | #include "softoff.hpp" |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 22 | #include "elog-gen-softoff.hpp" |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 23 | #include "config.h" |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 24 | namespace phosphor |
| 25 | { |
| 26 | namespace ipmi |
| 27 | { |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 28 | |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 29 | using namespace phosphor::logging; |
| 30 | using namespace sdbusplus::xyz::openbmc_project::Control::server; |
| 31 | |
| 32 | void SoftPowerOff::sendHostShutDownCmd() |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 33 | { |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 34 | std::string ctrlHostPath{CONTROL_HOST_OBJPATH}; |
| 35 | ctrlHostPath += "0"; |
| 36 | auto host = ::ipmi::getService(this->bus, |
| 37 | CONTROL_HOST_BUSNAME, |
| 38 | ctrlHostPath.c_str()); |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 39 | |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 40 | auto method = bus.new_method_call(host.c_str(), |
| 41 | ctrlHostPath.c_str(), |
| 42 | CONTROL_HOST_BUSNAME, |
| 43 | "Execute"); |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 44 | |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 45 | method.append(convertForMessage(Host::Command::SoftOff).c_str()); |
| 46 | |
| 47 | auto reply = bus.call(method); |
| 48 | if (reply.is_method_error()) |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 49 | { |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 50 | log<level::ERR>("Error in call to control host Execute"); |
| 51 | // TODO openbmc/openbmc#851 - Once available, throw returned error |
| 52 | throw std::runtime_error("Error in call to control host Execute"); |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 53 | } |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 54 | |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 55 | return; |
| 56 | } |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 57 | |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 58 | |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 59 | // Function called on host control signals |
| 60 | void SoftPowerOff::hostControlEvent(sdbusplus::message::message& msg) |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 61 | { |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 62 | std::string cmdCompleted{}; |
| 63 | std::string cmdStatus{}; |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 64 | |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 65 | msg.read(cmdCompleted, cmdStatus); |
| 66 | |
| 67 | log<level::DEBUG>("Host control signal values", |
| 68 | entry("COMMAND=%s",cmdCompleted.c_str()), |
| 69 | entry("STATUS=%s",cmdStatus.c_str())); |
| 70 | |
| 71 | if(Host::convertResultFromString(cmdStatus) == Host::Result::Success) |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 72 | { |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 73 | // Set our internal property indicating we got host attention |
| 74 | sdbusplus::xyz::openbmc_project::Ipmi::Internal |
| 75 | ::server::SoftPowerOff::responseReceived( |
| 76 | HostResponse::SoftOffReceived); |
| 77 | |
| 78 | // Start timer for host shutdown |
| 79 | using namespace std::chrono; |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 80 | auto time = duration_cast<microseconds>( |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 81 | seconds(IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS)); |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 82 | auto r = startTimer(time); |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 83 | if (r < 0) |
| 84 | { |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 85 | log<level::ERR>("Failure to start Host shutdown wait timer", |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 86 | entry("ERROR=%s", strerror(-r))); |
| 87 | } |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 88 | else |
| 89 | { |
| 90 | log<level::INFO>("Timer started waiting for host to shutdown", |
| 91 | entry("TIMEOUT_IN_MSEC=%llu", |
| 92 | duration_cast<milliseconds>(seconds |
| 93 | (IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS)))); |
| 94 | } |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 95 | } |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 96 | else |
| 97 | { |
| 98 | elog<xyz::openbmc_project::SoftPowerOff::Internal::SoftOffFailed>(); |
| 99 | } |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | // Starts a timer |
| 104 | int SoftPowerOff::startTimer(const std::chrono::microseconds& usec) |
| 105 | { |
| 106 | return timer.startTimer(usec); |
| 107 | } |
| 108 | |
| 109 | // Host Response handler |
| 110 | auto SoftPowerOff::responseReceived(HostResponse response) -> HostResponse |
| 111 | { |
| 112 | using namespace std::chrono; |
| 113 | |
| 114 | if (response == HostResponse::HostShutdown) |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 115 | { |
| 116 | // Disable the timer since Host has quiesced and we are |
| 117 | // done with soft power off part |
| 118 | auto r = timer.setTimer(SD_EVENT_OFF); |
| 119 | if (r < 0) |
| 120 | { |
| 121 | log<level::ERR>("Failure to STOP the timer", |
| 122 | entry("ERROR=%s", strerror(-r))); |
| 123 | } |
| 124 | |
| 125 | // This marks the completion of soft power off sequence. |
| 126 | completed = true; |
| 127 | } |
| 128 | |
| 129 | return sdbusplus::xyz::openbmc_project::Ipmi::Internal |
| 130 | ::server::SoftPowerOff::responseReceived(response); |
| 131 | } |
| 132 | |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 133 | } // namespace ipmi |
| 134 | } // namespace phosphor |