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 | |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 20 | #include <ipmid/utils.hpp> |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 21 | #include <phosphor-logging/log.hpp> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 22 | #include <xyz/openbmc_project/Control/Host/server.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 23 | |
| 24 | #include <chrono> |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 25 | namespace phosphor |
| 26 | { |
| 27 | namespace ipmi |
| 28 | { |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 29 | |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 30 | using namespace phosphor::logging; |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 31 | using namespace sdbusplus::server::xyz::openbmc_project::control; |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 32 | |
| 33 | void SoftPowerOff::sendHostShutDownCmd() |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 34 | { |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 35 | auto ctrlHostPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + |
| 36 | '0'; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 37 | auto host = ::ipmi::getService(this->bus, CONTROL_HOST_BUSNAME, |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 38 | ctrlHostPath.c_str()); |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 39 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 40 | auto method = bus.new_method_call(host.c_str(), ctrlHostPath.c_str(), |
| 41 | CONTROL_HOST_BUSNAME, "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()); |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 44 | try |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 45 | { |
George Liu | 3e3cc35 | 2023-07-26 15:59:31 +0800 | [diff] [blame] | 46 | auto reply = bus.call(method); |
| 47 | } |
| 48 | catch (const std::exception& e) |
| 49 | { |
| 50 | log<level::ERR>("Error in call to control host Execute", |
| 51 | entry("ERROR=%s", e.what())); |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 52 | // TODO openbmc/openbmc#851 - Once available, throw returned error |
| 53 | throw std::runtime_error("Error in call to control host Execute"); |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 54 | } |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 55 | } |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 56 | |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 57 | // Function called on host control signals |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 58 | void SoftPowerOff::hostControlEvent(sdbusplus::message_t& 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", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 66 | entry("COMMAND=%s", cmdCompleted.c_str()), |
| 67 | entry("STATUS=%s", cmdStatus.c_str())); |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 68 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 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 |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 72 | sdbusplus::server::xyz::openbmc_project::ipmi::internal::SoftPowerOff:: |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 73 | responseReceived(HostResponse::SoftOffReceived); |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 74 | |
| 75 | // Start timer for host shutdown |
| 76 | using namespace std::chrono; |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 77 | auto time = duration_cast<microseconds>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 78 | seconds(IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS)); |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 79 | auto r = startTimer(time); |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 80 | if (r < 0) |
| 81 | { |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 82 | log<level::ERR>("Failure to start Host shutdown wait timer", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 83 | entry("ERRNO=0x%X", -r)); |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 84 | } |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 85 | else |
| 86 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 87 | log<level::INFO>( |
| 88 | "Timer started waiting for host to shutdown", |
Joseph Reynolds | 510eb9c | 2018-05-30 11:51:28 -0500 | [diff] [blame] | 89 | entry("TIMEOUT_IN_MSEC=%llu", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 90 | (duration_cast<milliseconds>( |
| 91 | seconds(IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS))) |
| 92 | .count())); |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 93 | } |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 94 | } |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 95 | else |
| 96 | { |
Andrew Geissler | 5f4fe3c | 2017-05-31 19:34:41 -0500 | [diff] [blame] | 97 | // An error on the initial attention is not considered an error, just |
| 98 | // exit normally and allow remaining shutdown targets to run |
| 99 | log<level::INFO>("Timeout on host attention, continue with power down"); |
| 100 | completed = true; |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 101 | } |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | // Starts a timer |
| 106 | int SoftPowerOff::startTimer(const std::chrono::microseconds& usec) |
| 107 | { |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 108 | return timer.start(usec); |
Andrew Geissler | f0f496c | 2017-05-02 13:54:35 -0500 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | // Host Response handler |
| 112 | auto SoftPowerOff::responseReceived(HostResponse response) -> HostResponse |
| 113 | { |
| 114 | using namespace std::chrono; |
| 115 | |
| 116 | if (response == HostResponse::HostShutdown) |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 117 | { |
| 118 | // Disable the timer since Host has quiesced and we are |
| 119 | // done with soft power off part |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 120 | auto r = timer.stop(); |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 121 | if (r < 0) |
| 122 | { |
| 123 | log<level::ERR>("Failure to STOP the timer", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 124 | entry("ERRNO=0x%X", -r)); |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | // This marks the completion of soft power off sequence. |
| 128 | completed = true; |
| 129 | } |
| 130 | |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 131 | return sdbusplus::server::xyz::openbmc_project::ipmi::internal:: |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 132 | SoftPowerOff::responseReceived(response); |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 133 | } |
| 134 | |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 135 | } // namespace ipmi |
| 136 | } // namespace phosphor |