Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 1 | #include <functional> |
| 2 | #include <systemintfcmds.h> |
Vishwanatha Subbanna | 6e8979d | 2017-07-13 16:48:20 +0530 | [diff] [blame] | 3 | #include <host-ipmid/ipmid-host-cmd.hpp> |
| 4 | #include <host-ipmid/ipmid-host-cmd-utils.hpp> |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 5 | #include <utils.hpp> |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 6 | #include <phosphor-logging/log.hpp> |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 7 | #include <config.h> |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 8 | #include <host-interface.hpp> |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 9 | namespace phosphor |
| 10 | { |
| 11 | namespace host |
| 12 | { |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 13 | namespace command |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 14 | { |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 15 | |
| 16 | // When you see Base:: you know we're referencing our base class |
| 17 | namespace Base = sdbusplus::xyz::openbmc_project::Control::server; |
| 18 | |
| 19 | // IPMI OEM command. |
| 20 | // https://github.com/openbmc/openbmc/issues/2082 for handling |
| 21 | // Non-OEM commands that need to send SMS_ATN |
| 22 | using OEMCmd = uint8_t; |
| 23 | |
| 24 | // Map of IPMI OEM command to its equivalent interface command. |
| 25 | // This is needed when invoking the callback handler to indicate |
| 26 | // the status of the executed command. |
| 27 | static const std::map<OEMCmd, Host::Command> intfCommand = { |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 28 | { |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 29 | CMD_HEARTBEAT, |
| 30 | Base::Host::Command::Heartbeat |
| 31 | }, |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 32 | { |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 33 | CMD_POWER, |
| 34 | Base::Host::Command::SoftOff |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 35 | } |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 36 | }; |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 37 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 38 | // Map of Interface command to its corresponding IPMI OEM command. |
| 39 | // This is needed when pushing IPMI commands to command manager's |
| 40 | // queue. The same pair will be returned when IPMI asks us |
| 41 | // why a SMS_ATN was sent |
| 42 | static const std::map<Host::Command, IpmiCmdData> ipmiCommand = { |
| 43 | { |
| 44 | Base::Host::Command::Heartbeat, |
| 45 | std::make_pair(CMD_HEARTBEAT, 0x00) |
| 46 | }, |
| 47 | { |
| 48 | Base::Host::Command::SoftOff, |
| 49 | std::make_pair(CMD_POWER, SOFT_OFF) |
| 50 | } |
| 51 | }; |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 52 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 53 | // Called at user request |
| 54 | void Host::execute(Base::Host::Command command) |
Andrew Geissler | 8315970 | 2017-04-03 13:31:13 -0500 | [diff] [blame] | 55 | { |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 56 | using namespace phosphor::logging; |
Andrew Geissler | 1b9d4e5 | 2017-03-21 15:04:05 -0500 | [diff] [blame] | 57 | |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame^] | 58 | log<level::DEBUG>("Pushing cmd on to queue", |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 59 | entry("CONTROL_HOST_CMD=%s", |
| 60 | convertForMessage(command))); |
| 61 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 62 | auto cmd = std::make_tuple(ipmiCommand.at(command), |
| 63 | std::bind(&Host::commandStatusHandler, |
| 64 | this, std::placeholders::_1, |
| 65 | std::placeholders::_2)); |
Andrew Geissler | 0c07c32 | 2017-03-22 14:02:30 -0500 | [diff] [blame] | 66 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 67 | return ipmid_send_cmd_to_host(std::move(cmd)); |
Andrew Geissler | 62817fa9 | 2017-03-20 14:20:49 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 70 | // Called into by Command Manager |
| 71 | void Host::commandStatusHandler(IpmiCmdData cmd, bool status) |
| 72 | { |
| 73 | // Need to convert <cmd> to the equivalent one mentioned in spec |
| 74 | auto value = status ? Result::Success : Result::Failure; |
| 75 | |
| 76 | // Fire a signal |
| 77 | this->commandComplete(intfCommand.at(std::get<0>(cmd)), value); |
| 78 | } |
| 79 | |
| 80 | } // namespace command |
Andrew Geissler | dd2c6fd | 2017-03-16 15:53:20 -0500 | [diff] [blame] | 81 | } // namespace host |
| 82 | } // namepsace phosphor |