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