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