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