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