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