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/api.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 10 | #include <cstring> |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 11 | #include <ipmid-host/cmd.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 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 21 | //------------------------------------------------------------------- |
| 22 | // Called by Host post response from Get_Message_Flags |
| 23 | //------------------------------------------------------------------- |
| 24 | 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] | 25 | ipmi_request_t request, ipmi_response_t response, |
| 26 | ipmi_data_len_t data_len, ipmi_context_t context) |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 27 | { |
| 28 | ipmi_ret_t rc = IPMI_CC_OK; |
| 29 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 30 | struct oem_sel_timestamped oem_sel = {0}; |
| 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 |
| 62 | // value of 0x2 indicating we need Host read some data. |
| 63 | //------------------------------------------------------------------- |
| 64 | 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] | 65 | ipmi_request_t request, |
| 66 | ipmi_response_t response, |
| 67 | ipmi_data_len_t data_len, |
| 68 | ipmi_context_t context) |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 69 | { |
| 70 | // Generic return from IPMI commands. |
| 71 | ipmi_ret_t rc = IPMI_CC_OK; |
| 72 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 73 | // From IPMI spec V2.0 for Get Message Flags Command : |
| 74 | // bit:[1] from LSB : 1b = Event Message Buffer Full. |
| 75 | // Return as 0 if Event Message Buffer is not supported, |
| 76 | // or when the Event Message buffer is disabled. |
| 77 | // TODO. For now. assume its not disabled and send "0x2" anyway: |
| 78 | |
| 79 | uint8_t set_event_msg_buffer_full = 0x2; |
| 80 | *data_len = sizeof(set_event_msg_buffer_full); |
| 81 | |
| 82 | // Pack the actual response |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 83 | std::memcpy(response, &set_event_msg_buffer_full, *data_len); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 84 | |
| 85 | return rc; |
| 86 | } |
| 87 | |
| 88 | 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] | 89 | ipmi_request_t request, |
| 90 | ipmi_response_t response, |
| 91 | ipmi_data_len_t data_len, |
| 92 | ipmi_context_t context) |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 93 | { |
| 94 | ipmi_ret_t rc = IPMI_CC_OK; |
| 95 | *data_len = 0; |
| 96 | |
| 97 | // Event and message logging enabled by default so return for now |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 98 | #ifdef __IPMI_DEBUG__ |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 99 | std::printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n"); |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 100 | #endif |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 101 | |
| 102 | return rc; |
| 103 | } |
| 104 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 105 | namespace |
| 106 | { |
Lei YU | 12c2db7 | 2017-05-15 11:24:04 +0800 | [diff] [blame] | 107 | // Static storage to keep the object alive during process life |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 108 | std::unique_ptr<phosphor::host::command::Host> host |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 109 | __attribute__((init_priority(101))); |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 110 | std::unique_ptr<sdbusplus::server::manager::manager> objManager |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 111 | __attribute__((init_priority(101))); |
| 112 | } // namespace |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 113 | |
| 114 | #include <unistd.h> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 115 | void register_netfn_app_functions() |
| 116 | { |
| 117 | |
| 118 | // <Read Event Message Buffer> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 119 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, |
| 120 | ipmi_app_read_event, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 121 | |
| 122 | // <Set BMC Global Enables> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 123 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 124 | ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 125 | |
| 126 | // <Get Message Flags> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 127 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, |
| 128 | ipmi_app_get_msg_flags, SYSTEM_INTERFACE); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 129 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 130 | // Create new xyz.openbmc_project.host object on the bus |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 131 | auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0'; |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 132 | |
| 133 | // Add sdbusplus ObjectManager. |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 134 | auto& sdbusPlusHandler = ipmid_get_sdbus_plus_handler(); |
| 135 | objManager = std::make_unique<sdbusplus::server::manager::manager>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 136 | *sdbusPlusHandler, CONTROL_HOST_OBJ_MGR); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 137 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 138 | host = std::make_unique<phosphor::host::command::Host>(*sdbusPlusHandler, |
| 139 | objPath.c_str()); |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 140 | sdbusPlusHandler->request_name(CONTROL_HOST_BUSNAME); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 141 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 142 | return; |
| 143 | } |