Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 17 | #include "xyz/openbmc_project/Common/error.hpp" |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 18 | #include "xyz/openbmc_project/Led/Physical/server.hpp" |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 19 | |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 20 | #include <systemd/sd-journal.h> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 21 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 22 | #include <appcommands.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 23 | #include <array> |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 24 | #include <boost/container/flat_map.hpp> |
Yong Li | 23737fe | 2019-02-19 08:49:55 +0800 | [diff] [blame] | 25 | #include <boost/process/child.hpp> |
| 26 | #include <boost/process/io.hpp> |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 27 | #include <com/intel/Control/OCOTShutdownPolicy/server.hpp> |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 28 | #include <commandutils.hpp> |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 29 | #include <filesystem> |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 30 | #include <gpiod.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 31 | #include <iostream> |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 32 | #include <ipmid/api.hpp> |
Vernon Mauery | 5480ef6 | 2019-03-20 13:43:11 -0700 | [diff] [blame] | 33 | #include <ipmid/utils.hpp> |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 34 | #include <nlohmann/json.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 35 | #include <oemcommands.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 36 | #include <phosphor-logging/log.hpp> |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 37 | #include <regex> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 38 | #include <sdbusplus/bus.hpp> |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 39 | #include <sdbusplus/message/types.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 40 | #include <string> |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 41 | #include <variant> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 42 | #include <vector> |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 43 | #include <xyz/openbmc_project/Chassis/Control/NMISource/server.hpp> |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 44 | #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> |
| 45 | #include <xyz/openbmc_project/Control/Boot/Source/server.hpp> |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 46 | #include <xyz/openbmc_project/Control/PowerSupplyRedundancy/server.hpp> |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 47 | #include <xyz/openbmc_project/Control/Security/RestrictionMode/server.hpp> |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 48 | #include <xyz/openbmc_project/Control/Security/SpecialMode/server.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 49 | |
| 50 | namespace ipmi |
| 51 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 52 | static void registerOEMFunctions() __attribute__((constructor)); |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 53 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 54 | static constexpr size_t maxFRUStringLength = 0x3F; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 55 | |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 56 | static constexpr auto ethernetIntf = |
| 57 | "xyz.openbmc_project.Network.EthernetInterface"; |
| 58 | static constexpr auto networkIPIntf = "xyz.openbmc_project.Network.IP"; |
| 59 | static constexpr auto networkService = "xyz.openbmc_project.Network"; |
| 60 | static constexpr auto networkRoot = "/xyz/openbmc_project/network"; |
| 61 | |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 62 | static constexpr const char* oemNmiSourceIntf = |
| 63 | "xyz.openbmc_project.Chassis.Control.NMISource"; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 64 | static constexpr const char* oemNmiSourceObjPath = |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 65 | "/xyz/openbmc_project/Chassis/Control/NMISource"; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 66 | static constexpr const char* oemNmiBmcSourceObjPathProp = "BMCSource"; |
| 67 | static constexpr const char* oemNmiEnabledObjPathProp = "Enabled"; |
| 68 | |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 69 | static constexpr const char* dimmOffsetFile = "/var/lib/ipmi/ipmi_dimms.json"; |
| 70 | |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 71 | enum class NmiSource : uint8_t |
| 72 | { |
| 73 | none = 0, |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 74 | frontPanelButton = 1, |
| 75 | watchdog = 2, |
| 76 | chassisCmd = 3, |
| 77 | memoryError = 4, |
| 78 | pciBusError = 5, |
| 79 | pch = 6, |
| 80 | chipset = 7, |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 81 | }; |
| 82 | |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 83 | enum class SpecialUserIndex : uint8_t |
| 84 | { |
| 85 | rootUser = 0, |
| 86 | atScaleDebugUser = 1 |
| 87 | }; |
| 88 | |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 89 | static constexpr const char* restricionModeService = |
| 90 | "xyz.openbmc_project.RestrictionMode.Manager"; |
| 91 | static constexpr const char* restricionModeBasePath = |
| 92 | "/xyz/openbmc_project/control/security/restriction_mode"; |
| 93 | static constexpr const char* restricionModeIntf = |
| 94 | "xyz.openbmc_project.Control.Security.RestrictionMode"; |
| 95 | static constexpr const char* restricionModeProperty = "RestrictionMode"; |
| 96 | |
| 97 | static constexpr const char* specialModeService = |
| 98 | "xyz.openbmc_project.SpecialMode"; |
| 99 | static constexpr const char* specialModeBasePath = |
Richard Marian Thomaiyar | a7b7428 | 2019-09-22 21:53:14 +0530 | [diff] [blame] | 100 | "/xyz/openbmc_project/security/special_mode"; |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 101 | static constexpr const char* specialModeIntf = |
| 102 | "xyz.openbmc_project.Security.SpecialMode"; |
| 103 | static constexpr const char* specialModeProperty = "SpecialMode"; |
| 104 | |
| 105 | static constexpr const char* dBusPropertyIntf = |
| 106 | "org.freedesktop.DBus.Properties"; |
| 107 | static constexpr const char* dBusPropertyGetMethod = "Get"; |
| 108 | static constexpr const char* dBusPropertySetMethod = "Set"; |
| 109 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 110 | // return code: 0 successful |
| 111 | int8_t getChassisSerialNumber(sdbusplus::bus::bus& bus, std::string& serial) |
| 112 | { |
| 113 | std::string objpath = "/xyz/openbmc_project/FruDevice"; |
| 114 | std::string intf = "xyz.openbmc_project.FruDeviceManager"; |
| 115 | std::string service = getService(bus, intf, objpath); |
| 116 | ObjectValueTree valueTree = getManagedObjects(bus, service, "/"); |
| 117 | if (valueTree.empty()) |
| 118 | { |
| 119 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 120 | "No object implements interface", |
| 121 | phosphor::logging::entry("INTF=%s", intf.c_str())); |
| 122 | return -1; |
| 123 | } |
| 124 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 125 | for (const auto& item : valueTree) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 126 | { |
| 127 | auto interface = item.second.find("xyz.openbmc_project.FruDevice"); |
| 128 | if (interface == item.second.end()) |
| 129 | { |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | auto property = interface->second.find("CHASSIS_SERIAL_NUMBER"); |
| 134 | if (property == interface->second.end()) |
| 135 | { |
| 136 | continue; |
| 137 | } |
| 138 | |
| 139 | try |
| 140 | { |
| 141 | Value variant = property->second; |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 142 | std::string& result = std::get<std::string>(variant); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 143 | if (result.size() > maxFRUStringLength) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 144 | { |
| 145 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 146 | "FRU serial number exceed maximum length"); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 147 | return -1; |
| 148 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 149 | serial = result; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 150 | return 0; |
| 151 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 152 | catch (std::bad_variant_access& e) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 153 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 154 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 155 | return -1; |
| 156 | } |
| 157 | } |
| 158 | return -1; |
| 159 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 160 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 161 | ipmi_ret_t ipmiOEMWildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 162 | ipmi_request_t request, ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 163 | ipmi_data_len_t dataLen, ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 164 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 165 | printCommand(+netfn, +cmd); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 166 | // Status code. |
| 167 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 168 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 169 | return rc; |
| 170 | } |
| 171 | |
| 172 | // Returns the Chassis Identifier (serial #) |
| 173 | ipmi_ret_t ipmiOEMGetChassisIdentifier(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 174 | ipmi_request_t request, |
| 175 | ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 176 | ipmi_data_len_t dataLen, |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 177 | ipmi_context_t context) |
| 178 | { |
| 179 | std::string serial; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 180 | if (*dataLen != 0) // invalid request if there are extra parameters |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 181 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 182 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 183 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 184 | } |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 185 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 186 | if (getChassisSerialNumber(*dbus, serial) == 0) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 187 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 188 | *dataLen = serial.size(); // length will never exceed response length |
| 189 | // as it is checked in getChassisSerialNumber |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 190 | char* resp = static_cast<char*>(response); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 191 | serial.copy(resp, *dataLen); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 192 | return IPMI_CC_OK; |
| 193 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 194 | *dataLen = 0; |
| 195 | return IPMI_CC_RESPONSE_ERROR; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | ipmi_ret_t ipmiOEMSetSystemGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 199 | ipmi_request_t request, |
| 200 | ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 201 | ipmi_data_len_t dataLen, ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 202 | { |
| 203 | static constexpr size_t safeBufferLength = 50; |
| 204 | char buf[safeBufferLength] = {0}; |
| 205 | GUIDData* Data = reinterpret_cast<GUIDData*>(request); |
| 206 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 207 | if (*dataLen != sizeof(GUIDData)) // 16bytes |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 208 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 209 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 210 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 211 | } |
| 212 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 213 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 214 | |
| 215 | snprintf( |
| 216 | buf, safeBufferLength, |
| 217 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 218 | Data->timeLow4, Data->timeLow3, Data->timeLow2, Data->timeLow1, |
| 219 | Data->timeMid2, Data->timeMid1, Data->timeHigh2, Data->timeHigh1, |
| 220 | Data->clock2, Data->clock1, Data->node6, Data->node5, Data->node4, |
| 221 | Data->node3, Data->node2, Data->node1); |
| 222 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 223 | std::string guid = buf; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 224 | |
| 225 | std::string objpath = "/xyz/openbmc_project/control/host0/systemGUID"; |
| 226 | std::string intf = "xyz.openbmc_project.Common.UUID"; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 227 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 228 | std::string service = getService(*dbus, intf, objpath); |
| 229 | setDbusProperty(*dbus, service, objpath, intf, "UUID", guid); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 230 | return IPMI_CC_OK; |
| 231 | } |
| 232 | |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 233 | ipmi::RspType<> ipmiOEMDisableBMCSystemReset(bool disableResetOnSMI, |
| 234 | uint7_t reserved1) |
| 235 | { |
| 236 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 237 | |
| 238 | try |
| 239 | { |
| 240 | auto service = |
| 241 | ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath); |
| 242 | ipmi::setDbusProperty(*busp, service, bmcResetDisablesPath, |
| 243 | bmcResetDisablesIntf, "ResetOnSMI", |
| 244 | !disableResetOnSMI); |
| 245 | } |
| 246 | catch (std::exception& e) |
| 247 | { |
| 248 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 249 | "Failed to set BMC reset disables", |
| 250 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 251 | return ipmi::responseUnspecifiedError(); |
| 252 | } |
| 253 | |
| 254 | return ipmi::responseSuccess(); |
| 255 | } |
| 256 | |
| 257 | ipmi::RspType<bool, // disableResetOnSMI |
| 258 | uint7_t // reserved |
| 259 | > |
| 260 | ipmiOEMGetBMCResetDisables() |
| 261 | { |
| 262 | bool disableResetOnSMI = true; |
| 263 | |
| 264 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 265 | try |
| 266 | { |
| 267 | auto service = |
| 268 | ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath); |
| 269 | Value variant = |
| 270 | ipmi::getDbusProperty(*busp, service, bmcResetDisablesPath, |
| 271 | bmcResetDisablesIntf, "ResetOnSMI"); |
| 272 | disableResetOnSMI = !std::get<bool>(variant); |
| 273 | } |
| 274 | catch (std::exception& e) |
| 275 | { |
| 276 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 277 | "Failed to get BMC reset disables", |
| 278 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 279 | return ipmi::responseUnspecifiedError(); |
| 280 | } |
| 281 | |
| 282 | return ipmi::responseSuccess(disableResetOnSMI, 0); |
| 283 | } |
| 284 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 285 | ipmi_ret_t ipmiOEMSetBIOSID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 286 | ipmi_request_t request, ipmi_response_t response, |
| 287 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 288 | { |
| 289 | DeviceInfo* data = reinterpret_cast<DeviceInfo*>(request); |
| 290 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 291 | if ((*dataLen < 2) || (*dataLen != (1 + data->biosIDLength))) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 292 | { |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 293 | *dataLen = 0; |
| 294 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 295 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 296 | std::string idString((char*)data->biosId, data->biosIDLength); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 297 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 298 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 299 | std::string service = getService(*dbus, biosVersionIntf, biosObjPath); |
| 300 | setDbusProperty(*dbus, service, biosObjPath, biosVersionIntf, |
| 301 | biosVersionProp, idString); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 302 | uint8_t* bytesWritten = static_cast<uint8_t*>(response); |
| 303 | *bytesWritten = |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 304 | data->biosIDLength; // how many bytes are written into storage |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 305 | *dataLen = 1; |
| 306 | return IPMI_CC_OK; |
| 307 | } |
| 308 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 309 | bool getSwVerInfo(uint8_t& bmcMajor, uint8_t& bmcMinor, uint8_t& meMajor, |
| 310 | uint8_t& meMinor) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 311 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 312 | // step 1 : get BMC Major and Minor numbers from its DBUS property |
| 313 | std::optional<MetaRevision> rev{}; |
| 314 | try |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 315 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 316 | std::string version = getActiveSoftwareVersionInfo(); |
| 317 | rev = convertIntelVersion(version); |
| 318 | } |
| 319 | catch (const std::exception& e) |
| 320 | { |
| 321 | return false; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 322 | } |
| 323 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 324 | if (rev.has_value()) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 325 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 326 | MetaRevision revision = rev.value(); |
| 327 | bmcMajor = revision.major; |
| 328 | |
| 329 | revision.minor = (revision.minor > 99 ? 99 : revision.minor); |
| 330 | bmcMinor = revision.minor % 10 + (revision.minor / 10) * 16; |
| 331 | } |
| 332 | |
| 333 | // step 2 : get ME Major and Minor numbers from its DBUS property |
| 334 | try |
| 335 | { |
| 336 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 337 | std::string service = |
| 338 | getService(*dbus, "xyz.openbmc_project.Software.Version", |
| 339 | "/xyz/openbmc_project/me_version"); |
| 340 | Value variant = |
| 341 | getDbusProperty(*dbus, service, "/xyz/openbmc_project/me_version", |
| 342 | "xyz.openbmc_project.Software.Version", "Version"); |
| 343 | |
| 344 | std::string& meString = std::get<std::string>(variant); |
| 345 | |
| 346 | // get ME major number |
| 347 | std::regex pattern1("(\\d+?).(\\d+?).(\\d+?).(\\d+?).(\\d+?)"); |
| 348 | constexpr size_t matchedPhosphor = 6; |
| 349 | std::smatch results; |
| 350 | if (std::regex_match(meString, results, pattern1)) |
| 351 | { |
| 352 | if (results.size() == matchedPhosphor) |
| 353 | { |
| 354 | meMajor = static_cast<uint8_t>(std::stoi(results[1])); |
| 355 | meMinor = static_cast<uint8_t>(std::stoi(results[2])); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | catch (sdbusplus::exception::SdBusError& e) |
| 360 | { |
| 361 | return false; |
| 362 | } |
| 363 | return true; |
| 364 | } |
| 365 | |
| 366 | ipmi::RspType< |
| 367 | std::variant<std::string, |
| 368 | std::tuple<uint8_t, std::array<uint8_t, 2>, |
| 369 | std::array<uint8_t, 2>, std::array<uint8_t, 2>, |
| 370 | std::array<uint8_t, 2>, std::array<uint8_t, 2>>, |
| 371 | std::tuple<uint8_t, std::array<uint8_t, 2>>>> |
| 372 | ipmiOEMGetDeviceInfo(uint8_t entityType, uint8_t countToRead, |
| 373 | uint8_t offset) |
| 374 | { |
| 375 | if (countToRead == 0) |
| 376 | { |
| 377 | return ipmi::responseReqDataLenInvalid(); |
| 378 | } |
| 379 | |
| 380 | if (entityType > static_cast<uint8_t>(OEMDevEntityType::sdrVer)) |
| 381 | { |
| 382 | return ipmi::responseInvalidFieldRequest(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | // handle OEM command items |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 386 | switch (OEMDevEntityType(entityType)) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 387 | { |
| 388 | case OEMDevEntityType::biosId: |
| 389 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 390 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 391 | std::string service = |
| 392 | getService(*dbus, biosVersionIntf, biosObjPath); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 393 | try |
| 394 | { |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 395 | Value variant = |
| 396 | getDbusProperty(*dbus, service, biosObjPath, |
| 397 | biosVersionIntf, biosVersionProp); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 398 | std::string& idString = std::get<std::string>(variant); |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 399 | if (offset >= idString.size()) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 400 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 401 | return ipmi::responseParmOutOfRange(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 402 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 403 | size_t length = 0; |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 404 | if (countToRead > (idString.size() - offset)) |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 405 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 406 | length = idString.size() - offset; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 407 | } |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 408 | else |
| 409 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 410 | length = countToRead; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 411 | } |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 412 | |
| 413 | std::string readBuf = {0}; |
| 414 | readBuf.resize(length); |
| 415 | std::copy_n(idString.begin() + offset, length, |
| 416 | (readBuf.begin())); |
| 417 | return ipmi::responseSuccess(readBuf); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 418 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 419 | catch (std::bad_variant_access& e) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 420 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 421 | return ipmi::responseUnspecifiedError(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | break; |
| 425 | |
| 426 | case OEMDevEntityType::devVer: |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 427 | { |
| 428 | constexpr const size_t verLen = 2; |
| 429 | constexpr const size_t verTotalLen = 10; |
| 430 | std::array<uint8_t, verLen> bmcBuf = {0xff, 0xff}; |
| 431 | std::array<uint8_t, verLen> hsc0Buf = {0xff, 0xff}; |
| 432 | std::array<uint8_t, verLen> hsc1Buf = {0xff, 0xff}; |
| 433 | std::array<uint8_t, verLen> meBuf = {0xff, 0xff}; |
| 434 | std::array<uint8_t, verLen> hsc2Buf = {0xff, 0xff}; |
| 435 | // data0/1: BMC version number; data6/7: ME version number |
| 436 | // the others: HSC0/1/2 version number, not avaible. |
| 437 | if (true != getSwVerInfo(bmcBuf[0], bmcBuf[1], meBuf[0], meBuf[1])) |
| 438 | { |
| 439 | return ipmi::responseUnspecifiedError(); |
| 440 | } |
| 441 | return ipmi::responseSuccess( |
| 442 | std::tuple< |
| 443 | uint8_t, std::array<uint8_t, verLen>, |
| 444 | std::array<uint8_t, verLen>, std::array<uint8_t, verLen>, |
| 445 | std::array<uint8_t, verLen>, std::array<uint8_t, verLen>>{ |
| 446 | verTotalLen, bmcBuf, hsc0Buf, hsc1Buf, meBuf, hsc2Buf}); |
| 447 | } |
| 448 | break; |
| 449 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 450 | case OEMDevEntityType::sdrVer: |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 451 | { |
| 452 | constexpr const size_t sdrLen = 2; |
| 453 | std::array<uint8_t, sdrLen> readBuf = {0x01, 0x0}; |
| 454 | return ipmi::responseSuccess( |
| 455 | std::tuple<uint8_t, std::array<uint8_t, sdrLen>>{sdrLen, |
| 456 | readBuf}); |
| 457 | } |
| 458 | break; |
| 459 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 460 | default: |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 461 | return ipmi::responseInvalidFieldRequest(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 462 | } |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | ipmi_ret_t ipmiOEMGetAICFRU(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 466 | ipmi_request_t request, ipmi_response_t response, |
| 467 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 468 | { |
| 469 | if (*dataLen != 0) |
| 470 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 471 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 472 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 473 | } |
| 474 | |
| 475 | *dataLen = 1; |
| 476 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
| 477 | // temporary fix. We don't support AIC FRU now. Just tell BIOS that no |
| 478 | // AIC is available so that BIOS will not timeout repeatly which leads to |
| 479 | // slow booting. |
| 480 | *res = 0; // Byte1=Count of SlotPosition/FruID records. |
| 481 | return IPMI_CC_OK; |
| 482 | } |
| 483 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 484 | ipmi_ret_t ipmiOEMGetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 485 | ipmi_request_t request, |
| 486 | ipmi_response_t response, |
| 487 | ipmi_data_len_t dataLen, |
| 488 | ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 489 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 490 | GetPowerRestoreDelayRes* resp = |
| 491 | reinterpret_cast<GetPowerRestoreDelayRes*>(response); |
| 492 | |
| 493 | if (*dataLen != 0) |
| 494 | { |
| 495 | *dataLen = 0; |
| 496 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 497 | } |
| 498 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 499 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 500 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 501 | getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 502 | Value variant = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 503 | getDbusProperty(*dbus, service, powerRestoreDelayObjPath, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 504 | powerRestoreDelayIntf, powerRestoreDelayProp); |
| 505 | |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 506 | uint16_t delay = std::get<uint16_t>(variant); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 507 | resp->byteLSB = delay; |
| 508 | resp->byteMSB = delay >> 8; |
| 509 | |
| 510 | *dataLen = sizeof(GetPowerRestoreDelayRes); |
| 511 | |
| 512 | return IPMI_CC_OK; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 513 | } |
| 514 | |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 515 | static uint8_t bcdToDec(uint8_t val) |
| 516 | { |
| 517 | return ((val / 16 * 10) + (val % 16)); |
| 518 | } |
| 519 | |
| 520 | // Allows an update utility or system BIOS to send the status of an embedded |
| 521 | // firmware update attempt to the BMC. After received, BMC will create a logging |
| 522 | // record. |
| 523 | ipmi::RspType<> ipmiOEMSendEmbeddedFwUpdStatus(uint8_t status, uint8_t target, |
| 524 | uint8_t majorRevision, |
| 525 | uint8_t minorRevision, |
| 526 | uint32_t auxInfo) |
| 527 | { |
| 528 | std::string firmware; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 529 | int instance = (target & targetInstanceMask) >> targetInstanceShift; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 530 | target = (target & selEvtTargetMask) >> selEvtTargetShift; |
| 531 | |
| 532 | /* make sure the status is 0, 1, or 2 as per the spec */ |
| 533 | if (status > 2) |
| 534 | { |
| 535 | return ipmi::response(ipmi::ccInvalidFieldRequest); |
| 536 | } |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 537 | /* make sure the target is 0, 1, 2, or 4 as per the spec */ |
| 538 | if (target > 4 || target == 3) |
| 539 | { |
| 540 | return ipmi::response(ipmi::ccInvalidFieldRequest); |
| 541 | } |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 542 | /*orignal OEM command is to record OEM SEL. |
| 543 | But openbmc does not support OEM SEL, so we redirect it to redfish event |
| 544 | logging. */ |
| 545 | std::string buildInfo; |
| 546 | std::string action; |
| 547 | switch (FWUpdateTarget(target)) |
| 548 | { |
| 549 | case FWUpdateTarget::targetBMC: |
| 550 | firmware = "BMC"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 551 | buildInfo = "major: " + std::to_string(majorRevision) + " minor: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 552 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 553 | " BuildID: " + std::to_string(auxInfo); |
| 554 | buildInfo += std::to_string(auxInfo); |
| 555 | break; |
| 556 | case FWUpdateTarget::targetBIOS: |
| 557 | firmware = "BIOS"; |
| 558 | buildInfo = |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 559 | "major: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 560 | std::to_string(bcdToDec(majorRevision)) + // BCD encoded |
| 561 | " minor: " + |
| 562 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 563 | " ReleaseNumber: " + // ASCII encoded |
| 564 | std::to_string(static_cast<uint8_t>(auxInfo >> 0) - '0') + |
| 565 | std::to_string(static_cast<uint8_t>(auxInfo >> 8) - '0') + |
| 566 | std::to_string(static_cast<uint8_t>(auxInfo >> 16) - '0') + |
| 567 | std::to_string(static_cast<uint8_t>(auxInfo >> 24) - '0'); |
| 568 | break; |
| 569 | case FWUpdateTarget::targetME: |
| 570 | firmware = "ME"; |
| 571 | buildInfo = |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 572 | "major: " + std::to_string(majorRevision) + " minor1: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 573 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 574 | " minor2: " + |
| 575 | std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 0))) + |
| 576 | " build1: " + |
| 577 | std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 8))) + |
| 578 | " build2: " + |
| 579 | std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 16))); |
| 580 | break; |
| 581 | case FWUpdateTarget::targetOEMEWS: |
| 582 | firmware = "EWS"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 583 | buildInfo = "major: " + std::to_string(majorRevision) + " minor: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 584 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 585 | " BuildID: " + std::to_string(auxInfo); |
| 586 | break; |
| 587 | } |
| 588 | |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 589 | static const std::string openBMCMessageRegistryVersion("0.1"); |
| 590 | std::string redfishMsgID = "OpenBMC." + openBMCMessageRegistryVersion; |
| 591 | |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 592 | switch (status) |
| 593 | { |
| 594 | case 0x0: |
| 595 | action = "update started"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 596 | redfishMsgID += ".FirmwareUpdateStarted"; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 597 | break; |
| 598 | case 0x1: |
| 599 | action = "update completed successfully"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 600 | redfishMsgID += ".FirmwareUpdateCompleted"; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 601 | break; |
| 602 | case 0x2: |
| 603 | action = "update failure"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 604 | redfishMsgID += ".FirmwareUpdateFailed"; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 605 | break; |
| 606 | default: |
| 607 | action = "unknown"; |
| 608 | break; |
| 609 | } |
| 610 | |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 611 | std::string firmwareInstanceStr = |
| 612 | firmware + " instance: " + std::to_string(instance); |
| 613 | std::string message("[firmware update] " + firmwareInstanceStr + |
| 614 | " status: <" + action + "> " + buildInfo); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 615 | |
| 616 | sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", LOG_INFO, |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 617 | "REDFISH_MESSAGE_ID=%s", redfishMsgID.c_str(), |
| 618 | "REDFISH_MESSAGE_ARGS=%s,%s", firmwareInstanceStr.c_str(), |
| 619 | buildInfo.c_str(), NULL); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 620 | return ipmi::responseSuccess(); |
| 621 | } |
| 622 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 623 | ipmi_ret_t ipmiOEMSetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 624 | ipmi_request_t request, |
| 625 | ipmi_response_t response, |
| 626 | ipmi_data_len_t dataLen, |
| 627 | ipmi_context_t context) |
| 628 | { |
| 629 | SetPowerRestoreDelayReq* data = |
| 630 | reinterpret_cast<SetPowerRestoreDelayReq*>(request); |
| 631 | uint16_t delay = 0; |
| 632 | |
| 633 | if (*dataLen != sizeof(SetPowerRestoreDelayReq)) |
| 634 | { |
| 635 | *dataLen = 0; |
| 636 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 637 | } |
| 638 | delay = data->byteMSB; |
| 639 | delay = (delay << 8) | data->byteLSB; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 640 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 641 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 642 | getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath); |
| 643 | setDbusProperty(*dbus, service, powerRestoreDelayObjPath, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 644 | powerRestoreDelayIntf, powerRestoreDelayProp, delay); |
| 645 | *dataLen = 0; |
| 646 | |
| 647 | return IPMI_CC_OK; |
| 648 | } |
| 649 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 650 | static bool cpuPresent(const std::string& cpuName) |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 651 | { |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 652 | static constexpr const char* cpuPresencePathPrefix = |
| 653 | "/xyz/openbmc_project/inventory/system/chassis/motherboard/"; |
| 654 | static constexpr const char* cpuPresenceIntf = |
| 655 | "xyz.openbmc_project.Inventory.Item"; |
| 656 | std::string cpuPresencePath = cpuPresencePathPrefix + cpuName; |
| 657 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 658 | try |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 659 | { |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 660 | auto service = |
| 661 | ipmi::getService(*busp, cpuPresenceIntf, cpuPresencePath); |
| 662 | |
| 663 | ipmi::Value result = ipmi::getDbusProperty( |
| 664 | *busp, service, cpuPresencePath, cpuPresenceIntf, "Present"); |
| 665 | return std::get<bool>(result); |
| 666 | } |
| 667 | catch (const std::exception& e) |
| 668 | { |
| 669 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 670 | "Cannot find processor presence", |
| 671 | phosphor::logging::entry("NAME=%s", cpuName.c_str())); |
| 672 | return false; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | ipmi::RspType<bool, // CATERR Reset Enabled |
| 677 | bool, // ERR2 Reset Enabled |
| 678 | uint6_t, // reserved |
| 679 | uint8_t, // reserved, returns 0x3F |
| 680 | uint6_t, // CPU1 CATERR Count |
| 681 | uint2_t, // CPU1 Status |
| 682 | uint6_t, // CPU2 CATERR Count |
| 683 | uint2_t, // CPU2 Status |
| 684 | uint6_t, // CPU3 CATERR Count |
| 685 | uint2_t, // CPU3 Status |
| 686 | uint6_t, // CPU4 CATERR Count |
| 687 | uint2_t, // CPU4 Status |
| 688 | uint8_t // Crashdump Count |
| 689 | > |
| 690 | ipmiOEMGetProcessorErrConfig() |
| 691 | { |
| 692 | bool resetOnCATERR = false; |
| 693 | bool resetOnERR2 = false; |
| 694 | uint6_t cpu1CATERRCount = 0; |
| 695 | uint6_t cpu2CATERRCount = 0; |
| 696 | uint6_t cpu3CATERRCount = 0; |
| 697 | uint6_t cpu4CATERRCount = 0; |
| 698 | uint8_t crashdumpCount = 0; |
| 699 | uint2_t cpu1Status = |
| 700 | cpuPresent("CPU_1") ? CPUStatus::enabled : CPUStatus::notPresent; |
| 701 | uint2_t cpu2Status = |
| 702 | cpuPresent("CPU_2") ? CPUStatus::enabled : CPUStatus::notPresent; |
| 703 | uint2_t cpu3Status = |
| 704 | cpuPresent("CPU_3") ? CPUStatus::enabled : CPUStatus::notPresent; |
| 705 | uint2_t cpu4Status = |
| 706 | cpuPresent("CPU_4") ? CPUStatus::enabled : CPUStatus::notPresent; |
| 707 | |
| 708 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 709 | try |
| 710 | { |
| 711 | auto service = ipmi::getService(*busp, processorErrConfigIntf, |
| 712 | processorErrConfigObjPath); |
| 713 | |
| 714 | ipmi::PropertyMap result = ipmi::getAllDbusProperties( |
| 715 | *busp, service, processorErrConfigObjPath, processorErrConfigIntf); |
| 716 | resetOnCATERR = std::get<bool>(result.at("ResetOnCATERR")); |
| 717 | resetOnERR2 = std::get<bool>(result.at("ResetOnERR2")); |
| 718 | cpu1CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU1")); |
| 719 | cpu2CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU2")); |
| 720 | cpu3CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU3")); |
| 721 | cpu4CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU4")); |
| 722 | crashdumpCount = std::get<uint8_t>(result.at("CrashdumpCount")); |
| 723 | } |
| 724 | catch (const std::exception& e) |
| 725 | { |
| 726 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 727 | "Failed to fetch processor error config", |
| 728 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 729 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 732 | return ipmi::responseSuccess(resetOnCATERR, resetOnERR2, 0, 0x3F, |
| 733 | cpu1CATERRCount, cpu1Status, cpu2CATERRCount, |
| 734 | cpu2Status, cpu3CATERRCount, cpu3Status, |
| 735 | cpu4CATERRCount, cpu4Status, crashdumpCount); |
| 736 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 737 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 738 | ipmi::RspType<> ipmiOEMSetProcessorErrConfig( |
| 739 | bool resetOnCATERR, bool resetOnERR2, uint6_t reserved1, uint8_t reserved2, |
| 740 | std::optional<bool> clearCPUErrorCount, |
| 741 | std::optional<bool> clearCrashdumpCount, std::optional<uint6_t> reserved3) |
| 742 | { |
| 743 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 744 | |
| 745 | try |
| 746 | { |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 747 | auto service = ipmi::getService(*busp, processorErrConfigIntf, |
| 748 | processorErrConfigObjPath); |
| 749 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 750 | processorErrConfigIntf, "ResetOnCATERR", |
| 751 | resetOnCATERR); |
| 752 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 753 | processorErrConfigIntf, "ResetOnERR2", |
| 754 | resetOnERR2); |
| 755 | if (clearCPUErrorCount.value_or(false)) |
| 756 | { |
| 757 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
Jason M. Bills | d3e1993 | 2019-08-15 12:39:03 -0700 | [diff] [blame] | 758 | processorErrConfigIntf, "ErrorCountCPU1", |
| 759 | static_cast<uint8_t>(0)); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 760 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
Jason M. Bills | d3e1993 | 2019-08-15 12:39:03 -0700 | [diff] [blame] | 761 | processorErrConfigIntf, "ErrorCountCPU2", |
| 762 | static_cast<uint8_t>(0)); |
| 763 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 764 | processorErrConfigIntf, "ErrorCountCPU3", |
| 765 | static_cast<uint8_t>(0)); |
| 766 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 767 | processorErrConfigIntf, "ErrorCountCPU4", |
| 768 | static_cast<uint8_t>(0)); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 769 | } |
| 770 | if (clearCrashdumpCount.value_or(false)) |
| 771 | { |
| 772 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
Jason M. Bills | d3e1993 | 2019-08-15 12:39:03 -0700 | [diff] [blame] | 773 | processorErrConfigIntf, "CrashdumpCount", |
| 774 | static_cast<uint8_t>(0)); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 775 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 776 | } |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 777 | catch (std::exception& e) |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 778 | { |
Kuiying Wang | bc54667 | 2018-11-23 15:41:05 +0800 | [diff] [blame] | 779 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 780 | "Failed to set processor error config", |
| 781 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 782 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 785 | return ipmi::responseSuccess(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 788 | ipmi_ret_t ipmiOEMGetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 789 | ipmi_request_t request, |
| 790 | ipmi_response_t response, |
| 791 | ipmi_data_len_t dataLen, |
| 792 | ipmi_context_t context) |
| 793 | { |
| 794 | GetOEMShutdownPolicyRes* resp = |
| 795 | reinterpret_cast<GetOEMShutdownPolicyRes*>(response); |
| 796 | |
| 797 | if (*dataLen != 0) |
| 798 | { |
| 799 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 800 | "oem_get_shutdown_policy: invalid input len!"); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 801 | *dataLen = 0; |
| 802 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 803 | } |
| 804 | |
| 805 | *dataLen = 0; |
| 806 | |
| 807 | try |
| 808 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 809 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 810 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 811 | getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath); |
| 812 | Value variant = getDbusProperty( |
| 813 | *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf, |
| 814 | oemShutdownPolicyObjPathProp); |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 815 | |
| 816 | if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 817 | convertPolicyFromString(std::get<std::string>(variant)) == |
| 818 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy:: |
| 819 | NoShutdownOnOCOT) |
| 820 | { |
| 821 | resp->policy = 0; |
| 822 | } |
| 823 | else if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 824 | convertPolicyFromString(std::get<std::string>(variant)) == |
| 825 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 826 | Policy::ShutdownOnOCOT) |
| 827 | { |
| 828 | resp->policy = 1; |
| 829 | } |
| 830 | else |
| 831 | { |
| 832 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 833 | "oem_set_shutdown_policy: invalid property!", |
| 834 | phosphor::logging::entry( |
| 835 | "PROP=%s", std::get<std::string>(variant).c_str())); |
| 836 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 837 | } |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 838 | // TODO needs to check if it is multi-node products, |
| 839 | // policy is only supported on node 3/4 |
| 840 | resp->policySupport = shutdownPolicySupported; |
| 841 | } |
| 842 | catch (sdbusplus::exception_t& e) |
| 843 | { |
| 844 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 845 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 846 | } |
| 847 | |
| 848 | *dataLen = sizeof(GetOEMShutdownPolicyRes); |
| 849 | return IPMI_CC_OK; |
| 850 | } |
| 851 | |
| 852 | ipmi_ret_t ipmiOEMSetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 853 | ipmi_request_t request, |
| 854 | ipmi_response_t response, |
| 855 | ipmi_data_len_t dataLen, |
| 856 | ipmi_context_t context) |
| 857 | { |
| 858 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 859 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy policy = |
| 860 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy:: |
| 861 | NoShutdownOnOCOT; |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 862 | |
| 863 | // TODO needs to check if it is multi-node products, |
| 864 | // policy is only supported on node 3/4 |
| 865 | if (*dataLen != 1) |
| 866 | { |
| 867 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 868 | "oem_set_shutdown_policy: invalid input len!"); |
| 869 | *dataLen = 0; |
| 870 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 871 | } |
| 872 | |
| 873 | *dataLen = 0; |
| 874 | if ((*req != noShutdownOnOCOT) && (*req != shutdownOnOCOT)) |
| 875 | { |
| 876 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 877 | "oem_set_shutdown_policy: invalid input!"); |
| 878 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 879 | } |
| 880 | |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 881 | if (*req == noShutdownOnOCOT) |
| 882 | { |
| 883 | policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 884 | Policy::NoShutdownOnOCOT; |
| 885 | } |
| 886 | else |
| 887 | { |
| 888 | policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 889 | Policy::ShutdownOnOCOT; |
| 890 | } |
| 891 | |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 892 | try |
| 893 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 894 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 895 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 896 | getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath); |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 897 | setDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 898 | *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf, |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 899 | oemShutdownPolicyObjPathProp, |
| 900 | sdbusplus::com::intel::Control::server::convertForMessage(policy)); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 901 | } |
| 902 | catch (sdbusplus::exception_t& e) |
| 903 | { |
| 904 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 905 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 906 | } |
| 907 | |
| 908 | return IPMI_CC_OK; |
| 909 | } |
| 910 | |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 911 | /** @brief implementation for check the DHCP or not in IPv4 |
| 912 | * @param[in] Channel - Channel number |
| 913 | * @returns true or false. |
| 914 | */ |
| 915 | static bool isDHCPEnabled(uint8_t Channel) |
| 916 | { |
| 917 | try |
| 918 | { |
| 919 | auto ethdevice = getChannelName(Channel); |
| 920 | if (ethdevice.empty()) |
| 921 | { |
| 922 | return false; |
| 923 | } |
| 924 | auto ethIP = ethdevice + "/ipv4"; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 925 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 926 | auto ethernetObj = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 927 | getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP); |
| 928 | auto value = getDbusProperty(*dbus, networkService, ethernetObj.first, |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 929 | networkIPIntf, "Origin"); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 930 | if (std::get<std::string>(value) == |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 931 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP") |
| 932 | { |
| 933 | return true; |
| 934 | } |
| 935 | else |
| 936 | { |
| 937 | return false; |
| 938 | } |
| 939 | } |
| 940 | catch (sdbusplus::exception_t& e) |
| 941 | { |
| 942 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 943 | return true; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | /** @brief implementes for check the DHCP or not in IPv6 |
| 948 | * @param[in] Channel - Channel number |
| 949 | * @returns true or false. |
| 950 | */ |
| 951 | static bool isDHCPIPv6Enabled(uint8_t Channel) |
| 952 | { |
| 953 | |
| 954 | try |
| 955 | { |
| 956 | auto ethdevice = getChannelName(Channel); |
| 957 | if (ethdevice.empty()) |
| 958 | { |
| 959 | return false; |
| 960 | } |
| 961 | auto ethIP = ethdevice + "/ipv6"; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 962 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 963 | auto objectInfo = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 964 | getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP); |
| 965 | auto properties = getAllDbusProperties(*dbus, objectInfo.second, |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 966 | objectInfo.first, networkIPIntf); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 967 | if (std::get<std::string>(properties["Origin"]) == |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 968 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP") |
| 969 | { |
| 970 | return true; |
| 971 | } |
| 972 | else |
| 973 | { |
| 974 | return false; |
| 975 | } |
| 976 | } |
| 977 | catch (sdbusplus::exception_t& e) |
| 978 | { |
| 979 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 980 | return true; |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | /** @brief implementes the creating of default new user |
| 985 | * @param[in] userName - new username in 16 bytes. |
| 986 | * @param[in] userPassword - new password in 20 bytes |
| 987 | * @returns ipmi completion code. |
| 988 | */ |
| 989 | ipmi::RspType<> ipmiOEMSetUser2Activation( |
| 990 | std::array<uint8_t, ipmi::ipmiMaxUserName>& userName, |
| 991 | std::array<uint8_t, ipmi::maxIpmi20PasswordSize>& userPassword) |
| 992 | { |
| 993 | bool userState = false; |
| 994 | // Check for System Interface not exist and LAN should be static |
| 995 | for (uint8_t channel = 0; channel < maxIpmiChannels; channel++) |
| 996 | { |
| 997 | ChannelInfo chInfo; |
| 998 | try |
| 999 | { |
| 1000 | getChannelInfo(channel, chInfo); |
| 1001 | } |
| 1002 | catch (sdbusplus::exception_t& e) |
| 1003 | { |
| 1004 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1005 | "ipmiOEMSetUser2Activation: Failed to get Channel Info", |
| 1006 | phosphor::logging::entry("MSG: %s", e.description())); |
| 1007 | return ipmi::response(ipmi::ccUnspecifiedError); |
| 1008 | } |
| 1009 | if (chInfo.mediumType == |
| 1010 | static_cast<uint8_t>(EChannelMediumType::systemInterface)) |
| 1011 | { |
| 1012 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1013 | "ipmiOEMSetUser2Activation: system interface exist ."); |
| 1014 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1015 | } |
| 1016 | else |
| 1017 | { |
| 1018 | |
| 1019 | if (chInfo.mediumType == |
| 1020 | static_cast<uint8_t>(EChannelMediumType::lan8032)) |
| 1021 | { |
| 1022 | if (isDHCPIPv6Enabled(channel) || isDHCPEnabled(channel)) |
| 1023 | { |
| 1024 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1025 | "ipmiOEMSetUser2Activation: DHCP enabled ."); |
| 1026 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | uint8_t maxChUsers = 0, enabledUsers = 0, fixedUsers = 0; |
| 1032 | if (ipmi::ccSuccess == |
| 1033 | ipmiUserGetAllCounts(maxChUsers, enabledUsers, fixedUsers)) |
| 1034 | { |
| 1035 | if (enabledUsers > 1) |
| 1036 | { |
| 1037 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1038 | "ipmiOEMSetUser2Activation: more than one user is enabled."); |
| 1039 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1040 | } |
| 1041 | // Check the user 2 is enabled or not |
| 1042 | ipmiUserCheckEnabled(ipmiDefaultUserId, userState); |
| 1043 | if (userState == true) |
| 1044 | { |
| 1045 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1046 | "ipmiOEMSetUser2Activation: user 2 already enabled ."); |
| 1047 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1048 | } |
| 1049 | } |
| 1050 | else |
| 1051 | { |
| 1052 | return ipmi::response(ipmi::ccUnspecifiedError); |
| 1053 | } |
| 1054 | |
| 1055 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 1056 | PrivAccess privAccess = {PRIVILEGE_ADMIN, true, true, true, 0}; |
| 1057 | #endif |
| 1058 | #if BYTE_ORDER == BIG_ENDIAN |
| 1059 | PrivAccess privAccess = {0, true, true, true, PRIVILEGE_ADMIN}; |
| 1060 | #endif |
| 1061 | |
| 1062 | if (ipmi::ccSuccess == |
| 1063 | ipmiUserSetUserName(ipmiDefaultUserId, |
| 1064 | reinterpret_cast<const char*>(userName.data()))) |
| 1065 | { |
| 1066 | if (ipmi::ccSuccess == |
| 1067 | ipmiUserSetUserPassword( |
| 1068 | ipmiDefaultUserId, |
| 1069 | reinterpret_cast<const char*>(userPassword.data()))) |
| 1070 | { |
| 1071 | if (ipmi::ccSuccess == |
| 1072 | ipmiUserSetPrivilegeAccess( |
| 1073 | ipmiDefaultUserId, |
| 1074 | static_cast<uint8_t>(ipmi::EChannelID::chanLan1), |
| 1075 | privAccess, true)) |
| 1076 | { |
| 1077 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1078 | "ipmiOEMSetUser2Activation: user created successfully "); |
| 1079 | return ipmi::responseSuccess(); |
| 1080 | } |
| 1081 | } |
| 1082 | // we need to delete the default user id which added in this command as |
| 1083 | // password / priv setting is failed. |
| 1084 | ipmiUserSetUserName(ipmiDefaultUserId, ""); |
| 1085 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1086 | "ipmiOEMSetUser2Activation: password / priv setting is failed."); |
| 1087 | } |
| 1088 | else |
| 1089 | { |
| 1090 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1091 | "ipmiOEMSetUser2Activation: Setting username failed."); |
| 1092 | } |
| 1093 | |
| 1094 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1095 | } |
| 1096 | |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1097 | /** @brief implementes executing the linux command |
| 1098 | * @param[in] linux command |
| 1099 | * @returns status |
| 1100 | */ |
| 1101 | |
| 1102 | static uint8_t executeCmd(const char* path) |
| 1103 | { |
| 1104 | boost::process::child execProg(path); |
| 1105 | execProg.wait(); |
| 1106 | |
| 1107 | int retCode = execProg.exit_code(); |
| 1108 | if (retCode) |
| 1109 | { |
| 1110 | return ipmi::ccUnspecifiedError; |
| 1111 | } |
| 1112 | return ipmi::ccSuccess; |
| 1113 | } |
| 1114 | |
| 1115 | /** @brief implementes ASD Security event logging |
| 1116 | * @param[in] Event message string |
| 1117 | * @param[in] Event Severity |
| 1118 | * @returns status |
| 1119 | */ |
| 1120 | |
| 1121 | static void atScaleDebugEventlog(std::string msg, int severity) |
| 1122 | { |
| 1123 | std::string eventStr = "OpenBMC.0.1." + msg; |
| 1124 | sd_journal_send("MESSAGE=Security Event: %s", eventStr.c_str(), |
| 1125 | "PRIORITY=%i", severity, "REDFISH_MESSAGE_ID=%s", |
| 1126 | eventStr.c_str(), NULL); |
| 1127 | } |
| 1128 | |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1129 | /** @brief implementes setting password for special user |
| 1130 | * @param[in] specialUserIndex |
| 1131 | * @param[in] userPassword - new password in 20 bytes |
| 1132 | * @returns ipmi completion code. |
| 1133 | */ |
| 1134 | ipmi::RspType<> ipmiOEMSetSpecialUserPassword(ipmi::Context::ptr ctx, |
| 1135 | uint8_t specialUserIndex, |
| 1136 | std::vector<uint8_t> userPassword) |
| 1137 | { |
| 1138 | ChannelInfo chInfo; |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1139 | ipmi_ret_t status = ipmi::ccSuccess; |
| 1140 | |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1141 | try |
| 1142 | { |
| 1143 | getChannelInfo(ctx->channel, chInfo); |
| 1144 | } |
| 1145 | catch (sdbusplus::exception_t& e) |
| 1146 | { |
| 1147 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1148 | "ipmiOEMSetSpecialUserPassword: Failed to get Channel Info", |
| 1149 | phosphor::logging::entry("MSG: %s", e.description())); |
| 1150 | return ipmi::responseUnspecifiedError(); |
| 1151 | } |
| 1152 | if (chInfo.mediumType != |
| 1153 | static_cast<uint8_t>(EChannelMediumType::systemInterface)) |
| 1154 | { |
| 1155 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1156 | "ipmiOEMSetSpecialUserPassword: Error - supported only in KCS " |
| 1157 | "interface"); |
| 1158 | return ipmi::responseCommandNotAvailable(); |
| 1159 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1160 | |
| 1161 | // 0 for root user and 1 for AtScaleDebug is allowed |
| 1162 | if (specialUserIndex > |
| 1163 | static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser)) |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1164 | { |
| 1165 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1166 | "ipmiOEMSetSpecialUserPassword: Invalid user account"); |
| 1167 | return ipmi::responseParmOutOfRange(); |
| 1168 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1169 | if (userPassword.size() != 0) |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1170 | { |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1171 | constexpr uint8_t minPasswordSizeRequired = 6; |
| 1172 | std::string passwd; |
| 1173 | if (userPassword.size() < minPasswordSizeRequired || |
| 1174 | userPassword.size() > ipmi::maxIpmi20PasswordSize) |
| 1175 | { |
| 1176 | return ipmi::responseReqDataLenInvalid(); |
| 1177 | } |
| 1178 | passwd.assign(reinterpret_cast<const char*>(userPassword.data()), |
| 1179 | userPassword.size()); |
| 1180 | if (specialUserIndex == |
| 1181 | static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser)) |
| 1182 | { |
| 1183 | status = ipmiSetSpecialUserPassword("asdbg", passwd); |
| 1184 | |
| 1185 | atScaleDebugEventlog("AtScaleDebugSpecialUserEnabled", LOG_CRIT); |
| 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | status = ipmiSetSpecialUserPassword("root", passwd); |
| 1190 | } |
| 1191 | return ipmi::response(status); |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1192 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1193 | else |
| 1194 | { |
| 1195 | if (specialUserIndex == |
| 1196 | static_cast<uint8_t>(SpecialUserIndex::rootUser)) |
| 1197 | { |
| 1198 | status = executeCmd("passwd -d root"); |
| 1199 | } |
| 1200 | else |
| 1201 | { |
| 1202 | |
| 1203 | status = executeCmd("passwd -d asdbg"); |
| 1204 | |
| 1205 | if (status == 0) |
| 1206 | { |
| 1207 | atScaleDebugEventlog("AtScaleDebugSpecialUserDisabled", |
| 1208 | LOG_INFO); |
| 1209 | } |
| 1210 | } |
| 1211 | return ipmi::response(status); |
| 1212 | } |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1213 | } |
| 1214 | |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1215 | namespace ledAction |
| 1216 | { |
| 1217 | using namespace sdbusplus::xyz::openbmc_project::Led::server; |
| 1218 | std::map<Physical::Action, uint8_t> actionDbusToIpmi = { |
jayaprakash Mutyala | 934ee9c | 2019-12-13 17:49:27 +0000 | [diff] [blame] | 1219 | {Physical::Action::Off, 0}, |
| 1220 | {Physical::Action::On, 2}, |
| 1221 | {Physical::Action::Blink, 1}}; |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1222 | |
| 1223 | std::map<uint8_t, std::string> offsetObjPath = { |
| 1224 | {2, statusAmberObjPath}, {4, statusGreenObjPath}, {6, identifyLEDObjPath}}; |
| 1225 | |
| 1226 | } // namespace ledAction |
| 1227 | |
| 1228 | int8_t getLEDState(sdbusplus::bus::bus& bus, const std::string& intf, |
| 1229 | const std::string& objPath, uint8_t& state) |
| 1230 | { |
| 1231 | try |
| 1232 | { |
| 1233 | std::string service = getService(bus, intf, objPath); |
| 1234 | Value stateValue = |
| 1235 | getDbusProperty(bus, service, objPath, intf, "State"); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1236 | std::string strState = std::get<std::string>(stateValue); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1237 | state = ledAction::actionDbusToIpmi.at( |
| 1238 | sdbusplus::xyz::openbmc_project::Led::server::Physical:: |
| 1239 | convertActionFromString(strState)); |
| 1240 | } |
| 1241 | catch (sdbusplus::exception::SdBusError& e) |
| 1242 | { |
| 1243 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 1244 | return -1; |
| 1245 | } |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | ipmi_ret_t ipmiOEMGetLEDStatus(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1250 | ipmi_request_t request, ipmi_response_t response, |
| 1251 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 1252 | { |
| 1253 | uint8_t* resp = reinterpret_cast<uint8_t*>(response); |
| 1254 | // LED Status |
| 1255 | //[1:0] = Reserved |
| 1256 | //[3:2] = Status(Amber) |
| 1257 | //[5:4] = Status(Green) |
| 1258 | //[7:6] = System Identify |
| 1259 | // Status definitions: |
| 1260 | // 00b = Off |
| 1261 | // 01b = Blink |
| 1262 | // 10b = On |
| 1263 | // 11b = invalid |
| 1264 | if (*dataLen != 0) |
| 1265 | { |
| 1266 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1267 | "oem_get_led_status: invalid input len!"); |
| 1268 | *dataLen = 0; |
| 1269 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1270 | } |
| 1271 | |
| 1272 | phosphor::logging::log<phosphor::logging::level::DEBUG>("GET led status"); |
| 1273 | *resp = 0; |
| 1274 | *dataLen = 0; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1275 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1276 | for (auto it = ledAction::offsetObjPath.begin(); |
| 1277 | it != ledAction::offsetObjPath.end(); ++it) |
| 1278 | { |
| 1279 | uint8_t state = 0; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1280 | if (-1 == getLEDState(*dbus, ledIntf, it->second, state)) |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1281 | { |
| 1282 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1283 | "oem_get_led_status: fail to get ID LED status!"); |
| 1284 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1285 | } |
| 1286 | *resp |= state << it->first; |
| 1287 | } |
| 1288 | |
| 1289 | *dataLen = sizeof(*resp); |
| 1290 | return IPMI_CC_OK; |
| 1291 | } |
| 1292 | |
Yong Li | 23737fe | 2019-02-19 08:49:55 +0800 | [diff] [blame] | 1293 | ipmi_ret_t ipmiOEMCfgHostSerialPortSpeed(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1294 | ipmi_request_t request, |
| 1295 | ipmi_response_t response, |
| 1296 | ipmi_data_len_t dataLen, |
| 1297 | ipmi_context_t context) |
| 1298 | { |
| 1299 | CfgHostSerialReq* req = reinterpret_cast<CfgHostSerialReq*>(request); |
| 1300 | uint8_t* resp = reinterpret_cast<uint8_t*>(response); |
| 1301 | |
| 1302 | if (*dataLen == 0) |
| 1303 | { |
| 1304 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1305 | "CfgHostSerial: invalid input len!", |
| 1306 | phosphor::logging::entry("LEN=%d", *dataLen)); |
| 1307 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1308 | } |
| 1309 | |
| 1310 | switch (req->command) |
| 1311 | { |
| 1312 | case getHostSerialCfgCmd: |
| 1313 | { |
| 1314 | if (*dataLen != 1) |
| 1315 | { |
| 1316 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1317 | "CfgHostSerial: invalid input len!"); |
| 1318 | *dataLen = 0; |
| 1319 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1320 | } |
| 1321 | |
| 1322 | *dataLen = 0; |
| 1323 | |
| 1324 | boost::process::ipstream is; |
| 1325 | std::vector<std::string> data; |
| 1326 | std::string line; |
| 1327 | boost::process::child c1(fwGetEnvCmd, "-n", fwHostSerailCfgEnvName, |
| 1328 | boost::process::std_out > is); |
| 1329 | |
| 1330 | while (c1.running() && std::getline(is, line) && !line.empty()) |
| 1331 | { |
| 1332 | data.push_back(line); |
| 1333 | } |
| 1334 | |
| 1335 | c1.wait(); |
| 1336 | if (c1.exit_code()) |
| 1337 | { |
| 1338 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1339 | "CfgHostSerial:: error on execute", |
| 1340 | phosphor::logging::entry("EXECUTE=%s", fwSetEnvCmd)); |
| 1341 | // Using the default value |
| 1342 | *resp = 0; |
| 1343 | } |
| 1344 | else |
| 1345 | { |
| 1346 | if (data.size() != 1) |
| 1347 | { |
| 1348 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1349 | "CfgHostSerial:: error on read env"); |
| 1350 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1351 | } |
| 1352 | try |
| 1353 | { |
| 1354 | unsigned long tmp = std::stoul(data[0]); |
| 1355 | if (tmp > std::numeric_limits<uint8_t>::max()) |
| 1356 | { |
| 1357 | throw std::out_of_range("Out of range"); |
| 1358 | } |
| 1359 | *resp = static_cast<uint8_t>(tmp); |
| 1360 | } |
| 1361 | catch (const std::invalid_argument& e) |
| 1362 | { |
| 1363 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1364 | "invalid config ", |
| 1365 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1366 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1367 | } |
| 1368 | catch (const std::out_of_range& e) |
| 1369 | { |
| 1370 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1371 | "out_of_range config ", |
| 1372 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1373 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | *dataLen = 1; |
| 1378 | break; |
| 1379 | } |
| 1380 | case setHostSerialCfgCmd: |
| 1381 | { |
| 1382 | if (*dataLen != sizeof(CfgHostSerialReq)) |
| 1383 | { |
| 1384 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1385 | "CfgHostSerial: invalid input len!"); |
| 1386 | *dataLen = 0; |
| 1387 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1388 | } |
| 1389 | |
| 1390 | *dataLen = 0; |
| 1391 | |
| 1392 | if (req->parameter > HostSerialCfgParamMax) |
| 1393 | { |
| 1394 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1395 | "CfgHostSerial: invalid input!"); |
| 1396 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1397 | } |
| 1398 | |
| 1399 | boost::process::child c1(fwSetEnvCmd, fwHostSerailCfgEnvName, |
| 1400 | std::to_string(req->parameter)); |
| 1401 | |
| 1402 | c1.wait(); |
| 1403 | if (c1.exit_code()) |
| 1404 | { |
| 1405 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1406 | "CfgHostSerial:: error on execute", |
| 1407 | phosphor::logging::entry("EXECUTE=%s", fwGetEnvCmd)); |
| 1408 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1409 | } |
| 1410 | break; |
| 1411 | } |
| 1412 | default: |
| 1413 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1414 | "CfgHostSerial: invalid input!"); |
| 1415 | *dataLen = 0; |
| 1416 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1417 | } |
| 1418 | |
| 1419 | return IPMI_CC_OK; |
| 1420 | } |
| 1421 | |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1422 | constexpr const char* thermalModeInterface = |
| 1423 | "xyz.openbmc_project.Control.ThermalMode"; |
| 1424 | constexpr const char* thermalModePath = |
| 1425 | "/xyz/openbmc_project/control/thermal_mode"; |
| 1426 | |
| 1427 | bool getFanProfileInterface( |
| 1428 | sdbusplus::bus::bus& bus, |
| 1429 | boost::container::flat_map< |
| 1430 | std::string, std::variant<std::vector<std::string>, std::string>>& resp) |
| 1431 | { |
| 1432 | auto call = bus.new_method_call(settingsBusName, thermalModePath, PROP_INTF, |
| 1433 | "GetAll"); |
| 1434 | call.append(thermalModeInterface); |
| 1435 | try |
| 1436 | { |
| 1437 | auto data = bus.call(call); |
| 1438 | data.read(resp); |
| 1439 | } |
| 1440 | catch (sdbusplus::exception_t& e) |
| 1441 | { |
| 1442 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1443 | "getFanProfileInterface: can't get thermal mode!", |
| 1444 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1445 | return false; |
| 1446 | } |
| 1447 | return true; |
| 1448 | } |
| 1449 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1450 | /**@brief implements the OEM set fan config. |
| 1451 | * @param selectedFanProfile - fan profile to enable |
| 1452 | * @param reserved1 |
| 1453 | * @param performanceMode - Performance/Acoustic mode |
| 1454 | * @param reserved2 |
| 1455 | * @param setPerformanceMode - set Performance/Acoustic mode |
| 1456 | * @param setFanProfile - set fan profile |
| 1457 | * |
| 1458 | * @return IPMI completion code. |
| 1459 | **/ |
| 1460 | ipmi::RspType<> ipmiOEMSetFanConfig(uint8_t selectedFanProfile, |
| 1461 | |
| 1462 | uint2_t reserved1, bool performanceMode, |
| 1463 | uint3_t reserved2, bool setPerformanceMode, |
| 1464 | bool setFanProfile) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1465 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1466 | if (reserved1 || reserved2) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1467 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1468 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1469 | } |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1470 | // todo: tell bios to only send first 2 bytes |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1471 | boost::container::flat_map< |
| 1472 | std::string, std::variant<std::vector<std::string>, std::string>> |
| 1473 | profileData; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1474 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 1475 | if (!getFanProfileInterface(*dbus, profileData)) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1476 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1477 | return ipmi::responseUnspecifiedError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | std::vector<std::string>* supported = |
| 1481 | std::get_if<std::vector<std::string>>(&profileData["Supported"]); |
| 1482 | if (supported == nullptr) |
| 1483 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1484 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1485 | } |
| 1486 | std::string mode; |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1487 | if (setPerformanceMode) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1488 | { |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1489 | if (performanceMode) |
| 1490 | { |
| 1491 | |
| 1492 | if (std::find(supported->begin(), supported->end(), |
| 1493 | "Performance") != supported->end()) |
| 1494 | { |
| 1495 | mode = "Performance"; |
| 1496 | } |
| 1497 | } |
| 1498 | else |
| 1499 | { |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1500 | if (std::find(supported->begin(), supported->end(), "Acoustic") != |
| 1501 | supported->end()) |
| 1502 | { |
| 1503 | mode = "Acoustic"; |
| 1504 | } |
| 1505 | } |
| 1506 | if (mode.empty()) |
| 1507 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1508 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1509 | } |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1510 | |
| 1511 | try |
| 1512 | { |
| 1513 | setDbusProperty(*dbus, settingsBusName, thermalModePath, |
| 1514 | thermalModeInterface, "Current", mode); |
| 1515 | } |
| 1516 | catch (sdbusplus::exception_t& e) |
| 1517 | { |
| 1518 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1519 | "ipmiOEMSetFanConfig: can't set thermal mode!", |
| 1520 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 1521 | return ipmi::responseResponseError(); |
| 1522 | } |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1525 | return ipmi::responseSuccess(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1528 | ipmi::RspType<uint8_t, // profile support map |
| 1529 | uint8_t, // fan control profile enable |
| 1530 | uint8_t, // flags |
| 1531 | uint32_t // dimm presence bit map |
| 1532 | > |
| 1533 | ipmiOEMGetFanConfig(uint8_t dimmGroupId) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1534 | { |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1535 | boost::container::flat_map< |
| 1536 | std::string, std::variant<std::vector<std::string>, std::string>> |
| 1537 | profileData; |
| 1538 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1539 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 1540 | if (!getFanProfileInterface(*dbus, profileData)) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1541 | { |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1542 | return ipmi::responseResponseError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | std::string* current = std::get_if<std::string>(&profileData["Current"]); |
| 1546 | |
| 1547 | if (current == nullptr) |
| 1548 | { |
| 1549 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1550 | "ipmiOEMGetFanConfig: can't get current mode!"); |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1551 | return ipmi::responseResponseError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1552 | } |
| 1553 | bool performance = (*current == "Performance"); |
| 1554 | |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1555 | uint8_t flags = 0; |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1556 | if (performance) |
| 1557 | { |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1558 | flags |= 1 << 2; |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1559 | } |
| 1560 | |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1561 | return ipmi::responseSuccess(0, 0, flags, 0); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1562 | } |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1563 | constexpr const char* cfmLimitSettingPath = |
| 1564 | "/xyz/openbmc_project/control/cfm_limit"; |
| 1565 | constexpr const char* cfmLimitIface = "xyz.openbmc_project.Control.CFMLimit"; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1566 | constexpr const size_t legacyExitAirSensorNumber = 0x2e; |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1567 | constexpr const size_t legacyPCHSensorNumber = 0x22; |
| 1568 | constexpr const char* exitAirPathName = "Exit_Air"; |
| 1569 | constexpr const char* pchPathName = "SSB_Temp"; |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1570 | constexpr const char* pidConfigurationIface = |
| 1571 | "xyz.openbmc_project.Configuration.Pid"; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1572 | |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1573 | static std::string getConfigPath(const std::string& name) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1574 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1575 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1576 | auto method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1577 | dbus->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 1578 | "/xyz/openbmc_project/object_mapper", |
| 1579 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1580 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1581 | method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface}); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1582 | std::string path; |
| 1583 | GetSubTreeType resp; |
| 1584 | try |
| 1585 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1586 | auto reply = dbus->call(method); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1587 | reply.read(resp); |
| 1588 | } |
| 1589 | catch (sdbusplus::exception_t&) |
| 1590 | { |
| 1591 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1592 | "ipmiOEMGetFscParameter: mapper error"); |
| 1593 | }; |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1594 | auto config = |
| 1595 | std::find_if(resp.begin(), resp.end(), [&name](const auto& pair) { |
| 1596 | return pair.first.find(name) != std::string::npos; |
| 1597 | }); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1598 | if (config != resp.end()) |
| 1599 | { |
| 1600 | path = std::move(config->first); |
| 1601 | } |
| 1602 | return path; |
| 1603 | } |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1604 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1605 | // flat map to make alphabetical |
| 1606 | static boost::container::flat_map<std::string, PropertyMap> getPidConfigs() |
| 1607 | { |
| 1608 | boost::container::flat_map<std::string, PropertyMap> ret; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1609 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1610 | auto method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1611 | dbus->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 1612 | "/xyz/openbmc_project/object_mapper", |
| 1613 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1614 | |
| 1615 | method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface}); |
| 1616 | GetSubTreeType resp; |
| 1617 | |
| 1618 | try |
| 1619 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1620 | auto reply = dbus->call(method); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1621 | reply.read(resp); |
| 1622 | } |
| 1623 | catch (sdbusplus::exception_t&) |
| 1624 | { |
| 1625 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1626 | "getFanConfigPaths: mapper error"); |
| 1627 | }; |
| 1628 | for (const auto& [path, objects] : resp) |
| 1629 | { |
| 1630 | if (objects.empty()) |
| 1631 | { |
| 1632 | continue; // should be impossible |
| 1633 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 1634 | |
| 1635 | try |
| 1636 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1637 | ret.emplace(path, |
| 1638 | getAllDbusProperties(*dbus, objects[0].first, path, |
| 1639 | pidConfigurationIface)); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 1640 | } |
| 1641 | catch (sdbusplus::exception_t& e) |
| 1642 | { |
| 1643 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1644 | "getPidConfigs: can't get DbusProperties!", |
| 1645 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1646 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1647 | } |
| 1648 | return ret; |
| 1649 | } |
| 1650 | |
| 1651 | ipmi::RspType<uint8_t> ipmiOEMGetFanSpeedOffset(void) |
| 1652 | { |
| 1653 | boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs(); |
| 1654 | if (data.empty()) |
| 1655 | { |
| 1656 | return ipmi::responseResponseError(); |
| 1657 | } |
| 1658 | uint8_t minOffset = std::numeric_limits<uint8_t>::max(); |
| 1659 | for (const auto& [_, pid] : data) |
| 1660 | { |
| 1661 | auto findClass = pid.find("Class"); |
| 1662 | if (findClass == pid.end()) |
| 1663 | { |
| 1664 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1665 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1666 | "configurations"); |
| 1667 | return ipmi::responseResponseError(); |
| 1668 | } |
| 1669 | std::string type = std::get<std::string>(findClass->second); |
| 1670 | if (type == "fan") |
| 1671 | { |
| 1672 | auto findOutLimit = pid.find("OutLimitMin"); |
| 1673 | if (findOutLimit == pid.end()) |
| 1674 | { |
| 1675 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1676 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1677 | "configurations"); |
| 1678 | return ipmi::responseResponseError(); |
| 1679 | } |
| 1680 | // get the min out of all the offsets |
| 1681 | minOffset = std::min( |
| 1682 | minOffset, |
| 1683 | static_cast<uint8_t>(std::get<double>(findOutLimit->second))); |
| 1684 | } |
| 1685 | } |
| 1686 | if (minOffset == std::numeric_limits<uint8_t>::max()) |
| 1687 | { |
| 1688 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1689 | "ipmiOEMGetFscParameter: found no fan configurations!"); |
| 1690 | return ipmi::responseResponseError(); |
| 1691 | } |
| 1692 | |
| 1693 | return ipmi::responseSuccess(minOffset); |
| 1694 | } |
| 1695 | |
| 1696 | ipmi::RspType<> ipmiOEMSetFanSpeedOffset(uint8_t offset) |
| 1697 | { |
| 1698 | boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs(); |
| 1699 | if (data.empty()) |
| 1700 | { |
| 1701 | |
| 1702 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1703 | "ipmiOEMSetFanSpeedOffset: found no pid configurations!"); |
| 1704 | return ipmi::responseResponseError(); |
| 1705 | } |
| 1706 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1707 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1708 | bool found = false; |
| 1709 | for (const auto& [path, pid] : data) |
| 1710 | { |
| 1711 | auto findClass = pid.find("Class"); |
| 1712 | if (findClass == pid.end()) |
| 1713 | { |
| 1714 | |
| 1715 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1716 | "ipmiOEMSetFanSpeedOffset: found illegal pid " |
| 1717 | "configurations"); |
| 1718 | return ipmi::responseResponseError(); |
| 1719 | } |
| 1720 | std::string type = std::get<std::string>(findClass->second); |
| 1721 | if (type == "fan") |
| 1722 | { |
| 1723 | auto findOutLimit = pid.find("OutLimitMin"); |
| 1724 | if (findOutLimit == pid.end()) |
| 1725 | { |
| 1726 | |
| 1727 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1728 | "ipmiOEMSetFanSpeedOffset: found illegal pid " |
| 1729 | "configurations"); |
| 1730 | return ipmi::responseResponseError(); |
| 1731 | } |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1732 | ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1733 | path, pidConfigurationIface, "OutLimitMin", |
| 1734 | static_cast<double>(offset)); |
| 1735 | found = true; |
| 1736 | } |
| 1737 | } |
| 1738 | if (!found) |
| 1739 | { |
| 1740 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1741 | "ipmiOEMSetFanSpeedOffset: set no fan offsets"); |
| 1742 | return ipmi::responseResponseError(); |
| 1743 | } |
| 1744 | |
| 1745 | return ipmi::responseSuccess(); |
| 1746 | } |
| 1747 | |
| 1748 | ipmi::RspType<> ipmiOEMSetFscParameter(uint8_t command, uint8_t param1, |
| 1749 | uint8_t param2) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1750 | { |
| 1751 | constexpr const size_t disableLimiting = 0x0; |
| 1752 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1753 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1754 | if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1755 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1756 | std::string pathName; |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1757 | if (param1 == legacyExitAirSensorNumber) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1758 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1759 | pathName = exitAirPathName; |
| 1760 | } |
| 1761 | else if (param1 == legacyPCHSensorNumber) |
| 1762 | { |
| 1763 | pathName = pchPathName; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1764 | } |
| 1765 | else |
| 1766 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1767 | return ipmi::responseParmOutOfRange(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1768 | } |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1769 | std::string path = getConfigPath(pathName); |
| 1770 | ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", path, |
| 1771 | pidConfigurationIface, "SetPoint", |
| 1772 | static_cast<double>(param2)); |
| 1773 | return ipmi::responseSuccess(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1774 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1775 | else if (command == static_cast<uint8_t>(setFscParamFlags::cfm)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1776 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1777 | uint16_t cfm = param1 | (static_cast<uint16_t>(param2) << 8); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1778 | |
| 1779 | // must be greater than 50 based on eps |
| 1780 | if (cfm < 50 && cfm != disableLimiting) |
| 1781 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1782 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | try |
| 1786 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1787 | ipmi::setDbusProperty(*dbus, settingsBusName, cfmLimitSettingPath, |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1788 | cfmLimitIface, "Limit", |
| 1789 | static_cast<double>(cfm)); |
| 1790 | } |
| 1791 | catch (sdbusplus::exception_t& e) |
| 1792 | { |
| 1793 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1794 | "ipmiOEMSetFscParameter: can't set cfm setting!", |
| 1795 | phosphor::logging::entry("ERR=%s", e.what())); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1796 | return ipmi::responseResponseError(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1797 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1798 | return ipmi::responseSuccess(); |
| 1799 | } |
| 1800 | else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm)) |
| 1801 | { |
| 1802 | constexpr const size_t maxDomainCount = 8; |
| 1803 | uint8_t requestedDomainMask = param1; |
| 1804 | boost::container::flat_map data = getPidConfigs(); |
| 1805 | if (data.empty()) |
| 1806 | { |
| 1807 | |
| 1808 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1809 | "ipmiOEMSetFscParameter: found no pid configurations!"); |
| 1810 | return ipmi::responseResponseError(); |
| 1811 | } |
| 1812 | size_t count = 0; |
| 1813 | for (const auto& [path, pid] : data) |
| 1814 | { |
| 1815 | auto findClass = pid.find("Class"); |
| 1816 | if (findClass == pid.end()) |
| 1817 | { |
| 1818 | |
| 1819 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1820 | "ipmiOEMSetFscParameter: found illegal pid " |
| 1821 | "configurations"); |
| 1822 | return ipmi::responseResponseError(); |
| 1823 | } |
| 1824 | std::string type = std::get<std::string>(findClass->second); |
| 1825 | if (type == "fan") |
| 1826 | { |
| 1827 | if (requestedDomainMask & (1 << count)) |
| 1828 | { |
| 1829 | ipmi::setDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1830 | *dbus, "xyz.openbmc_project.EntityManager", path, |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1831 | pidConfigurationIface, "OutLimitMax", |
| 1832 | static_cast<double>(param2)); |
| 1833 | } |
| 1834 | count++; |
| 1835 | } |
| 1836 | } |
| 1837 | return ipmi::responseSuccess(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1838 | } |
| 1839 | else |
| 1840 | { |
| 1841 | // todo other command parts possibly |
| 1842 | // tcontrol is handled in peci now |
| 1843 | // fan speed offset not implemented yet |
| 1844 | // domain pwm limit not implemented |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1845 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1846 | } |
| 1847 | } |
| 1848 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1849 | ipmi::RspType< |
| 1850 | std::variant<uint8_t, std::array<uint8_t, 2>, std::array<uint16_t, 2>>> |
| 1851 | ipmiOEMGetFscParameter(uint8_t command, std::optional<uint8_t> param) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1852 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1853 | constexpr uint8_t legacyDefaultSetpoint = -128; |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1854 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1855 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1856 | if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1857 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1858 | if (!param) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1859 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1860 | return ipmi::responseReqDataLenInvalid(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1863 | std::string pathName; |
| 1864 | |
| 1865 | if (*param == legacyExitAirSensorNumber) |
| 1866 | { |
| 1867 | pathName = exitAirPathName; |
| 1868 | } |
| 1869 | else if (*param == legacyPCHSensorNumber) |
| 1870 | { |
| 1871 | pathName = pchPathName; |
| 1872 | } |
| 1873 | else |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1874 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1875 | return ipmi::responseParmOutOfRange(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1876 | } |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1877 | |
| 1878 | uint8_t setpoint = legacyDefaultSetpoint; |
| 1879 | std::string path = getConfigPath(pathName); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1880 | if (path.size()) |
| 1881 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1882 | Value val = ipmi::getDbusProperty( |
| 1883 | *dbus, "xyz.openbmc_project.EntityManager", path, |
| 1884 | pidConfigurationIface, "SetPoint"); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1885 | setpoint = std::floor(std::get<double>(val) + 0.5); |
| 1886 | } |
| 1887 | |
| 1888 | // old implementation used to return the "default" and current, we |
| 1889 | // don't make the default readily available so just make both the |
| 1890 | // same |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1891 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1892 | return ipmi::responseSuccess( |
| 1893 | std::array<uint8_t, 2>{setpoint, setpoint}); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1894 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1895 | else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm)) |
| 1896 | { |
| 1897 | constexpr const size_t maxDomainCount = 8; |
| 1898 | |
| 1899 | if (!param) |
| 1900 | { |
| 1901 | return ipmi::responseReqDataLenInvalid(); |
| 1902 | } |
| 1903 | uint8_t requestedDomain = *param; |
| 1904 | if (requestedDomain >= maxDomainCount) |
| 1905 | { |
| 1906 | return ipmi::responseInvalidFieldRequest(); |
| 1907 | } |
| 1908 | |
| 1909 | boost::container::flat_map data = getPidConfigs(); |
| 1910 | if (data.empty()) |
| 1911 | { |
| 1912 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1913 | "ipmiOEMGetFscParameter: found no pid configurations!"); |
| 1914 | return ipmi::responseResponseError(); |
| 1915 | } |
| 1916 | size_t count = 0; |
| 1917 | for (const auto& [_, pid] : data) |
| 1918 | { |
| 1919 | auto findClass = pid.find("Class"); |
| 1920 | if (findClass == pid.end()) |
| 1921 | { |
| 1922 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1923 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1924 | "configurations"); |
| 1925 | return ipmi::responseResponseError(); |
| 1926 | } |
| 1927 | std::string type = std::get<std::string>(findClass->second); |
| 1928 | if (type == "fan") |
| 1929 | { |
| 1930 | if (requestedDomain == count) |
| 1931 | { |
| 1932 | auto findOutLimit = pid.find("OutLimitMax"); |
| 1933 | if (findOutLimit == pid.end()) |
| 1934 | { |
| 1935 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1936 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1937 | "configurations"); |
| 1938 | return ipmi::responseResponseError(); |
| 1939 | } |
| 1940 | |
| 1941 | return ipmi::responseSuccess( |
| 1942 | static_cast<uint8_t>(std::floor( |
| 1943 | std::get<double>(findOutLimit->second) + 0.5))); |
| 1944 | } |
| 1945 | else |
| 1946 | { |
| 1947 | count++; |
| 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | return ipmi::responseInvalidFieldRequest(); |
| 1953 | } |
| 1954 | else if (command == static_cast<uint8_t>(setFscParamFlags::cfm)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1955 | { |
| 1956 | |
| 1957 | /* |
| 1958 | DataLen should be 1, but host is sending us an extra bit. As the |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1959 | previous behavior didn't seem to prevent this, ignore the check for |
| 1960 | now. |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1961 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1962 | if (param) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1963 | { |
| 1964 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1965 | "ipmiOEMGetFscParameter: invalid input len!"); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1966 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1967 | } |
| 1968 | */ |
| 1969 | Value cfmLimit; |
| 1970 | Value cfmMaximum; |
| 1971 | try |
| 1972 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1973 | cfmLimit = ipmi::getDbusProperty(*dbus, settingsBusName, |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1974 | cfmLimitSettingPath, cfmLimitIface, |
| 1975 | "Limit"); |
| 1976 | cfmMaximum = ipmi::getDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1977 | *dbus, "xyz.openbmc_project.ExitAirTempSensor", |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1978 | "/xyz/openbmc_project/control/MaxCFM", cfmLimitIface, "Limit"); |
| 1979 | } |
| 1980 | catch (sdbusplus::exception_t& e) |
| 1981 | { |
| 1982 | phosphor::logging::log<phosphor::logging::level::ERR>( |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1983 | "ipmiOEMGetFscParameter: can't get cfm setting!", |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1984 | phosphor::logging::entry("ERR=%s", e.what())); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1985 | return ipmi::responseResponseError(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1988 | double cfmMax = std::get<double>(cfmMaximum); |
| 1989 | double cfmLim = std::get<double>(cfmLimit); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1990 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1991 | cfmLim = std::floor(cfmLim + 0.5); |
| 1992 | cfmMax = std::floor(cfmMax + 0.5); |
| 1993 | uint16_t cfmLimResp = static_cast<uint16_t>(cfmLim); |
| 1994 | uint16_t cfmMaxResp = static_cast<uint16_t>(cfmMax); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1995 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1996 | return ipmi::responseSuccess( |
| 1997 | std::array<uint16_t, 2>{cfmLimResp, cfmMaxResp}); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1998 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1999 | |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2000 | else |
| 2001 | { |
| 2002 | // todo other command parts possibly |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2003 | // domain pwm limit not implemented |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2004 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2005 | } |
| 2006 | } |
| 2007 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2008 | using crConfigVariant = |
| 2009 | std::variant<bool, uint8_t, uint32_t, std::vector<uint8_t>, std::string>; |
| 2010 | |
| 2011 | int setCRConfig(ipmi::Context::ptr ctx, const std::string& property, |
| 2012 | const crConfigVariant& value, |
| 2013 | std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT) |
| 2014 | { |
| 2015 | boost::system::error_code ec; |
| 2016 | ctx->bus->yield_method_call<void>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2017 | ctx->yield, ec, "xyz.openbmc_project.Settings", |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2018 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2019 | "org.freedesktop.DBus.Properties", "Set", |
| 2020 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", property, value); |
| 2021 | if (ec) |
| 2022 | { |
| 2023 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2024 | "Failed to set dbus property to cold redundancy"); |
| 2025 | return -1; |
| 2026 | } |
| 2027 | |
| 2028 | return 0; |
| 2029 | } |
| 2030 | |
| 2031 | int getCRConfig(ipmi::Context::ptr ctx, const std::string& property, |
| 2032 | crConfigVariant& value, |
| 2033 | std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT) |
| 2034 | { |
| 2035 | boost::system::error_code ec; |
| 2036 | value = ctx->bus->yield_method_call<crConfigVariant>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2037 | ctx->yield, ec, "xyz.openbmc_project.Settings", |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2038 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2039 | "org.freedesktop.DBus.Properties", "Get", |
| 2040 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", property); |
| 2041 | if (ec) |
| 2042 | { |
| 2043 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2044 | "Failed to get dbus property to cold redundancy"); |
| 2045 | return -1; |
| 2046 | } |
| 2047 | return 0; |
| 2048 | } |
| 2049 | |
| 2050 | uint8_t getPSUCount(void) |
| 2051 | { |
| 2052 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 2053 | ipmi::Value num; |
| 2054 | try |
| 2055 | { |
| 2056 | num = ipmi::getDbusProperty( |
| 2057 | *dbus, "xyz.openbmc_project.PSURedundancy", |
| 2058 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2059 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", "PSUNumber"); |
| 2060 | } |
| 2061 | catch (sdbusplus::exception_t& e) |
| 2062 | { |
| 2063 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2064 | "Failed to get PSUNumber property from dbus interface"); |
| 2065 | return 0; |
| 2066 | } |
| 2067 | uint8_t* pNum = std::get_if<uint8_t>(&num); |
| 2068 | if (!pNum) |
| 2069 | { |
| 2070 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2071 | "Error to get PSU Number"); |
| 2072 | return 0; |
| 2073 | } |
| 2074 | return *pNum; |
| 2075 | } |
| 2076 | |
| 2077 | bool validateCRAlgo(std::vector<uint8_t>& conf, uint8_t num) |
| 2078 | { |
| 2079 | if (conf.size() < num) |
| 2080 | { |
| 2081 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2082 | "Invalid PSU Ranking"); |
| 2083 | return false; |
| 2084 | } |
| 2085 | std::set<uint8_t> confSet; |
| 2086 | for (uint8_t i = 0; i < num; i++) |
| 2087 | { |
| 2088 | if (conf[i] > num) |
| 2089 | { |
| 2090 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2091 | "PSU Ranking is larger than current PSU number"); |
| 2092 | return false; |
| 2093 | } |
| 2094 | confSet.emplace(conf[i]); |
| 2095 | } |
| 2096 | |
| 2097 | if (confSet.size() != num) |
| 2098 | { |
| 2099 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2100 | "duplicate PSU Ranking"); |
| 2101 | return false; |
| 2102 | } |
| 2103 | return true; |
| 2104 | } |
| 2105 | |
| 2106 | enum class crParameter |
| 2107 | { |
| 2108 | crStatus = 0, |
| 2109 | crFeature = 1, |
| 2110 | rotationFeature = 2, |
| 2111 | rotationAlgo = 3, |
| 2112 | rotationPeriod = 4, |
| 2113 | numOfPSU = 5 |
| 2114 | }; |
| 2115 | |
| 2116 | constexpr ipmi::Cc ccParameterNotSupported = 0x80; |
| 2117 | static const constexpr uint32_t oneDay = 0x15180; |
| 2118 | static const constexpr uint32_t oneMonth = 0xf53700; |
| 2119 | static const constexpr uint8_t userSpecific = 0x01; |
| 2120 | static const constexpr uint8_t crSetCompleted = 0; |
| 2121 | ipmi::RspType<uint8_t> ipmiOEMSetCRConfig(ipmi::Context::ptr ctx, |
| 2122 | uint8_t parameter, |
| 2123 | ipmi::message::Payload& payload) |
| 2124 | { |
| 2125 | switch (static_cast<crParameter>(parameter)) |
| 2126 | { |
| 2127 | case crParameter::crFeature: |
| 2128 | { |
| 2129 | uint8_t param1; |
| 2130 | if (payload.unpack(param1) || !payload.fullyUnpacked()) |
| 2131 | { |
| 2132 | return ipmi::responseReqDataLenInvalid(); |
| 2133 | } |
| 2134 | // ColdRedundancy Enable can only be true or flase |
| 2135 | if (param1 > 1) |
| 2136 | { |
| 2137 | return ipmi::responseInvalidFieldRequest(); |
| 2138 | } |
| 2139 | if (setCRConfig(ctx, "ColdRedundancyEnabled", |
| 2140 | static_cast<bool>(param1))) |
| 2141 | { |
| 2142 | return ipmi::responseResponseError(); |
| 2143 | } |
| 2144 | break; |
| 2145 | } |
| 2146 | case crParameter::rotationFeature: |
| 2147 | { |
| 2148 | uint8_t param1; |
| 2149 | if (payload.unpack(param1) || !payload.fullyUnpacked()) |
| 2150 | { |
| 2151 | return ipmi::responseReqDataLenInvalid(); |
| 2152 | } |
| 2153 | // Rotation Enable can only be true or false |
| 2154 | if (param1 > 1) |
| 2155 | { |
| 2156 | return ipmi::responseInvalidFieldRequest(); |
| 2157 | } |
| 2158 | if (setCRConfig(ctx, "RotationEnabled", static_cast<bool>(param1))) |
| 2159 | { |
| 2160 | return ipmi::responseResponseError(); |
| 2161 | } |
| 2162 | break; |
| 2163 | } |
| 2164 | case crParameter::rotationAlgo: |
| 2165 | { |
| 2166 | // Rotation Algorithm can only be 0-BMC Specific or 1-User Specific |
| 2167 | std::string algoName; |
| 2168 | uint8_t param1; |
| 2169 | if (payload.unpack(param1)) |
| 2170 | { |
| 2171 | return ipmi::responseReqDataLenInvalid(); |
| 2172 | } |
| 2173 | switch (param1) |
| 2174 | { |
| 2175 | case 0: |
| 2176 | algoName = "xyz.openbmc_project.Control." |
| 2177 | "PowerSupplyRedundancy.Algo.bmcSpecific"; |
| 2178 | break; |
| 2179 | case 1: |
| 2180 | algoName = "xyz.openbmc_project.Control." |
| 2181 | "PowerSupplyRedundancy.Algo.userSpecific"; |
| 2182 | break; |
| 2183 | default: |
| 2184 | return ipmi::responseInvalidFieldRequest(); |
| 2185 | } |
| 2186 | if (setCRConfig(ctx, "RotationAlgorithm", algoName)) |
| 2187 | { |
| 2188 | return ipmi::responseResponseError(); |
| 2189 | } |
| 2190 | |
| 2191 | uint8_t numberOfPSU = getPSUCount(); |
| 2192 | if (!numberOfPSU) |
| 2193 | { |
| 2194 | return ipmi::responseResponseError(); |
| 2195 | } |
| 2196 | std::vector<uint8_t> rankOrder; |
| 2197 | |
| 2198 | if (param1 == userSpecific) |
| 2199 | { |
| 2200 | if (payload.unpack(rankOrder) || !payload.fullyUnpacked()) |
| 2201 | { |
| 2202 | ipmi::responseReqDataLenInvalid(); |
| 2203 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2204 | if (rankOrder.size() != numberOfPSU) |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2205 | { |
| 2206 | return ipmi::responseReqDataLenInvalid(); |
| 2207 | } |
| 2208 | |
| 2209 | if (!validateCRAlgo(rankOrder, numberOfPSU)) |
| 2210 | { |
| 2211 | return ipmi::responseInvalidFieldRequest(); |
| 2212 | } |
| 2213 | } |
| 2214 | else |
| 2215 | { |
| 2216 | if (rankOrder.size() > 0) |
| 2217 | { |
| 2218 | return ipmi::responseReqDataLenInvalid(); |
| 2219 | } |
| 2220 | for (uint8_t i = 1; i <= numberOfPSU; i++) |
| 2221 | { |
| 2222 | rankOrder.emplace_back(i); |
| 2223 | } |
| 2224 | } |
| 2225 | if (setCRConfig(ctx, "RotationRankOrder", rankOrder)) |
| 2226 | { |
| 2227 | return ipmi::responseResponseError(); |
| 2228 | } |
| 2229 | break; |
| 2230 | } |
| 2231 | case crParameter::rotationPeriod: |
| 2232 | { |
| 2233 | // Minimum Rotation period is One day (86400 seconds) and Max |
| 2234 | // Rotation Period is 6 month (0xf53700 seconds) |
| 2235 | uint32_t period; |
| 2236 | if (payload.unpack(period) || !payload.fullyUnpacked()) |
| 2237 | { |
| 2238 | return ipmi::responseReqDataLenInvalid(); |
| 2239 | } |
| 2240 | if ((period < oneDay) || (period > oneMonth)) |
| 2241 | { |
| 2242 | return ipmi::responseInvalidFieldRequest(); |
| 2243 | } |
| 2244 | if (setCRConfig(ctx, "PeriodOfRotation", period)) |
| 2245 | { |
| 2246 | return ipmi::responseResponseError(); |
| 2247 | } |
| 2248 | break; |
| 2249 | } |
| 2250 | default: |
| 2251 | { |
| 2252 | return ipmi::response(ccParameterNotSupported); |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | // TODO Halfwidth needs to set SetInProgress |
| 2257 | if (setCRConfig(ctx, "ColdRedundancyStatus", |
Cheng C Yang | e8cecdf | 2019-08-26 23:48:08 +0800 | [diff] [blame] | 2258 | std::string("xyz.openbmc_project.Control." |
| 2259 | "PowerSupplyRedundancy.Status.completed"))) |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2260 | { |
| 2261 | return ipmi::responseResponseError(); |
| 2262 | } |
| 2263 | return ipmi::responseSuccess(crSetCompleted); |
| 2264 | } |
| 2265 | |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2266 | ipmi::RspType<uint8_t, std::variant<uint8_t, uint32_t, std::vector<uint8_t>>> |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2267 | ipmiOEMGetCRConfig(ipmi::Context::ptr ctx, uint8_t parameter) |
| 2268 | { |
| 2269 | crConfigVariant value; |
| 2270 | switch (static_cast<crParameter>(parameter)) |
| 2271 | { |
| 2272 | case crParameter::crStatus: |
| 2273 | { |
| 2274 | if (getCRConfig(ctx, "ColdRedundancyStatus", value)) |
| 2275 | { |
| 2276 | return ipmi::responseResponseError(); |
| 2277 | } |
| 2278 | std::string* pStatus = std::get_if<std::string>(&value); |
| 2279 | if (!pStatus) |
| 2280 | { |
| 2281 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2282 | "Error to get ColdRedundancyStatus property"); |
| 2283 | return ipmi::responseResponseError(); |
| 2284 | } |
| 2285 | namespace server = sdbusplus::xyz::openbmc_project::Control::server; |
| 2286 | auto status = |
| 2287 | server::PowerSupplyRedundancy::convertStatusFromString( |
| 2288 | *pStatus); |
| 2289 | switch (status) |
| 2290 | { |
| 2291 | case server::PowerSupplyRedundancy::Status::inProgress: |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2292 | return ipmi::responseSuccess(parameter, |
| 2293 | static_cast<uint8_t>(0)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2294 | |
| 2295 | case server::PowerSupplyRedundancy::Status::completed: |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2296 | return ipmi::responseSuccess(parameter, |
| 2297 | static_cast<uint8_t>(1)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2298 | default: |
| 2299 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2300 | "Error to get valid status"); |
| 2301 | return ipmi::responseResponseError(); |
| 2302 | } |
| 2303 | } |
| 2304 | case crParameter::crFeature: |
| 2305 | { |
| 2306 | if (getCRConfig(ctx, "ColdRedundancyEnabled", value)) |
| 2307 | { |
| 2308 | return ipmi::responseResponseError(); |
| 2309 | } |
| 2310 | bool* pResponse = std::get_if<bool>(&value); |
| 2311 | if (!pResponse) |
| 2312 | { |
| 2313 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2314 | "Error to get ColdRedundancyEnable property"); |
| 2315 | return ipmi::responseResponseError(); |
| 2316 | } |
| 2317 | |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2318 | return ipmi::responseSuccess(parameter, |
| 2319 | static_cast<uint8_t>(*pResponse)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2320 | } |
| 2321 | case crParameter::rotationFeature: |
| 2322 | { |
| 2323 | if (getCRConfig(ctx, "RotationEnabled", value)) |
| 2324 | { |
| 2325 | return ipmi::responseResponseError(); |
| 2326 | } |
| 2327 | bool* pResponse = std::get_if<bool>(&value); |
| 2328 | if (!pResponse) |
| 2329 | { |
| 2330 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2331 | "Error to get RotationEnabled property"); |
| 2332 | return ipmi::responseResponseError(); |
| 2333 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2334 | return ipmi::responseSuccess(parameter, |
| 2335 | static_cast<uint8_t>(*pResponse)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2336 | } |
| 2337 | case crParameter::rotationAlgo: |
| 2338 | { |
| 2339 | if (getCRConfig(ctx, "RotationAlgorithm", value)) |
| 2340 | { |
| 2341 | return ipmi::responseResponseError(); |
| 2342 | } |
| 2343 | |
| 2344 | std::string* pAlgo = std::get_if<std::string>(&value); |
| 2345 | if (!pAlgo) |
| 2346 | { |
| 2347 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2348 | "Error to get RotationAlgorithm property"); |
| 2349 | return ipmi::responseResponseError(); |
| 2350 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2351 | std::vector<uint8_t> response; |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2352 | namespace server = sdbusplus::xyz::openbmc_project::Control::server; |
| 2353 | auto algo = |
| 2354 | server::PowerSupplyRedundancy::convertAlgoFromString(*pAlgo); |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2355 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2356 | switch (algo) |
| 2357 | { |
| 2358 | case server::PowerSupplyRedundancy::Algo::bmcSpecific: |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2359 | response.push_back(0); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2360 | break; |
| 2361 | case server::PowerSupplyRedundancy::Algo::userSpecific: |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2362 | response.push_back(1); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2363 | break; |
| 2364 | default: |
| 2365 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2366 | "Error to get valid algo"); |
| 2367 | return ipmi::responseResponseError(); |
| 2368 | } |
| 2369 | |
| 2370 | if (getCRConfig(ctx, "RotationRankOrder", value)) |
| 2371 | { |
| 2372 | return ipmi::responseResponseError(); |
| 2373 | } |
| 2374 | std::vector<uint8_t>* pResponse = |
| 2375 | std::get_if<std::vector<uint8_t>>(&value); |
| 2376 | if (!pResponse) |
| 2377 | { |
| 2378 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2379 | "Error to get RotationRankOrder property"); |
| 2380 | return ipmi::responseResponseError(); |
| 2381 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2382 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2383 | std::copy(pResponse->begin(), pResponse->end(), |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2384 | std::back_inserter(response)); |
| 2385 | |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2386 | return ipmi::responseSuccess(parameter, response); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2387 | } |
| 2388 | case crParameter::rotationPeriod: |
| 2389 | { |
| 2390 | if (getCRConfig(ctx, "PeriodOfRotation", value)) |
| 2391 | { |
| 2392 | return ipmi::responseResponseError(); |
| 2393 | } |
| 2394 | uint32_t* pResponse = std::get_if<uint32_t>(&value); |
| 2395 | if (!pResponse) |
| 2396 | { |
| 2397 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2398 | "Error to get RotationAlgorithm property"); |
| 2399 | return ipmi::responseResponseError(); |
| 2400 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2401 | return ipmi::responseSuccess(parameter, *pResponse); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2402 | } |
| 2403 | case crParameter::numOfPSU: |
| 2404 | { |
| 2405 | uint8_t numberOfPSU = getPSUCount(); |
| 2406 | if (!numberOfPSU) |
| 2407 | { |
| 2408 | return ipmi::responseResponseError(); |
| 2409 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2410 | return ipmi::responseSuccess(parameter, numberOfPSU); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2411 | } |
| 2412 | default: |
| 2413 | { |
| 2414 | return ipmi::response(ccParameterNotSupported); |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2419 | ipmi::RspType<> ipmiOEMSetFaultIndication(uint8_t sourceId, uint8_t faultType, |
| 2420 | uint8_t faultState, |
| 2421 | uint8_t faultGroup, |
| 2422 | std::array<uint8_t, 8>& ledStateData) |
| 2423 | { |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2424 | constexpr auto maxFaultType = static_cast<size_t>(RemoteFaultType::max); |
| 2425 | static const std::array<std::string, maxFaultType> faultNames = { |
| 2426 | "faultFan", "faultTemp", "faultPower", |
| 2427 | "faultDriveSlot", "faultSoftware", "faultMemory"}; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2428 | |
| 2429 | constexpr uint8_t maxFaultSource = 0x4; |
| 2430 | constexpr uint8_t skipLEDs = 0xFF; |
| 2431 | constexpr uint8_t pinSize = 64; |
| 2432 | constexpr uint8_t groupSize = 16; |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2433 | constexpr uint8_t groupNum = 5; // 4 for fault memory, 1 for faultFan |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2434 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2435 | // same pin names need to be defined in dts file |
| 2436 | static const std::array<std::array<std::string, groupSize>, groupNum> |
| 2437 | faultLedPinNames = {{ |
| 2438 | "LED_CPU1_CH1_DIMM1_FAULT", |
| 2439 | "LED_CPU1_CH1_DIMM2_FAULT", |
| 2440 | "LED_CPU1_CH2_DIMM1_FAULT", |
| 2441 | "LED_CPU1_CH2_DIMM2_FAULT", |
| 2442 | "LED_CPU1_CH3_DIMM1_FAULT", |
| 2443 | "LED_CPU1_CH3_DIMM2_FAULT", |
| 2444 | "LED_CPU1_CH4_DIMM1_FAULT", |
| 2445 | "LED_CPU1_CH4_DIMM2_FAULT", |
| 2446 | "LED_CPU1_CH5_DIMM1_FAULT", |
| 2447 | "LED_CPU1_CH5_DIMM2_FAULT", |
| 2448 | "LED_CPU1_CH6_DIMM1_FAULT", |
| 2449 | "LED_CPU1_CH6_DIMM2_FAULT", |
| 2450 | "", |
| 2451 | "", |
| 2452 | "", |
| 2453 | "", // end of group1 |
| 2454 | "LED_CPU2_CH1_DIMM1_FAULT", |
| 2455 | "LED_CPU2_CH1_DIMM2_FAULT", |
| 2456 | "LED_CPU2_CH2_DIMM1_FAULT", |
| 2457 | "LED_CPU2_CH2_DIMM2_FAULT", |
| 2458 | "LED_CPU2_CH3_DIMM1_FAULT", |
| 2459 | "LED_CPU2_CH3_DIMM2_FAULT", |
| 2460 | "LED_CPU2_CH4_DIMM1_FAULT", |
| 2461 | "LED_CPU2_CH4_DIMM2_FAULT", |
| 2462 | "LED_CPU2_CH5_DIMM1_FAULT", |
| 2463 | "LED_CPU2_CH5_DIMM2_FAULT", |
| 2464 | "LED_CPU2_CH6_DIMM1_FAULT", |
| 2465 | "LED_CPU2_CH6_DIMM2_FAULT", |
| 2466 | "", |
| 2467 | "", |
| 2468 | "", |
| 2469 | "", // endof group2 |
| 2470 | "LED_CPU3_CH1_DIMM1_FAULT", |
| 2471 | "LED_CPU3_CH1_DIMM2_FAULT", |
| 2472 | "LED_CPU3_CH2_DIMM1_FAULT", |
| 2473 | "LED_CPU3_CH2_DIMM2_FAULT", |
| 2474 | "LED_CPU3_CH3_DIMM1_FAULT", |
| 2475 | "LED_CPU3_CH3_DIMM2_FAULT", |
| 2476 | "LED_CPU3_CH4_DIMM1_FAULT", |
| 2477 | "LED_CPU3_CH4_DIMM2_FAULT", |
| 2478 | "LED_CPU3_CH5_DIMM1_FAULT", |
| 2479 | "LED_CPU3_CH5_DIMM2_FAULT", |
| 2480 | "LED_CPU3_CH6_DIMM1_FAULT", |
| 2481 | "LED_CPU3_CH6_DIMM2_FAULT", |
| 2482 | "", |
| 2483 | "", |
| 2484 | "", |
| 2485 | "", // end of group3 |
| 2486 | "LED_CPU4_CH1_DIMM1_FAULT", |
| 2487 | "LED_CPU4_CH1_DIMM2_FAULT", |
| 2488 | "LED_CPU4_CH2_DIMM1_FAULT", |
| 2489 | "LED_CPU4_CH2_DIMM2_FAULT", |
| 2490 | "LED_CPU4_CH3_DIMM1_FAULT", |
| 2491 | "LED_CPU4_CH3_DIMM2_FAULT", |
| 2492 | "LED_CPU4_CH4_DIMM1_FAULT", |
| 2493 | "LED_CPU4_CH4_DIMM2_FAULT", |
| 2494 | "LED_CPU4_CH5_DIMM1_FAULT", |
| 2495 | "LED_CPU4_CH5_DIMM2_FAULT", |
| 2496 | "LED_CPU4_CH6_DIMM1_FAULT", |
| 2497 | "LED_CPU4_CH6_DIMM2_FAULT", |
| 2498 | "", |
| 2499 | "", |
| 2500 | "", |
| 2501 | "", // end of group4 |
| 2502 | "LED_FAN1_FAULT", |
| 2503 | "LED_FAN2_FAULT", |
| 2504 | "LED_FAN3_FAULT", |
| 2505 | "LED_FAN4_FAULT", |
| 2506 | "LED_FAN5_FAULT", |
| 2507 | "LED_FAN6_FAULT", |
| 2508 | "LED_FAN7_FAULT", |
| 2509 | "LED_FAN8_FAULT", |
| 2510 | "", |
| 2511 | "", |
| 2512 | "", |
| 2513 | "", |
| 2514 | "", |
| 2515 | "", |
| 2516 | "", |
| 2517 | "" // end of group5 |
| 2518 | }}; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2519 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2520 | // Validate the source, fault type -- |
| 2521 | // (Byte 1) sourceId: Unspecified, Hot-Swap Controller 0, Hot-Swap |
| 2522 | // Controller 1, BIOS (Byte 2) fault type: fan, temperature, power, |
| 2523 | // driveslot, software, memory (Byte 3) FaultState: OK, Degraded, |
| 2524 | // Non-Critical, Critical, Non-Recoverable, (Byte 4) is faultGroup, |
| 2525 | // definition differs based on fault type (Byte 2) |
| 2526 | // Type Fan=> Group: 0=FanGroupID, FF-not used |
| 2527 | // Byte 5-11 00h, not used |
| 2528 | // Byte12 FanLedState [7:0]-Fans 7:0 |
| 2529 | // Type Memory=> Group: 0 = DIMM GroupID, FF-not used |
| 2530 | // Byte 5:12 - DIMM LED state (64bit field, LS Byte first) |
| 2531 | // [63:48] = CPU4 channels 7:0, 2 bits per channel |
| 2532 | // [47:32] = CPU3 channels 7:0, 2 bits per channel |
| 2533 | // [31:16] = CPU2 channels 7:0, 2 bits per channel |
| 2534 | // [15:0] = CPU1 channels 7:0, 2 bits per channel |
| 2535 | // Type Other=> Component Fault LED Group ID, not used set to 0xFF |
| 2536 | // Byte[5:12]: reserved 0x00h |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2537 | if ((sourceId >= maxFaultSource) || |
| 2538 | (faultType >= static_cast<int8_t>(RemoteFaultType::max)) || |
| 2539 | (faultState >= static_cast<int8_t>(RemoteFaultState::maxFaultState)) || |
| 2540 | (faultGroup >= static_cast<int8_t>(DimmFaultType::maxFaultGroup))) |
| 2541 | { |
| 2542 | return ipmi::responseParmOutOfRange(); |
| 2543 | } |
| 2544 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2545 | size_t pinGroupOffset = 0; |
| 2546 | size_t pinGroupMax = pinSize / groupSize; |
| 2547 | if (RemoteFaultType::fan == RemoteFaultType(faultType)) |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2548 | { |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2549 | pinGroupOffset = 4; |
| 2550 | pinGroupMax = groupNum - pinSize / groupSize; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | switch (RemoteFaultType(faultType)) |
| 2554 | { |
| 2555 | case (RemoteFaultType::fan): |
| 2556 | case (RemoteFaultType::memory): |
| 2557 | { |
| 2558 | if (faultGroup == skipLEDs) |
| 2559 | { |
| 2560 | return ipmi::responseSuccess(); |
| 2561 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2562 | // calculate led state bit filed count, each byte has 8bits |
| 2563 | // the maximum bits will be 8 * 8 bits |
| 2564 | constexpr uint8_t size = sizeof(ledStateData) * 8; |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2565 | |
| 2566 | // assemble ledState |
| 2567 | uint64_t ledState = 0; |
| 2568 | bool hasError = false; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2569 | for (int i = 0; i < sizeof(ledStateData); i++) |
| 2570 | { |
| 2571 | ledState = (uint64_t)(ledState << 8); |
| 2572 | ledState = (uint64_t)(ledState | (uint64_t)ledStateData[i]); |
| 2573 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2574 | std::bitset<size> ledStateBits(ledState); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2575 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2576 | for (int group = 0; group < pinGroupMax; group++) |
| 2577 | { |
| 2578 | for (int i = 0; i < groupSize; i++) |
| 2579 | { // skip non-existing pins |
| 2580 | if (0 == faultLedPinNames[group + pinGroupOffset][i].size()) |
| 2581 | { |
| 2582 | continue; |
| 2583 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2584 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2585 | gpiod::line line = gpiod::find_line( |
| 2586 | faultLedPinNames[group + pinGroupOffset][i]); |
| 2587 | if (!line) |
| 2588 | { |
| 2589 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2590 | "Not Find Led Gpio Device!", |
| 2591 | phosphor::logging::entry( |
| 2592 | "DEVICE=%s", |
| 2593 | faultLedPinNames[group + pinGroupOffset][i] |
| 2594 | .c_str())); |
| 2595 | hasError = true; |
| 2596 | continue; |
| 2597 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2598 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2599 | bool activeHigh = |
| 2600 | (line.active_state() == gpiod::line::ACTIVE_HIGH); |
| 2601 | try |
| 2602 | { |
| 2603 | line.request( |
| 2604 | {"faultLed", gpiod::line_request::DIRECTION_OUTPUT, |
| 2605 | activeHigh |
| 2606 | ? 0 |
| 2607 | : gpiod::line_request::FLAG_ACTIVE_LOW}); |
| 2608 | line.set_value(ledStateBits[i + group * groupSize]); |
| 2609 | } |
| 2610 | catch (std::system_error&) |
| 2611 | { |
| 2612 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2613 | "Error write Led Gpio Device!", |
| 2614 | phosphor::logging::entry( |
| 2615 | "DEVICE=%s", |
| 2616 | faultLedPinNames[group + pinGroupOffset][i] |
| 2617 | .c_str())); |
| 2618 | hasError = true; |
| 2619 | continue; |
| 2620 | } |
| 2621 | } // for int i |
| 2622 | } |
| 2623 | if (hasError) |
| 2624 | { |
| 2625 | return ipmi::responseResponseError(); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2626 | } |
| 2627 | break; |
| 2628 | } |
| 2629 | default: |
| 2630 | { |
| 2631 | // now only support two fault types |
| 2632 | return ipmi::responseParmOutOfRange(); |
| 2633 | } |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2634 | } // switch |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2635 | return ipmi::responseSuccess(); |
| 2636 | } |
| 2637 | |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2638 | ipmi::RspType<uint8_t> ipmiOEMReadBoardProductId() |
| 2639 | { |
| 2640 | uint8_t prodId = 0; |
| 2641 | try |
| 2642 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2643 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2644 | const DbusObjectInfo& object = getDbusObject( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2645 | *dbus, "xyz.openbmc_project.Inventory.Item.Board", |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2646 | "/xyz/openbmc_project/inventory/system/board/", "Baseboard"); |
| 2647 | const Value& propValue = getDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2648 | *dbus, object.second, object.first, |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2649 | "xyz.openbmc_project.Inventory.Item.Board", "ProductId"); |
| 2650 | prodId = static_cast<uint8_t>(std::get<uint64_t>(propValue)); |
| 2651 | } |
| 2652 | catch (std::exception& e) |
| 2653 | { |
| 2654 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2655 | "ipmiOEMReadBoardProductId: Product ID read failed!", |
| 2656 | phosphor::logging::entry("ERR=%s", e.what())); |
| 2657 | } |
| 2658 | return ipmi::responseSuccess(prodId); |
| 2659 | } |
| 2660 | |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2661 | /** @brief implements the get security mode command |
| 2662 | * @param ctx - ctx pointer |
| 2663 | * |
| 2664 | * @returns IPMI completion code with following data |
| 2665 | * - restriction mode value - As specified in |
| 2666 | * xyz.openbmc_project.Control.Security.RestrictionMode.interface.yaml |
| 2667 | * - special mode value - As specified in |
| 2668 | * xyz.openbmc_project.Control.Security.SpecialMode.interface.yaml |
| 2669 | */ |
| 2670 | ipmi::RspType<uint8_t, uint8_t> ipmiGetSecurityMode(ipmi::Context::ptr ctx) |
| 2671 | { |
| 2672 | namespace securityNameSpace = |
| 2673 | sdbusplus::xyz::openbmc_project::Control::Security::server; |
| 2674 | uint8_t restrictionModeValue = 0; |
| 2675 | uint8_t specialModeValue = 0; |
| 2676 | |
| 2677 | boost::system::error_code ec; |
| 2678 | auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2679 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2680 | dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf, |
| 2681 | restricionModeProperty); |
| 2682 | if (ec) |
| 2683 | { |
| 2684 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2685 | "ipmiGetSecurityMode: failed to get RestrictionMode property", |
| 2686 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2687 | return ipmi::responseUnspecifiedError(); |
| 2688 | } |
| 2689 | restrictionModeValue = static_cast<uint8_t>( |
| 2690 | securityNameSpace::RestrictionMode::convertModesFromString( |
| 2691 | std::get<std::string>(varRestrMode))); |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 2692 | auto varSpecialMode = |
| 2693 | ctx->bus->yield_method_call<std::variant<std::string>>( |
| 2694 | ctx->yield, ec, specialModeService, specialModeBasePath, |
| 2695 | dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf, |
| 2696 | specialModeProperty); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2697 | if (ec) |
| 2698 | { |
| 2699 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2700 | "ipmiGetSecurityMode: failed to get SpecialMode property", |
| 2701 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2702 | // fall through, let us not worry about SpecialMode property, which is |
| 2703 | // not required in user scenario |
| 2704 | } |
| 2705 | else |
| 2706 | { |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 2707 | specialModeValue = static_cast<uint8_t>( |
| 2708 | securityNameSpace::SpecialMode::convertModesFromString( |
| 2709 | std::get<std::string>(varSpecialMode))); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2710 | } |
| 2711 | return ipmi::responseSuccess(restrictionModeValue, specialModeValue); |
| 2712 | } |
| 2713 | |
| 2714 | /** @brief implements the set security mode command |
| 2715 | * Command allows to upgrade the restriction mode and won't allow |
| 2716 | * to downgrade from system interface |
| 2717 | * @param ctx - ctx pointer |
| 2718 | * @param restrictionMode - restriction mode value to be set. |
| 2719 | * |
| 2720 | * @returns IPMI completion code |
| 2721 | */ |
| 2722 | ipmi::RspType<> ipmiSetSecurityMode(ipmi::Context::ptr ctx, |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2723 | uint8_t restrictionMode, |
| 2724 | std::optional<uint8_t> specialMode) |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2725 | { |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2726 | #ifndef BMC_VALIDATION_UNSECURE_FEATURE |
| 2727 | if (specialMode) |
| 2728 | { |
| 2729 | return ipmi::responseReqDataLenInvalid(); |
| 2730 | } |
| 2731 | #endif |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2732 | namespace securityNameSpace = |
| 2733 | sdbusplus::xyz::openbmc_project::Control::Security::server; |
| 2734 | |
| 2735 | ChannelInfo chInfo; |
| 2736 | if (getChannelInfo(ctx->channel, chInfo) != ccSuccess) |
| 2737 | { |
| 2738 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2739 | "ipmiSetSecurityMode: Failed to get Channel Info", |
| 2740 | phosphor::logging::entry("CHANNEL=%d", ctx->channel)); |
| 2741 | return ipmi::responseUnspecifiedError(); |
| 2742 | } |
| 2743 | auto reqMode = |
| 2744 | static_cast<securityNameSpace::RestrictionMode::Modes>(restrictionMode); |
| 2745 | |
| 2746 | if ((reqMode < securityNameSpace::RestrictionMode::Modes::Provisioning) || |
| 2747 | (reqMode > |
| 2748 | securityNameSpace::RestrictionMode::Modes::ProvisionedHostDisabled)) |
| 2749 | { |
| 2750 | return ipmi::responseInvalidFieldRequest(); |
| 2751 | } |
| 2752 | |
| 2753 | boost::system::error_code ec; |
| 2754 | auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2755 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2756 | dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf, |
| 2757 | restricionModeProperty); |
| 2758 | if (ec) |
| 2759 | { |
| 2760 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2761 | "ipmiSetSecurityMode: failed to get RestrictionMode property", |
| 2762 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2763 | return ipmi::responseUnspecifiedError(); |
| 2764 | } |
| 2765 | auto currentRestrictionMode = |
| 2766 | securityNameSpace::RestrictionMode::convertModesFromString( |
| 2767 | std::get<std::string>(varRestrMode)); |
| 2768 | |
| 2769 | if (chInfo.mediumType != |
| 2770 | static_cast<uint8_t>(EChannelMediumType::lan8032) && |
| 2771 | currentRestrictionMode > reqMode) |
| 2772 | { |
| 2773 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2774 | "ipmiSetSecurityMode - Downgrading security mode not supported " |
| 2775 | "through system interface", |
| 2776 | phosphor::logging::entry( |
| 2777 | "CUR_MODE=%d", static_cast<uint8_t>(currentRestrictionMode)), |
| 2778 | phosphor::logging::entry("REQ_MODE=%d", restrictionMode)); |
| 2779 | return ipmi::responseCommandNotAvailable(); |
| 2780 | } |
| 2781 | |
| 2782 | ec.clear(); |
| 2783 | ctx->bus->yield_method_call<>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2784 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2785 | dBusPropertyIntf, dBusPropertySetMethod, restricionModeIntf, |
| 2786 | restricionModeProperty, |
| 2787 | static_cast<std::variant<std::string>>( |
| 2788 | securityNameSpace::convertForMessage(reqMode))); |
| 2789 | |
| 2790 | if (ec) |
| 2791 | { |
| 2792 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2793 | "ipmiSetSecurityMode: failed to set RestrictionMode property", |
| 2794 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2795 | return ipmi::responseUnspecifiedError(); |
| 2796 | } |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2797 | |
| 2798 | #ifdef BMC_VALIDATION_UNSECURE_FEATURE |
| 2799 | if (specialMode) |
| 2800 | { |
| 2801 | ec.clear(); |
| 2802 | ctx->bus->yield_method_call<>( |
| 2803 | ctx->yield, ec, specialModeService, specialModeBasePath, |
| 2804 | dBusPropertyIntf, dBusPropertySetMethod, specialModeIntf, |
| 2805 | specialModeProperty, |
| 2806 | static_cast<std::variant<std::string>>( |
| 2807 | securityNameSpace::convertForMessage( |
| 2808 | static_cast<securityNameSpace::SpecialMode::Modes>( |
| 2809 | specialMode.value())))); |
| 2810 | |
| 2811 | if (ec) |
| 2812 | { |
| 2813 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2814 | "ipmiSetSecurityMode: failed to set SpecialMode property", |
| 2815 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2816 | return ipmi::responseUnspecifiedError(); |
| 2817 | } |
| 2818 | } |
| 2819 | #endif |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2820 | return ipmi::responseSuccess(); |
| 2821 | } |
| 2822 | |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 2823 | ipmi::RspType<uint8_t /* restore status */> |
| 2824 | ipmiRestoreConfiguration(const std::array<uint8_t, 3>& clr, uint8_t cmd) |
| 2825 | { |
| 2826 | static constexpr std::array<uint8_t, 3> expClr = {'C', 'L', 'R'}; |
| 2827 | |
| 2828 | if (clr != expClr) |
| 2829 | { |
| 2830 | return ipmi::responseInvalidFieldRequest(); |
| 2831 | } |
| 2832 | constexpr uint8_t cmdStatus = 0; |
| 2833 | constexpr uint8_t cmdDefaultRestore = 0xaa; |
| 2834 | constexpr uint8_t cmdFullRestore = 0xbb; |
| 2835 | constexpr uint8_t cmdFormat = 0xcc; |
| 2836 | |
| 2837 | constexpr const char* restoreOpFname = "/tmp/.rwfs/.restore_op"; |
| 2838 | |
| 2839 | switch (cmd) |
| 2840 | { |
| 2841 | case cmdStatus: |
| 2842 | break; |
| 2843 | case cmdDefaultRestore: |
| 2844 | case cmdFullRestore: |
| 2845 | case cmdFormat: |
| 2846 | { |
| 2847 | // write file to rwfs root |
| 2848 | int value = (cmd - 1) & 0x03; // map aa, bb, cc => 1, 2, 3 |
| 2849 | std::ofstream restoreFile(restoreOpFname); |
| 2850 | if (!restoreFile) |
| 2851 | { |
| 2852 | return ipmi::responseUnspecifiedError(); |
| 2853 | } |
| 2854 | restoreFile << value << "\n"; |
| 2855 | break; |
| 2856 | } |
| 2857 | default: |
| 2858 | return ipmi::responseInvalidFieldRequest(); |
| 2859 | } |
| 2860 | |
| 2861 | constexpr uint8_t restorePending = 0; |
| 2862 | constexpr uint8_t restoreComplete = 1; |
| 2863 | |
| 2864 | uint8_t restoreStatus = std::filesystem::exists(restoreOpFname) |
| 2865 | ? restorePending |
| 2866 | : restoreComplete; |
| 2867 | return ipmi::responseSuccess(restoreStatus); |
| 2868 | } |
| 2869 | |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2870 | ipmi::RspType<uint8_t> ipmiOEMGetNmiSource(void) |
| 2871 | { |
| 2872 | uint8_t bmcSource; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2873 | namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2874 | |
| 2875 | try |
| 2876 | { |
| 2877 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 2878 | std::string service = |
| 2879 | getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath); |
| 2880 | Value variant = |
| 2881 | getDbusProperty(*dbus, service, oemNmiSourceObjPath, |
| 2882 | oemNmiSourceIntf, oemNmiBmcSourceObjPathProp); |
| 2883 | |
| 2884 | switch (nmi::NMISource::convertBMCSourceSignalFromString( |
| 2885 | std::get<std::string>(variant))) |
| 2886 | { |
| 2887 | case nmi::NMISource::BMCSourceSignal::None: |
| 2888 | bmcSource = static_cast<uint8_t>(NmiSource::none); |
| 2889 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2890 | case nmi::NMISource::BMCSourceSignal::FrontPanelButton: |
| 2891 | bmcSource = static_cast<uint8_t>(NmiSource::frontPanelButton); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2892 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2893 | case nmi::NMISource::BMCSourceSignal::Watchdog: |
| 2894 | bmcSource = static_cast<uint8_t>(NmiSource::watchdog); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2895 | break; |
| 2896 | case nmi::NMISource::BMCSourceSignal::ChassisCmd: |
| 2897 | bmcSource = static_cast<uint8_t>(NmiSource::chassisCmd); |
| 2898 | break; |
| 2899 | case nmi::NMISource::BMCSourceSignal::MemoryError: |
| 2900 | bmcSource = static_cast<uint8_t>(NmiSource::memoryError); |
| 2901 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2902 | case nmi::NMISource::BMCSourceSignal::PciBusError: |
| 2903 | bmcSource = static_cast<uint8_t>(NmiSource::pciBusError); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2904 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2905 | case nmi::NMISource::BMCSourceSignal::PCH: |
| 2906 | bmcSource = static_cast<uint8_t>(NmiSource::pch); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2907 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2908 | case nmi::NMISource::BMCSourceSignal::Chipset: |
| 2909 | bmcSource = static_cast<uint8_t>(NmiSource::chipset); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2910 | break; |
| 2911 | default: |
| 2912 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2913 | "NMI source: invalid property!", |
| 2914 | phosphor::logging::entry( |
| 2915 | "PROP=%s", std::get<std::string>(variant).c_str())); |
| 2916 | return ipmi::responseResponseError(); |
| 2917 | } |
| 2918 | } |
| 2919 | catch (sdbusplus::exception::SdBusError& e) |
| 2920 | { |
| 2921 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 2922 | return ipmi::responseResponseError(); |
| 2923 | } |
| 2924 | |
| 2925 | return ipmi::responseSuccess(bmcSource); |
| 2926 | } |
| 2927 | |
| 2928 | ipmi::RspType<> ipmiOEMSetNmiSource(uint8_t sourceId) |
| 2929 | { |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2930 | namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2931 | |
| 2932 | nmi::NMISource::BMCSourceSignal bmcSourceSignal = |
| 2933 | nmi::NMISource::BMCSourceSignal::None; |
| 2934 | |
| 2935 | switch (NmiSource(sourceId)) |
| 2936 | { |
| 2937 | case NmiSource::none: |
| 2938 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::None; |
| 2939 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2940 | case NmiSource::frontPanelButton: |
| 2941 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::FrontPanelButton; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2942 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2943 | case NmiSource::watchdog: |
| 2944 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Watchdog; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2945 | break; |
| 2946 | case NmiSource::chassisCmd: |
| 2947 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChassisCmd; |
| 2948 | break; |
| 2949 | case NmiSource::memoryError: |
| 2950 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::MemoryError; |
| 2951 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2952 | case NmiSource::pciBusError: |
| 2953 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PciBusError; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2954 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2955 | case NmiSource::pch: |
| 2956 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PCH; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2957 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2958 | case NmiSource::chipset: |
| 2959 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Chipset; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2960 | break; |
| 2961 | default: |
| 2962 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2963 | "NMI source: invalid property!"); |
| 2964 | return ipmi::responseResponseError(); |
| 2965 | } |
| 2966 | |
| 2967 | try |
| 2968 | { |
| 2969 | // keep NMI signal source |
| 2970 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 2971 | std::string service = |
| 2972 | getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath); |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2973 | setDbusProperty(*dbus, service, oemNmiSourceObjPath, oemNmiSourceIntf, |
| 2974 | oemNmiBmcSourceObjPathProp, |
| 2975 | nmi::convertForMessage(bmcSourceSignal)); |
Chen Yugang | 99be633 | 2019-08-09 16:20:48 +0800 | [diff] [blame] | 2976 | // set Enabled property to inform NMI source handling |
| 2977 | // to trigger a NMI_OUT BSOD. |
| 2978 | // if it's triggered by NMI source property changed, |
| 2979 | // NMI_OUT BSOD could be missed if the same source occurs twice in a row |
| 2980 | if (bmcSourceSignal != nmi::NMISource::BMCSourceSignal::None) |
| 2981 | { |
| 2982 | setDbusProperty(*dbus, service, oemNmiSourceObjPath, |
| 2983 | oemNmiSourceIntf, oemNmiEnabledObjPathProp, |
| 2984 | static_cast<bool>(true)); |
| 2985 | } |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2986 | } |
| 2987 | catch (sdbusplus::exception_t& e) |
| 2988 | { |
| 2989 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 2990 | return ipmi::responseResponseError(); |
| 2991 | } |
| 2992 | |
| 2993 | return ipmi::responseSuccess(); |
| 2994 | } |
| 2995 | |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 2996 | namespace dimmOffset |
| 2997 | { |
| 2998 | constexpr const char* dimmPower = "DimmPower"; |
| 2999 | constexpr const char* staticCltt = "StaticCltt"; |
| 3000 | constexpr const char* offsetPath = "/xyz/openbmc_project/Inventory/Item/Dimm"; |
| 3001 | constexpr const char* offsetInterface = |
| 3002 | "xyz.openbmc_project.Inventory.Item.Dimm.Offset"; |
| 3003 | constexpr const char* property = "DimmOffset"; |
| 3004 | |
| 3005 | }; // namespace dimmOffset |
| 3006 | |
| 3007 | ipmi::RspType<> |
| 3008 | ipmiOEMSetDimmOffset(uint8_t type, |
| 3009 | const std::vector<std::tuple<uint8_t, uint8_t>>& data) |
| 3010 | { |
| 3011 | if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) && |
| 3012 | type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3013 | { |
| 3014 | return ipmi::responseInvalidFieldRequest(); |
| 3015 | } |
| 3016 | |
| 3017 | if (data.empty()) |
| 3018 | { |
| 3019 | return ipmi::responseInvalidFieldRequest(); |
| 3020 | } |
| 3021 | nlohmann::json json; |
| 3022 | |
| 3023 | std::ifstream jsonStream(dimmOffsetFile); |
| 3024 | if (jsonStream.good()) |
| 3025 | { |
| 3026 | json = nlohmann::json::parse(jsonStream, nullptr, false); |
| 3027 | if (json.is_discarded()) |
| 3028 | { |
| 3029 | json = nlohmann::json(); |
| 3030 | } |
| 3031 | jsonStream.close(); |
| 3032 | } |
| 3033 | |
| 3034 | std::string typeName; |
| 3035 | if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower)) |
| 3036 | { |
| 3037 | typeName = dimmOffset::dimmPower; |
| 3038 | } |
| 3039 | else |
| 3040 | { |
| 3041 | typeName = dimmOffset::staticCltt; |
| 3042 | } |
| 3043 | |
| 3044 | nlohmann::json& field = json[typeName]; |
| 3045 | |
| 3046 | for (const auto& [index, value] : data) |
| 3047 | { |
| 3048 | field[index] = value; |
| 3049 | } |
| 3050 | |
| 3051 | for (nlohmann::json& val : field) |
| 3052 | { |
| 3053 | if (val == nullptr) |
| 3054 | { |
| 3055 | val = static_cast<uint8_t>(0); |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | std::ofstream output(dimmOffsetFile); |
| 3060 | if (!output.good()) |
| 3061 | { |
| 3062 | std::cerr << "Error writing json file\n"; |
| 3063 | return ipmi::responseResponseError(); |
| 3064 | } |
| 3065 | |
| 3066 | output << json.dump(4); |
| 3067 | |
| 3068 | if (type == static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3069 | { |
| 3070 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 3071 | |
| 3072 | std::variant<std::vector<uint8_t>> offsets = |
| 3073 | field.get<std::vector<uint8_t>>(); |
| 3074 | auto call = bus->new_method_call( |
| 3075 | settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set"); |
| 3076 | call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets); |
| 3077 | try |
| 3078 | { |
| 3079 | bus->call(call); |
| 3080 | } |
| 3081 | catch (sdbusplus::exception_t& e) |
| 3082 | { |
| 3083 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3084 | "ipmiOEMSetDimmOffset: can't set dimm offsets!", |
| 3085 | phosphor::logging::entry("ERR=%s", e.what())); |
| 3086 | return ipmi::responseResponseError(); |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | return ipmi::responseSuccess(); |
| 3091 | } |
| 3092 | |
| 3093 | ipmi::RspType<uint8_t> ipmiOEMGetDimmOffset(uint8_t type, uint8_t index) |
| 3094 | { |
| 3095 | |
| 3096 | if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) && |
| 3097 | type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3098 | { |
| 3099 | return ipmi::responseInvalidFieldRequest(); |
| 3100 | } |
| 3101 | |
| 3102 | std::ifstream jsonStream(dimmOffsetFile); |
| 3103 | |
| 3104 | auto json = nlohmann::json::parse(jsonStream, nullptr, false); |
| 3105 | if (json.is_discarded()) |
| 3106 | { |
| 3107 | std::cerr << "File error in " << dimmOffsetFile << "\n"; |
| 3108 | return ipmi::responseResponseError(); |
| 3109 | } |
| 3110 | |
| 3111 | std::string typeName; |
| 3112 | if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower)) |
| 3113 | { |
| 3114 | typeName = dimmOffset::dimmPower; |
| 3115 | } |
| 3116 | else |
| 3117 | { |
| 3118 | typeName = dimmOffset::staticCltt; |
| 3119 | } |
| 3120 | |
| 3121 | auto it = json.find(typeName); |
| 3122 | if (it == json.end()) |
| 3123 | { |
| 3124 | return ipmi::responseInvalidFieldRequest(); |
| 3125 | } |
| 3126 | |
| 3127 | if (it->size() <= index) |
| 3128 | { |
| 3129 | return ipmi::responseInvalidFieldRequest(); |
| 3130 | } |
| 3131 | |
| 3132 | uint8_t resp = it->at(index).get<uint8_t>(); |
| 3133 | return ipmi::responseSuccess(resp); |
| 3134 | } |
| 3135 | |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3136 | namespace boot_options |
| 3137 | { |
| 3138 | |
| 3139 | using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server; |
| 3140 | using IpmiValue = uint8_t; |
| 3141 | constexpr auto ipmiDefault = 0; |
| 3142 | |
| 3143 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
| 3144 | {0x01, Source::Sources::Network}, |
| 3145 | {0x02, Source::Sources::Disk}, |
| 3146 | {0x05, Source::Sources::ExternalMedia}, |
| 3147 | {0x0f, Source::Sources::RemovableMedia}, |
| 3148 | {ipmiDefault, Source::Sources::Default}}; |
| 3149 | |
| 3150 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3151 | {0x06, Mode::Modes::Setup}, {ipmiDefault, Mode::Modes::Regular}}; |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3152 | |
| 3153 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
| 3154 | {Source::Sources::Network, 0x01}, |
| 3155 | {Source::Sources::Disk, 0x02}, |
| 3156 | {Source::Sources::ExternalMedia, 0x05}, |
| 3157 | {Source::Sources::RemovableMedia, 0x0f}, |
| 3158 | {Source::Sources::Default, ipmiDefault}}; |
| 3159 | |
| 3160 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3161 | {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, ipmiDefault}}; |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3162 | |
| 3163 | static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; |
| 3164 | static constexpr auto bootSourceIntf = |
| 3165 | "xyz.openbmc_project.Control.Boot.Source"; |
| 3166 | static constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable"; |
| 3167 | static constexpr auto persistentObjPath = |
| 3168 | "/xyz/openbmc_project/control/host0/boot"; |
| 3169 | static constexpr auto oneTimePath = |
| 3170 | "/xyz/openbmc_project/control/host0/boot/one_time"; |
| 3171 | static constexpr auto bootSourceProp = "BootSource"; |
| 3172 | static constexpr auto bootModeProp = "BootMode"; |
| 3173 | static constexpr auto oneTimeBootEnableProp = "Enabled"; |
| 3174 | static constexpr auto httpBootMode = |
| 3175 | "xyz.openbmc_project.Control.Boot.Source.Sources.Http"; |
| 3176 | |
| 3177 | enum class BootOptionParameter : size_t |
| 3178 | { |
| 3179 | setInProgress = 0x0, |
| 3180 | bootFlags = 0x5, |
| 3181 | }; |
| 3182 | static constexpr uint8_t setComplete = 0x0; |
| 3183 | static constexpr uint8_t setInProgress = 0x1; |
| 3184 | static uint8_t transferStatus = setComplete; |
| 3185 | static constexpr uint8_t setParmVersion = 0x01; |
| 3186 | static constexpr uint8_t setParmBootFlagsPermanent = 0x40; |
| 3187 | static constexpr uint8_t setParmBootFlagsValidOneTime = 0x80; |
| 3188 | static constexpr uint8_t setParmBootFlagsValidPermanent = 0xC0; |
| 3189 | static constexpr uint8_t httpBoot = 0xd; |
| 3190 | static constexpr uint8_t bootSourceMask = 0x3c; |
| 3191 | |
| 3192 | } // namespace boot_options |
| 3193 | |
| 3194 | ipmi::RspType<uint8_t, // version |
| 3195 | uint8_t, // param |
| 3196 | uint8_t, // data0, dependent on parameter |
| 3197 | std::optional<uint8_t> // data1, dependent on parameter |
| 3198 | > |
| 3199 | ipmiOemGetEfiBootOptions(uint8_t parameter, uint8_t set, uint8_t block) |
| 3200 | { |
| 3201 | using namespace boot_options; |
| 3202 | uint8_t bootOption = 0; |
| 3203 | |
| 3204 | if (parameter == static_cast<uint8_t>(BootOptionParameter::setInProgress)) |
| 3205 | { |
| 3206 | return ipmi::responseSuccess(setParmVersion, parameter, transferStatus, |
| 3207 | std::nullopt); |
| 3208 | } |
| 3209 | |
| 3210 | if (parameter != static_cast<uint8_t>(BootOptionParameter::bootFlags)) |
| 3211 | { |
| 3212 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3213 | "Unsupported parameter"); |
| 3214 | return ipmi::responseResponseError(); |
| 3215 | } |
| 3216 | |
| 3217 | try |
| 3218 | { |
| 3219 | auto oneTimeEnabled = false; |
| 3220 | // read one time Enabled property |
| 3221 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3222 | std::string service = getService(*dbus, enabledIntf, oneTimePath); |
| 3223 | Value variant = getDbusProperty(*dbus, service, oneTimePath, |
| 3224 | enabledIntf, oneTimeBootEnableProp); |
| 3225 | oneTimeEnabled = std::get<bool>(variant); |
| 3226 | |
| 3227 | // get BootSource and BootMode properties |
| 3228 | // according to oneTimeEnable |
| 3229 | auto bootObjPath = oneTimePath; |
| 3230 | if (oneTimeEnabled == false) |
| 3231 | { |
| 3232 | bootObjPath = persistentObjPath; |
| 3233 | } |
| 3234 | |
| 3235 | service = getService(*dbus, bootModeIntf, bootObjPath); |
| 3236 | variant = getDbusProperty(*dbus, service, bootObjPath, bootModeIntf, |
| 3237 | bootModeProp); |
| 3238 | |
| 3239 | auto bootMode = |
| 3240 | Mode::convertModesFromString(std::get<std::string>(variant)); |
| 3241 | |
| 3242 | service = getService(*dbus, bootSourceIntf, bootObjPath); |
| 3243 | variant = getDbusProperty(*dbus, service, bootObjPath, bootSourceIntf, |
| 3244 | bootSourceProp); |
| 3245 | |
| 3246 | if (std::get<std::string>(variant) == httpBootMode) |
| 3247 | { |
| 3248 | bootOption = httpBoot; |
| 3249 | } |
| 3250 | else |
| 3251 | { |
| 3252 | auto bootSource = Source::convertSourcesFromString( |
| 3253 | std::get<std::string>(variant)); |
| 3254 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 3255 | if (Source::Sources::Default == bootSource) |
| 3256 | { |
| 3257 | bootOption = modeDbusToIpmi.at(bootMode); |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | uint8_t oneTime = oneTimeEnabled ? setParmBootFlagsValidOneTime |
| 3262 | : setParmBootFlagsValidPermanent; |
| 3263 | bootOption <<= 2; // shift for responseconstexpr |
| 3264 | return ipmi::responseSuccess(setParmVersion, parameter, oneTime, |
| 3265 | bootOption); |
| 3266 | } |
| 3267 | catch (sdbusplus::exception_t& e) |
| 3268 | { |
| 3269 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3270 | return ipmi::responseResponseError(); |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | ipmi::RspType<> ipmiOemSetEfiBootOptions(uint8_t bootFlag, uint8_t bootParam, |
| 3275 | std::optional<uint8_t> bootOption) |
| 3276 | { |
| 3277 | using namespace boot_options; |
| 3278 | auto oneTimeEnabled = false; |
| 3279 | |
| 3280 | if (bootFlag == static_cast<uint8_t>(BootOptionParameter::setInProgress)) |
| 3281 | { |
| 3282 | if (bootOption) |
| 3283 | { |
| 3284 | return ipmi::responseReqDataLenInvalid(); |
| 3285 | } |
| 3286 | |
| 3287 | if (transferStatus == setInProgress) |
| 3288 | { |
| 3289 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3290 | "boot option set in progress!"); |
| 3291 | return ipmi::responseResponseError(); |
| 3292 | } |
| 3293 | |
| 3294 | transferStatus = bootParam; |
| 3295 | return ipmi::responseSuccess(); |
| 3296 | } |
| 3297 | |
| 3298 | if (bootFlag != (uint8_t)BootOptionParameter::bootFlags) |
| 3299 | { |
| 3300 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3301 | "Unsupported parameter"); |
| 3302 | return ipmi::responseResponseError(); |
| 3303 | } |
| 3304 | |
| 3305 | if (!bootOption) |
| 3306 | { |
| 3307 | return ipmi::responseReqDataLenInvalid(); |
| 3308 | } |
| 3309 | |
| 3310 | if (((bootOption.value() & bootSourceMask) >> 2) != |
| 3311 | httpBoot) // not http boot, exit |
| 3312 | { |
| 3313 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3314 | "wrong boot option parameter!"); |
| 3315 | return ipmi::responseParmOutOfRange(); |
| 3316 | } |
| 3317 | |
| 3318 | try |
| 3319 | { |
| 3320 | bool permanent = (bootParam & setParmBootFlagsPermanent) == |
| 3321 | setParmBootFlagsPermanent; |
| 3322 | |
| 3323 | // read one time Enabled property |
| 3324 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3325 | std::string service = getService(*dbus, enabledIntf, oneTimePath); |
| 3326 | Value variant = getDbusProperty(*dbus, service, oneTimePath, |
| 3327 | enabledIntf, oneTimeBootEnableProp); |
| 3328 | oneTimeEnabled = std::get<bool>(variant); |
| 3329 | |
| 3330 | /* |
| 3331 | * Check if the current boot setting is onetime or permanent, if the |
| 3332 | * request in the command is otherwise, then set the "Enabled" |
| 3333 | * property in one_time object path to 'True' to indicate onetime |
| 3334 | * and 'False' to indicate permanent. |
| 3335 | * |
| 3336 | * Once the onetime/permanent setting is applied, then the bootMode |
| 3337 | * and bootSource is updated for the corresponding object. |
| 3338 | */ |
| 3339 | if (permanent == oneTimeEnabled) |
| 3340 | { |
| 3341 | setDbusProperty(*dbus, service, oneTimePath, enabledIntf, |
| 3342 | oneTimeBootEnableProp, !permanent); |
| 3343 | } |
| 3344 | |
| 3345 | // set BootSource and BootMode properties |
| 3346 | // according to oneTimeEnable or persistent |
| 3347 | auto bootObjPath = oneTimePath; |
| 3348 | if (oneTimeEnabled == false) |
| 3349 | { |
| 3350 | bootObjPath = persistentObjPath; |
| 3351 | } |
| 3352 | std::string bootMode = |
| 3353 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; |
| 3354 | std::string bootSource = httpBootMode; |
| 3355 | |
| 3356 | service = getService(*dbus, bootModeIntf, bootObjPath); |
| 3357 | setDbusProperty(*dbus, service, bootObjPath, bootModeIntf, bootModeProp, |
| 3358 | bootMode); |
| 3359 | |
| 3360 | service = getService(*dbus, bootSourceIntf, bootObjPath); |
| 3361 | setDbusProperty(*dbus, service, bootObjPath, bootSourceIntf, |
| 3362 | bootSourceProp, bootSource); |
| 3363 | } |
| 3364 | catch (sdbusplus::exception_t& e) |
| 3365 | { |
| 3366 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3367 | return ipmi::responseResponseError(); |
| 3368 | } |
| 3369 | |
| 3370 | return ipmi::responseSuccess(); |
| 3371 | } |
| 3372 | |
Cheng C Yang | 4e6ee15 | 2019-09-25 10:27:44 +0800 | [diff] [blame] | 3373 | using BasicVariantType = |
| 3374 | std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string, |
| 3375 | int64_t, uint64_t, double, int32_t, uint32_t, int16_t, |
| 3376 | uint16_t, uint8_t, bool>; |
| 3377 | using PropertyMapType = |
| 3378 | boost::container::flat_map<std::string, BasicVariantType>; |
| 3379 | static constexpr const std::array<const char*, 1> psuPresenceTypes = { |
| 3380 | "xyz.openbmc_project.Configuration.PSUPresence"}; |
| 3381 | int getPSUAddress(ipmi::Context::ptr ctx, uint8_t& bus, |
| 3382 | std::vector<uint64_t>& addrTable) |
| 3383 | { |
| 3384 | boost::system::error_code ec; |
| 3385 | GetSubTreeType subtree = ctx->bus->yield_method_call<GetSubTreeType>( |
| 3386 | ctx->yield, ec, "xyz.openbmc_project.ObjectMapper", |
| 3387 | "/xyz/openbmc_project/object_mapper", |
| 3388 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 3389 | "/xyz/openbmc_project/inventory/system", 3, psuPresenceTypes); |
| 3390 | if (ec) |
| 3391 | { |
| 3392 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3393 | "Failed to set dbus property to cold redundancy"); |
| 3394 | return -1; |
| 3395 | } |
| 3396 | for (const auto& object : subtree) |
| 3397 | { |
| 3398 | std::string pathName = object.first; |
| 3399 | for (const auto& serviceIface : object.second) |
| 3400 | { |
| 3401 | std::string serviceName = serviceIface.first; |
| 3402 | |
| 3403 | ec.clear(); |
| 3404 | PropertyMapType propMap = |
| 3405 | ctx->bus->yield_method_call<PropertyMapType>( |
| 3406 | ctx->yield, ec, serviceName, pathName, |
| 3407 | "org.freedesktop.DBus.Properties", "GetAll", |
| 3408 | "xyz.openbmc_project.Configuration.PSUPresence"); |
| 3409 | if (ec) |
| 3410 | { |
| 3411 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3412 | "Failed to set dbus property to cold redundancy"); |
| 3413 | return -1; |
| 3414 | } |
| 3415 | auto psuBus = std::get_if<uint64_t>(&propMap["Bus"]); |
| 3416 | auto psuAddress = |
| 3417 | std::get_if<std::vector<uint64_t>>(&propMap["Address"]); |
| 3418 | |
| 3419 | if (psuBus == nullptr || psuAddress == nullptr) |
| 3420 | { |
| 3421 | std::cerr << "error finding necessary " |
| 3422 | "entry in configuration\n"; |
| 3423 | return -1; |
| 3424 | } |
| 3425 | bus = static_cast<uint8_t>(*psuBus); |
| 3426 | addrTable = *psuAddress; |
| 3427 | return 0; |
| 3428 | } |
| 3429 | } |
| 3430 | return -1; |
| 3431 | } |
| 3432 | |
| 3433 | static const constexpr uint8_t addrOffset = 8; |
| 3434 | static const constexpr uint8_t psuRevision = 0xd9; |
| 3435 | static const constexpr uint8_t defaultPSUBus = 7; |
| 3436 | // Second Minor, Primary Minor, Major |
| 3437 | static const constexpr size_t verLen = 3; |
| 3438 | ipmi::RspType<std::vector<uint8_t>> ipmiOEMGetPSUVersion(ipmi::Context::ptr ctx) |
| 3439 | { |
| 3440 | uint8_t bus = defaultPSUBus; |
| 3441 | std::vector<uint64_t> addrTable; |
| 3442 | std::vector<uint8_t> result; |
| 3443 | if (getPSUAddress(ctx, bus, addrTable)) |
| 3444 | { |
| 3445 | std::cerr << "Failed to get PSU bus and address\n"; |
| 3446 | return ipmi::responseResponseError(); |
| 3447 | } |
| 3448 | |
| 3449 | for (const auto& slaveAddr : addrTable) |
| 3450 | { |
| 3451 | std::vector<uint8_t> writeData = {psuRevision}; |
| 3452 | std::vector<uint8_t> readBuf(verLen); |
| 3453 | uint8_t addr = static_cast<uint8_t>(slaveAddr) + addrOffset; |
| 3454 | std::string i2cBus = "/dev/i2c-" + std::to_string(bus); |
| 3455 | |
| 3456 | auto retI2C = ipmi::i2cWriteRead(i2cBus, addr, writeData, readBuf); |
| 3457 | if (retI2C != ipmi::ccSuccess) |
| 3458 | { |
| 3459 | for (size_t idx = 0; idx < verLen; idx++) |
| 3460 | { |
| 3461 | result.emplace_back(0x00); |
| 3462 | } |
| 3463 | } |
| 3464 | else |
| 3465 | { |
| 3466 | for (const uint8_t& data : readBuf) |
| 3467 | { |
| 3468 | result.emplace_back(data); |
| 3469 | } |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | return ipmi::responseSuccess(result); |
| 3474 | } |
| 3475 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 3476 | /** @brief implements the maximum size of |
| 3477 | * bridgeable messages used between KCS and |
| 3478 | * IPMB interfacesget security mode command. |
| 3479 | * |
| 3480 | * @returns IPMI completion code with following data |
| 3481 | * - KCS Buffer Size (In multiples of four bytes) |
| 3482 | * - IPMB Buffer Size (In multiples of four bytes) |
| 3483 | **/ |
| 3484 | ipmi::RspType<uint8_t, uint8_t> ipmiOEMGetBufferSize() |
| 3485 | { |
| 3486 | // for now this is hard coded; really this number is dependent on |
| 3487 | // the BMC kcs driver as well as the host kcs driver.... |
| 3488 | // we can't know the latter. |
| 3489 | uint8_t kcsMaxBufferSize = 63 / 4; |
| 3490 | uint8_t ipmbMaxBufferSize = 128 / 4; |
| 3491 | |
| 3492 | return ipmi::responseSuccess(kcsMaxBufferSize, ipmbMaxBufferSize); |
| 3493 | } |
| 3494 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 3495 | static void registerOEMFunctions(void) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 3496 | { |
| 3497 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 3498 | "Registering OEM commands"); |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3499 | ipmiPrintAndRegister(intel::netFnGeneral, IPMI_CMD_WILDCARD, NULL, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 3500 | ipmiOEMWildcard, |
| 3501 | PRIVILEGE_USER); // wildcard default handler |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3502 | |
| 3503 | ipmiPrintAndRegister(intel::netFnApp, IPMI_CMD_WILDCARD, NULL, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 3504 | ipmiOEMWildcard, |
| 3505 | PRIVILEGE_USER); // wildcard default handler |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3506 | |
| 3507 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3508 | intel::general::cmdGetChassisIdentifier, NULL, |
| 3509 | ipmiOEMGetChassisIdentifier, |
| 3510 | PRIVILEGE_USER); // get chassis identifier |
| 3511 | |
| 3512 | ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetSystemGUID, |
| 3513 | NULL, ipmiOEMSetSystemGUID, |
| 3514 | PRIVILEGE_ADMIN); // set system guid |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3515 | |
| 3516 | // <Disable BMC System Reset Action> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3517 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3518 | intel::general::cmdDisableBMCSystemReset, Privilege::Admin, |
| 3519 | ipmiOEMDisableBMCSystemReset); |
| 3520 | |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3521 | // <Get BMC Reset Disables> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3522 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3523 | intel::general::cmdGetBMCResetDisables, Privilege::Admin, |
| 3524 | ipmiOEMGetBMCResetDisables); |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3525 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3526 | ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetBIOSID, |
| 3527 | NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 3528 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 3529 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3530 | intel::general::cmdGetOEMDeviceInfo, Privilege::User, |
| 3531 | ipmiOEMGetDeviceInfo); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 3532 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3533 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3534 | intel::general::cmdGetAICSlotFRUIDSlotPosRecords, NULL, |
| 3535 | ipmiOEMGetAICFRU, PRIVILEGE_USER); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 3536 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3537 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3538 | intel::general::cmdSendEmbeddedFWUpdStatus, |
| 3539 | Privilege::Operator, ipmiOEMSendEmbeddedFwUpdStatus); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 3540 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3541 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3542 | intel::general::cmdSetPowerRestoreDelay, NULL, |
| 3543 | ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR); |
| 3544 | |
| 3545 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3546 | intel::general::cmdGetPowerRestoreDelay, NULL, |
| 3547 | ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER); |
| 3548 | |
| 3549 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3550 | intel::general::cmdSetOEMUser2Activation, |
| 3551 | Privilege::Callback, ipmiOEMSetUser2Activation); |
| 3552 | |
| 3553 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3554 | intel::general::cmdSetSpecialUserPassword, |
| 3555 | Privilege::Callback, ipmiOEMSetSpecialUserPassword); |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 3556 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3557 | // <Get Processor Error Config> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3558 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3559 | intel::general::cmdGetProcessorErrConfig, Privilege::User, |
| 3560 | ipmiOEMGetProcessorErrConfig); |
| 3561 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3562 | // <Set Processor Error Config> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3563 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3564 | intel::general::cmdSetProcessorErrConfig, Privilege::Admin, |
| 3565 | ipmiOEMSetProcessorErrConfig); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3566 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3567 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3568 | intel::general::cmdSetShutdownPolicy, NULL, |
| 3569 | ipmiOEMSetShutdownPolicy, PRIVILEGE_ADMIN); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3570 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3571 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3572 | intel::general::cmdGetShutdownPolicy, NULL, |
| 3573 | ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3574 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 3575 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3576 | intel::general::cmdSetFanConfig, Privilege::User, |
| 3577 | ipmiOEMSetFanConfig); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3578 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3579 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3580 | intel::general::cmdGetFanConfig, Privilege::User, |
| 3581 | ipmiOEMGetFanConfig); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 3582 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3583 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3584 | intel::general::cmdGetFanSpeedOffset, Privilege::User, |
| 3585 | ipmiOEMGetFanSpeedOffset); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 3586 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3587 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3588 | intel::general::cmdSetFanSpeedOffset, Privilege::User, |
| 3589 | ipmiOEMSetFanSpeedOffset); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 3590 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3591 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3592 | intel::general::cmdSetFscParameter, Privilege::User, |
| 3593 | ipmiOEMSetFscParameter); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 3594 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3595 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3596 | intel::general::cmdGetFscParameter, Privilege::User, |
| 3597 | ipmiOEMGetFscParameter); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 3598 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3599 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3600 | intel::general::cmdReadBaseBoardProductId, Privilege::Admin, |
| 3601 | ipmiOEMReadBoardProductId); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3602 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3603 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3604 | intel::general::cmdGetNmiStatus, Privilege::User, |
| 3605 | ipmiOEMGetNmiSource); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3606 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3607 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3608 | intel::general::cmdSetNmiStatus, Privilege::Operator, |
| 3609 | ipmiOEMSetNmiSource); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3610 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3611 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3612 | intel::general::cmdGetEfiBootOptions, Privilege::User, |
| 3613 | ipmiOemGetEfiBootOptions); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3614 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3615 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3616 | intel::general::cmdSetEfiBootOptions, Privilege::Operator, |
| 3617 | ipmiOemSetEfiBootOptions); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 3618 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3619 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3620 | intel::general::cmdGetSecurityMode, Privilege::User, |
| 3621 | ipmiGetSecurityMode); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 3622 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3623 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3624 | intel::general::cmdSetSecurityMode, Privilege::Admin, |
| 3625 | ipmiSetSecurityMode); |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 3626 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3627 | ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdGetLEDStatus, |
| 3628 | NULL, ipmiOEMGetLEDStatus, PRIVILEGE_ADMIN); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 3629 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3630 | ipmiPrintAndRegister(ipmi::intel::netFnPlatform, |
| 3631 | ipmi::intel::platform::cmdCfgHostSerialPortSpeed, NULL, |
| 3632 | ipmiOEMCfgHostSerialPortSpeed, PRIVILEGE_ADMIN); |
| 3633 | |
| 3634 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3635 | intel::general::cmdSetFaultIndication, Privilege::Operator, |
| 3636 | ipmiOEMSetFaultIndication); |
| 3637 | |
| 3638 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3639 | intel::general::cmdSetColdRedundancyConfig, Privilege::User, |
| 3640 | ipmiOEMSetCRConfig); |
| 3641 | |
| 3642 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3643 | intel::general::cmdGetColdRedundancyConfig, Privilege::User, |
| 3644 | ipmiOEMGetCRConfig); |
| 3645 | |
| 3646 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3647 | intel::general::cmdRestoreConfiguration, Privilege::Admin, |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 3648 | ipmiRestoreConfiguration); |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3649 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3650 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3651 | intel::general::cmdSetDimmOffset, Privilege::Operator, |
| 3652 | ipmiOEMSetDimmOffset); |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3653 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3654 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3655 | intel::general::cmdGetDimmOffset, Privilege::Operator, |
| 3656 | ipmiOEMGetDimmOffset); |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3657 | |
Cheng C Yang | 4e6ee15 | 2019-09-25 10:27:44 +0800 | [diff] [blame] | 3658 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3659 | intel::general::cmdGetPSUVersion, Privilege::User, |
| 3660 | ipmiOEMGetPSUVersion); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 3661 | |
| 3662 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3663 | intel::general::cmdGetBufferSize, Privilege::User, |
| 3664 | ipmiOEMGetBufferSize); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | } // namespace ipmi |