Vishwanatha Subbanna | b891a57 | 2017-03-31 11:34:48 +0530 | [diff] [blame] | 1 | #include "config.h" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2 | |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 3 | #include "systemintfcmds.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 5 | #include "host-cmd-manager.hpp" |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 6 | #include "host-interface.hpp" |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 7 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 8 | #include <cstring> |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 9 | #include <ipmid-host/cmd.hpp> |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 10 | #include <ipmid/api.hpp> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 11 | |
| 12 | void register_netfn_app_functions() __attribute__((constructor)); |
| 13 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 14 | using namespace sdbusplus::xyz::openbmc_project::Control::server; |
| 15 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 16 | // For accessing Host command manager |
| 17 | using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>; |
| 18 | extern cmdManagerPtr& ipmid_get_host_cmd_manager(); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 19 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 20 | //------------------------------------------------------------------- |
| 21 | // Called by Host post response from Get_Message_Flags |
| 22 | //------------------------------------------------------------------- |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 23 | ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, |
| 24 | ipmi_response_t response, |
| 25 | ipmi_data_len_t data_len, ipmi_context_t) |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 26 | { |
| 27 | ipmi_ret_t rc = IPMI_CC_OK; |
| 28 | |
Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 29 | struct oem_sel_timestamped oem_sel = {}; |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 30 | *data_len = sizeof(struct oem_sel_timestamped); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 31 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 32 | // either id[0] -or- id[1] can be filled in. We will use id[0] |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 33 | oem_sel.id[0] = SEL_OEM_ID_0; |
| 34 | oem_sel.id[1] = SEL_OEM_ID_0; |
| 35 | oem_sel.type = SEL_RECORD_TYPE_OEM; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 36 | |
| 37 | // Following 3 bytes are from IANA Manufactre_Id field. See below |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 38 | oem_sel.manuf_id[0] = 0x41; |
| 39 | oem_sel.manuf_id[1] = 0xA7; |
| 40 | oem_sel.manuf_id[2] = 0x00; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 41 | |
| 42 | // per IPMI spec NetFuntion for OEM |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 43 | oem_sel.netfun = 0x3A; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 44 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 45 | // Read from the Command Manager queue. What gets returned is a |
| 46 | // pair of <command, data> that can be directly used here |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 47 | auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand(); |
| 48 | oem_sel.cmd = hostCmd.first; |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 49 | oem_sel.data[0] = hostCmd.second; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 50 | |
| 51 | // All '0xFF' since unused. |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 52 | std::memset(&oem_sel.data[1], 0xFF, 3); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 53 | |
| 54 | // Pack the actual response |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 55 | std::memcpy(response, &oem_sel, *data_len); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 56 | return rc; |
| 57 | } |
| 58 | |
| 59 | //--------------------------------------------------------------------- |
| 60 | // Called by Host on seeing a SMS_ATN bit set. Return a hardcoded |
XP Chen | 414d2f7 | 2021-09-20 16:19:11 -0500 | [diff] [blame] | 61 | // value of 0x0 to indicate Event Message Buffer is not supported |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 62 | //------------------------------------------------------------------- |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 63 | ipmi::RspType<uint8_t> ipmiAppGetMessageFlags() |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 64 | { |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 65 | // From IPMI spec V2.0 for Get Message Flags Command : |
| 66 | // bit:[1] from LSB : 1b = Event Message Buffer Full. |
| 67 | // Return as 0 if Event Message Buffer is not supported, |
| 68 | // or when the Event Message buffer is disabled. |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 69 | // This path is used to communicate messages to the host |
| 70 | // from within the phosphor::host::command::Manager |
XP Chen | 414d2f7 | 2021-09-20 16:19:11 -0500 | [diff] [blame] | 71 | constexpr uint8_t setEventMsgBufferNotSupported = 0x0; |
| 72 | return ipmi::responseSuccess(setEventMsgBufferNotSupported); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 73 | } |
| 74 | |
Yong Li | 5aa2693 | 2019-11-04 13:25:43 +0800 | [diff] [blame] | 75 | ipmi::RspType<bool, // Receive Message Queue Interrupt Enabled |
| 76 | bool, // Event Message Buffer Full Interrupt Enabled |
| 77 | bool, // Event Message Buffer Enabled |
| 78 | bool, // System Event Logging Enabled |
| 79 | uint1_t, // Reserved |
| 80 | bool, // OEM 0 enabled |
| 81 | bool, // OEM 1 enabled |
| 82 | bool // OEM 2 enabled |
| 83 | > |
| 84 | ipmiAppGetBMCGlobalEnable() |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 85 | { |
Yong Li | 5aa2693 | 2019-11-04 13:25:43 +0800 | [diff] [blame] | 86 | return ipmi::responseSuccess(true, false, false, true, 0, false, false, |
| 87 | false); |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 88 | } |
| 89 | |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 90 | ipmi::RspType<> ipmiAppSetBMCGlobalEnable( |
| 91 | ipmi::Context::ptr ctx, bool receiveMessageQueueInterruptEnabled, |
| 92 | bool eventMessageBufferFullInterruptEnabled, bool eventMessageBufferEnabled, |
| 93 | bool systemEventLogEnable, uint1_t reserved, bool OEM0Enabled, |
| 94 | bool OEM1Enabled, bool OEM2Enabled) |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 95 | { |
Yong Li | a249a08 | 2019-10-29 13:37:17 +0800 | [diff] [blame] | 96 | ipmi::ChannelInfo chInfo; |
| 97 | |
| 98 | if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess) |
| 99 | { |
| 100 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 101 | "Failed to get Channel Info", |
| 102 | phosphor::logging::entry("CHANNEL=%d", ctx->channel)); |
| 103 | return ipmi::responseUnspecifiedError(); |
| 104 | } |
| 105 | |
| 106 | if (chInfo.mediumType != |
| 107 | static_cast<uint8_t>(ipmi::EChannelMediumType::systemInterface)) |
| 108 | { |
| 109 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 110 | "Error - supported only in system interface"); |
| 111 | return ipmi::responseCommandNotAvailable(); |
| 112 | } |
| 113 | |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 114 | // Recv Message Queue and SEL are enabled by default. |
| 115 | // Event Message buffer are disabled by default (not supported). |
| 116 | // Any request that try to change the mask will be rejected |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 117 | if (!receiveMessageQueueInterruptEnabled || !systemEventLogEnable || |
| 118 | eventMessageBufferFullInterruptEnabled || eventMessageBufferEnabled || |
| 119 | OEM0Enabled || OEM1Enabled || OEM2Enabled || reserved) |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 120 | { |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 121 | return ipmi::responseInvalidFieldRequest(); |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 122 | } |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 123 | |
| 124 | return ipmi::responseSuccess(); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 125 | } |
| 126 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 127 | namespace |
| 128 | { |
Lei YU | 12c2db7 | 2017-05-15 11:24:04 +0800 | [diff] [blame] | 129 | // Static storage to keep the object alive during process life |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 130 | std::unique_ptr<phosphor::host::command::Host> host |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 131 | __attribute__((init_priority(101))); |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 132 | std::unique_ptr<sdbusplus::server::manager_t> objManager |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 133 | __attribute__((init_priority(101))); |
| 134 | } // namespace |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 135 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 136 | void register_netfn_app_functions() |
| 137 | { |
| 138 | |
| 139 | // <Read Event Message Buffer> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 140 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, |
| 141 | ipmi_app_read_event, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 142 | |
| 143 | // <Set BMC Global Enables> |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 144 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 145 | ipmi::app::cmdSetBmcGlobalEnables, |
| 146 | ipmi::Privilege::Admin, ipmiAppSetBMCGlobalEnable); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 147 | |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 148 | // <Get BMC Global Enables> |
Yong Li | 5aa2693 | 2019-11-04 13:25:43 +0800 | [diff] [blame] | 149 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 150 | ipmi::app::cmdGetBmcGlobalEnables, |
| 151 | ipmi::Privilege::User, ipmiAppGetBMCGlobalEnable); |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 152 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 153 | // <Get Message Flags> |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 154 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 155 | ipmi::app::cmdGetMessageFlags, ipmi::Privilege::Admin, |
| 156 | ipmiAppGetMessageFlags); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 157 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 158 | // Create new xyz.openbmc_project.host object on the bus |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 159 | auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0'; |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 160 | |
Vernon Mauery | 20ff333 | 2019-03-01 16:52:25 -0800 | [diff] [blame] | 161 | std::unique_ptr<sdbusplus::asio::connection>& sdbusp = |
| 162 | ipmid_get_sdbus_plus_handler(); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 163 | |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 164 | // Add sdbusplus ObjectManager. |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 165 | objManager = std::make_unique<sdbusplus::server::manager_t>( |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 166 | *sdbusp, CONTROL_HOST_OBJ_MGR); |
| 167 | |
| 168 | host = std::make_unique<phosphor::host::command::Host>(*sdbusp, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 169 | objPath.c_str()); |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 170 | sdbusp->request_name(CONTROL_HOST_BUSNAME); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 171 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 172 | return; |
| 173 | } |