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