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> |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 18 | #include "softoff.hpp" |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 19 | #include "config.h" |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 20 | namespace phosphor |
| 21 | { |
| 22 | namespace ipmi |
| 23 | { |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 24 | |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 25 | // Sends the SMS_ATN to host if value is set |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 26 | void SoftPowerOff::sendSMSAttn() |
| 27 | { |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 28 | using namespace std::chrono; |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 29 | auto method = bus.new_method_call(HOST_IPMI_BUS, |
| 30 | HOST_IPMI_OBJ, |
| 31 | HOST_IPMI_INTF, |
| 32 | "setAttention"); |
| 33 | |
| 34 | // If there is any exception, would be thrown here. |
| 35 | // BT returns '0' on success and bus_error on failure. |
| 36 | bus.call_noreply(method); |
| 37 | |
Vishwanatha Subbanna | d27e71e | 2017-02-01 18:02:38 +0530 | [diff] [blame] | 38 | // Start the timer |
| 39 | auto time = duration_cast<microseconds>( |
| 40 | seconds(IPMI_SMS_ATN_ACK_TIMEOUT_SECS)); |
| 41 | auto r = timer.startTimer(time); |
| 42 | if (r < 0) |
| 43 | { |
| 44 | throw std::runtime_error("Error starting timer"); |
| 45 | } |
Vishwanatha Subbanna | 7cc9d71 | 2017-01-24 18:48:40 +0530 | [diff] [blame] | 46 | return; |
| 47 | } |
Vishwanatha Subbanna | bcb7688 | 2017-01-25 16:29:43 +0530 | [diff] [blame] | 48 | |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 49 | // Starts a timer |
| 50 | int SoftPowerOff::startTimer(const std::chrono::microseconds& usec) |
| 51 | { |
| 52 | return timer.startTimer(usec); |
| 53 | } |
| 54 | |
| 55 | // Host Response handler |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 56 | auto SoftPowerOff::responseReceived(HostResponse response) -> HostResponse |
| 57 | { |
| 58 | using namespace std::chrono; |
| 59 | using namespace phosphor::logging; |
| 60 | |
| 61 | if (response == HostResponse::SoftOffReceived) |
| 62 | { |
| 63 | // Need to stop the running timer and then start a new timer |
| 64 | auto time = duration_cast<microseconds>( |
| 65 | seconds(IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS)); |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 66 | auto r = startTimer(time); |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 67 | if (r < 0) |
| 68 | { |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 69 | log<level::ERR>("Failure to start Host shutdown wait timer", |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 70 | entry("ERROR=%s", strerror(-r))); |
| 71 | } |
Vishwanatha Subbanna | 917454b | 2017-02-24 00:16:05 +0530 | [diff] [blame] | 72 | else |
| 73 | { |
| 74 | log<level::INFO>("Timer started waiting for host to shutdown", |
| 75 | entry("TIMEOUT_IN_MSEC=%llu", |
| 76 | duration_cast<milliseconds>(seconds |
| 77 | (IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS)))); |
| 78 | } |
Vishwanatha Subbanna | 31272b8 | 2017-02-01 18:53:14 +0530 | [diff] [blame] | 79 | } |
| 80 | else if (response == HostResponse::HostShutdown) |
| 81 | { |
| 82 | // Disable the timer since Host has quiesced and we are |
| 83 | // done with soft power off part |
| 84 | auto r = timer.setTimer(SD_EVENT_OFF); |
| 85 | if (r < 0) |
| 86 | { |
| 87 | log<level::ERR>("Failure to STOP the timer", |
| 88 | entry("ERROR=%s", strerror(-r))); |
| 89 | } |
| 90 | |
| 91 | // This marks the completion of soft power off sequence. |
| 92 | completed = true; |
| 93 | } |
| 94 | |
| 95 | return sdbusplus::xyz::openbmc_project::Ipmi::Internal |
| 96 | ::server::SoftPowerOff::responseReceived(response); |
| 97 | } |
| 98 | |
Vishwanatha Subbanna | 506aa0f | 2017-01-24 14:58:25 +0530 | [diff] [blame] | 99 | } // namespace ipmi |
| 100 | } // namespace phosphor |