Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Intel Corporation. |
| 3 | * Copyright (c) 2018-present Facebook. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include "xyz/openbmc_project/Common/error.hpp" |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 19 | #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> |
| 20 | #include <xyz/openbmc_project/Control/Boot/Source/server.hpp> |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 21 | #include <xyz/openbmc_project/Control/Boot/Type/server.hpp> |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 22 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 23 | #include <ipmid/api.hpp> |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 24 | #include <ipmid/utils.hpp> |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 25 | #include <commandutils.hpp> |
| 26 | #include <nlohmann/json.hpp> |
| 27 | #include <oemcommands.hpp> |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 28 | #include <phosphor-logging/log.hpp> |
| 29 | #include <sdbusplus/bus.hpp> |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 30 | |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 31 | #include <ipmid/api.hpp> |
| 32 | #include <ipmid/api-types.hpp> |
| 33 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 34 | #include <array> |
| 35 | #include <cstring> |
| 36 | #include <fstream> |
| 37 | #include <iomanip> |
| 38 | #include <iostream> |
| 39 | #include <sstream> |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 40 | #include <string> |
| 41 | #include <vector> |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 42 | #include <regex> |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 43 | |
| 44 | #define SIZE_IANA_ID 3 |
| 45 | |
| 46 | namespace ipmi |
| 47 | { |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 48 | |
| 49 | using namespace phosphor::logging; |
| 50 | |
Karthikeyan Pasupathi | e1ff81f | 2022-11-21 17:54:46 +0530 | [diff] [blame] | 51 | void getSelectorPosition(size_t& position); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 52 | static void registerOEMFunctions() __attribute__((constructor)); |
Patrick Williams | cd315e0 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 53 | sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 54 | static constexpr size_t maxFRUStringLength = 0x3F; |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 55 | constexpr uint8_t cmdSetSystemGuid = 0xEF; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 56 | |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 57 | constexpr uint8_t cmdSetQDimmInfo = 0x12; |
| 58 | constexpr uint8_t cmdGetQDimmInfo = 0x13; |
| 59 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 60 | int plat_udbg_get_post_desc(uint8_t, uint8_t*, uint8_t, uint8_t*, uint8_t*, |
| 61 | uint8_t*); |
| 62 | int plat_udbg_get_gpio_desc(uint8_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*, |
| 63 | uint8_t*); |
| 64 | ipmi_ret_t plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t*, uint8_t*, |
| 65 | uint8_t*); |
| 66 | ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t*, |
| 67 | uint8_t*); |
| 68 | int sendMeCmd(uint8_t, uint8_t, std::vector<uint8_t>&, std::vector<uint8_t>&); |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 69 | |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 70 | int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&, |
| 71 | std::vector<uint8_t>&); |
| 72 | |
Vijay Khemka | feaa981 | 2019-08-27 15:08:08 -0700 | [diff] [blame] | 73 | nlohmann::json oemData __attribute__((init_priority(101))); |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 74 | |
Vijay Khemka | f2246ce | 2020-05-27 14:26:35 -0700 | [diff] [blame] | 75 | static constexpr size_t GUID_SIZE = 16; |
| 76 | // TODO Make offset and location runtime configurable to ensure we |
| 77 | // can make each define their own locations. |
| 78 | static constexpr off_t OFFSET_SYS_GUID = 0x17F0; |
| 79 | static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom"; |
| 80 | |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 81 | enum class LanParam : uint8_t |
| 82 | { |
| 83 | INPROGRESS = 0, |
| 84 | AUTHSUPPORT = 1, |
| 85 | AUTHENABLES = 2, |
| 86 | IP = 3, |
| 87 | IPSRC = 4, |
| 88 | MAC = 5, |
| 89 | SUBNET = 6, |
| 90 | GATEWAY = 12, |
| 91 | VLAN = 20, |
| 92 | CIPHER_SUITE_COUNT = 22, |
| 93 | CIPHER_SUITE_ENTRIES = 23, |
| 94 | IPV6 = 59, |
| 95 | }; |
| 96 | |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 97 | namespace network |
| 98 | { |
| 99 | |
| 100 | constexpr auto ROOT = "/xyz/openbmc_project/network"; |
| 101 | constexpr auto SERVICE = "xyz.openbmc_project.Network"; |
| 102 | constexpr auto IPV4_TYPE = "ipv4"; |
| 103 | constexpr auto IPV6_TYPE = "ipv6"; |
| 104 | constexpr auto IPV4_PREFIX = "169.254"; |
| 105 | constexpr auto IPV6_PREFIX = "fe80"; |
| 106 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 107 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
Potin Lai | 8d1a81e | 2022-12-20 11:13:45 +0800 | [diff] [blame^] | 108 | constexpr auto IPV4_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv4"; |
| 109 | constexpr auto IPV6_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv6"; |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 110 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 111 | bool isLinkLocalIP(const std::string& address) |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 112 | { |
| 113 | return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0; |
| 114 | } |
| 115 | |
Patrick Williams | cd315e0 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 116 | DbusObjectInfo getIPObject(sdbusplus::bus_t& bus, const std::string& interface, |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 117 | const std::string& serviceRoot, |
Potin Lai | 8d1a81e | 2022-12-20 11:13:45 +0800 | [diff] [blame^] | 118 | const std::string& protocol, |
| 119 | const std::string& ethdev) |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 120 | { |
Potin Lai | 8d1a81e | 2022-12-20 11:13:45 +0800 | [diff] [blame^] | 121 | auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, ethdev); |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 122 | |
| 123 | if (objectTree.empty()) |
| 124 | { |
| 125 | log<level::ERR>("No Object has implemented the IP interface", |
| 126 | entry("INTERFACE=%s", interface.c_str())); |
| 127 | } |
| 128 | |
| 129 | DbusObjectInfo objectInfo; |
| 130 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 131 | for (auto& object : objectTree) |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 132 | { |
| 133 | auto variant = |
| 134 | ipmi::getDbusProperty(bus, object.second.begin()->first, |
Potin Lai | 8d1a81e | 2022-12-20 11:13:45 +0800 | [diff] [blame^] | 135 | object.first, IP_INTERFACE, "Type"); |
| 136 | if (std::get<std::string>(variant) != protocol) |
| 137 | { |
| 138 | continue; |
| 139 | } |
| 140 | |
| 141 | variant = ipmi::getDbusProperty(bus, object.second.begin()->first, |
| 142 | object.first, IP_INTERFACE, "Address"); |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 143 | |
| 144 | objectInfo = std::make_pair(object.first, object.second.begin()->first); |
| 145 | |
| 146 | // if LinkLocalIP found look for Non-LinkLocalIP |
| 147 | if (isLinkLocalIP(std::get<std::string>(variant))) |
| 148 | { |
| 149 | continue; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | return objectInfo; |
| 157 | } |
| 158 | |
| 159 | } // namespace network |
| 160 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 161 | namespace boot |
| 162 | { |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 163 | using BootSource = |
| 164 | sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources; |
| 165 | using BootMode = |
| 166 | sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes; |
| 167 | using BootType = |
| 168 | sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 169 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 170 | using IpmiValue = uint8_t; |
| 171 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 172 | std::map<IpmiValue, BootSource> sourceIpmiToDbus = { |
| 173 | {0x0f, BootSource::Default}, {0x00, BootSource::RemovableMedia}, |
| 174 | {0x01, BootSource::Network}, {0x02, BootSource::Disk}, |
| 175 | {0x03, BootSource::ExternalMedia}, {0x09, BootSource::Network}}; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 176 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 177 | std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x06, BootMode::Setup}, |
| 178 | {0x00, BootMode::Regular}}; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 179 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 180 | std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy}, |
| 181 | {0x01, BootType::EFI}}; |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 182 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 183 | std::map<std::optional<BootSource>, IpmiValue> sourceDbusToIpmi = { |
| 184 | {BootSource::Default, 0x0f}, |
| 185 | {BootSource::RemovableMedia, 0x00}, |
| 186 | {BootSource::Network, 0x01}, |
| 187 | {BootSource::Disk, 0x02}, |
| 188 | {BootSource::ExternalMedia, 0x03}}; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 189 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 190 | std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = { |
| 191 | {BootMode::Setup, 0x06}, {BootMode::Regular, 0x00}}; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 192 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 193 | std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = { |
| 194 | {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}}; |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 195 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 196 | static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; |
| 197 | static constexpr auto bootSourceIntf = |
| 198 | "xyz.openbmc_project.Control.Boot.Source"; |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 199 | static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type"; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 200 | static constexpr auto bootSourceProp = "BootSource"; |
| 201 | static constexpr auto bootModeProp = "BootMode"; |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 202 | static constexpr auto bootTypeProp = "BootType"; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 203 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 204 | std::tuple<std::string, std::string> objPath(size_t id) |
| 205 | { |
| 206 | std::string hostName = "host" + std::to_string(id); |
| 207 | std::string bootObjPath = |
| 208 | "/xyz/openbmc_project/control/" + hostName + "/boot"; |
| 209 | return std::make_tuple(std::move(bootObjPath), std::move(hostName)); |
| 210 | } |
| 211 | |
| 212 | } // namespace boot |
| 213 | |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 214 | //---------------------------------------------------------------------- |
| 215 | // Helper functions for storing oem data |
| 216 | //---------------------------------------------------------------------- |
| 217 | |
| 218 | void flushOemData() |
| 219 | { |
| 220 | std::ofstream file(JSON_OEM_DATA_FILE); |
| 221 | file << oemData; |
Vijay Khemka | feaa981 | 2019-08-27 15:08:08 -0700 | [diff] [blame] | 222 | file.close(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 223 | return; |
| 224 | } |
| 225 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 226 | std::string bytesToStr(uint8_t* byte, int len) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 227 | { |
| 228 | std::stringstream ss; |
| 229 | int i; |
| 230 | |
| 231 | ss << std::hex; |
| 232 | for (i = 0; i < len; i++) |
| 233 | { |
| 234 | ss << std::setw(2) << std::setfill('0') << (int)byte[i]; |
| 235 | } |
| 236 | |
| 237 | return ss.str(); |
| 238 | } |
| 239 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 240 | int strToBytes(std::string& str, uint8_t* data) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 241 | { |
| 242 | std::string sstr; |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 243 | size_t i; |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 244 | |
| 245 | for (i = 0; i < (str.length()) / 2; i++) |
| 246 | { |
| 247 | sstr = str.substr(i * 2, 2); |
| 248 | data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16); |
| 249 | } |
| 250 | return i; |
| 251 | } |
| 252 | |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 253 | int readDimmType(std::string& data, uint8_t param) |
| 254 | { |
| 255 | nlohmann::json dimmObj; |
| 256 | /* Get dimm type names stored in json file */ |
| 257 | std::ifstream file(JSON_DIMM_TYPE_FILE); |
| 258 | if (file) |
| 259 | { |
| 260 | file >> dimmObj; |
| 261 | file.close(); |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 266 | "DIMM type names file not found", |
| 267 | phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE)); |
| 268 | return -1; |
| 269 | } |
| 270 | |
| 271 | std::string dimmKey = "dimm_type" + std::to_string(param); |
| 272 | auto obj = dimmObj[dimmKey]["short_name"]; |
| 273 | data = obj; |
| 274 | return 0; |
| 275 | } |
| 276 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 277 | ipmi_ret_t getNetworkData(uint8_t lan_param, char* data) |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 278 | { |
| 279 | ipmi_ret_t rc = IPMI_CC_OK; |
Patrick Williams | cd315e0 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 280 | sdbusplus::bus_t bus(ipmid_get_sd_bus_connection()); |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 281 | |
| 282 | const std::string ethdevice = "eth0"; |
| 283 | |
| 284 | switch (static_cast<LanParam>(lan_param)) |
| 285 | { |
Vijay Khemka | d119402 | 2020-05-27 18:58:33 -0700 | [diff] [blame] | 286 | case LanParam::IP: |
| 287 | { |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 288 | std::string ipaddress; |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 289 | auto ipObjectInfo = ipmi::network::getIPObject( |
Potin Lai | 8d1a81e | 2022-12-20 11:13:45 +0800 | [diff] [blame^] | 290 | bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT, |
| 291 | ipmi::network::IPV4_PROTOCOL, ethdevice); |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 292 | |
| 293 | auto properties = ipmi::getAllDbusProperties( |
| 294 | bus, ipObjectInfo.second, ipObjectInfo.first, |
| 295 | ipmi::network::IP_INTERFACE); |
| 296 | |
Patrick Williams | ef0efbc | 2020-05-13 11:26:51 -0500 | [diff] [blame] | 297 | ipaddress = std::get<std::string>(properties["Address"]); |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 298 | |
| 299 | std::strcpy(data, ipaddress.c_str()); |
| 300 | } |
| 301 | break; |
| 302 | |
Vijay Khemka | d119402 | 2020-05-27 18:58:33 -0700 | [diff] [blame] | 303 | case LanParam::IPV6: |
| 304 | { |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 305 | std::string ipaddress; |
Vijay Khemka | a723189 | 2019-10-11 11:35:05 -0700 | [diff] [blame] | 306 | auto ipObjectInfo = ipmi::network::getIPObject( |
Potin Lai | 8d1a81e | 2022-12-20 11:13:45 +0800 | [diff] [blame^] | 307 | bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT, |
| 308 | ipmi::network::IPV6_PROTOCOL, ethdevice); |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 309 | |
| 310 | auto properties = ipmi::getAllDbusProperties( |
| 311 | bus, ipObjectInfo.second, ipObjectInfo.first, |
| 312 | ipmi::network::IP_INTERFACE); |
| 313 | |
Patrick Williams | ef0efbc | 2020-05-13 11:26:51 -0500 | [diff] [blame] | 314 | ipaddress = std::get<std::string>(properties["Address"]); |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 315 | |
| 316 | std::strcpy(data, ipaddress.c_str()); |
| 317 | } |
| 318 | break; |
| 319 | |
Vijay Khemka | d119402 | 2020-05-27 18:58:33 -0700 | [diff] [blame] | 320 | case LanParam::MAC: |
| 321 | { |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 322 | std::string macAddress; |
| 323 | auto macObjectInfo = |
| 324 | ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE, |
| 325 | ipmi::network::ROOT, ethdevice); |
| 326 | |
| 327 | auto variant = ipmi::getDbusProperty( |
| 328 | bus, macObjectInfo.second, macObjectInfo.first, |
| 329 | ipmi::network::MAC_INTERFACE, "MACAddress"); |
| 330 | |
Patrick Williams | ef0efbc | 2020-05-13 11:26:51 -0500 | [diff] [blame] | 331 | macAddress = std::get<std::string>(variant); |
Vijay Khemka | 1b6fae3 | 2019-03-25 17:43:01 -0700 | [diff] [blame] | 332 | |
| 333 | sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT, |
| 334 | (data), (data + 1), (data + 2), (data + 3), (data + 4), |
| 335 | (data + 5)); |
| 336 | std::strcpy(data, macAddress.c_str()); |
| 337 | } |
| 338 | break; |
| 339 | |
| 340 | default: |
| 341 | rc = IPMI_CC_PARM_OUT_OF_RANGE; |
| 342 | } |
| 343 | return rc; |
| 344 | } |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 345 | |
Karthikeyan Pasupathi | 39836ff | 2022-01-17 12:20:06 +0530 | [diff] [blame] | 346 | bool isMultiHostPlatform() |
| 347 | { |
| 348 | bool platform; |
Jayashree Dhanapal | 4ec8056 | 2022-06-28 15:41:47 +0530 | [diff] [blame] | 349 | if (hostInstances == "0") |
Karthikeyan Pasupathi | 39836ff | 2022-01-17 12:20:06 +0530 | [diff] [blame] | 350 | { |
| 351 | platform = false; |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | platform = true; |
| 356 | } |
| 357 | return platform; |
| 358 | } |
| 359 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 360 | // return code: 0 successful |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 361 | int8_t getFruData(std::string& data, std::string& name) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 362 | { |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 363 | size_t pos; |
| 364 | static constexpr const auto depth = 0; |
| 365 | std::vector<std::string> paths; |
| 366 | std::string machinePath; |
| 367 | std::string baseBoard = "Baseboard"; |
| 368 | |
| 369 | bool platform = isMultiHostPlatform(); |
| 370 | if (platform == true) |
| 371 | { |
Karthikeyan Pasupathi | e1ff81f | 2022-11-21 17:54:46 +0530 | [diff] [blame] | 372 | getSelectorPosition(pos); |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | sd_bus* bus = NULL; |
| 376 | int ret = sd_bus_default_system(&bus); |
| 377 | if (ret < 0) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 378 | { |
| 379 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 380 | "Failed to connect to system bus", |
| 381 | phosphor::logging::entry("ERRNO=0x%X", -ret)); |
| 382 | sd_bus_unref(bus); |
| 383 | return -1; |
| 384 | } |
Patrick Williams | cd315e0 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 385 | sdbusplus::bus_t dbus(bus); |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 386 | auto mapperCall = dbus.new_method_call("xyz.openbmc_project.ObjectMapper", |
| 387 | "/xyz/openbmc_project/object_mapper", |
| 388 | "xyz.openbmc_project.ObjectMapper", |
| 389 | "GetSubTreePaths"); |
| 390 | static constexpr std::array<const char*, 1> interface = { |
| 391 | "xyz.openbmc_project.Inventory.Decorator.Asset"}; |
| 392 | mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface); |
| 393 | |
| 394 | try |
| 395 | { |
| 396 | auto reply = dbus.call(mapperCall); |
| 397 | reply.read(paths); |
| 398 | } |
| 399 | catch (sdbusplus::exception_t& e) |
| 400 | { |
| 401 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 402 | return -1; |
| 403 | } |
| 404 | |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 405 | for (const auto& path : paths) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 406 | { |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 407 | if (platform == true) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 408 | { |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 409 | if (pos == BMC_POS) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 410 | { |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 411 | machinePath = baseBoard; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 412 | } |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 413 | else |
| 414 | { |
| 415 | machinePath = "_" + std::to_string(pos); |
| 416 | } |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 417 | } |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 418 | else |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 419 | { |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 420 | machinePath = baseBoard; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 421 | } |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 422 | |
| 423 | auto found = path.find(machinePath); |
Patrick Williams | 123cbcc | 2022-06-24 06:13:59 -0500 | [diff] [blame] | 424 | if (found == std::string::npos) |
Karthikeyan Pasupathi | 98aabdb | 2022-04-06 17:18:51 +0530 | [diff] [blame] | 425 | { |
| 426 | continue; |
| 427 | } |
| 428 | |
| 429 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 430 | std::string service = getService( |
| 431 | *dbus, "xyz.openbmc_project.Inventory.Decorator.Asset", path); |
| 432 | |
| 433 | auto Value = ipmi::getDbusProperty( |
| 434 | *dbus, service, path, |
| 435 | "xyz.openbmc_project.Inventory.Decorator.Asset", name); |
| 436 | |
| 437 | data = std::get<std::string>(Value); |
| 438 | return 0; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 439 | } |
| 440 | return -1; |
| 441 | } |
| 442 | |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 443 | int8_t sysConfig(std::vector<std::string>& data, size_t pos) |
| 444 | { |
| 445 | nlohmann::json sysObj; |
| 446 | std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(pos); |
| 447 | std::string result, typeName; |
| 448 | uint8_t res[MAX_BUF]; |
| 449 | |
| 450 | /* Get sysConfig data stored in json file */ |
| 451 | std::ifstream file(JSON_OEM_DATA_FILE); |
| 452 | if (file) |
| 453 | { |
| 454 | file >> sysObj; |
| 455 | file.close(); |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 460 | "oemData file not found", |
| 461 | phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE)); |
| 462 | return -1; |
| 463 | } |
| 464 | |
| 465 | if (sysObj.find(dimmInfo) == sysObj.end()) |
| 466 | { |
| 467 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 468 | "sysconfig key not available", |
| 469 | phosphor::logging::entry("SYS_JSON_KEY=%s", dimmInfo.c_str())); |
| 470 | return -1; |
| 471 | } |
| 472 | /* Get dimm type names stored in json file */ |
| 473 | nlohmann::json dimmObj; |
| 474 | std::ifstream dimmFile(JSON_DIMM_TYPE_FILE); |
| 475 | if (file) |
| 476 | { |
| 477 | dimmFile >> dimmObj; |
| 478 | dimmFile.close(); |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 483 | "DIMM type names file not found", |
| 484 | phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE)); |
| 485 | return -1; |
| 486 | } |
| 487 | std::vector<std::string> a; |
| 488 | for (auto& j : dimmObj.items()) |
| 489 | { |
| 490 | std::string name = j.key(); |
| 491 | a.push_back(name); |
| 492 | } |
| 493 | |
| 494 | uint8_t len = a.size(); |
| 495 | for (uint8_t ii = 0; ii < len; ii++) |
| 496 | { |
| 497 | std::string indKey = std::to_string(ii); |
| 498 | std::string speedSize = sysObj[dimmInfo][indKey][DIMM_SPEED]; |
| 499 | strToBytes(speedSize, res); |
| 500 | auto speed = (res[1] << 8 | res[0]); |
| 501 | size_t dimmSize = ((res[3] << 8 | res[2]) / 1000); |
| 502 | |
| 503 | if (dimmSize == 0) |
| 504 | { |
| 505 | std::cerr << "Dimm information not available for slot_" + |
| 506 | std::to_string(ii) |
| 507 | << std::endl; |
| 508 | continue; |
| 509 | } |
| 510 | std::string type = sysObj[dimmInfo][indKey][DIMM_TYPE]; |
| 511 | std::string dualInlineMem = sysObj[dimmInfo][indKey][KEY_DIMM_TYPE]; |
| 512 | strToBytes(type, res); |
| 513 | size_t dimmType = res[0]; |
| 514 | if (dimmVenMap.find(dimmType) == dimmVenMap.end()) |
| 515 | { |
| 516 | typeName = "unknown"; |
| 517 | } |
| 518 | else |
| 519 | { |
| 520 | typeName = dimmVenMap[dimmType]; |
| 521 | } |
| 522 | result = dualInlineMem + "/" + typeName + "/" + std::to_string(speed) + |
| 523 | "MHz" + "/" + std::to_string(dimmSize) + "GB"; |
| 524 | data.push_back(result); |
| 525 | } |
| 526 | return 0; |
| 527 | } |
| 528 | |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 529 | int8_t procInfo(std::string& result, size_t pos) |
| 530 | { |
| 531 | std::vector<char> data; |
| 532 | uint8_t res[MAX_BUF]; |
| 533 | std::string procIndex = "00"; |
| 534 | nlohmann::json proObj; |
| 535 | std::string procInfo = KEY_Q_PROC_INFO + std::to_string(pos); |
| 536 | /* Get processor data stored in json file */ |
| 537 | std::ifstream file(JSON_OEM_DATA_FILE); |
| 538 | if (file) |
| 539 | { |
| 540 | file >> proObj; |
| 541 | file.close(); |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 546 | "oemData file not found", |
| 547 | phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE)); |
| 548 | return -1; |
| 549 | } |
| 550 | if (proObj.find(procInfo) == proObj.end()) |
| 551 | { |
| 552 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 553 | "processor info key not available", |
| 554 | phosphor::logging::entry("PROC_JSON_KEY=%s", procInfo.c_str())); |
| 555 | return -1; |
| 556 | } |
| 557 | std::string procName = proObj[procInfo][procIndex][KEY_PROC_NAME]; |
| 558 | std::string basicInfo = proObj[procInfo][procIndex][KEY_BASIC_INFO]; |
| 559 | // Processor Product Name |
| 560 | strToBytes(procName, res); |
| 561 | data.assign(reinterpret_cast<char*>(&res), |
| 562 | reinterpret_cast<char*>(&res) + sizeof(res)); |
| 563 | |
| 564 | std::string s(data.begin(), data.end()); |
| 565 | std::regex regex(" "); |
| 566 | std::vector<std::string> productName( |
| 567 | std::sregex_token_iterator(s.begin(), s.end(), regex, -1), |
| 568 | std::sregex_token_iterator()); |
| 569 | |
| 570 | // Processor core and frequency |
| 571 | strToBytes(basicInfo, res); |
| 572 | uint16_t coreNum = res[0]; |
| 573 | double procFrequency = (float)(res[4] << 8 | res[3]) / 1000; |
| 574 | result = "CPU:" + productName[2] + "/" + std::to_string(procFrequency) + |
| 575 | "GHz" + "/" + std::to_string(coreNum) + "c"; |
| 576 | return 0; |
| 577 | } |
| 578 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 579 | typedef struct |
| 580 | { |
| 581 | uint8_t cur_power_state; |
| 582 | uint8_t last_power_event; |
| 583 | uint8_t misc_power_state; |
| 584 | uint8_t front_panel_button_cap_status; |
| 585 | } ipmi_get_chassis_status_t; |
| 586 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 587 | //---------------------------------------------------------------------- |
| 588 | // Get Debug Frame Info |
| 589 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 590 | ipmi_ret_t ipmiOemDbgGetFrameInfo(ipmi_netfn_t, ipmi_cmd_t, |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 591 | ipmi_request_t request, |
| 592 | ipmi_response_t response, |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 593 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 594 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 595 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 596 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 597 | uint8_t num_frames = 3; |
| 598 | |
| 599 | std::memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 600 | res[SIZE_IANA_ID] = num_frames; |
| 601 | *data_len = SIZE_IANA_ID + 1; |
| 602 | |
| 603 | return IPMI_CC_OK; |
| 604 | } |
| 605 | |
| 606 | //---------------------------------------------------------------------- |
| 607 | // Get Debug Updated Frames |
| 608 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 609 | ipmi_ret_t ipmiOemDbgGetUpdFrames(ipmi_netfn_t, ipmi_cmd_t, |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 610 | ipmi_request_t request, |
| 611 | ipmi_response_t response, |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 612 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 613 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 614 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 615 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 616 | uint8_t num_updates = 3; |
| 617 | *data_len = 4; |
| 618 | |
| 619 | std::memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 620 | res[SIZE_IANA_ID] = num_updates; |
| 621 | *data_len = SIZE_IANA_ID + num_updates + 1; |
| 622 | res[SIZE_IANA_ID + 1] = 1; // info page update |
| 623 | res[SIZE_IANA_ID + 2] = 2; // cri sel update |
| 624 | res[SIZE_IANA_ID + 3] = 3; // cri sensor update |
| 625 | |
| 626 | return IPMI_CC_OK; |
| 627 | } |
| 628 | |
| 629 | //---------------------------------------------------------------------- |
| 630 | // Get Debug POST Description |
| 631 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 632 | ipmi_ret_t ipmiOemDbgGetPostDesc(ipmi_netfn_t, ipmi_cmd_t, |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 633 | ipmi_request_t request, |
| 634 | ipmi_response_t response, |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 635 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 636 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 637 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 638 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 639 | uint8_t index = 0; |
| 640 | uint8_t next = 0; |
| 641 | uint8_t end = 0; |
| 642 | uint8_t phase = 0; |
Vijay Khemka | cc0d6d9 | 2019-08-27 14:51:17 -0700 | [diff] [blame] | 643 | uint8_t descLen = 0; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 644 | int ret; |
| 645 | |
| 646 | index = req[3]; |
| 647 | phase = req[4]; |
| 648 | |
Vijay Khemka | cc0d6d9 | 2019-08-27 14:51:17 -0700 | [diff] [blame] | 649 | ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 650 | if (ret) |
| 651 | { |
| 652 | memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 653 | *data_len = SIZE_IANA_ID; |
| 654 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 655 | } |
| 656 | |
| 657 | memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 658 | res[3] = index; |
| 659 | res[4] = next; |
| 660 | res[5] = phase; |
| 661 | res[6] = end; |
Vijay Khemka | cc0d6d9 | 2019-08-27 14:51:17 -0700 | [diff] [blame] | 662 | res[7] = descLen; |
| 663 | *data_len = SIZE_IANA_ID + 5 + descLen; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 664 | |
| 665 | return IPMI_CC_OK; |
| 666 | } |
| 667 | |
| 668 | //---------------------------------------------------------------------- |
| 669 | // Get Debug GPIO Description |
| 670 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 671 | ipmi_ret_t ipmiOemDbgGetGpioDesc(ipmi_netfn_t, ipmi_cmd_t, |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 672 | ipmi_request_t request, |
| 673 | ipmi_response_t response, |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 674 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 675 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 676 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 677 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 678 | |
Vijay Khemka | 38183d6 | 2019-08-28 16:19:33 -0700 | [diff] [blame] | 679 | uint8_t index = 0; |
| 680 | uint8_t next = 0; |
| 681 | uint8_t level = 0; |
| 682 | uint8_t pinDef = 0; |
| 683 | uint8_t descLen = 0; |
| 684 | int ret; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 685 | |
Vijay Khemka | 38183d6 | 2019-08-28 16:19:33 -0700 | [diff] [blame] | 686 | index = req[3]; |
| 687 | |
| 688 | ret = plat_udbg_get_gpio_desc(index, &next, &level, &pinDef, &descLen, |
| 689 | &res[8]); |
| 690 | if (ret) |
| 691 | { |
| 692 | memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 693 | *data_len = SIZE_IANA_ID; |
| 694 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 695 | } |
| 696 | |
| 697 | memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 698 | res[3] = index; |
| 699 | res[4] = next; |
| 700 | res[5] = level; |
| 701 | res[6] = pinDef; |
| 702 | res[7] = descLen; |
| 703 | *data_len = SIZE_IANA_ID + 5 + descLen; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 704 | |
| 705 | return IPMI_CC_OK; |
| 706 | } |
| 707 | |
| 708 | //---------------------------------------------------------------------- |
| 709 | // Get Debug Frame Data |
| 710 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 711 | ipmi_ret_t ipmiOemDbgGetFrameData(ipmi_netfn_t, ipmi_cmd_t, |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 712 | ipmi_request_t request, |
| 713 | ipmi_response_t response, |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 714 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 715 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 716 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 717 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 718 | uint8_t frame; |
| 719 | uint8_t page; |
| 720 | uint8_t next; |
| 721 | uint8_t count; |
| 722 | int ret; |
| 723 | |
| 724 | frame = req[3]; |
| 725 | page = req[4]; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 726 | |
| 727 | ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]); |
| 728 | if (ret) |
| 729 | { |
| 730 | memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 731 | *data_len = SIZE_IANA_ID; |
| 732 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 733 | } |
| 734 | |
| 735 | memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 736 | res[3] = frame; |
| 737 | res[4] = page; |
| 738 | res[5] = next; |
| 739 | res[6] = count; |
| 740 | *data_len = SIZE_IANA_ID + 4 + count; |
| 741 | |
| 742 | return IPMI_CC_OK; |
| 743 | } |
| 744 | |
| 745 | //---------------------------------------------------------------------- |
| 746 | // Get Debug Control Panel |
| 747 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 748 | ipmi_ret_t ipmiOemDbgGetCtrlPanel(ipmi_netfn_t, ipmi_cmd_t, |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 749 | ipmi_request_t request, |
| 750 | ipmi_response_t response, |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 751 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 752 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 753 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 754 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 755 | |
| 756 | uint8_t panel; |
| 757 | uint8_t operation; |
| 758 | uint8_t item; |
| 759 | uint8_t count; |
| 760 | ipmi_ret_t ret; |
| 761 | |
| 762 | panel = req[3]; |
| 763 | operation = req[4]; |
| 764 | item = req[5]; |
| 765 | |
| 766 | ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]); |
| 767 | |
| 768 | std::memcpy(res, req, SIZE_IANA_ID); // IANA ID |
| 769 | *data_len = SIZE_IANA_ID + count; |
| 770 | |
| 771 | return ret; |
| 772 | } |
| 773 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 774 | //---------------------------------------------------------------------- |
| 775 | // Set Dimm Info (CMD_OEM_SET_DIMM_INFO) |
| 776 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 777 | ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, |
| 778 | ipmi_response_t, ipmi_data_len_t data_len, |
| 779 | ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 780 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 781 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 782 | |
| 783 | uint8_t index = req[0]; |
| 784 | uint8_t type = req[1]; |
| 785 | uint16_t speed; |
| 786 | uint32_t size; |
| 787 | |
| 788 | memcpy(&speed, &req[2], 2); |
| 789 | memcpy(&size, &req[4], 4); |
| 790 | |
| 791 | std::stringstream ss; |
| 792 | ss << std::hex; |
| 793 | ss << std::setw(2) << std::setfill('0') << (int)index; |
| 794 | |
| 795 | oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index; |
| 796 | oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type; |
| 797 | oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed; |
| 798 | oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size; |
| 799 | |
| 800 | flushOemData(); |
| 801 | |
| 802 | *data_len = 0; |
| 803 | |
| 804 | return IPMI_CC_OK; |
| 805 | } |
| 806 | |
| 807 | //---------------------------------------------------------------------- |
| 808 | // Get Board ID (CMD_OEM_GET_BOARD_ID) |
| 809 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 810 | ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, |
| 811 | ipmi_response_t, ipmi_data_len_t data_len, |
| 812 | ipmi_context_t) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 813 | { |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 814 | /* TODO: Needs to implement this after GPIO implementation */ |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 815 | *data_len = 0; |
| 816 | |
| 817 | return IPMI_CC_OK; |
| 818 | } |
| 819 | |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 820 | /* Helper functions to set boot order */ |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 821 | void setBootOrder(std::string bootObjPath, uint8_t* data, |
| 822 | std::string bootOrderKey) |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 823 | { |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 824 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 825 | |
| 826 | // SETTING BOOT MODE PROPERTY |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 827 | uint8_t bootModeBit = data[0] & 0x06; |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 828 | auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit); |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 829 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 830 | std::string bootOption = |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 831 | sdbusplus::message::convert_to_string<boot::BootMode>(bootValue); |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 832 | |
| 833 | std::string service = |
| 834 | getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath); |
| 835 | setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf, |
| 836 | ipmi::boot::bootModeProp, bootOption); |
| 837 | |
| 838 | // SETTING BOOT SOURCE PROPERTY |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 839 | auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]); |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 840 | std::string bootSource = |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 841 | sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder); |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 842 | |
| 843 | service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath); |
| 844 | setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf, |
| 845 | ipmi::boot::bootSourceProp, bootSource); |
| 846 | |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 847 | // SETTING BOOT TYPE PROPERTY |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 848 | uint8_t bootTypeBit = data[0] & 0x01; |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 849 | auto bootTypeVal = ipmi::boot::typeIpmiToDbus.at(bootTypeBit); |
| 850 | |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 851 | std::string bootType = |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 852 | sdbusplus::message::convert_to_string<boot::BootType>(bootTypeVal); |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 853 | |
| 854 | service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath); |
| 855 | |
| 856 | setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf, |
| 857 | ipmi::boot::bootTypeProp, bootType); |
| 858 | |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 859 | nlohmann::json bootMode; |
| 860 | uint8_t mode = data[0]; |
| 861 | int i; |
| 862 | |
| 863 | bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false); |
| 864 | bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false); |
| 865 | bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false); |
| 866 | bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false); |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 867 | oemData[bootOrderKey][KEY_BOOT_MODE] = bootMode; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 868 | |
| 869 | /* Initialize boot sequence array */ |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 870 | oemData[bootOrderKey][KEY_BOOT_SEQ] = {}; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 871 | for (i = 1; i < SIZE_BOOT_ORDER; i++) |
| 872 | { |
| 873 | if (data[i] >= BOOT_SEQ_ARRAY_SIZE) |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 874 | oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = "NA"; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 875 | else |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 876 | oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = bootSeq[data[i]]; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | flushOemData(); |
| 880 | } |
| 881 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 882 | //---------------------------------------------------------------------- |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 883 | // Set Boot Order (CMD_OEM_SET_BOOT_ORDER) |
| 884 | //---------------------------------------------------------------------- |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 885 | ipmi::RspType<std::vector<uint8_t>> |
| 886 | ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 887 | { |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 888 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 889 | uint8_t bootSeq[SIZE_BOOT_ORDER]; |
| 890 | size_t len = data.size(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 891 | |
| 892 | if (len != SIZE_BOOT_ORDER) |
| 893 | { |
| 894 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 895 | "Invalid Boot order length received"); |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 896 | return ipmi::responseReqDataLenInvalid(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 899 | std::copy(std::begin(data), std::end(data), bootSeq); |
Jayashree Dhanapal | 4ec8056 | 2022-06-28 15:41:47 +0530 | [diff] [blame] | 900 | std::optional<size_t> hostId = findHost(ctx->hostIdx); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 901 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 902 | if (!hostId) |
| 903 | { |
| 904 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 905 | "Invalid Host Id received"); |
| 906 | return ipmi::responseInvalidCommand(); |
| 907 | } |
| 908 | auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId); |
| 909 | |
| 910 | setBootOrder(bootObjPath, bootSeq, hostName); |
| 911 | |
| 912 | return ipmi::responseSuccess(data); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | //---------------------------------------------------------------------- |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 916 | // Get Boot Order (CMD_OEM_GET_BOOT_ORDER) |
| 917 | //---------------------------------------------------------------------- |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 918 | ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t> |
| 919 | ipmiOemGetBootOrder(ipmi::Context::ptr ctx) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 920 | { |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 921 | uint8_t bootSeq[SIZE_BOOT_ORDER]; |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 922 | uint8_t mode = 0; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 923 | |
Jayashree Dhanapal | 4ec8056 | 2022-06-28 15:41:47 +0530 | [diff] [blame] | 924 | std::optional<size_t> hostId = findHost(ctx->hostIdx); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 925 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 926 | if (!hostId) |
| 927 | { |
| 928 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 929 | "Invalid Host Id received"); |
| 930 | return ipmi::responseInvalidCommand(); |
| 931 | } |
| 932 | auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId); |
| 933 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 934 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 935 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 936 | // GETTING PROPERTY OF MODE INTERFACE |
| 937 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 938 | std::string service = |
| 939 | getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath); |
| 940 | Value variant = |
| 941 | getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf, |
| 942 | ipmi::boot::bootModeProp); |
| 943 | |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 944 | auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>( |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 945 | std::get<std::string>(variant)); |
| 946 | |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 947 | uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode); |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 948 | |
| 949 | // GETTING PROPERTY OF SOURCE INTERFACE |
| 950 | |
| 951 | service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath); |
| 952 | variant = |
| 953 | getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf, |
| 954 | ipmi::boot::bootSourceProp); |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 955 | |
| 956 | auto bootSource = sdbusplus::message::convert_from_string<boot::BootSource>( |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 957 | std::get<std::string>(variant)); |
| 958 | |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 959 | uint8_t bootOrder = ipmi::boot::sourceDbusToIpmi.at(bootSource); |
| 960 | |
| 961 | // GETTING PROPERTY OF TYPE INTERFACE |
| 962 | |
| 963 | service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath); |
| 964 | variant = |
| 965 | getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf, |
| 966 | ipmi::boot::bootTypeProp); |
Jayashree Dhanapal | 77ee489 | 2022-04-08 16:53:51 +0530 | [diff] [blame] | 967 | |
| 968 | auto bootType = sdbusplus::message::convert_from_string<boot::BootType>( |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 969 | std::get<std::string>(variant)); |
| 970 | |
| 971 | uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType); |
| 972 | |
| 973 | uint8_t bootVal = bootOption | bootTypeVal; |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 974 | |
| 975 | if (oemData.find(hostName) == oemData.end()) |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 976 | { |
| 977 | /* Return default boot order 0100090203ff */ |
| 978 | uint8_t defaultBoot[SIZE_BOOT_ORDER] = { |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 979 | BOOT_MODE_UEFI, |
| 980 | static_cast<uint8_t>(bootMap["USB_DEV"]), |
| 981 | static_cast<uint8_t>(bootMap["NET_IPV6"]), |
| 982 | static_cast<uint8_t>(bootMap["SATA_HDD"]), |
| 983 | static_cast<uint8_t>(bootMap["SATA_CD"]), |
| 984 | 0xff}; |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 985 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 986 | memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER); |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 987 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 988 | "Set default boot order"); |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 989 | setBootOrder(bootObjPath, defaultBoot, hostName); |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 990 | } |
| 991 | else |
| 992 | { |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 993 | nlohmann::json bootMode = oemData[hostName][KEY_BOOT_MODE]; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 994 | if (bootMode["UEFI"]) |
| 995 | mode |= BOOT_MODE_UEFI; |
| 996 | if (bootMode["CMOS_CLR"]) |
| 997 | mode |= BOOT_MODE_CMOS_CLR; |
| 998 | if (bootMode["BOOT_FLAG"]) |
| 999 | mode |= BOOT_MODE_BOOT_FLAG; |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1000 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 1001 | bootSeq[0] = mode; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 1002 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 1003 | for (int i = 1; i < SIZE_BOOT_ORDER; i++) |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 1004 | { |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 1005 | std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1]; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 1006 | if (bootMap.find(seqStr) != bootMap.end()) |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 1007 | bootSeq[i] = bootMap[seqStr]; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 1008 | else |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 1009 | bootSeq[i] = 0xff; |
Vijay Khemka | 877d5dd | 2019-12-16 14:46:21 -0800 | [diff] [blame] | 1010 | } |
| 1011 | } |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1012 | |
Jayashree Dhanapal | 778147d | 2022-03-30 16:48:53 +0530 | [diff] [blame] | 1013 | return ipmi::responseSuccess(bootVal, bootOrder, bootSeq[2], bootSeq[3], |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 1014 | bootSeq[4], bootSeq[5]); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1015 | } |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1016 | // Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO) |
| 1017 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1018 | ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t, ipmi_cmd_t, |
| 1019 | ipmi_request_t request, ipmi_response_t, |
| 1020 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1021 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1022 | machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1023 | uint8_t len = *data_len; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1024 | |
| 1025 | *data_len = 0; |
| 1026 | |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1027 | if (len < sizeof(machineConfigInfo_t)) |
| 1028 | { |
| 1029 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1030 | "Invalid machine configuration length received"); |
| 1031 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1032 | } |
| 1033 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1034 | if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*)) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1035 | oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN"; |
| 1036 | else |
| 1037 | oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = |
| 1038 | chassisType[req->chassis_type]; |
| 1039 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1040 | if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*)) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1041 | oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN"; |
| 1042 | else |
| 1043 | oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type]; |
| 1044 | |
| 1045 | oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt; |
| 1046 | oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt; |
| 1047 | oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt; |
| 1048 | oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt; |
| 1049 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1050 | if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*)) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1051 | oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN"; |
| 1052 | else |
| 1053 | oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type]; |
| 1054 | |
| 1055 | oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {}; |
| 1056 | int i = 0; |
| 1057 | if (req->pcie_card_loc & BIT_0) |
| 1058 | oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1"; |
| 1059 | if (req->pcie_card_loc & BIT_1) |
| 1060 | oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2"; |
| 1061 | if (req->pcie_card_loc & BIT_2) |
| 1062 | oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3"; |
| 1063 | if (req->pcie_card_loc & BIT_3) |
| 1064 | oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4"; |
| 1065 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1066 | if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*)) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1067 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN"; |
| 1068 | else |
| 1069 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = |
| 1070 | pcieType[req->slot1_pcie_type]; |
| 1071 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1072 | if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*)) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1073 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN"; |
| 1074 | else |
| 1075 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = |
| 1076 | pcieType[req->slot2_pcie_type]; |
| 1077 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1078 | if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*)) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1079 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN"; |
| 1080 | else |
| 1081 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = |
| 1082 | pcieType[req->slot3_pcie_type]; |
| 1083 | |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1084 | if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*)) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1085 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN"; |
| 1086 | else |
| 1087 | oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = |
| 1088 | pcieType[req->slot4_pcie_type]; |
| 1089 | |
| 1090 | oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt; |
| 1091 | |
| 1092 | flushOemData(); |
| 1093 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1094 | return IPMI_CC_OK; |
| 1095 | } |
| 1096 | |
| 1097 | //---------------------------------------------------------------------- |
| 1098 | // Set POST start (CMD_OEM_SET_POST_START) |
| 1099 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1100 | ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, |
| 1101 | ipmi_response_t, ipmi_data_len_t data_len, |
| 1102 | ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1103 | { |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1104 | phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event"); |
| 1105 | |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1106 | /* Do nothing, return success */ |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1107 | *data_len = 0; |
| 1108 | return IPMI_CC_OK; |
| 1109 | } |
| 1110 | |
| 1111 | //---------------------------------------------------------------------- |
| 1112 | // Set POST End (CMD_OEM_SET_POST_END) |
| 1113 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1114 | ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, |
| 1115 | ipmi_response_t, ipmi_data_len_t data_len, |
| 1116 | ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1117 | { |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1118 | struct timespec ts; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1119 | |
| 1120 | phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event"); |
| 1121 | |
| 1122 | *data_len = 0; |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1123 | |
| 1124 | // Timestamp post end time. |
| 1125 | clock_gettime(CLOCK_REALTIME, &ts); |
| 1126 | oemData[KEY_TS_SLED] = ts.tv_sec; |
| 1127 | flushOemData(); |
| 1128 | |
| 1129 | // Sync time with system |
| 1130 | // TODO: Add code for syncing time |
| 1131 | |
| 1132 | return IPMI_CC_OK; |
| 1133 | } |
| 1134 | |
| 1135 | //---------------------------------------------------------------------- |
| 1136 | // Set PPIN Info (CMD_OEM_SET_PPIN_INFO) |
| 1137 | //---------------------------------------------------------------------- |
| 1138 | // Inform BMC about PPIN data of 8 bytes for each CPU |
| 1139 | // |
| 1140 | // Request: |
| 1141 | // Byte 1:8 – CPU0 PPIN data |
| 1142 | // Optional: |
| 1143 | // Byte 9:16 – CPU1 PPIN data |
| 1144 | // |
| 1145 | // Response: |
| 1146 | // Byte 1 – Completion Code |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1147 | ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, |
| 1148 | ipmi_response_t, ipmi_data_len_t data_len, |
| 1149 | ipmi_context_t) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1150 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1151 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1152 | std::string ppinStr; |
| 1153 | int len; |
| 1154 | |
| 1155 | if (*data_len > SIZE_CPU_PPIN * 2) |
| 1156 | len = SIZE_CPU_PPIN * 2; |
| 1157 | else |
| 1158 | len = *data_len; |
| 1159 | *data_len = 0; |
| 1160 | |
| 1161 | ppinStr = bytesToStr(req, len); |
| 1162 | oemData[KEY_PPIN_INFO] = ppinStr.c_str(); |
| 1163 | flushOemData(); |
| 1164 | |
| 1165 | return IPMI_CC_OK; |
| 1166 | } |
| 1167 | |
| 1168 | //---------------------------------------------------------------------- |
| 1169 | // Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER) |
| 1170 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1171 | ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, |
| 1172 | ipmi_response_t, ipmi_data_len_t data_len, |
| 1173 | ipmi_context_t) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1174 | { |
| 1175 | /* Do nothing, return success */ |
| 1176 | *data_len = 0; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1177 | return IPMI_CC_OK; |
| 1178 | } |
| 1179 | |
Vijay Khemka | f2246ce | 2020-05-27 14:26:35 -0700 | [diff] [blame] | 1180 | // Helper function to set guid at offset in EEPROM |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1181 | [[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid) |
Vijay Khemka | f2246ce | 2020-05-27 14:26:35 -0700 | [diff] [blame] | 1182 | { |
| 1183 | int fd = -1; |
| 1184 | ssize_t len; |
| 1185 | int ret = 0; |
| 1186 | |
| 1187 | errno = 0; |
| 1188 | |
| 1189 | // Check if file is present |
| 1190 | if (access(FRU_EEPROM, F_OK) == -1) |
| 1191 | { |
| 1192 | std::cerr << "Unable to access: " << FRU_EEPROM << std::endl; |
| 1193 | return errno; |
| 1194 | } |
| 1195 | |
| 1196 | // Open the file |
| 1197 | fd = open(FRU_EEPROM, O_WRONLY); |
| 1198 | if (fd == -1) |
| 1199 | { |
| 1200 | std::cerr << "Unable to open: " << FRU_EEPROM << std::endl; |
| 1201 | return errno; |
| 1202 | } |
| 1203 | |
| 1204 | // seek to the offset |
| 1205 | lseek(fd, offset, SEEK_SET); |
| 1206 | |
| 1207 | // Write bytes to location |
| 1208 | len = write(fd, guid, GUID_SIZE); |
| 1209 | if (len != GUID_SIZE) |
| 1210 | { |
| 1211 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1212 | "GUID write data to EEPROM failed"); |
| 1213 | ret = errno; |
| 1214 | } |
| 1215 | |
| 1216 | close(fd); |
| 1217 | return ret; |
| 1218 | } |
| 1219 | |
| 1220 | //---------------------------------------------------------------------- |
| 1221 | // Set System GUID (CMD_OEM_SET_SYSTEM_GUID) |
| 1222 | //---------------------------------------------------------------------- |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 1223 | #if BIC_ENABLED |
Bonnie Lo | 3f67127 | 2022-10-12 15:46:45 +0800 | [diff] [blame] | 1224 | ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx, |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 1225 | std::vector<uint8_t> reqData) |
| 1226 | { |
| 1227 | std::vector<uint8_t> respData; |
| 1228 | |
| 1229 | if (reqData.size() != GUID_SIZE) // 16bytes |
| 1230 | { |
| 1231 | |
| 1232 | return ipmi::responseReqDataLenInvalid(); |
| 1233 | } |
| 1234 | |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 1235 | uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2; |
| 1236 | |
| 1237 | if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData)) |
| 1238 | return ipmi::responseUnspecifiedError(); |
| 1239 | |
| 1240 | return ipmi::responseSuccess(); |
| 1241 | } |
| 1242 | |
| 1243 | #else |
Potin Lai | d5353ca | 2022-08-11 04:52:11 +0000 | [diff] [blame] | 1244 | ipmi_ret_t ipmiOemSetSystemGuid(ipmi_netfn_t, ipmi_cmd_t, |
| 1245 | ipmi_request_t request, ipmi_response_t, |
| 1246 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | f2246ce | 2020-05-27 14:26:35 -0700 | [diff] [blame] | 1247 | { |
| 1248 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 1249 | |
| 1250 | if (*data_len != GUID_SIZE) // 16bytes |
| 1251 | { |
| 1252 | *data_len = 0; |
| 1253 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1254 | } |
| 1255 | |
| 1256 | *data_len = 0; |
| 1257 | |
| 1258 | if (setGUID(OFFSET_SYS_GUID, req)) |
| 1259 | { |
| 1260 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1261 | } |
| 1262 | return IPMI_CC_OK; |
| 1263 | } |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 1264 | #endif |
Vijay Khemka | f2246ce | 2020-05-27 14:26:35 -0700 | [diff] [blame] | 1265 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1266 | //---------------------------------------------------------------------- |
| 1267 | // Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO) |
| 1268 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1269 | ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t, |
| 1270 | ipmi_response_t, ipmi_data_len_t data_len, |
| 1271 | ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1272 | { |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1273 | /* Do nothing, return success */ |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1274 | *data_len = 0; |
| 1275 | return IPMI_CC_OK; |
| 1276 | } |
| 1277 | |
| 1278 | //---------------------------------------------------------------------- |
| 1279 | // Set PPR (CMD_OEM_SET_PPR) |
| 1280 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1281 | ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, |
| 1282 | ipmi_response_t, ipmi_data_len_t data_len, |
| 1283 | ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1284 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1285 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1286 | uint8_t pprCnt, pprAct, pprIndex; |
| 1287 | uint8_t selParam = req[0]; |
| 1288 | uint8_t len = *data_len; |
| 1289 | std::stringstream ss; |
| 1290 | std::string str; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1291 | |
| 1292 | *data_len = 0; |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1293 | |
| 1294 | switch (selParam) |
| 1295 | { |
| 1296 | case PPR_ACTION: |
| 1297 | if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) == |
| 1298 | oemData[KEY_PPR].end()) |
| 1299 | return CC_PARAM_NOT_SUPP_IN_CURR_STATE; |
| 1300 | |
| 1301 | pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT]; |
| 1302 | if (pprCnt == 0) |
| 1303 | return CC_PARAM_NOT_SUPP_IN_CURR_STATE; |
| 1304 | |
| 1305 | pprAct = req[1]; |
| 1306 | /* Check if ppr is enabled or disabled */ |
| 1307 | if (!(pprAct & 0x80)) |
| 1308 | pprAct = 0; |
| 1309 | |
| 1310 | oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct; |
| 1311 | break; |
| 1312 | case PPR_ROW_COUNT: |
| 1313 | if (req[1] > 100) |
| 1314 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1315 | |
| 1316 | oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1]; |
| 1317 | break; |
| 1318 | case PPR_ROW_ADDR: |
| 1319 | pprIndex = req[1]; |
| 1320 | if (pprIndex > 100) |
| 1321 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1322 | |
| 1323 | if (len < PPR_ROW_ADDR_LEN + 1) |
| 1324 | { |
| 1325 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1326 | "Invalid PPR Row Address length received"); |
| 1327 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1328 | } |
| 1329 | |
| 1330 | ss << std::hex; |
| 1331 | ss << std::setw(2) << std::setfill('0') << (int)pprIndex; |
| 1332 | |
| 1333 | oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex; |
| 1334 | |
| 1335 | str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN); |
| 1336 | oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str(); |
| 1337 | break; |
| 1338 | case PPR_HISTORY_DATA: |
| 1339 | pprIndex = req[1]; |
| 1340 | if (pprIndex > 100) |
| 1341 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1342 | |
| 1343 | if (len < PPR_HST_DATA_LEN + 1) |
| 1344 | { |
| 1345 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1346 | "Invalid PPR history data length received"); |
| 1347 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1348 | } |
| 1349 | |
| 1350 | ss << std::hex; |
| 1351 | ss << std::setw(2) << std::setfill('0') << (int)pprIndex; |
| 1352 | |
| 1353 | oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex; |
| 1354 | |
| 1355 | str = bytesToStr(&req[1], PPR_HST_DATA_LEN); |
| 1356 | oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str(); |
| 1357 | break; |
| 1358 | default: |
| 1359 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1360 | break; |
| 1361 | } |
| 1362 | |
| 1363 | flushOemData(); |
| 1364 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1365 | return IPMI_CC_OK; |
| 1366 | } |
| 1367 | |
| 1368 | //---------------------------------------------------------------------- |
| 1369 | // Get PPR (CMD_OEM_GET_PPR) |
| 1370 | //---------------------------------------------------------------------- |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1371 | ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, |
| 1372 | ipmi_response_t response, ipmi_data_len_t data_len, |
| 1373 | ipmi_context_t) |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1374 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1375 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
| 1376 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1377 | uint8_t pprCnt, pprIndex; |
| 1378 | uint8_t selParam = req[0]; |
| 1379 | std::stringstream ss; |
| 1380 | std::string str; |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1381 | |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1382 | /* Any failure will return zero length data */ |
| 1383 | *data_len = 0; |
| 1384 | |
| 1385 | switch (selParam) |
| 1386 | { |
| 1387 | case PPR_ACTION: |
| 1388 | res[0] = 0; |
| 1389 | *data_len = 1; |
| 1390 | |
| 1391 | if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) != |
| 1392 | oemData[KEY_PPR].end()) |
| 1393 | { |
| 1394 | pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT]; |
| 1395 | if (pprCnt != 0) |
| 1396 | { |
| 1397 | if (oemData[KEY_PPR].find(KEY_PPR_ACTION) != |
| 1398 | oemData[KEY_PPR].end()) |
| 1399 | { |
| 1400 | res[0] = oemData[KEY_PPR][KEY_PPR_ACTION]; |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | break; |
| 1405 | case PPR_ROW_COUNT: |
| 1406 | res[0] = 0; |
| 1407 | *data_len = 1; |
| 1408 | if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) != |
| 1409 | oemData[KEY_PPR].end()) |
| 1410 | res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT]; |
| 1411 | break; |
| 1412 | case PPR_ROW_ADDR: |
| 1413 | pprIndex = req[1]; |
| 1414 | if (pprIndex > 100) |
| 1415 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1416 | |
| 1417 | ss << std::hex; |
| 1418 | ss << std::setw(2) << std::setfill('0') << (int)pprIndex; |
| 1419 | |
| 1420 | if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end()) |
| 1421 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1422 | |
| 1423 | if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) == |
| 1424 | oemData[KEY_PPR][ss.str()].end()) |
| 1425 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1426 | |
| 1427 | str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR]; |
| 1428 | *data_len = strToBytes(str, res); |
| 1429 | break; |
| 1430 | case PPR_HISTORY_DATA: |
| 1431 | pprIndex = req[1]; |
| 1432 | if (pprIndex > 100) |
| 1433 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1434 | |
| 1435 | ss << std::hex; |
| 1436 | ss << std::setw(2) << std::setfill('0') << (int)pprIndex; |
| 1437 | |
| 1438 | if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end()) |
| 1439 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1440 | |
| 1441 | if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) == |
| 1442 | oemData[KEY_PPR][ss.str()].end()) |
| 1443 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1444 | |
| 1445 | str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA]; |
| 1446 | *data_len = strToBytes(str, res); |
| 1447 | break; |
| 1448 | default: |
| 1449 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1450 | break; |
| 1451 | } |
| 1452 | |
| 1453 | return IPMI_CC_OK; |
| 1454 | } |
| 1455 | |
| 1456 | /* FB OEM QC Commands */ |
| 1457 | |
| 1458 | //---------------------------------------------------------------------- |
| 1459 | // Set Proc Info (CMD_OEM_Q_SET_PROC_INFO) |
| 1460 | //---------------------------------------------------------------------- |
| 1461 | //"Request: |
| 1462 | // Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first |
| 1463 | // Byte 4 – Processor Index, 0 base |
| 1464 | // Byte 5 – Parameter Selector |
| 1465 | // Byte 6..N – Configuration parameter data (see below for Parameters |
| 1466 | // of Processor Information) |
| 1467 | // Response: |
| 1468 | // Byte 1 – Completion code |
| 1469 | // |
| 1470 | // Parameter#1: (Processor Product Name) |
| 1471 | // |
| 1472 | // Byte 1..48 –Product name(ASCII code) |
| 1473 | // Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz |
| 1474 | // |
| 1475 | // Param#2: Processor Basic Information |
| 1476 | // Byte 1 – Core Number |
| 1477 | // Byte 2 – Thread Number (LSB) |
| 1478 | // Byte 3 – Thread Number (MSB) |
| 1479 | // Byte 4 – Processor frequency in MHz (LSB) |
| 1480 | // Byte 5 – Processor frequency in MHz (MSB) |
| 1481 | // Byte 6..7 – Revision |
| 1482 | // |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1483 | |
| 1484 | ipmi::RspType<> ipmiOemQSetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, |
| 1485 | uint8_t, uint8_t procIndex, |
| 1486 | uint8_t paramSel, |
| 1487 | std::vector<uint8_t> request) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1488 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1489 | uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1490 | std::stringstream ss; |
| 1491 | std::string str; |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1492 | uint8_t len = request.size(); |
| 1493 | auto hostId = findHost(ctx->hostIdx); |
| 1494 | if (!hostId) |
| 1495 | { |
| 1496 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1497 | "Invalid Host Id received"); |
| 1498 | return ipmi::responseInvalidCommand(); |
| 1499 | } |
| 1500 | std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1501 | /* check for requested data params */ |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1502 | if (len < 5 || paramSel < 1 || paramSel >= numParam) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1503 | { |
| 1504 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1505 | "Invalid parameter received"); |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1506 | return ipmi::responseParmOutOfRange(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1507 | } |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1508 | ss << std::hex; |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1509 | ss << std::setw(2) << std::setfill('0') << (int)procIndex; |
| 1510 | oemData[procInfo][ss.str()][KEY_PROC_INDEX] = procIndex; |
| 1511 | str = bytesToStr(request.data(), len); |
| 1512 | oemData[procInfo][ss.str()][cpuInfoKey[paramSel]] = str.c_str(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1513 | flushOemData(); |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1514 | return ipmi::responseSuccess(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | //---------------------------------------------------------------------- |
| 1518 | // Get Proc Info (CMD_OEM_Q_GET_PROC_INFO) |
| 1519 | //---------------------------------------------------------------------- |
| 1520 | // Request: |
| 1521 | // Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first |
| 1522 | // Byte 4 – Processor Index, 0 base |
| 1523 | // Byte 5 – Parameter Selector |
| 1524 | // Response: |
| 1525 | // Byte 1 – Completion code |
| 1526 | // Byte 2..N – Configuration Parameter Data (see below for Parameters |
| 1527 | // of Processor Information) |
| 1528 | // |
| 1529 | // Parameter#1: (Processor Product Name) |
| 1530 | // |
| 1531 | // Byte 1..48 –Product name(ASCII code) |
| 1532 | // Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz |
| 1533 | // |
| 1534 | // Param#2: Processor Basic Information |
| 1535 | // Byte 1 – Core Number |
| 1536 | // Byte 2 – Thread Number (LSB) |
| 1537 | // Byte 3 – Thread Number (MSB) |
| 1538 | // Byte 4 – Processor frequency in MHz (LSB) |
| 1539 | // Byte 5 – Processor frequency in MHz (MSB) |
| 1540 | // Byte 6..7 – Revision |
| 1541 | // |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1542 | |
| 1543 | ipmi::RspType<std::vector<uint8_t>> |
| 1544 | ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t, |
| 1545 | uint8_t procIndex, uint8_t paramSel) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1546 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1547 | uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1548 | std::stringstream ss; |
| 1549 | std::string str; |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1550 | uint8_t res[MAX_BUF]; |
| 1551 | auto hostId = findHost(ctx->hostIdx); |
| 1552 | if (!hostId) |
| 1553 | { |
| 1554 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1555 | "Invalid Host Id received"); |
| 1556 | return ipmi::responseInvalidCommand(); |
| 1557 | } |
| 1558 | std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId); |
| 1559 | if (paramSel < 1 || paramSel >= numParam) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1560 | { |
| 1561 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1562 | "Invalid parameter received"); |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1563 | return ipmi::responseParmOutOfRange(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1564 | } |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1565 | ss << std::hex; |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 1566 | ss << std::setw(2) << std::setfill('0') << (int)procIndex; |
| 1567 | if (oemData[procInfo].find(ss.str()) == oemData[procInfo].end()) |
| 1568 | return ipmi::responseCommandNotAvailable(); |
| 1569 | if (oemData[procInfo][ss.str()].find(cpuInfoKey[paramSel]) == |
| 1570 | oemData[procInfo][ss.str()].end()) |
| 1571 | return ipmi::responseCommandNotAvailable(); |
| 1572 | str = oemData[procInfo][ss.str()][cpuInfoKey[paramSel]]; |
| 1573 | int dataLen = strToBytes(str, res); |
| 1574 | std::vector<uint8_t> response(&res[0], &res[dataLen]); |
| 1575 | return ipmi::responseSuccess(response); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | //---------------------------------------------------------------------- |
| 1579 | // Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO) |
| 1580 | //---------------------------------------------------------------------- |
| 1581 | // Request: |
| 1582 | // Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first |
| 1583 | // Byte 4 – DIMM Index, 0 base |
| 1584 | // Byte 5 – Parameter Selector |
| 1585 | // Byte 6..N – Configuration parameter data (see below for Parameters |
| 1586 | // of DIMM Information) |
| 1587 | // Response: |
| 1588 | // Byte 1 – Completion code |
| 1589 | // |
| 1590 | // Param#1 (DIMM Location): |
| 1591 | // Byte 1 – DIMM Present |
| 1592 | // Byte 1 – DIMM Present |
| 1593 | // 01h – Present |
| 1594 | // FFh – Not Present |
| 1595 | // Byte 2 – Node Number, 0 base |
| 1596 | // Byte 3 – Channel Number , 0 base |
| 1597 | // Byte 4 – DIMM Number , 0 base |
| 1598 | // |
| 1599 | // Param#2 (DIMM Type): |
| 1600 | // Byte 1 – DIMM Type |
| 1601 | // Bit [7:6] |
| 1602 | // For DDR3 |
| 1603 | // 00 – Normal Voltage (1.5V) |
| 1604 | // 01 – Ultra Low Voltage (1.25V) |
| 1605 | // 10 – Low Voltage (1.35V) |
| 1606 | // 11 – Reserved |
| 1607 | // For DDR4 |
| 1608 | // 00 – Reserved |
| 1609 | // 01 – Reserved |
| 1610 | // 10 – Reserved |
| 1611 | // 11 – Normal Voltage (1.2V) |
| 1612 | // Bit [5:0] |
| 1613 | // 0x00 – SDRAM |
| 1614 | // 0x01 – DDR-1 RAM |
| 1615 | // 0x02 – Rambus |
| 1616 | // 0x03 – DDR-2 RAM |
| 1617 | // 0x04 – FBDIMM |
| 1618 | // 0x05 – DDR-3 RAM |
| 1619 | // 0x06 – DDR-4 RAM |
| 1620 | // |
| 1621 | // Param#3 (DIMM Speed): |
| 1622 | // Byte 1..2 – DIMM speed in MHz, LSB |
| 1623 | // Byte 3..6 – DIMM size in Mbytes, LSB |
| 1624 | // |
| 1625 | // Param#4 (Module Part Number): |
| 1626 | // Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C) |
| 1627 | // |
| 1628 | // Param#5 (Module Serial Number): |
| 1629 | // Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C) |
| 1630 | // |
| 1631 | // Param#6 (Module Manufacturer ID): |
| 1632 | // Byte 1 - Module Manufacturer ID, LSB |
| 1633 | // Byte 2 - Module Manufacturer ID, MSB |
| 1634 | // |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1635 | ipmi::RspType<> ipmiOemQSetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, |
| 1636 | uint8_t, uint8_t dimmIndex, |
| 1637 | uint8_t paramSel, |
| 1638 | std::vector<uint8_t> request) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1639 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1640 | uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1641 | std::stringstream ss; |
| 1642 | std::string str; |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1643 | uint8_t len = request.size(); |
| 1644 | std::string dimmType; |
| 1645 | readDimmType(dimmType, dimmIndex); |
Patrick Williams | 6d9e9a7 | 2022-07-18 10:30:50 -0500 | [diff] [blame] | 1646 | auto hostId = findHost(ctx->hostIdx); |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1647 | if (!hostId) |
| 1648 | { |
| 1649 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1650 | "Invalid Host Id received"); |
| 1651 | return ipmi::responseInvalidCommand(); |
| 1652 | } |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1653 | |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1654 | std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1655 | |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1656 | if (len < 3 || paramSel < 1 || paramSel >= numParam) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1657 | { |
| 1658 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1659 | "Invalid parameter received"); |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1660 | return ipmi::responseParmOutOfRange(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1663 | ss << std::hex; |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1664 | ss << (int)dimmIndex; |
| 1665 | oemData[dimmInfo][ss.str()][KEY_DIMM_INDEX] = dimmIndex; |
| 1666 | oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType; |
| 1667 | str = bytesToStr(request.data(), len); |
| 1668 | oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]] = str.c_str(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1669 | flushOemData(); |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1670 | return ipmi::responseSuccess(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1673 | // Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO) |
| 1674 | //---------------------------------------------------------------------- |
| 1675 | // Request: |
| 1676 | // Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first |
| 1677 | // Byte 4 – DIMM Index, 0 base |
| 1678 | // Byte 5 – Parameter Selector |
| 1679 | // Byte 6..N – Configuration parameter data (see below for Parameters |
| 1680 | // of DIMM Information) |
| 1681 | // Response: |
| 1682 | // Byte 1 – Completion code |
| 1683 | // Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters |
| 1684 | // of DIMM Information) |
| 1685 | // |
| 1686 | // Param#1 (DIMM Location): |
| 1687 | // Byte 1 – DIMM Present |
| 1688 | // Byte 1 – DIMM Present |
| 1689 | // 01h – Present |
| 1690 | // FFh – Not Present |
| 1691 | // Byte 2 – Node Number, 0 base |
| 1692 | // Byte 3 – Channel Number , 0 base |
| 1693 | // Byte 4 – DIMM Number , 0 base |
| 1694 | // |
| 1695 | // Param#2 (DIMM Type): |
| 1696 | // Byte 1 – DIMM Type |
| 1697 | // Bit [7:6] |
| 1698 | // For DDR3 |
| 1699 | // 00 – Normal Voltage (1.5V) |
| 1700 | // 01 – Ultra Low Voltage (1.25V) |
| 1701 | // 10 – Low Voltage (1.35V) |
| 1702 | // 11 – Reserved |
| 1703 | // For DDR4 |
| 1704 | // 00 – Reserved |
| 1705 | // 01 – Reserved |
| 1706 | // 10 – Reserved |
| 1707 | // 11 – Normal Voltage (1.2V) |
| 1708 | // Bit [5:0] |
| 1709 | // 0x00 – SDRAM |
| 1710 | // 0x01 – DDR-1 RAM |
| 1711 | // 0x02 – Rambus |
| 1712 | // 0x03 – DDR-2 RAM |
| 1713 | // 0x04 – FBDIMM |
| 1714 | // 0x05 – DDR-3 RAM |
| 1715 | // 0x06 – DDR-4 RAM |
| 1716 | // |
| 1717 | // Param#3 (DIMM Speed): |
| 1718 | // Byte 1..2 – DIMM speed in MHz, LSB |
| 1719 | // Byte 3..6 – DIMM size in Mbytes, LSB |
| 1720 | // |
| 1721 | // Param#4 (Module Part Number): |
| 1722 | // Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C) |
| 1723 | // |
| 1724 | // Param#5 (Module Serial Number): |
| 1725 | // Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C) |
| 1726 | // |
| 1727 | // Param#6 (Module Manufacturer ID): |
| 1728 | // Byte 1 - Module Manufacturer ID, LSB |
| 1729 | // Byte 2 - Module Manufacturer ID, MSB |
| 1730 | // |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1731 | ipmi::RspType<std::vector<uint8_t>> |
| 1732 | ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t, |
| 1733 | uint8_t dimmIndex, uint8_t paramSel) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1734 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1735 | uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*); |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1736 | uint8_t res[MAX_BUF]; |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1737 | std::stringstream ss; |
| 1738 | std::string str; |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1739 | std::string dimmType; |
| 1740 | readDimmType(dimmType, dimmIndex); |
Patrick Williams | 6d9e9a7 | 2022-07-18 10:30:50 -0500 | [diff] [blame] | 1741 | auto hostId = findHost(ctx->hostIdx); |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1742 | if (!hostId) |
| 1743 | { |
| 1744 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1745 | "Invalid Host Id received"); |
| 1746 | return ipmi::responseInvalidCommand(); |
| 1747 | } |
| 1748 | std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1749 | |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1750 | if (paramSel < 1 || paramSel >= numParam) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1751 | { |
| 1752 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1753 | "Invalid parameter received"); |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1754 | return ipmi::responseParmOutOfRange(); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1755 | } |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1756 | ss << std::hex; |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 1757 | ss << (int)dimmIndex; |
| 1758 | oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType; |
| 1759 | if (oemData[dimmInfo].find(ss.str()) == oemData[dimmInfo].end()) |
| 1760 | return ipmi::responseCommandNotAvailable(); |
| 1761 | if (oemData[dimmInfo][ss.str()].find(dimmInfoKey[paramSel]) == |
| 1762 | oemData[dimmInfo][ss.str()].end()) |
| 1763 | return ipmi::responseCommandNotAvailable(); |
| 1764 | str = oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]]; |
| 1765 | int data_length = strToBytes(str, res); |
| 1766 | std::vector<uint8_t> response(&res[0], &res[data_length]); |
| 1767 | return ipmi::responseSuccess(response); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | //---------------------------------------------------------------------- |
| 1771 | // Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO) |
| 1772 | //---------------------------------------------------------------------- |
| 1773 | // BIOS issue this command to provide HDD information to BMC. |
| 1774 | // |
| 1775 | // BIOS just can get information by standard ATA / SMART command for |
| 1776 | // OB SATA controller. |
| 1777 | // BIOS can get |
| 1778 | // 1. Serial Number |
| 1779 | // 2. Model Name |
| 1780 | // 3. HDD FW Version |
| 1781 | // 4. HDD Capacity |
| 1782 | // 5. HDD WWN |
| 1783 | // |
| 1784 | // Use Get HDD info Param #5 to know the MAX HDD info index. |
| 1785 | // |
| 1786 | // Request: |
| 1787 | // Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first |
| 1788 | // Byte 4 – |
| 1789 | // [7:4] Reserved |
| 1790 | // [3:0] HDD Controller Type |
| 1791 | // 0x00 – BIOS |
| 1792 | // 0x01 – Expander |
| 1793 | // 0x02 – LSI |
| 1794 | // Byte 5 – HDD Info Index, 0 base |
| 1795 | // Byte 6 – Parameter Selector |
| 1796 | // Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD |
| 1797 | // Information) |
| 1798 | // |
| 1799 | // Response: |
| 1800 | // Byte 1 – Completion Code |
| 1801 | // |
| 1802 | // Param#0 (HDD Location): |
| 1803 | // Byte 1 – Controller |
| 1804 | // [7:3] Device Number |
| 1805 | // [2:0] Function Number |
| 1806 | // For Intel C610 series (Wellsburg) |
| 1807 | // D31:F2 (0xFA) – SATA control 1 |
| 1808 | // D31:F5 (0xFD) – SATA control 2 |
| 1809 | // D17:F4 (0x8C) – sSata control |
| 1810 | // Byte 2 – Port Number |
| 1811 | // Byte 3 – Location (0xFF: No HDD Present) |
| 1812 | // BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param |
| 1813 | // #1~4, #6, #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if |
| 1814 | // the HDD present. BMC or other people who know the HDD location has |
| 1815 | // responsibility for update Location info |
| 1816 | // |
| 1817 | // Param#1 (Serial Number): |
| 1818 | // Bytes 1..33: HDD Serial Number |
| 1819 | // |
| 1820 | // Param#2 (Model Name): |
| 1821 | // Byte 1..33 – HDD Model Name |
| 1822 | // |
| 1823 | // Param#3 (HDD FW Version): |
| 1824 | // Byte 1..17 –HDD FW version |
| 1825 | // |
| 1826 | // Param#4 (Capacity): |
| 1827 | // Byte 1..4 –HDD Block Size, LSB |
| 1828 | // Byte 5..12 - HDD Block Number, LSB |
| 1829 | // HDD Capacity = HDD Block size * HDD BLock number (Unit Byte) |
| 1830 | // |
| 1831 | // Param#5 (Max HDD Quantity): |
| 1832 | // Byte 1 - Max HDD Quantity |
| 1833 | // Max supported port numbers in this PCH |
| 1834 | // |
| 1835 | // Param#6 (HDD Type) |
| 1836 | // Byte 1 – HDD Type |
| 1837 | // 0h – Reserved |
| 1838 | // 1h – SAS |
| 1839 | // 2h – SATA |
| 1840 | // 3h – PCIE SSD (NVME) |
| 1841 | // |
| 1842 | // Param#7 (HDD WWN) |
| 1843 | // Data 1...8: HDD World Wide Name, LSB |
| 1844 | // |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1845 | ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t, ipmi_cmd_t, |
| 1846 | ipmi_request_t request, ipmi_response_t, |
| 1847 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1848 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1849 | qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request); |
| 1850 | uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1851 | uint8_t ctrlType = req->hddCtrlType & 0x0f; |
| 1852 | std::stringstream ss; |
| 1853 | std::string str; |
| 1854 | uint8_t len = *data_len; |
| 1855 | |
| 1856 | *data_len = 0; |
| 1857 | |
| 1858 | /* check for requested data params */ |
| 1859 | if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam || |
| 1860 | ctrlType > 2) |
| 1861 | { |
| 1862 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1863 | "Invalid parameter received"); |
| 1864 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1865 | } |
| 1866 | |
| 1867 | len = len - 6; // Get Actual data length |
| 1868 | |
| 1869 | ss << std::hex; |
| 1870 | ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex; |
| 1871 | oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType; |
| 1872 | oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] = |
| 1873 | req->hddIndex; |
| 1874 | |
| 1875 | str = bytesToStr(req->data, len); |
| 1876 | oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()] |
| 1877 | [driveInfoKey[req->paramSel]] = str.c_str(); |
| 1878 | flushOemData(); |
| 1879 | |
| 1880 | return IPMI_CC_OK; |
| 1881 | } |
| 1882 | |
| 1883 | //---------------------------------------------------------------------- |
| 1884 | // Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO) |
| 1885 | //---------------------------------------------------------------------- |
| 1886 | // BMC needs to check HDD presented or not first. If NOT presented, return |
| 1887 | // completion code 0xD5. |
| 1888 | // |
| 1889 | // Request: |
| 1890 | // Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first |
| 1891 | // Byte 4 – |
| 1892 | //[7:4] Reserved |
| 1893 | //[3:0] HDD Controller Type |
| 1894 | // 0x00 – BIOS |
| 1895 | // 0x01 – Expander |
| 1896 | // 0x02 – LSI |
| 1897 | // Byte 5 – HDD Index, 0 base |
| 1898 | // Byte 6 – Parameter Selector (See Above Set HDD Information) |
| 1899 | // Response: |
| 1900 | // Byte 1 – Completion Code |
| 1901 | // 0xD5 – Not support in current status (HDD Not Present) |
| 1902 | // Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD |
| 1903 | // Information) |
| 1904 | // |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1905 | ipmi_ret_t ipmiOemQGetDriveInfo(ipmi_netfn_t, ipmi_cmd_t, |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1906 | ipmi_request_t request, |
| 1907 | ipmi_response_t response, |
Willy Tu | e39f939 | 2022-06-15 13:24:20 -0700 | [diff] [blame] | 1908 | ipmi_data_len_t data_len, ipmi_context_t) |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1909 | { |
Vijay Khemka | 63c99be | 2020-05-27 19:14:35 -0700 | [diff] [blame] | 1910 | qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request); |
| 1911 | uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*); |
| 1912 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 1913 | uint8_t ctrlType = req->hddCtrlType & 0x0f; |
| 1914 | std::stringstream ss; |
| 1915 | std::string str; |
| 1916 | |
| 1917 | *data_len = 0; |
| 1918 | |
| 1919 | /* check for requested data params */ |
| 1920 | if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2) |
| 1921 | { |
| 1922 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1923 | "Invalid parameter received"); |
| 1924 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 1925 | } |
| 1926 | |
| 1927 | if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) == |
| 1928 | oemData[KEY_Q_DRIVE_INFO].end()) |
| 1929 | return CC_PARAM_NOT_SUPP_IN_CURR_STATE; |
| 1930 | |
| 1931 | ss << std::hex; |
| 1932 | ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex; |
| 1933 | |
| 1934 | if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) == |
| 1935 | oemData[KEY_Q_DRIVE_INFO].end()) |
| 1936 | return CC_PARAM_NOT_SUPP_IN_CURR_STATE; |
| 1937 | |
| 1938 | if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find( |
| 1939 | dimmInfoKey[req->paramSel]) == |
| 1940 | oemData[KEY_Q_DRIVE_INFO][ss.str()].end()) |
| 1941 | return CC_PARAM_NOT_SUPP_IN_CURR_STATE; |
| 1942 | |
| 1943 | str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()] |
| 1944 | [dimmInfoKey[req->paramSel]]; |
| 1945 | *data_len = strToBytes(str, res); |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 1946 | |
| 1947 | return IPMI_CC_OK; |
| 1948 | } |
| 1949 | |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1950 | /* Helper function for sending DCMI commands to ME/BIC and |
| 1951 | * getting response back |
| 1952 | */ |
| 1953 | ipmi::RspType<std::vector<uint8_t>> |
| 1954 | sendDCMICmd([[maybe_unused]] ipmi::Context::ptr ctx, |
| 1955 | [[maybe_unused]] uint8_t cmd, std::vector<uint8_t>& cmdData) |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1956 | { |
| 1957 | std::vector<uint8_t> respData; |
| 1958 | |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1959 | #if BIC_ENABLED |
| 1960 | |
| 1961 | uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2; |
| 1962 | |
| 1963 | if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, cmdData, respData)) |
| 1964 | { |
| 1965 | return ipmi::responseUnspecifiedError(); |
| 1966 | } |
| 1967 | |
| 1968 | #else |
| 1969 | |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1970 | /* Add group id as first byte to request for ME command */ |
| 1971 | cmdData.insert(cmdData.begin(), groupDCMI); |
| 1972 | |
| 1973 | if (sendMeCmd(ipmi::netFnGroup, cmd, cmdData, respData)) |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1974 | { |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1975 | return ipmi::responseUnspecifiedError(); |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1976 | } |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1977 | |
| 1978 | /* Remove group id as first byte as it will be added by IPMID */ |
| 1979 | respData.erase(respData.begin()); |
| 1980 | |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1981 | #endif |
| 1982 | |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1983 | return ipmi::responseSuccess(std::move(respData)); |
| 1984 | } |
| 1985 | |
| 1986 | /* DCMI Command handellers. */ |
| 1987 | |
| 1988 | ipmi::RspType<std::vector<uint8_t>> |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1989 | ipmiOemDCMIGetPowerReading(ipmi::Context::ptr ctx, |
| 1990 | std::vector<uint8_t> reqData) |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1991 | { |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1992 | return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerReading, reqData); |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | ipmi::RspType<std::vector<uint8_t>> |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1996 | ipmiOemDCMIGetPowerLimit(ipmi::Context::ptr ctx, |
| 1997 | std::vector<uint8_t> reqData) |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 1998 | { |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 1999 | return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerLimit, reqData); |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | ipmi::RspType<std::vector<uint8_t>> |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 2003 | ipmiOemDCMISetPowerLimit(ipmi::Context::ptr ctx, |
| 2004 | std::vector<uint8_t> reqData) |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 2005 | { |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 2006 | return sendDCMICmd(ctx, ipmi::dcmi::cmdSetPowerLimit, reqData); |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | ipmi::RspType<std::vector<uint8_t>> |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 2010 | ipmiOemDCMIApplyPowerLimit(ipmi::Context::ptr ctx, |
| 2011 | std::vector<uint8_t> reqData) |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 2012 | { |
Logananth Sundararaj | e4d6fe7 | 2022-08-23 20:36:31 +0530 | [diff] [blame] | 2013 | return sendDCMICmd(ctx, ipmi::dcmi::cmdActDeactivatePwrLimit, reqData); |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 2016 | static void registerOEMFunctions(void) |
| 2017 | { |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2018 | /* Get OEM data from json file */ |
| 2019 | std::ifstream file(JSON_OEM_DATA_FILE); |
| 2020 | if (file) |
Vijay Khemka | feaa981 | 2019-08-27 15:08:08 -0700 | [diff] [blame] | 2021 | { |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2022 | file >> oemData; |
Vijay Khemka | feaa981 | 2019-08-27 15:08:08 -0700 | [diff] [blame] | 2023 | file.close(); |
| 2024 | } |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2025 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 2026 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 2027 | "Registering OEM commands"); |
Vijay Khemka | 7c0aea4 | 2020-03-05 13:31:53 -0800 | [diff] [blame] | 2028 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 2029 | ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO, |
| 2030 | NULL, ipmiOemDbgGetFrameInfo, |
| 2031 | PRIVILEGE_USER); // get debug frame info |
| 2032 | ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, |
| 2033 | CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL, |
| 2034 | ipmiOemDbgGetUpdFrames, |
| 2035 | PRIVILEGE_USER); // get debug updated frames |
| 2036 | ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC, |
| 2037 | NULL, ipmiOemDbgGetPostDesc, |
| 2038 | PRIVILEGE_USER); // get debug post description |
| 2039 | ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC, |
| 2040 | NULL, ipmiOemDbgGetGpioDesc, |
| 2041 | PRIVILEGE_USER); // get debug gpio description |
| 2042 | ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA, |
| 2043 | NULL, ipmiOemDbgGetFrameData, |
| 2044 | PRIVILEGE_USER); // get debug frame data |
| 2045 | ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL, |
| 2046 | NULL, ipmiOemDbgGetCtrlPanel, |
| 2047 | PRIVILEGE_USER); // get debug control panel |
| 2048 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL, |
| 2049 | ipmiOemSetDimmInfo, |
| 2050 | PRIVILEGE_USER); // Set Dimm Info |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2051 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL, |
| 2052 | ipmiOemGetBoardID, |
| 2053 | PRIVILEGE_USER); // Get Board ID |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 2054 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL, |
| 2055 | ipmiOemSetMachineCfgInfo, |
| 2056 | PRIVILEGE_USER); // Set Machine Config Info |
| 2057 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL, |
| 2058 | ipmiOemSetPostStart, |
| 2059 | PRIVILEGE_USER); // Set POST start |
| 2060 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL, |
| 2061 | ipmiOemSetPostEnd, |
| 2062 | PRIVILEGE_USER); // Set POST End |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2063 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL, |
| 2064 | ipmiOemSetPPINInfo, |
| 2065 | PRIVILEGE_USER); // Set PPIN Info |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 2066 | #if BIC_ENABLED |
| 2067 | |
| 2068 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne, |
| 2069 | ipmi::cmdSetSystemGuid, ipmi::Privilege::User, |
| 2070 | ipmiOemSetSystemGuid); |
| 2071 | #else |
| 2072 | |
Vijay Khemka | f2246ce | 2020-05-27 14:26:35 -0700 | [diff] [blame] | 2073 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL, |
| 2074 | ipmiOemSetSystemGuid, |
| 2075 | PRIVILEGE_USER); // Set System GUID |
Manikandan Elumalai | 5f8e343 | 2020-12-02 03:46:55 +0530 | [diff] [blame] | 2076 | #endif |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2077 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL, |
| 2078 | ipmiOemSetAdrTrigger, |
| 2079 | PRIVILEGE_USER); // Set ADR Trigger |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 2080 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL, |
| 2081 | ipmiOemSetBiosFlashInfo, |
| 2082 | PRIVILEGE_USER); // Set Bios Flash Info |
| 2083 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr, |
| 2084 | PRIVILEGE_USER); // Set PPR |
| 2085 | ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr, |
| 2086 | PRIVILEGE_USER); // Get PPR |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2087 | /* FB OEM QC Commands */ |
Karthikeyan Pasupathi | d532fec | 2022-07-14 14:43:42 +0530 | [diff] [blame] | 2088 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour, |
| 2089 | CMD_OEM_Q_SET_PROC_INFO, ipmi::Privilege::User, |
| 2090 | ipmiOemQSetProcInfo); // Set Proc Info |
| 2091 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour, |
| 2092 | CMD_OEM_Q_GET_PROC_INFO, ipmi::Privilege::User, |
| 2093 | ipmiOemQGetProcInfo); // Get Proc Info |
Karthikeyan Pasupathi | 10ff3d8 | 2022-04-06 16:27:25 +0530 | [diff] [blame] | 2094 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour, |
| 2095 | ipmi::cmdSetQDimmInfo, ipmi::Privilege::User, |
| 2096 | ipmiOemQSetDimmInfo); // Set Dimm Info |
| 2097 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour, |
| 2098 | ipmi::cmdGetQDimmInfo, ipmi::Privilege::User, |
| 2099 | ipmiOemQGetDimmInfo); // Get Dimm Info |
Vijay Khemka | 1d4a069 | 2019-04-09 15:20:28 -0700 | [diff] [blame] | 2100 | ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL, |
| 2101 | ipmiOemQSetDriveInfo, |
| 2102 | PRIVILEGE_USER); // Set Drive Info |
| 2103 | ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL, |
| 2104 | ipmiOemQGetDriveInfo, |
| 2105 | PRIVILEGE_USER); // Get Drive Info |
Vijay Khemka | dd14c0f | 2020-03-18 14:48:13 -0700 | [diff] [blame] | 2106 | |
| 2107 | /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */ |
| 2108 | ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI, |
| 2109 | ipmi::dcmi::cmdGetPowerReading, |
| 2110 | ipmi::Privilege::User, |
| 2111 | ipmiOemDCMIGetPowerReading); // Get Power Reading |
| 2112 | |
| 2113 | ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI, |
| 2114 | ipmi::dcmi::cmdGetPowerLimit, |
| 2115 | ipmi::Privilege::User, |
| 2116 | ipmiOemDCMIGetPowerLimit); // Get Power Limit |
| 2117 | |
| 2118 | ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI, |
| 2119 | ipmi::dcmi::cmdSetPowerLimit, |
| 2120 | ipmi::Privilege::Operator, |
| 2121 | ipmiOemDCMISetPowerLimit); // Set Power Limit |
| 2122 | |
| 2123 | ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI, |
| 2124 | ipmi::dcmi::cmdActDeactivatePwrLimit, |
| 2125 | ipmi::Privilege::Operator, |
| 2126 | ipmiOemDCMIApplyPowerLimit); // Apply Power Limit |
| 2127 | |
Jayashree-D | f0cf665 | 2020-11-30 11:03:30 +0530 | [diff] [blame] | 2128 | /* FB OEM BOOT ORDER COMMANDS */ |
| 2129 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne, |
| 2130 | CMD_OEM_GET_BOOT_ORDER, ipmi::Privilege::User, |
| 2131 | ipmiOemGetBootOrder); // Get Boot Order |
| 2132 | |
| 2133 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne, |
| 2134 | CMD_OEM_SET_BOOT_ORDER, ipmi::Privilege::User, |
| 2135 | ipmiOemSetBootOrder); // Set Boot Order |
| 2136 | |
Vijay Khemka | e7d23d0 | 2019-03-08 13:13:40 -0800 | [diff] [blame] | 2137 | return; |
| 2138 | } |
| 2139 | |
| 2140 | } // namespace ipmi |