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