blob: e88096fc1890d240143a69e7f1d8952e2e5ba74c [file] [log] [blame]
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +05301/**
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 Subbannad27e71e2017-02-01 18:02:38 +053016#include <chrono>
17#include <phosphor-logging/log.hpp>
Vishwanatha Subbanna7cc9d712017-01-24 18:48:40 +053018#include "softoff.hpp"
Vishwanatha Subbannad27e71e2017-02-01 18:02:38 +053019#include "config.h"
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +053020namespace phosphor
21{
22namespace ipmi
23{
Vishwanatha Subbanna7cc9d712017-01-24 18:48:40 +053024
Vishwanatha Subbanna7cc9d712017-01-24 18:48:40 +053025/** @brief Send the SMS_ATN to host if value is set */
26void SoftPowerOff::sendSMSAttn()
27{
Vishwanatha Subbannad27e71e2017-02-01 18:02:38 +053028 using namespace std::chrono;
Vishwanatha Subbanna7cc9d712017-01-24 18:48:40 +053029 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 Subbannad27e71e2017-02-01 18:02:38 +053038 // 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 Subbanna7cc9d712017-01-24 18:48:40 +053046 return;
47}
Vishwanatha Subbannabcb76882017-01-25 16:29:43 +053048
Vishwanatha Subbanna31272b82017-02-01 18:53:14 +053049/** @brief Host Response handler */
50auto SoftPowerOff::responseReceived(HostResponse response) -> HostResponse
51{
52 using namespace std::chrono;
53 using namespace phosphor::logging;
54
55 if (response == HostResponse::SoftOffReceived)
56 {
57 // Need to stop the running timer and then start a new timer
58 auto time = duration_cast<microseconds>(
59 seconds(IPMI_HOST_SHUTDOWN_COMPLETE_TIMEOUT_SECS));
60 auto r = timer.startTimer(time);
61 if (r < 0)
62 {
63 log<level::ERR>("Failure to start HostQuiesce wait timer",
64 entry("ERROR=%s", strerror(-r)));
65 }
66 }
67 else if (response == HostResponse::HostShutdown)
68 {
69 // Disable the timer since Host has quiesced and we are
70 // done with soft power off part
71 auto r = timer.setTimer(SD_EVENT_OFF);
72 if (r < 0)
73 {
74 log<level::ERR>("Failure to STOP the timer",
75 entry("ERROR=%s", strerror(-r)));
76 }
77
78 // This marks the completion of soft power off sequence.
79 completed = true;
80 }
81
82 return sdbusplus::xyz::openbmc_project::Ipmi::Internal
83 ::server::SoftPowerOff::responseReceived(response);
84}
85
Vishwanatha Subbanna506aa0f2017-01-24 14:58:25 +053086} // namespace ipmi
87} // namespace phosphor