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 | |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 20 | // global enables |
| 21 | // bit0 - Message Receive Queue enable |
| 22 | // bit1 - Enable Event Message Buffer Full Interrupt |
| 23 | // bit2 - Enable Event Message Buffer |
| 24 | // bit3 - Enable System Event Logging |
| 25 | // bit4 - reserved |
| 26 | // bit5-7 - OEM 0~2 enables |
| 27 | static constexpr uint8_t selEnable = 0x08; |
| 28 | static constexpr uint8_t recvMsgQueueEnable = 0x01; |
| 29 | static constexpr uint8_t globalEnablesDefault = selEnable | recvMsgQueueEnable; |
| 30 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 31 | //------------------------------------------------------------------- |
| 32 | // Called by Host post response from Get_Message_Flags |
| 33 | //------------------------------------------------------------------- |
| 34 | ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 35 | ipmi_request_t request, ipmi_response_t response, |
| 36 | ipmi_data_len_t data_len, ipmi_context_t context) |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 37 | { |
| 38 | ipmi_ret_t rc = IPMI_CC_OK; |
| 39 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 40 | struct oem_sel_timestamped oem_sel = {0}; |
| 41 | *data_len = sizeof(struct oem_sel_timestamped); |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 42 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 43 | // 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] | 44 | oem_sel.id[0] = SEL_OEM_ID_0; |
| 45 | oem_sel.id[1] = SEL_OEM_ID_0; |
| 46 | oem_sel.type = SEL_RECORD_TYPE_OEM; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 47 | |
| 48 | // Following 3 bytes are from IANA Manufactre_Id field. See below |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 49 | oem_sel.manuf_id[0] = 0x41; |
| 50 | oem_sel.manuf_id[1] = 0xA7; |
| 51 | oem_sel.manuf_id[2] = 0x00; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 52 | |
| 53 | // per IPMI spec NetFuntion for OEM |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 54 | oem_sel.netfun = 0x3A; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 55 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 56 | // Read from the Command Manager queue. What gets returned is a |
| 57 | // pair of <command, data> that can be directly used here |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 58 | auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand(); |
| 59 | oem_sel.cmd = hostCmd.first; |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 60 | oem_sel.data[0] = hostCmd.second; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 61 | |
| 62 | // All '0xFF' since unused. |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 63 | std::memset(&oem_sel.data[1], 0xFF, 3); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 64 | |
| 65 | // Pack the actual response |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 66 | std::memcpy(response, &oem_sel, *data_len); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 67 | return rc; |
| 68 | } |
| 69 | |
| 70 | //--------------------------------------------------------------------- |
| 71 | // Called by Host on seeing a SMS_ATN bit set. Return a hardcoded |
| 72 | // value of 0x2 indicating we need Host read some data. |
| 73 | //------------------------------------------------------------------- |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 74 | ipmi::RspType<uint8_t> ipmiAppGetMessageFlags() |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 75 | { |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 76 | // From IPMI spec V2.0 for Get Message Flags Command : |
| 77 | // bit:[1] from LSB : 1b = Event Message Buffer Full. |
| 78 | // Return as 0 if Event Message Buffer is not supported, |
| 79 | // or when the Event Message buffer is disabled. |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 80 | // This path is used to communicate messages to the host |
| 81 | // from within the phosphor::host::command::Manager |
| 82 | constexpr uint8_t setEventMsgBufferFull = 0x2; |
| 83 | return ipmi::responseSuccess(setEventMsgBufferFull); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 84 | } |
| 85 | |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 86 | ipmi_ret_t ipmi_app_get_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 87 | ipmi_request_t request, |
| 88 | ipmi_response_t response, |
| 89 | ipmi_data_len_t data_len, |
| 90 | ipmi_context_t context) |
| 91 | { |
| 92 | ipmi_ret_t rc = IPMI_CC_OK; |
| 93 | if (0 != *data_len) |
| 94 | { |
| 95 | *data_len = 0; |
| 96 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 97 | } |
| 98 | *data_len = sizeof(globalEnablesDefault); |
| 99 | *reinterpret_cast<uint8_t*>(response) = globalEnablesDefault; |
| 100 | return rc; |
| 101 | } |
| 102 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 103 | ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 104 | ipmi_request_t request, |
| 105 | ipmi_response_t response, |
| 106 | ipmi_data_len_t data_len, |
| 107 | ipmi_context_t context) |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 108 | { |
| 109 | ipmi_ret_t rc = IPMI_CC_OK; |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 110 | |
| 111 | uint8_t reqMask = *reinterpret_cast<uint8_t*>(request); |
| 112 | if (sizeof(reqMask) != *data_len) |
| 113 | { |
| 114 | *data_len = 0; |
| 115 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 116 | } |
| 117 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 118 | *data_len = 0; |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 119 | // Recv Message Queue and SEL are enabled by default. |
| 120 | // Event Message buffer are disabled by default (not supported). |
| 121 | // Any request that try to change the mask will be rejected |
| 122 | if (reqMask != (selEnable | recvMsgQueueEnable)) |
| 123 | { |
| 124 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 125 | } |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 126 | return rc; |
| 127 | } |
| 128 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 129 | namespace |
| 130 | { |
Lei YU | 12c2db7 | 2017-05-15 11:24:04 +0800 | [diff] [blame] | 131 | // Static storage to keep the object alive during process life |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 132 | std::unique_ptr<phosphor::host::command::Host> host |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 133 | __attribute__((init_priority(101))); |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 134 | std::unique_ptr<sdbusplus::server::manager::manager> objManager |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 135 | __attribute__((init_priority(101))); |
| 136 | } // namespace |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 137 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 138 | void register_netfn_app_functions() |
| 139 | { |
| 140 | |
| 141 | // <Read Event Message Buffer> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 142 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, |
| 143 | ipmi_app_read_event, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 144 | |
| 145 | // <Set BMC Global Enables> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 146 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 147 | ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 148 | |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 149 | // <Get BMC Global Enables> |
| 150 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_BMC_GLOBAL_ENABLES, NULL, |
| 151 | ipmi_app_get_bmc_global_enables, SYSTEM_INTERFACE); |
| 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. |
| 165 | objManager = std::make_unique<sdbusplus::server::manager::manager>( |
| 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 | } |