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