xref: /openbmc/fb-ipmi-oem/src/oemcommands.cpp (revision 4ae63e71c53db34cff1648100a6fe4559c1b7132)
1e7d23d0eSVijay Khemka /*
2e7d23d0eSVijay Khemka  * Copyright (c)  2018 Intel Corporation.
3e7d23d0eSVijay Khemka  * Copyright (c)  2018-present Facebook.
4e7d23d0eSVijay Khemka  *
5e7d23d0eSVijay Khemka  * Licensed under the Apache License, Version 2.0 (the "License");
6e7d23d0eSVijay Khemka  * you may not use this file except in compliance with the License.
7e7d23d0eSVijay Khemka  * You may obtain a copy of the License at
8e7d23d0eSVijay Khemka  *
9e7d23d0eSVijay Khemka  *      http://www.apache.org/licenses/LICENSE-2.0
10e7d23d0eSVijay Khemka  *
11e7d23d0eSVijay Khemka  * Unless required by applicable law or agreed to in writing, software
12e7d23d0eSVijay Khemka  * distributed under the License is distributed on an "AS IS" BASIS,
13e7d23d0eSVijay Khemka  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14e7d23d0eSVijay Khemka  * See the License for the specific language governing permissions and
15e7d23d0eSVijay Khemka  * limitations under the License.
16e7d23d0eSVijay Khemka  */
17e7d23d0eSVijay Khemka 
18e7d23d0eSVijay Khemka #include "xyz/openbmc_project/Common/error.hpp"
19f0cf6658SJayashree-D #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
20f0cf6658SJayashree-D #include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
21778147daSJayashree Dhanapal #include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
22e7d23d0eSVijay Khemka 
2363c99be4SVijay Khemka #include <ipmid/api.hpp>
241b6fae3fSVijay Khemka #include <ipmid/utils.hpp>
2563c99be4SVijay Khemka #include <commandutils.hpp>
2663c99be4SVijay Khemka #include <nlohmann/json.hpp>
2763c99be4SVijay Khemka #include <oemcommands.hpp>
28e7d23d0eSVijay Khemka #include <phosphor-logging/log.hpp>
29e7d23d0eSVijay Khemka #include <sdbusplus/bus.hpp>
3063c99be4SVijay Khemka 
315f8e3435SManikandan Elumalai #include <ipmid/api.hpp>
325f8e3435SManikandan Elumalai #include <ipmid/api-types.hpp>
335f8e3435SManikandan Elumalai 
3463c99be4SVijay Khemka #include <array>
3563c99be4SVijay Khemka #include <cstring>
3663c99be4SVijay Khemka #include <fstream>
3763c99be4SVijay Khemka #include <iomanip>
3863c99be4SVijay Khemka #include <iostream>
3963c99be4SVijay Khemka #include <sstream>
40e7d23d0eSVijay Khemka #include <string>
41e7d23d0eSVijay Khemka #include <vector>
42d532fecaSKarthikeyan Pasupathi #include <regex>
43e7d23d0eSVijay Khemka 
44e7d23d0eSVijay Khemka #define SIZE_IANA_ID 3
45e7d23d0eSVijay Khemka 
46e7d23d0eSVijay Khemka namespace ipmi
47e7d23d0eSVijay Khemka {
48a7231893SVijay Khemka 
49a7231893SVijay Khemka using namespace phosphor::logging;
50a7231893SVijay Khemka 
51e1ff81faSKarthikeyan Pasupathi void getSelectorPosition(size_t& position);
52e7d23d0eSVijay Khemka static void registerOEMFunctions() __attribute__((constructor));
53cd315e07SPatrick Williams sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
54e7d23d0eSVijay Khemka static constexpr size_t maxFRUStringLength = 0x3F;
555f8e3435SManikandan Elumalai constexpr uint8_t cmdSetSystemGuid = 0xEF;
56e7d23d0eSVijay Khemka 
5710ff3d86SKarthikeyan Pasupathi constexpr uint8_t cmdSetQDimmInfo = 0x12;
5810ff3d86SKarthikeyan Pasupathi constexpr uint8_t cmdGetQDimmInfo = 0x13;
5910ff3d86SKarthikeyan Pasupathi 
60cc0d6d92SVijay Khemka int plat_udbg_get_post_desc(uint8_t, uint8_t*, uint8_t, uint8_t*, uint8_t*,
61cc0d6d92SVijay Khemka                             uint8_t*);
6238183d66SVijay Khemka int plat_udbg_get_gpio_desc(uint8_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*,
6338183d66SVijay Khemka                             uint8_t*);
64e7d23d0eSVijay Khemka ipmi_ret_t plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t*, uint8_t*,
65e7d23d0eSVijay Khemka                                     uint8_t*);
66e7d23d0eSVijay Khemka ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t*,
67e7d23d0eSVijay Khemka                                    uint8_t*);
68dd14c0f7SVijay Khemka int sendMeCmd(uint8_t, uint8_t, std::vector<uint8_t>&, std::vector<uint8_t>&);
69dd14c0f7SVijay Khemka 
705f8e3435SManikandan Elumalai int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
715f8e3435SManikandan Elumalai                std::vector<uint8_t>&);
725f8e3435SManikandan Elumalai 
73feaa9811SVijay Khemka nlohmann::json oemData __attribute__((init_priority(101)));
741b6fae3fSVijay Khemka 
75f2246ce8SVijay Khemka static constexpr size_t GUID_SIZE = 16;
76f2246ce8SVijay Khemka // TODO Make offset and location runtime configurable to ensure we
77f2246ce8SVijay Khemka // can make each define their own locations.
78f2246ce8SVijay Khemka static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
79f2246ce8SVijay Khemka static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
80f2246ce8SVijay Khemka 
811b6fae3fSVijay Khemka enum class LanParam : uint8_t
821b6fae3fSVijay Khemka {
831b6fae3fSVijay Khemka     INPROGRESS = 0,
841b6fae3fSVijay Khemka     AUTHSUPPORT = 1,
851b6fae3fSVijay Khemka     AUTHENABLES = 2,
861b6fae3fSVijay Khemka     IP = 3,
871b6fae3fSVijay Khemka     IPSRC = 4,
881b6fae3fSVijay Khemka     MAC = 5,
891b6fae3fSVijay Khemka     SUBNET = 6,
901b6fae3fSVijay Khemka     GATEWAY = 12,
911b6fae3fSVijay Khemka     VLAN = 20,
921b6fae3fSVijay Khemka     CIPHER_SUITE_COUNT = 22,
931b6fae3fSVijay Khemka     CIPHER_SUITE_ENTRIES = 23,
941b6fae3fSVijay Khemka     IPV6 = 59,
951b6fae3fSVijay Khemka };
961b6fae3fSVijay Khemka 
97a7231893SVijay Khemka namespace network
98a7231893SVijay Khemka {
99a7231893SVijay Khemka 
100a7231893SVijay Khemka constexpr auto ROOT = "/xyz/openbmc_project/network";
101a7231893SVijay Khemka constexpr auto SERVICE = "xyz.openbmc_project.Network";
102a7231893SVijay Khemka constexpr auto IPV4_TYPE = "ipv4";
103a7231893SVijay Khemka constexpr auto IPV6_TYPE = "ipv6";
104a7231893SVijay Khemka constexpr auto IPV4_PREFIX = "169.254";
105a7231893SVijay Khemka constexpr auto IPV6_PREFIX = "fe80";
106a7231893SVijay Khemka constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
107a7231893SVijay Khemka constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
1088d1a81e8SPotin Lai constexpr auto IPV4_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
1098d1a81e8SPotin Lai constexpr auto IPV6_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
110a7231893SVijay Khemka 
111a7231893SVijay Khemka bool isLinkLocalIP(const std::string& address)
112a7231893SVijay Khemka {
113a7231893SVijay Khemka     return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
114a7231893SVijay Khemka }
115a7231893SVijay Khemka 
116cd315e07SPatrick Williams DbusObjectInfo getIPObject(sdbusplus::bus_t& bus, const std::string& interface,
117a7231893SVijay Khemka                            const std::string& serviceRoot,
1188d1a81e8SPotin Lai                            const std::string& protocol,
1198d1a81e8SPotin Lai                            const std::string& ethdev)
120a7231893SVijay Khemka {
1218d1a81e8SPotin Lai     auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, ethdev);
122a7231893SVijay Khemka 
123a7231893SVijay Khemka     if (objectTree.empty())
124a7231893SVijay Khemka     {
125a7231893SVijay Khemka         log<level::ERR>("No Object has implemented the IP interface",
126a7231893SVijay Khemka                         entry("INTERFACE=%s", interface.c_str()));
127a7231893SVijay Khemka     }
128a7231893SVijay Khemka 
129a7231893SVijay Khemka     DbusObjectInfo objectInfo;
130a7231893SVijay Khemka 
131a7231893SVijay Khemka     for (auto& object : objectTree)
132a7231893SVijay Khemka     {
133a7231893SVijay Khemka         auto variant =
134a7231893SVijay Khemka             ipmi::getDbusProperty(bus, object.second.begin()->first,
1358d1a81e8SPotin Lai                                   object.first, IP_INTERFACE, "Type");
1368d1a81e8SPotin Lai         if (std::get<std::string>(variant) != protocol)
1378d1a81e8SPotin Lai         {
1388d1a81e8SPotin Lai             continue;
1398d1a81e8SPotin Lai         }
1408d1a81e8SPotin Lai 
1418d1a81e8SPotin Lai         variant = ipmi::getDbusProperty(bus, object.second.begin()->first,
142a7231893SVijay Khemka                                         object.first, IP_INTERFACE, "Address");
143a7231893SVijay Khemka 
144a7231893SVijay Khemka         objectInfo = std::make_pair(object.first, object.second.begin()->first);
145a7231893SVijay Khemka 
146a7231893SVijay Khemka         // if LinkLocalIP found look for Non-LinkLocalIP
147a7231893SVijay Khemka         if (isLinkLocalIP(std::get<std::string>(variant)))
148a7231893SVijay Khemka         {
149a7231893SVijay Khemka             continue;
150a7231893SVijay Khemka         }
151a7231893SVijay Khemka         else
152a7231893SVijay Khemka         {
153a7231893SVijay Khemka             break;
154a7231893SVijay Khemka         }
155a7231893SVijay Khemka     }
156a7231893SVijay Khemka     return objectInfo;
157a7231893SVijay Khemka }
158a7231893SVijay Khemka 
159a7231893SVijay Khemka } // namespace network
160a7231893SVijay Khemka 
161f0cf6658SJayashree-D namespace boot
162f0cf6658SJayashree-D {
16377ee489fSJayashree Dhanapal using BootSource =
16477ee489fSJayashree Dhanapal     sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources;
16577ee489fSJayashree Dhanapal using BootMode =
16677ee489fSJayashree Dhanapal     sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes;
16777ee489fSJayashree Dhanapal using BootType =
16877ee489fSJayashree Dhanapal     sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types;
169f0cf6658SJayashree-D 
170f0cf6658SJayashree-D using IpmiValue = uint8_t;
171f0cf6658SJayashree-D 
17277ee489fSJayashree Dhanapal std::map<IpmiValue, BootSource> sourceIpmiToDbus = {
17377ee489fSJayashree Dhanapal     {0x0f, BootSource::Default},       {0x00, BootSource::RemovableMedia},
17477ee489fSJayashree Dhanapal     {0x01, BootSource::Network},       {0x02, BootSource::Disk},
17577ee489fSJayashree Dhanapal     {0x03, BootSource::ExternalMedia}, {0x09, BootSource::Network}};
176f0cf6658SJayashree-D 
177c0f918b5SDelphine CC Chiu std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x04, BootMode::Setup},
17877ee489fSJayashree Dhanapal                                                 {0x00, BootMode::Regular}};
179f0cf6658SJayashree-D 
18077ee489fSJayashree Dhanapal std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy},
18177ee489fSJayashree Dhanapal                                                 {0x01, BootType::EFI}};
182778147daSJayashree Dhanapal 
18377ee489fSJayashree Dhanapal std::map<std::optional<BootSource>, IpmiValue> sourceDbusToIpmi = {
18477ee489fSJayashree Dhanapal     {BootSource::Default, 0x0f},
18577ee489fSJayashree Dhanapal     {BootSource::RemovableMedia, 0x00},
18677ee489fSJayashree Dhanapal     {BootSource::Network, 0x01},
18777ee489fSJayashree Dhanapal     {BootSource::Disk, 0x02},
18877ee489fSJayashree Dhanapal     {BootSource::ExternalMedia, 0x03}};
189f0cf6658SJayashree-D 
19077ee489fSJayashree Dhanapal std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = {
191c0f918b5SDelphine CC Chiu     {BootMode::Setup, 0x04}, {BootMode::Regular, 0x00}};
192f0cf6658SJayashree-D 
19377ee489fSJayashree Dhanapal std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = {
19477ee489fSJayashree Dhanapal     {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}};
195778147daSJayashree Dhanapal 
196c0f918b5SDelphine CC Chiu static constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
197f0cf6658SJayashree-D static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
198f0cf6658SJayashree-D static constexpr auto bootSourceIntf =
199f0cf6658SJayashree-D     "xyz.openbmc_project.Control.Boot.Source";
200778147daSJayashree Dhanapal static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
201f0cf6658SJayashree-D static constexpr auto bootSourceProp = "BootSource";
202f0cf6658SJayashree-D static constexpr auto bootModeProp = "BootMode";
203778147daSJayashree Dhanapal static constexpr auto bootTypeProp = "BootType";
204c0f918b5SDelphine CC Chiu static constexpr auto bootEnableProp = "Enabled";
205f0cf6658SJayashree-D 
206f0cf6658SJayashree-D std::tuple<std::string, std::string> objPath(size_t id)
207f0cf6658SJayashree-D {
208f0cf6658SJayashree-D     std::string hostName = "host" + std::to_string(id);
209f0cf6658SJayashree-D     std::string bootObjPath =
210f0cf6658SJayashree-D         "/xyz/openbmc_project/control/" + hostName + "/boot";
211f0cf6658SJayashree-D     return std::make_tuple(std::move(bootObjPath), std::move(hostName));
212f0cf6658SJayashree-D }
213f0cf6658SJayashree-D 
214f0cf6658SJayashree-D } // namespace boot
215f0cf6658SJayashree-D 
2161d4a0697SVijay Khemka //----------------------------------------------------------------------
2171d4a0697SVijay Khemka // Helper functions for storing oem data
2181d4a0697SVijay Khemka //----------------------------------------------------------------------
2191d4a0697SVijay Khemka 
2201d4a0697SVijay Khemka void flushOemData()
2211d4a0697SVijay Khemka {
2221d4a0697SVijay Khemka     std::ofstream file(JSON_OEM_DATA_FILE);
2231d4a0697SVijay Khemka     file << oemData;
224feaa9811SVijay Khemka     file.close();
2251d4a0697SVijay Khemka     return;
2261d4a0697SVijay Khemka }
2271d4a0697SVijay Khemka 
2281d4a0697SVijay Khemka std::string bytesToStr(uint8_t* byte, int len)
2291d4a0697SVijay Khemka {
2301d4a0697SVijay Khemka     std::stringstream ss;
2311d4a0697SVijay Khemka     int i;
2321d4a0697SVijay Khemka 
2331d4a0697SVijay Khemka     ss << std::hex;
2341d4a0697SVijay Khemka     for (i = 0; i < len; i++)
2351d4a0697SVijay Khemka     {
2361d4a0697SVijay Khemka         ss << std::setw(2) << std::setfill('0') << (int)byte[i];
2371d4a0697SVijay Khemka     }
2381d4a0697SVijay Khemka 
2391d4a0697SVijay Khemka     return ss.str();
2401d4a0697SVijay Khemka }
2411d4a0697SVijay Khemka 
2421d4a0697SVijay Khemka int strToBytes(std::string& str, uint8_t* data)
2431d4a0697SVijay Khemka {
2441d4a0697SVijay Khemka     std::string sstr;
245e39f9393SWilly Tu     size_t i;
2461d4a0697SVijay Khemka 
2471d4a0697SVijay Khemka     for (i = 0; i < (str.length()) / 2; i++)
2481d4a0697SVijay Khemka     {
2491d4a0697SVijay Khemka         sstr = str.substr(i * 2, 2);
2501d4a0697SVijay Khemka         data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16);
2511d4a0697SVijay Khemka     }
2521d4a0697SVijay Khemka     return i;
2531d4a0697SVijay Khemka }
2541d4a0697SVijay Khemka 
25510ff3d86SKarthikeyan Pasupathi int readDimmType(std::string& data, uint8_t param)
25610ff3d86SKarthikeyan Pasupathi {
25710ff3d86SKarthikeyan Pasupathi     nlohmann::json dimmObj;
25810ff3d86SKarthikeyan Pasupathi     /* Get dimm type names stored in json file */
25910ff3d86SKarthikeyan Pasupathi     std::ifstream file(JSON_DIMM_TYPE_FILE);
26010ff3d86SKarthikeyan Pasupathi     if (file)
26110ff3d86SKarthikeyan Pasupathi     {
26210ff3d86SKarthikeyan Pasupathi         file >> dimmObj;
26310ff3d86SKarthikeyan Pasupathi         file.close();
26410ff3d86SKarthikeyan Pasupathi     }
26510ff3d86SKarthikeyan Pasupathi     else
26610ff3d86SKarthikeyan Pasupathi     {
26710ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
26810ff3d86SKarthikeyan Pasupathi             "DIMM type names file not found",
26910ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
27010ff3d86SKarthikeyan Pasupathi         return -1;
27110ff3d86SKarthikeyan Pasupathi     }
27210ff3d86SKarthikeyan Pasupathi 
27310ff3d86SKarthikeyan Pasupathi     std::string dimmKey = "dimm_type" + std::to_string(param);
27410ff3d86SKarthikeyan Pasupathi     auto obj = dimmObj[dimmKey]["short_name"];
27510ff3d86SKarthikeyan Pasupathi     data = obj;
27610ff3d86SKarthikeyan Pasupathi     return 0;
27710ff3d86SKarthikeyan Pasupathi }
27810ff3d86SKarthikeyan Pasupathi 
2791b6fae3fSVijay Khemka ipmi_ret_t getNetworkData(uint8_t lan_param, char* data)
2801b6fae3fSVijay Khemka {
2811b6fae3fSVijay Khemka     ipmi_ret_t rc = IPMI_CC_OK;
282cd315e07SPatrick Williams     sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
2831b6fae3fSVijay Khemka 
2841b6fae3fSVijay Khemka     const std::string ethdevice = "eth0";
2851b6fae3fSVijay Khemka 
2861b6fae3fSVijay Khemka     switch (static_cast<LanParam>(lan_param))
2871b6fae3fSVijay Khemka     {
288d1194024SVijay Khemka         case LanParam::IP:
289d1194024SVijay Khemka         {
2901b6fae3fSVijay Khemka             std::string ipaddress;
291a7231893SVijay Khemka             auto ipObjectInfo = ipmi::network::getIPObject(
2928d1a81e8SPotin Lai                 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
2938d1a81e8SPotin Lai                 ipmi::network::IPV4_PROTOCOL, ethdevice);
2941b6fae3fSVijay Khemka 
2951b6fae3fSVijay Khemka             auto properties = ipmi::getAllDbusProperties(
2961b6fae3fSVijay Khemka                 bus, ipObjectInfo.second, ipObjectInfo.first,
2971b6fae3fSVijay Khemka                 ipmi::network::IP_INTERFACE);
2981b6fae3fSVijay Khemka 
299ef0efbc4SPatrick Williams             ipaddress = std::get<std::string>(properties["Address"]);
3001b6fae3fSVijay Khemka 
3011b6fae3fSVijay Khemka             std::strcpy(data, ipaddress.c_str());
3021b6fae3fSVijay Khemka         }
3031b6fae3fSVijay Khemka         break;
3041b6fae3fSVijay Khemka 
305d1194024SVijay Khemka         case LanParam::IPV6:
306d1194024SVijay Khemka         {
3071b6fae3fSVijay Khemka             std::string ipaddress;
308a7231893SVijay Khemka             auto ipObjectInfo = ipmi::network::getIPObject(
3098d1a81e8SPotin Lai                 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
3108d1a81e8SPotin Lai                 ipmi::network::IPV6_PROTOCOL, ethdevice);
3111b6fae3fSVijay Khemka 
3121b6fae3fSVijay Khemka             auto properties = ipmi::getAllDbusProperties(
3131b6fae3fSVijay Khemka                 bus, ipObjectInfo.second, ipObjectInfo.first,
3141b6fae3fSVijay Khemka                 ipmi::network::IP_INTERFACE);
3151b6fae3fSVijay Khemka 
316ef0efbc4SPatrick Williams             ipaddress = std::get<std::string>(properties["Address"]);
3171b6fae3fSVijay Khemka 
3181b6fae3fSVijay Khemka             std::strcpy(data, ipaddress.c_str());
3191b6fae3fSVijay Khemka         }
3201b6fae3fSVijay Khemka         break;
3211b6fae3fSVijay Khemka 
322d1194024SVijay Khemka         case LanParam::MAC:
323d1194024SVijay Khemka         {
3241b6fae3fSVijay Khemka             std::string macAddress;
3251b6fae3fSVijay Khemka             auto macObjectInfo =
3261b6fae3fSVijay Khemka                 ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE,
3271b6fae3fSVijay Khemka                                     ipmi::network::ROOT, ethdevice);
3281b6fae3fSVijay Khemka 
3291b6fae3fSVijay Khemka             auto variant = ipmi::getDbusProperty(
3301b6fae3fSVijay Khemka                 bus, macObjectInfo.second, macObjectInfo.first,
3311b6fae3fSVijay Khemka                 ipmi::network::MAC_INTERFACE, "MACAddress");
3321b6fae3fSVijay Khemka 
333ef0efbc4SPatrick Williams             macAddress = std::get<std::string>(variant);
3341b6fae3fSVijay Khemka 
3351b6fae3fSVijay Khemka             sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
3361b6fae3fSVijay Khemka                    (data), (data + 1), (data + 2), (data + 3), (data + 4),
3371b6fae3fSVijay Khemka                    (data + 5));
3381b6fae3fSVijay Khemka             std::strcpy(data, macAddress.c_str());
3391b6fae3fSVijay Khemka         }
3401b6fae3fSVijay Khemka         break;
3411b6fae3fSVijay Khemka 
3421b6fae3fSVijay Khemka         default:
3431b6fae3fSVijay Khemka             rc = IPMI_CC_PARM_OUT_OF_RANGE;
3441b6fae3fSVijay Khemka     }
3451b6fae3fSVijay Khemka     return rc;
3461b6fae3fSVijay Khemka }
347e7d23d0eSVijay Khemka 
34839836ffaSKarthikeyan Pasupathi bool isMultiHostPlatform()
34939836ffaSKarthikeyan Pasupathi {
35039836ffaSKarthikeyan Pasupathi     bool platform;
3514ec80567SJayashree Dhanapal     if (hostInstances == "0")
35239836ffaSKarthikeyan Pasupathi     {
35339836ffaSKarthikeyan Pasupathi         platform = false;
35439836ffaSKarthikeyan Pasupathi     }
35539836ffaSKarthikeyan Pasupathi     else
35639836ffaSKarthikeyan Pasupathi     {
35739836ffaSKarthikeyan Pasupathi         platform = true;
35839836ffaSKarthikeyan Pasupathi     }
35939836ffaSKarthikeyan Pasupathi     return platform;
36039836ffaSKarthikeyan Pasupathi }
36139836ffaSKarthikeyan Pasupathi 
362e7d23d0eSVijay Khemka // return code: 0 successful
363e7d23d0eSVijay Khemka int8_t getFruData(std::string& data, std::string& name)
364e7d23d0eSVijay Khemka {
36598aabdb1SKarthikeyan Pasupathi     size_t pos;
36698aabdb1SKarthikeyan Pasupathi     static constexpr const auto depth = 0;
36798aabdb1SKarthikeyan Pasupathi     std::vector<std::string> paths;
36898aabdb1SKarthikeyan Pasupathi     std::string machinePath;
36998aabdb1SKarthikeyan Pasupathi     std::string baseBoard = "Baseboard";
37098aabdb1SKarthikeyan Pasupathi 
37198aabdb1SKarthikeyan Pasupathi     bool platform = isMultiHostPlatform();
37298aabdb1SKarthikeyan Pasupathi     if (platform == true)
37398aabdb1SKarthikeyan Pasupathi     {
374e1ff81faSKarthikeyan Pasupathi         getSelectorPosition(pos);
37598aabdb1SKarthikeyan Pasupathi     }
37698aabdb1SKarthikeyan Pasupathi 
37798aabdb1SKarthikeyan Pasupathi     sd_bus* bus = NULL;
37898aabdb1SKarthikeyan Pasupathi     int ret = sd_bus_default_system(&bus);
37998aabdb1SKarthikeyan Pasupathi     if (ret < 0)
380e7d23d0eSVijay Khemka     {
381e7d23d0eSVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
38298aabdb1SKarthikeyan Pasupathi             "Failed to connect to system bus",
38398aabdb1SKarthikeyan Pasupathi             phosphor::logging::entry("ERRNO=0x%X", -ret));
38498aabdb1SKarthikeyan Pasupathi         sd_bus_unref(bus);
385e7d23d0eSVijay Khemka         return -1;
386e7d23d0eSVijay Khemka     }
387cd315e07SPatrick Williams     sdbusplus::bus_t dbus(bus);
38898aabdb1SKarthikeyan Pasupathi     auto mapperCall = dbus.new_method_call("xyz.openbmc_project.ObjectMapper",
38998aabdb1SKarthikeyan Pasupathi                                            "/xyz/openbmc_project/object_mapper",
39098aabdb1SKarthikeyan Pasupathi                                            "xyz.openbmc_project.ObjectMapper",
39198aabdb1SKarthikeyan Pasupathi                                            "GetSubTreePaths");
39298aabdb1SKarthikeyan Pasupathi     static constexpr std::array<const char*, 1> interface = {
39398aabdb1SKarthikeyan Pasupathi         "xyz.openbmc_project.Inventory.Decorator.Asset"};
39498aabdb1SKarthikeyan Pasupathi     mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface);
395e7d23d0eSVijay Khemka 
396e7d23d0eSVijay Khemka     try
397e7d23d0eSVijay Khemka     {
39898aabdb1SKarthikeyan Pasupathi         auto reply = dbus.call(mapperCall);
39998aabdb1SKarthikeyan Pasupathi         reply.read(paths);
400e7d23d0eSVijay Khemka     }
40198aabdb1SKarthikeyan Pasupathi     catch (sdbusplus::exception_t& e)
402e7d23d0eSVijay Khemka     {
403e7d23d0eSVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
404e7d23d0eSVijay Khemka         return -1;
405e7d23d0eSVijay Khemka     }
40698aabdb1SKarthikeyan Pasupathi 
40798aabdb1SKarthikeyan Pasupathi     for (const auto& path : paths)
40898aabdb1SKarthikeyan Pasupathi     {
40998aabdb1SKarthikeyan Pasupathi         if (platform == true)
41098aabdb1SKarthikeyan Pasupathi         {
41198aabdb1SKarthikeyan Pasupathi             if (pos == BMC_POS)
41298aabdb1SKarthikeyan Pasupathi             {
41398aabdb1SKarthikeyan Pasupathi                 machinePath = baseBoard;
41498aabdb1SKarthikeyan Pasupathi             }
41598aabdb1SKarthikeyan Pasupathi             else
41698aabdb1SKarthikeyan Pasupathi             {
41798aabdb1SKarthikeyan Pasupathi                 machinePath = "_" + std::to_string(pos);
41898aabdb1SKarthikeyan Pasupathi             }
41998aabdb1SKarthikeyan Pasupathi         }
42098aabdb1SKarthikeyan Pasupathi         else
42198aabdb1SKarthikeyan Pasupathi         {
42298aabdb1SKarthikeyan Pasupathi             machinePath = baseBoard;
42398aabdb1SKarthikeyan Pasupathi         }
42498aabdb1SKarthikeyan Pasupathi 
42598aabdb1SKarthikeyan Pasupathi         auto found = path.find(machinePath);
426123cbcc4SPatrick Williams         if (found == std::string::npos)
42798aabdb1SKarthikeyan Pasupathi         {
42898aabdb1SKarthikeyan Pasupathi             continue;
42998aabdb1SKarthikeyan Pasupathi         }
43098aabdb1SKarthikeyan Pasupathi 
43198aabdb1SKarthikeyan Pasupathi         std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
43298aabdb1SKarthikeyan Pasupathi         std::string service = getService(
43398aabdb1SKarthikeyan Pasupathi             *dbus, "xyz.openbmc_project.Inventory.Decorator.Asset", path);
43498aabdb1SKarthikeyan Pasupathi 
43598aabdb1SKarthikeyan Pasupathi         auto Value = ipmi::getDbusProperty(
43698aabdb1SKarthikeyan Pasupathi             *dbus, service, path,
43798aabdb1SKarthikeyan Pasupathi             "xyz.openbmc_project.Inventory.Decorator.Asset", name);
43898aabdb1SKarthikeyan Pasupathi 
43998aabdb1SKarthikeyan Pasupathi         data = std::get<std::string>(Value);
44098aabdb1SKarthikeyan Pasupathi         return 0;
441e7d23d0eSVijay Khemka     }
442e7d23d0eSVijay Khemka     return -1;
443e7d23d0eSVijay Khemka }
444e7d23d0eSVijay Khemka 
44510ff3d86SKarthikeyan Pasupathi int8_t sysConfig(std::vector<std::string>& data, size_t pos)
44610ff3d86SKarthikeyan Pasupathi {
44710ff3d86SKarthikeyan Pasupathi     nlohmann::json sysObj;
44810ff3d86SKarthikeyan Pasupathi     std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(pos);
44910ff3d86SKarthikeyan Pasupathi     std::string result, typeName;
45010ff3d86SKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
45110ff3d86SKarthikeyan Pasupathi 
45210ff3d86SKarthikeyan Pasupathi     /* Get sysConfig data stored in json file */
45310ff3d86SKarthikeyan Pasupathi     std::ifstream file(JSON_OEM_DATA_FILE);
45410ff3d86SKarthikeyan Pasupathi     if (file)
45510ff3d86SKarthikeyan Pasupathi     {
45610ff3d86SKarthikeyan Pasupathi         file >> sysObj;
45710ff3d86SKarthikeyan Pasupathi         file.close();
45810ff3d86SKarthikeyan Pasupathi     }
45910ff3d86SKarthikeyan Pasupathi     else
46010ff3d86SKarthikeyan Pasupathi     {
46110ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
46210ff3d86SKarthikeyan Pasupathi             "oemData file not found",
46310ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
46410ff3d86SKarthikeyan Pasupathi         return -1;
46510ff3d86SKarthikeyan Pasupathi     }
46610ff3d86SKarthikeyan Pasupathi 
46710ff3d86SKarthikeyan Pasupathi     if (sysObj.find(dimmInfo) == sysObj.end())
46810ff3d86SKarthikeyan Pasupathi     {
46910ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
47010ff3d86SKarthikeyan Pasupathi             "sysconfig key not available",
47110ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("SYS_JSON_KEY=%s", dimmInfo.c_str()));
47210ff3d86SKarthikeyan Pasupathi         return -1;
47310ff3d86SKarthikeyan Pasupathi     }
47410ff3d86SKarthikeyan Pasupathi     /* Get dimm type names stored in json file */
47510ff3d86SKarthikeyan Pasupathi     nlohmann::json dimmObj;
47610ff3d86SKarthikeyan Pasupathi     std::ifstream dimmFile(JSON_DIMM_TYPE_FILE);
47710ff3d86SKarthikeyan Pasupathi     if (file)
47810ff3d86SKarthikeyan Pasupathi     {
47910ff3d86SKarthikeyan Pasupathi         dimmFile >> dimmObj;
48010ff3d86SKarthikeyan Pasupathi         dimmFile.close();
48110ff3d86SKarthikeyan Pasupathi     }
48210ff3d86SKarthikeyan Pasupathi     else
48310ff3d86SKarthikeyan Pasupathi     {
48410ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
48510ff3d86SKarthikeyan Pasupathi             "DIMM type names file not found",
48610ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
48710ff3d86SKarthikeyan Pasupathi         return -1;
48810ff3d86SKarthikeyan Pasupathi     }
48910ff3d86SKarthikeyan Pasupathi     std::vector<std::string> a;
49010ff3d86SKarthikeyan Pasupathi     for (auto& j : dimmObj.items())
49110ff3d86SKarthikeyan Pasupathi     {
49210ff3d86SKarthikeyan Pasupathi         std::string name = j.key();
49310ff3d86SKarthikeyan Pasupathi         a.push_back(name);
49410ff3d86SKarthikeyan Pasupathi     }
49510ff3d86SKarthikeyan Pasupathi 
49610ff3d86SKarthikeyan Pasupathi     uint8_t len = a.size();
49710ff3d86SKarthikeyan Pasupathi     for (uint8_t ii = 0; ii < len; ii++)
49810ff3d86SKarthikeyan Pasupathi     {
49910ff3d86SKarthikeyan Pasupathi         std::string indKey = std::to_string(ii);
50010ff3d86SKarthikeyan Pasupathi         std::string speedSize = sysObj[dimmInfo][indKey][DIMM_SPEED];
50110ff3d86SKarthikeyan Pasupathi         strToBytes(speedSize, res);
50210ff3d86SKarthikeyan Pasupathi         auto speed = (res[1] << 8 | res[0]);
50310ff3d86SKarthikeyan Pasupathi         size_t dimmSize = ((res[3] << 8 | res[2]) / 1000);
50410ff3d86SKarthikeyan Pasupathi 
50510ff3d86SKarthikeyan Pasupathi         if (dimmSize == 0)
50610ff3d86SKarthikeyan Pasupathi         {
50710ff3d86SKarthikeyan Pasupathi             std::cerr << "Dimm information not available for slot_" +
50810ff3d86SKarthikeyan Pasupathi                              std::to_string(ii)
50910ff3d86SKarthikeyan Pasupathi                       << std::endl;
51010ff3d86SKarthikeyan Pasupathi             continue;
51110ff3d86SKarthikeyan Pasupathi         }
51210ff3d86SKarthikeyan Pasupathi         std::string type = sysObj[dimmInfo][indKey][DIMM_TYPE];
51310ff3d86SKarthikeyan Pasupathi         std::string dualInlineMem = sysObj[dimmInfo][indKey][KEY_DIMM_TYPE];
51410ff3d86SKarthikeyan Pasupathi         strToBytes(type, res);
51510ff3d86SKarthikeyan Pasupathi         size_t dimmType = res[0];
51610ff3d86SKarthikeyan Pasupathi         if (dimmVenMap.find(dimmType) == dimmVenMap.end())
51710ff3d86SKarthikeyan Pasupathi         {
51810ff3d86SKarthikeyan Pasupathi             typeName = "unknown";
51910ff3d86SKarthikeyan Pasupathi         }
52010ff3d86SKarthikeyan Pasupathi         else
52110ff3d86SKarthikeyan Pasupathi         {
52210ff3d86SKarthikeyan Pasupathi             typeName = dimmVenMap[dimmType];
52310ff3d86SKarthikeyan Pasupathi         }
52410ff3d86SKarthikeyan Pasupathi         result = dualInlineMem + "/" + typeName + "/" + std::to_string(speed) +
52510ff3d86SKarthikeyan Pasupathi                  "MHz" + "/" + std::to_string(dimmSize) + "GB";
52610ff3d86SKarthikeyan Pasupathi         data.push_back(result);
52710ff3d86SKarthikeyan Pasupathi     }
52810ff3d86SKarthikeyan Pasupathi     return 0;
52910ff3d86SKarthikeyan Pasupathi }
53010ff3d86SKarthikeyan Pasupathi 
531d532fecaSKarthikeyan Pasupathi int8_t procInfo(std::string& result, size_t pos)
532d532fecaSKarthikeyan Pasupathi {
533d532fecaSKarthikeyan Pasupathi     std::vector<char> data;
534d532fecaSKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
535d532fecaSKarthikeyan Pasupathi     std::string procIndex = "00";
536d532fecaSKarthikeyan Pasupathi     nlohmann::json proObj;
537d532fecaSKarthikeyan Pasupathi     std::string procInfo = KEY_Q_PROC_INFO + std::to_string(pos);
538d532fecaSKarthikeyan Pasupathi     /* Get processor data stored in json file */
539d532fecaSKarthikeyan Pasupathi     std::ifstream file(JSON_OEM_DATA_FILE);
540d532fecaSKarthikeyan Pasupathi     if (file)
541d532fecaSKarthikeyan Pasupathi     {
542d532fecaSKarthikeyan Pasupathi         file >> proObj;
543d532fecaSKarthikeyan Pasupathi         file.close();
544d532fecaSKarthikeyan Pasupathi     }
545d532fecaSKarthikeyan Pasupathi     else
546d532fecaSKarthikeyan Pasupathi     {
547d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
548d532fecaSKarthikeyan Pasupathi             "oemData file not found",
549d532fecaSKarthikeyan Pasupathi             phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
550d532fecaSKarthikeyan Pasupathi         return -1;
551d532fecaSKarthikeyan Pasupathi     }
552d532fecaSKarthikeyan Pasupathi     if (proObj.find(procInfo) == proObj.end())
553d532fecaSKarthikeyan Pasupathi     {
554d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
555d532fecaSKarthikeyan Pasupathi             "processor info key not available",
556d532fecaSKarthikeyan Pasupathi             phosphor::logging::entry("PROC_JSON_KEY=%s", procInfo.c_str()));
557d532fecaSKarthikeyan Pasupathi         return -1;
558d532fecaSKarthikeyan Pasupathi     }
559d532fecaSKarthikeyan Pasupathi     std::string procName = proObj[procInfo][procIndex][KEY_PROC_NAME];
560d532fecaSKarthikeyan Pasupathi     std::string basicInfo = proObj[procInfo][procIndex][KEY_BASIC_INFO];
561d532fecaSKarthikeyan Pasupathi     // Processor Product Name
562d532fecaSKarthikeyan Pasupathi     strToBytes(procName, res);
563d532fecaSKarthikeyan Pasupathi     data.assign(reinterpret_cast<char*>(&res),
564d532fecaSKarthikeyan Pasupathi                 reinterpret_cast<char*>(&res) + sizeof(res));
565d532fecaSKarthikeyan Pasupathi 
566d532fecaSKarthikeyan Pasupathi     std::string s(data.begin(), data.end());
567d532fecaSKarthikeyan Pasupathi     std::regex regex(" ");
568d532fecaSKarthikeyan Pasupathi     std::vector<std::string> productName(
569d532fecaSKarthikeyan Pasupathi         std::sregex_token_iterator(s.begin(), s.end(), regex, -1),
570d532fecaSKarthikeyan Pasupathi         std::sregex_token_iterator());
571d532fecaSKarthikeyan Pasupathi 
572d532fecaSKarthikeyan Pasupathi     // Processor core and frequency
573d532fecaSKarthikeyan Pasupathi     strToBytes(basicInfo, res);
574d532fecaSKarthikeyan Pasupathi     uint16_t coreNum = res[0];
575d532fecaSKarthikeyan Pasupathi     double procFrequency = (float)(res[4] << 8 | res[3]) / 1000;
576d532fecaSKarthikeyan Pasupathi     result = "CPU:" + productName[2] + "/" + std::to_string(procFrequency) +
577d532fecaSKarthikeyan Pasupathi              "GHz" + "/" + std::to_string(coreNum) + "c";
578d532fecaSKarthikeyan Pasupathi     return 0;
579d532fecaSKarthikeyan Pasupathi }
580d532fecaSKarthikeyan Pasupathi 
581e7d23d0eSVijay Khemka typedef struct
582e7d23d0eSVijay Khemka {
583e7d23d0eSVijay Khemka     uint8_t cur_power_state;
584e7d23d0eSVijay Khemka     uint8_t last_power_event;
585e7d23d0eSVijay Khemka     uint8_t misc_power_state;
586e7d23d0eSVijay Khemka     uint8_t front_panel_button_cap_status;
587e7d23d0eSVijay Khemka } ipmi_get_chassis_status_t;
588e7d23d0eSVijay Khemka 
589e7d23d0eSVijay Khemka //----------------------------------------------------------------------
590e7d23d0eSVijay Khemka // Get Debug Frame Info
591e7d23d0eSVijay Khemka //----------------------------------------------------------------------
592e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetFrameInfo(ipmi_netfn_t, ipmi_cmd_t,
593e7d23d0eSVijay Khemka                                   ipmi_request_t request,
594e7d23d0eSVijay Khemka                                   ipmi_response_t response,
595e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
596e7d23d0eSVijay Khemka {
597e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
598e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
599e7d23d0eSVijay Khemka     uint8_t num_frames = 3;
600e7d23d0eSVijay Khemka 
601e7d23d0eSVijay Khemka     std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
602e7d23d0eSVijay Khemka     res[SIZE_IANA_ID] = num_frames;
603e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + 1;
604e7d23d0eSVijay Khemka 
605e7d23d0eSVijay Khemka     return IPMI_CC_OK;
606e7d23d0eSVijay Khemka }
607e7d23d0eSVijay Khemka 
608e7d23d0eSVijay Khemka //----------------------------------------------------------------------
609e7d23d0eSVijay Khemka // Get Debug Updated Frames
610e7d23d0eSVijay Khemka //----------------------------------------------------------------------
611e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetUpdFrames(ipmi_netfn_t, ipmi_cmd_t,
612e7d23d0eSVijay Khemka                                   ipmi_request_t request,
613e7d23d0eSVijay Khemka                                   ipmi_response_t response,
614e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
615e7d23d0eSVijay Khemka {
616e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
617e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
618e7d23d0eSVijay Khemka     uint8_t num_updates = 3;
619e7d23d0eSVijay Khemka     *data_len = 4;
620e7d23d0eSVijay Khemka 
621e7d23d0eSVijay Khemka     std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
622e7d23d0eSVijay Khemka     res[SIZE_IANA_ID] = num_updates;
623e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + num_updates + 1;
624e7d23d0eSVijay Khemka     res[SIZE_IANA_ID + 1] = 1; // info page update
625e7d23d0eSVijay Khemka     res[SIZE_IANA_ID + 2] = 2; // cri sel update
626e7d23d0eSVijay Khemka     res[SIZE_IANA_ID + 3] = 3; // cri sensor update
627e7d23d0eSVijay Khemka 
628e7d23d0eSVijay Khemka     return IPMI_CC_OK;
629e7d23d0eSVijay Khemka }
630e7d23d0eSVijay Khemka 
631e7d23d0eSVijay Khemka //----------------------------------------------------------------------
632e7d23d0eSVijay Khemka // Get Debug POST Description
633e7d23d0eSVijay Khemka //----------------------------------------------------------------------
634e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetPostDesc(ipmi_netfn_t, ipmi_cmd_t,
635e7d23d0eSVijay Khemka                                  ipmi_request_t request,
636e7d23d0eSVijay Khemka                                  ipmi_response_t response,
637e39f9393SWilly Tu                                  ipmi_data_len_t data_len, ipmi_context_t)
638e7d23d0eSVijay Khemka {
639e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
640e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
641e7d23d0eSVijay Khemka     uint8_t index = 0;
642e7d23d0eSVijay Khemka     uint8_t next = 0;
643e7d23d0eSVijay Khemka     uint8_t end = 0;
644e7d23d0eSVijay Khemka     uint8_t phase = 0;
645cc0d6d92SVijay Khemka     uint8_t descLen = 0;
646e7d23d0eSVijay Khemka     int ret;
647e7d23d0eSVijay Khemka 
648e7d23d0eSVijay Khemka     index = req[3];
649e7d23d0eSVijay Khemka     phase = req[4];
650e7d23d0eSVijay Khemka 
651cc0d6d92SVijay Khemka     ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
652e7d23d0eSVijay Khemka     if (ret)
653e7d23d0eSVijay Khemka     {
654e7d23d0eSVijay Khemka         memcpy(res, req, SIZE_IANA_ID); // IANA ID
655e7d23d0eSVijay Khemka         *data_len = SIZE_IANA_ID;
656e7d23d0eSVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
657e7d23d0eSVijay Khemka     }
658e7d23d0eSVijay Khemka 
659e7d23d0eSVijay Khemka     memcpy(res, req, SIZE_IANA_ID); // IANA ID
660e7d23d0eSVijay Khemka     res[3] = index;
661e7d23d0eSVijay Khemka     res[4] = next;
662e7d23d0eSVijay Khemka     res[5] = phase;
663e7d23d0eSVijay Khemka     res[6] = end;
664cc0d6d92SVijay Khemka     res[7] = descLen;
665cc0d6d92SVijay Khemka     *data_len = SIZE_IANA_ID + 5 + descLen;
666e7d23d0eSVijay Khemka 
667e7d23d0eSVijay Khemka     return IPMI_CC_OK;
668e7d23d0eSVijay Khemka }
669e7d23d0eSVijay Khemka 
670e7d23d0eSVijay Khemka //----------------------------------------------------------------------
671e7d23d0eSVijay Khemka // Get Debug GPIO Description
672e7d23d0eSVijay Khemka //----------------------------------------------------------------------
673e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetGpioDesc(ipmi_netfn_t, ipmi_cmd_t,
674e7d23d0eSVijay Khemka                                  ipmi_request_t request,
675e7d23d0eSVijay Khemka                                  ipmi_response_t response,
676e39f9393SWilly Tu                                  ipmi_data_len_t data_len, ipmi_context_t)
677e7d23d0eSVijay Khemka {
678e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
679e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
680e7d23d0eSVijay Khemka 
68138183d66SVijay Khemka     uint8_t index = 0;
68238183d66SVijay Khemka     uint8_t next = 0;
68338183d66SVijay Khemka     uint8_t level = 0;
68438183d66SVijay Khemka     uint8_t pinDef = 0;
68538183d66SVijay Khemka     uint8_t descLen = 0;
68638183d66SVijay Khemka     int ret;
687e7d23d0eSVijay Khemka 
68838183d66SVijay Khemka     index = req[3];
68938183d66SVijay Khemka 
69038183d66SVijay Khemka     ret = plat_udbg_get_gpio_desc(index, &next, &level, &pinDef, &descLen,
69138183d66SVijay Khemka                                   &res[8]);
69238183d66SVijay Khemka     if (ret)
69338183d66SVijay Khemka     {
69438183d66SVijay Khemka         memcpy(res, req, SIZE_IANA_ID); // IANA ID
69538183d66SVijay Khemka         *data_len = SIZE_IANA_ID;
69638183d66SVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
69738183d66SVijay Khemka     }
69838183d66SVijay Khemka 
69938183d66SVijay Khemka     memcpy(res, req, SIZE_IANA_ID); // IANA ID
70038183d66SVijay Khemka     res[3] = index;
70138183d66SVijay Khemka     res[4] = next;
70238183d66SVijay Khemka     res[5] = level;
70338183d66SVijay Khemka     res[6] = pinDef;
70438183d66SVijay Khemka     res[7] = descLen;
70538183d66SVijay Khemka     *data_len = SIZE_IANA_ID + 5 + descLen;
706e7d23d0eSVijay Khemka 
707e7d23d0eSVijay Khemka     return IPMI_CC_OK;
708e7d23d0eSVijay Khemka }
709e7d23d0eSVijay Khemka 
710e7d23d0eSVijay Khemka //----------------------------------------------------------------------
711e7d23d0eSVijay Khemka // Get Debug Frame Data
712e7d23d0eSVijay Khemka //----------------------------------------------------------------------
713e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetFrameData(ipmi_netfn_t, ipmi_cmd_t,
714e7d23d0eSVijay Khemka                                   ipmi_request_t request,
715e7d23d0eSVijay Khemka                                   ipmi_response_t response,
716e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
717e7d23d0eSVijay Khemka {
718e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
719e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
720e7d23d0eSVijay Khemka     uint8_t frame;
721e7d23d0eSVijay Khemka     uint8_t page;
722e7d23d0eSVijay Khemka     uint8_t next;
723e7d23d0eSVijay Khemka     uint8_t count;
724e7d23d0eSVijay Khemka     int ret;
725e7d23d0eSVijay Khemka 
726e7d23d0eSVijay Khemka     frame = req[3];
727e7d23d0eSVijay Khemka     page = req[4];
728e7d23d0eSVijay Khemka 
729e7d23d0eSVijay Khemka     ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]);
730e7d23d0eSVijay Khemka     if (ret)
731e7d23d0eSVijay Khemka     {
732e7d23d0eSVijay Khemka         memcpy(res, req, SIZE_IANA_ID); // IANA ID
733e7d23d0eSVijay Khemka         *data_len = SIZE_IANA_ID;
734e7d23d0eSVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
735e7d23d0eSVijay Khemka     }
736e7d23d0eSVijay Khemka 
737e7d23d0eSVijay Khemka     memcpy(res, req, SIZE_IANA_ID); // IANA ID
738e7d23d0eSVijay Khemka     res[3] = frame;
739e7d23d0eSVijay Khemka     res[4] = page;
740e7d23d0eSVijay Khemka     res[5] = next;
741e7d23d0eSVijay Khemka     res[6] = count;
742e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + 4 + count;
743e7d23d0eSVijay Khemka 
744e7d23d0eSVijay Khemka     return IPMI_CC_OK;
745e7d23d0eSVijay Khemka }
746e7d23d0eSVijay Khemka 
747e7d23d0eSVijay Khemka //----------------------------------------------------------------------
748e7d23d0eSVijay Khemka // Get Debug Control Panel
749e7d23d0eSVijay Khemka //----------------------------------------------------------------------
750e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetCtrlPanel(ipmi_netfn_t, ipmi_cmd_t,
751e7d23d0eSVijay Khemka                                   ipmi_request_t request,
752e7d23d0eSVijay Khemka                                   ipmi_response_t response,
753e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
754e7d23d0eSVijay Khemka {
755e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
756e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
757e7d23d0eSVijay Khemka 
758e7d23d0eSVijay Khemka     uint8_t panel;
759e7d23d0eSVijay Khemka     uint8_t operation;
760e7d23d0eSVijay Khemka     uint8_t item;
761e7d23d0eSVijay Khemka     uint8_t count;
762e7d23d0eSVijay Khemka     ipmi_ret_t ret;
763e7d23d0eSVijay Khemka 
764e7d23d0eSVijay Khemka     panel = req[3];
765e7d23d0eSVijay Khemka     operation = req[4];
766e7d23d0eSVijay Khemka     item = req[5];
767e7d23d0eSVijay Khemka 
768e7d23d0eSVijay Khemka     ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]);
769e7d23d0eSVijay Khemka 
770e7d23d0eSVijay Khemka     std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
771e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + count;
772e7d23d0eSVijay Khemka 
773e7d23d0eSVijay Khemka     return ret;
774e7d23d0eSVijay Khemka }
775e7d23d0eSVijay Khemka 
776e7d23d0eSVijay Khemka //----------------------------------------------------------------------
777e7d23d0eSVijay Khemka // Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
778e7d23d0eSVijay Khemka //----------------------------------------------------------------------
779e39f9393SWilly Tu ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
780e39f9393SWilly Tu                               ipmi_response_t, ipmi_data_len_t data_len,
781e39f9393SWilly Tu                               ipmi_context_t)
782e7d23d0eSVijay Khemka {
783e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
7841d4a0697SVijay Khemka 
7851d4a0697SVijay Khemka     uint8_t index = req[0];
7861d4a0697SVijay Khemka     uint8_t type = req[1];
7871d4a0697SVijay Khemka     uint16_t speed;
7881d4a0697SVijay Khemka     uint32_t size;
7891d4a0697SVijay Khemka 
7901d4a0697SVijay Khemka     memcpy(&speed, &req[2], 2);
7911d4a0697SVijay Khemka     memcpy(&size, &req[4], 4);
7921d4a0697SVijay Khemka 
7931d4a0697SVijay Khemka     std::stringstream ss;
7941d4a0697SVijay Khemka     ss << std::hex;
7951d4a0697SVijay Khemka     ss << std::setw(2) << std::setfill('0') << (int)index;
7961d4a0697SVijay Khemka 
7971d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index;
7981d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type;
7991d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed;
8001d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size;
8011d4a0697SVijay Khemka 
8021d4a0697SVijay Khemka     flushOemData();
8031d4a0697SVijay Khemka 
8041d4a0697SVijay Khemka     *data_len = 0;
8051d4a0697SVijay Khemka 
8061d4a0697SVijay Khemka     return IPMI_CC_OK;
8071d4a0697SVijay Khemka }
8081d4a0697SVijay Khemka 
8091d4a0697SVijay Khemka //----------------------------------------------------------------------
8101d4a0697SVijay Khemka // Get Board ID (CMD_OEM_GET_BOARD_ID)
8111d4a0697SVijay Khemka //----------------------------------------------------------------------
812e39f9393SWilly Tu ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
813e39f9393SWilly Tu                              ipmi_response_t, ipmi_data_len_t data_len,
814e39f9393SWilly Tu                              ipmi_context_t)
8151d4a0697SVijay Khemka {
8161d4a0697SVijay Khemka     /* TODO: Needs to implement this after GPIO implementation */
817e7d23d0eSVijay Khemka     *data_len = 0;
818e7d23d0eSVijay Khemka 
819e7d23d0eSVijay Khemka     return IPMI_CC_OK;
820e7d23d0eSVijay Khemka }
821e7d23d0eSVijay Khemka 
822*4ae63e71SBonnie Lo //----------------------------------------------------------------------
823*4ae63e71SBonnie Lo // Get port 80 record (CMD_OEM_GET_80PORT_RECORD)
824*4ae63e71SBonnie Lo //----------------------------------------------------------------------
825*4ae63e71SBonnie Lo ipmi::RspType<std::vector<uint8_t>>
826*4ae63e71SBonnie Lo     ipmiOemGet80PortRecord(ipmi::Context::ptr ctx)
827*4ae63e71SBonnie Lo {
828*4ae63e71SBonnie Lo     auto postCodeService = "xyz.openbmc_project.State.Boot.PostCode" +
829*4ae63e71SBonnie Lo                            std::to_string(ctx->hostIdx + 1);
830*4ae63e71SBonnie Lo     auto postCodeObjPath = "/xyz/openbmc_project/State/Boot/PostCode" +
831*4ae63e71SBonnie Lo                            std::to_string(ctx->hostIdx + 1);
832*4ae63e71SBonnie Lo     constexpr auto postCodeInterface =
833*4ae63e71SBonnie Lo         "xyz.openbmc_project.State.Boot.PostCode";
834*4ae63e71SBonnie Lo     const static uint16_t lastestPostCodeIndex = 1;
835*4ae63e71SBonnie Lo     constexpr const auto maxPostCodeLen =
836*4ae63e71SBonnie Lo         224; // The length must be lower than IPMB limitation
837*4ae63e71SBonnie Lo     size_t startIndex = 0;
838*4ae63e71SBonnie Lo 
839*4ae63e71SBonnie Lo     std::vector<std::tuple<uint64_t, std::vector<uint8_t>>> postCodes;
840*4ae63e71SBonnie Lo     std::vector<uint8_t> resData;
841*4ae63e71SBonnie Lo 
842*4ae63e71SBonnie Lo     auto conn = getSdBus();
843*4ae63e71SBonnie Lo     /* Get the post codes by calling GetPostCodes method */
844*4ae63e71SBonnie Lo     auto msg =
845*4ae63e71SBonnie Lo         conn->new_method_call(postCodeService.c_str(), postCodeObjPath.c_str(),
846*4ae63e71SBonnie Lo                               postCodeInterface, "GetPostCodes");
847*4ae63e71SBonnie Lo     msg.append(lastestPostCodeIndex);
848*4ae63e71SBonnie Lo 
849*4ae63e71SBonnie Lo     try
850*4ae63e71SBonnie Lo     {
851*4ae63e71SBonnie Lo         auto reply = conn->call(msg);
852*4ae63e71SBonnie Lo         reply.read(postCodes);
853*4ae63e71SBonnie Lo     }
854*4ae63e71SBonnie Lo     catch (const sdbusplus::exception::SdBusError& e)
855*4ae63e71SBonnie Lo     {
856*4ae63e71SBonnie Lo         phosphor::logging::log<phosphor::logging::level::ERR>(
857*4ae63e71SBonnie Lo             "IPMI Get80PortRecord Failed in call method",
858*4ae63e71SBonnie Lo             phosphor::logging::entry("ERROR=%s", e.what()));
859*4ae63e71SBonnie Lo         return ipmi::responseUnspecifiedError();
860*4ae63e71SBonnie Lo     }
861*4ae63e71SBonnie Lo 
862*4ae63e71SBonnie Lo     /* Get post code data */
863*4ae63e71SBonnie Lo     for (size_t i = 0; i < postCodes.size(); ++i)
864*4ae63e71SBonnie Lo     {
865*4ae63e71SBonnie Lo         uint64_t primaryPostCode = std::get<uint64_t>(postCodes[i]);
866*4ae63e71SBonnie Lo         for (int j = postCodeSize - 1; j >= 0; --j)
867*4ae63e71SBonnie Lo         {
868*4ae63e71SBonnie Lo             uint8_t postCode =
869*4ae63e71SBonnie Lo                 ((primaryPostCode >> (sizeof(uint64_t) * j)) & 0xFF);
870*4ae63e71SBonnie Lo             resData.emplace_back(postCode);
871*4ae63e71SBonnie Lo         }
872*4ae63e71SBonnie Lo     }
873*4ae63e71SBonnie Lo 
874*4ae63e71SBonnie Lo     std::vector<uint8_t> response;
875*4ae63e71SBonnie Lo     if (resData.size() > maxPostCodeLen)
876*4ae63e71SBonnie Lo     {
877*4ae63e71SBonnie Lo         startIndex = resData.size() - maxPostCodeLen;
878*4ae63e71SBonnie Lo     }
879*4ae63e71SBonnie Lo 
880*4ae63e71SBonnie Lo     response.assign(resData.begin() + startIndex, resData.end());
881*4ae63e71SBonnie Lo 
882*4ae63e71SBonnie Lo     return ipmi::responseSuccess(response);
883*4ae63e71SBonnie Lo }
884*4ae63e71SBonnie Lo 
885877d5dd9SVijay Khemka /* Helper functions to set boot order */
886f0cf6658SJayashree-D void setBootOrder(std::string bootObjPath, uint8_t* data,
887f0cf6658SJayashree-D                   std::string bootOrderKey)
888877d5dd9SVijay Khemka {
889f0cf6658SJayashree-D     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
890f0cf6658SJayashree-D 
891f0cf6658SJayashree-D     // SETTING BOOT MODE PROPERTY
892c0f918b5SDelphine CC Chiu     uint8_t bootModeBit = data[0] & 0x04;
89377ee489fSJayashree Dhanapal     auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit);
894778147daSJayashree Dhanapal 
895f0cf6658SJayashree-D     std::string bootOption =
89677ee489fSJayashree Dhanapal         sdbusplus::message::convert_to_string<boot::BootMode>(bootValue);
897f0cf6658SJayashree-D 
898f0cf6658SJayashree-D     std::string service =
899f0cf6658SJayashree-D         getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
900f0cf6658SJayashree-D     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
901f0cf6658SJayashree-D                     ipmi::boot::bootModeProp, bootOption);
902f0cf6658SJayashree-D 
903f0cf6658SJayashree-D     // SETTING BOOT SOURCE PROPERTY
90477ee489fSJayashree Dhanapal     auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]);
905f0cf6658SJayashree-D     std::string bootSource =
90677ee489fSJayashree Dhanapal         sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder);
907f0cf6658SJayashree-D 
908f0cf6658SJayashree-D     service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
909f0cf6658SJayashree-D     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
910f0cf6658SJayashree-D                     ipmi::boot::bootSourceProp, bootSource);
911f0cf6658SJayashree-D 
912778147daSJayashree Dhanapal     // SETTING BOOT TYPE PROPERTY
913778147daSJayashree Dhanapal     uint8_t bootTypeBit = data[0] & 0x01;
91477ee489fSJayashree Dhanapal     auto bootTypeVal = ipmi::boot::typeIpmiToDbus.at(bootTypeBit);
91577ee489fSJayashree Dhanapal 
916778147daSJayashree Dhanapal     std::string bootType =
91777ee489fSJayashree Dhanapal         sdbusplus::message::convert_to_string<boot::BootType>(bootTypeVal);
918778147daSJayashree Dhanapal 
919778147daSJayashree Dhanapal     service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
920778147daSJayashree Dhanapal 
921778147daSJayashree Dhanapal     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
922778147daSJayashree Dhanapal                     ipmi::boot::bootTypeProp, bootType);
923778147daSJayashree Dhanapal 
924c0f918b5SDelphine CC Chiu     // Set the valid bit to boot enabled property
925c0f918b5SDelphine CC Chiu     service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
926c0f918b5SDelphine CC Chiu 
927c0f918b5SDelphine CC Chiu     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf,
928c0f918b5SDelphine CC Chiu                     ipmi::boot::bootEnableProp,
929c0f918b5SDelphine CC Chiu                     (data[0] & BOOT_MODE_BOOT_FLAG) ? true : false);
930c0f918b5SDelphine CC Chiu 
931877d5dd9SVijay Khemka     nlohmann::json bootMode;
932877d5dd9SVijay Khemka     uint8_t mode = data[0];
933877d5dd9SVijay Khemka     int i;
934877d5dd9SVijay Khemka 
935877d5dd9SVijay Khemka     bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
936877d5dd9SVijay Khemka     bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
937877d5dd9SVijay Khemka     bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
938877d5dd9SVijay Khemka     bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);
939f0cf6658SJayashree-D     oemData[bootOrderKey][KEY_BOOT_MODE] = bootMode;
940877d5dd9SVijay Khemka 
941877d5dd9SVijay Khemka     /* Initialize boot sequence array */
942f0cf6658SJayashree-D     oemData[bootOrderKey][KEY_BOOT_SEQ] = {};
943877d5dd9SVijay Khemka     for (i = 1; i < SIZE_BOOT_ORDER; i++)
944877d5dd9SVijay Khemka     {
945877d5dd9SVijay Khemka         if (data[i] >= BOOT_SEQ_ARRAY_SIZE)
946f0cf6658SJayashree-D             oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = "NA";
947877d5dd9SVijay Khemka         else
948f0cf6658SJayashree-D             oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = bootSeq[data[i]];
949877d5dd9SVijay Khemka     }
950877d5dd9SVijay Khemka 
951877d5dd9SVijay Khemka     flushOemData();
952877d5dd9SVijay Khemka }
953877d5dd9SVijay Khemka 
954e7d23d0eSVijay Khemka //----------------------------------------------------------------------
9551d4a0697SVijay Khemka // Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
9561d4a0697SVijay Khemka //----------------------------------------------------------------------
957f0cf6658SJayashree-D ipmi::RspType<std::vector<uint8_t>>
958f0cf6658SJayashree-D     ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data)
9591d4a0697SVijay Khemka {
9601d4a0697SVijay Khemka 
961f0cf6658SJayashree-D     uint8_t bootSeq[SIZE_BOOT_ORDER];
962f0cf6658SJayashree-D     size_t len = data.size();
9631d4a0697SVijay Khemka 
9641d4a0697SVijay Khemka     if (len != SIZE_BOOT_ORDER)
9651d4a0697SVijay Khemka     {
9661d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
9671d4a0697SVijay Khemka             "Invalid Boot order length received");
968f0cf6658SJayashree-D         return ipmi::responseReqDataLenInvalid();
9691d4a0697SVijay Khemka     }
9701d4a0697SVijay Khemka 
971f0cf6658SJayashree-D     std::copy(std::begin(data), std::end(data), bootSeq);
9724ec80567SJayashree Dhanapal     std::optional<size_t> hostId = findHost(ctx->hostIdx);
9731d4a0697SVijay Khemka 
974f0cf6658SJayashree-D     if (!hostId)
975f0cf6658SJayashree-D     {
976f0cf6658SJayashree-D         phosphor::logging::log<phosphor::logging::level::ERR>(
977f0cf6658SJayashree-D             "Invalid Host Id received");
978f0cf6658SJayashree-D         return ipmi::responseInvalidCommand();
979f0cf6658SJayashree-D     }
980f0cf6658SJayashree-D     auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
981f0cf6658SJayashree-D 
982f0cf6658SJayashree-D     setBootOrder(bootObjPath, bootSeq, hostName);
983f0cf6658SJayashree-D 
984f0cf6658SJayashree-D     return ipmi::responseSuccess(data);
9851d4a0697SVijay Khemka }
9861d4a0697SVijay Khemka 
9871d4a0697SVijay Khemka //----------------------------------------------------------------------
988e7d23d0eSVijay Khemka // Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
989e7d23d0eSVijay Khemka //----------------------------------------------------------------------
990f0cf6658SJayashree-D ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
991f0cf6658SJayashree-D     ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
992e7d23d0eSVijay Khemka {
993f0cf6658SJayashree-D     uint8_t bootSeq[SIZE_BOOT_ORDER];
9941d4a0697SVijay Khemka     uint8_t mode = 0;
995e7d23d0eSVijay Khemka 
9964ec80567SJayashree Dhanapal     std::optional<size_t> hostId = findHost(ctx->hostIdx);
9971d4a0697SVijay Khemka 
998f0cf6658SJayashree-D     if (!hostId)
999f0cf6658SJayashree-D     {
1000f0cf6658SJayashree-D         phosphor::logging::log<phosphor::logging::level::ERR>(
1001f0cf6658SJayashree-D             "Invalid Host Id received");
1002f0cf6658SJayashree-D         return ipmi::responseInvalidCommand();
1003f0cf6658SJayashree-D     }
1004f0cf6658SJayashree-D     auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
1005f0cf6658SJayashree-D 
1006f0cf6658SJayashree-D     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1007f0cf6658SJayashree-D 
100877ee489fSJayashree Dhanapal     // GETTING PROPERTY OF MODE INTERFACE
100977ee489fSJayashree Dhanapal 
1010f0cf6658SJayashree-D     std::string service =
1011f0cf6658SJayashree-D         getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
1012f0cf6658SJayashree-D     Value variant =
1013f0cf6658SJayashree-D         getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
1014f0cf6658SJayashree-D                         ipmi::boot::bootModeProp);
1015f0cf6658SJayashree-D 
101677ee489fSJayashree Dhanapal     auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>(
1017f0cf6658SJayashree-D         std::get<std::string>(variant));
1018f0cf6658SJayashree-D 
1019778147daSJayashree Dhanapal     uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
1020f0cf6658SJayashree-D 
1021778147daSJayashree Dhanapal     // GETTING PROPERTY OF TYPE INTERFACE
1022778147daSJayashree Dhanapal 
1023778147daSJayashree Dhanapal     service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
1024778147daSJayashree Dhanapal     variant =
1025778147daSJayashree Dhanapal         getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
1026778147daSJayashree Dhanapal                         ipmi::boot::bootTypeProp);
102777ee489fSJayashree Dhanapal 
102877ee489fSJayashree Dhanapal     auto bootType = sdbusplus::message::convert_from_string<boot::BootType>(
1029778147daSJayashree Dhanapal         std::get<std::string>(variant));
1030778147daSJayashree Dhanapal 
1031c0f918b5SDelphine CC Chiu     // Get the valid bit from boot enabled property
1032c0f918b5SDelphine CC Chiu     service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
1033c0f918b5SDelphine CC Chiu     variant =
1034c0f918b5SDelphine CC Chiu         getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf,
1035c0f918b5SDelphine CC Chiu                         ipmi::boot::bootEnableProp);
1036c0f918b5SDelphine CC Chiu 
1037c0f918b5SDelphine CC Chiu     bool validFlag = std::get<bool>(variant);
1038c0f918b5SDelphine CC Chiu 
1039778147daSJayashree Dhanapal     uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
1040778147daSJayashree Dhanapal 
1041778147daSJayashree Dhanapal     uint8_t bootVal = bootOption | bootTypeVal;
1042f0cf6658SJayashree-D 
1043c0f918b5SDelphine CC Chiu     if (validFlag)
1044c0f918b5SDelphine CC Chiu     {
1045c0f918b5SDelphine CC Chiu         bootVal |= BOOT_MODE_BOOT_FLAG;
1046c0f918b5SDelphine CC Chiu     }
1047c0f918b5SDelphine CC Chiu 
1048f0cf6658SJayashree-D     if (oemData.find(hostName) == oemData.end())
1049877d5dd9SVijay Khemka     {
1050877d5dd9SVijay Khemka         /* Return default boot order 0100090203ff */
1051877d5dd9SVijay Khemka         uint8_t defaultBoot[SIZE_BOOT_ORDER] = {
1052e39f9393SWilly Tu             BOOT_MODE_UEFI,
1053e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["USB_DEV"]),
1054e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["NET_IPV6"]),
1055e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["SATA_HDD"]),
1056e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["SATA_CD"]),
1057e39f9393SWilly Tu             0xff};
1058877d5dd9SVijay Khemka 
1059f0cf6658SJayashree-D         memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER);
1060877d5dd9SVijay Khemka         phosphor::logging::log<phosphor::logging::level::INFO>(
1061877d5dd9SVijay Khemka             "Set default boot order");
1062f0cf6658SJayashree-D         setBootOrder(bootObjPath, defaultBoot, hostName);
1063877d5dd9SVijay Khemka     }
1064877d5dd9SVijay Khemka     else
1065877d5dd9SVijay Khemka     {
1066f0cf6658SJayashree-D         nlohmann::json bootMode = oemData[hostName][KEY_BOOT_MODE];
10671d4a0697SVijay Khemka         if (bootMode["CMOS_CLR"])
1068c0f918b5SDelphine CC Chiu             bootVal |= BOOT_MODE_CMOS_CLR;
10691d4a0697SVijay Khemka 
1070f0cf6658SJayashree-D         bootSeq[0] = mode;
10711d4a0697SVijay Khemka 
1072f0cf6658SJayashree-D         for (int i = 1; i < SIZE_BOOT_ORDER; i++)
1073877d5dd9SVijay Khemka         {
1074f0cf6658SJayashree-D             std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
1075877d5dd9SVijay Khemka             if (bootMap.find(seqStr) != bootMap.end())
1076f0cf6658SJayashree-D                 bootSeq[i] = bootMap[seqStr];
1077877d5dd9SVijay Khemka             else
1078f0cf6658SJayashree-D                 bootSeq[i] = 0xff;
1079877d5dd9SVijay Khemka         }
1080877d5dd9SVijay Khemka     }
1081e7d23d0eSVijay Khemka 
1082c0f918b5SDelphine CC Chiu     return ipmi::responseSuccess(bootVal, bootSeq[1], bootSeq[2], bootSeq[3],
1083f0cf6658SJayashree-D                                  bootSeq[4], bootSeq[5]);
1084e7d23d0eSVijay Khemka }
1085e7d23d0eSVijay Khemka // Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
1086e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1087e39f9393SWilly Tu ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t, ipmi_cmd_t,
1088e39f9393SWilly Tu                                     ipmi_request_t request, ipmi_response_t,
1089e39f9393SWilly Tu                                     ipmi_data_len_t data_len, ipmi_context_t)
1090e7d23d0eSVijay Khemka {
10911d4a0697SVijay Khemka     machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request);
10921d4a0697SVijay Khemka     uint8_t len = *data_len;
1093e7d23d0eSVijay Khemka 
1094e7d23d0eSVijay Khemka     *data_len = 0;
1095e7d23d0eSVijay Khemka 
10961d4a0697SVijay Khemka     if (len < sizeof(machineConfigInfo_t))
10971d4a0697SVijay Khemka     {
10981d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
10991d4a0697SVijay Khemka             "Invalid machine configuration length received");
11001d4a0697SVijay Khemka         return IPMI_CC_REQ_DATA_LEN_INVALID;
11011d4a0697SVijay Khemka     }
11021d4a0697SVijay Khemka 
11031d4a0697SVijay Khemka     if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*))
11041d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN";
11051d4a0697SVijay Khemka     else
11061d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] =
11071d4a0697SVijay Khemka             chassisType[req->chassis_type];
11081d4a0697SVijay Khemka 
11091d4a0697SVijay Khemka     if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*))
11101d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN";
11111d4a0697SVijay Khemka     else
11121d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type];
11131d4a0697SVijay Khemka 
11141d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt;
11151d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt;
11161d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt;
11171d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt;
11181d4a0697SVijay Khemka 
11191d4a0697SVijay Khemka     if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*))
11201d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN";
11211d4a0697SVijay Khemka     else
11221d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type];
11231d4a0697SVijay Khemka 
11241d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {};
11251d4a0697SVijay Khemka     int i = 0;
11261d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_0)
11271d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1";
11281d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_1)
11291d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2";
11301d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_2)
11311d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3";
11321d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_3)
11331d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4";
11341d4a0697SVijay Khemka 
11351d4a0697SVijay Khemka     if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11361d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN";
11371d4a0697SVijay Khemka     else
11381d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] =
11391d4a0697SVijay Khemka             pcieType[req->slot1_pcie_type];
11401d4a0697SVijay Khemka 
11411d4a0697SVijay Khemka     if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11421d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN";
11431d4a0697SVijay Khemka     else
11441d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] =
11451d4a0697SVijay Khemka             pcieType[req->slot2_pcie_type];
11461d4a0697SVijay Khemka 
11471d4a0697SVijay Khemka     if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11481d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN";
11491d4a0697SVijay Khemka     else
11501d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] =
11511d4a0697SVijay Khemka             pcieType[req->slot3_pcie_type];
11521d4a0697SVijay Khemka 
11531d4a0697SVijay Khemka     if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11541d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN";
11551d4a0697SVijay Khemka     else
11561d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] =
11571d4a0697SVijay Khemka             pcieType[req->slot4_pcie_type];
11581d4a0697SVijay Khemka 
11591d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt;
11601d4a0697SVijay Khemka 
11611d4a0697SVijay Khemka     flushOemData();
11621d4a0697SVijay Khemka 
1163e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1164e7d23d0eSVijay Khemka }
1165e7d23d0eSVijay Khemka 
1166e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1167e7d23d0eSVijay Khemka // Set POST start (CMD_OEM_SET_POST_START)
1168e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1169e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1170e39f9393SWilly Tu                                ipmi_response_t, ipmi_data_len_t data_len,
1171e39f9393SWilly Tu                                ipmi_context_t)
1172e7d23d0eSVijay Khemka {
1173e7d23d0eSVijay Khemka     phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
1174e7d23d0eSVijay Khemka 
11751d4a0697SVijay Khemka     /* Do nothing, return success */
1176e7d23d0eSVijay Khemka     *data_len = 0;
1177e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1178e7d23d0eSVijay Khemka }
1179e7d23d0eSVijay Khemka 
1180e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1181e7d23d0eSVijay Khemka // Set POST End (CMD_OEM_SET_POST_END)
1182e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1183e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1184e39f9393SWilly Tu                              ipmi_response_t, ipmi_data_len_t data_len,
1185e39f9393SWilly Tu                              ipmi_context_t)
1186e7d23d0eSVijay Khemka {
11871d4a0697SVijay Khemka     struct timespec ts;
1188e7d23d0eSVijay Khemka 
1189e7d23d0eSVijay Khemka     phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
1190e7d23d0eSVijay Khemka 
1191e7d23d0eSVijay Khemka     *data_len = 0;
11921d4a0697SVijay Khemka 
11931d4a0697SVijay Khemka     // Timestamp post end time.
11941d4a0697SVijay Khemka     clock_gettime(CLOCK_REALTIME, &ts);
11951d4a0697SVijay Khemka     oemData[KEY_TS_SLED] = ts.tv_sec;
11961d4a0697SVijay Khemka     flushOemData();
11971d4a0697SVijay Khemka 
11981d4a0697SVijay Khemka     // Sync time with system
11991d4a0697SVijay Khemka     // TODO: Add code for syncing time
12001d4a0697SVijay Khemka 
12011d4a0697SVijay Khemka     return IPMI_CC_OK;
12021d4a0697SVijay Khemka }
12031d4a0697SVijay Khemka 
12041d4a0697SVijay Khemka //----------------------------------------------------------------------
12051d4a0697SVijay Khemka // Set PPIN Info (CMD_OEM_SET_PPIN_INFO)
12061d4a0697SVijay Khemka //----------------------------------------------------------------------
12071d4a0697SVijay Khemka // Inform BMC about PPIN data of 8 bytes for each CPU
12081d4a0697SVijay Khemka //
12091d4a0697SVijay Khemka // Request:
12101d4a0697SVijay Khemka // Byte 1:8 – CPU0 PPIN data
12111d4a0697SVijay Khemka // Optional:
12121d4a0697SVijay Khemka // Byte 9:16 – CPU1 PPIN data
12131d4a0697SVijay Khemka //
12141d4a0697SVijay Khemka // Response:
12151d4a0697SVijay Khemka // Byte 1 – Completion Code
1216e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1217e39f9393SWilly Tu                               ipmi_response_t, ipmi_data_len_t data_len,
1218e39f9393SWilly Tu                               ipmi_context_t)
12191d4a0697SVijay Khemka {
12201d4a0697SVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
12211d4a0697SVijay Khemka     std::string ppinStr;
12221d4a0697SVijay Khemka     int len;
12231d4a0697SVijay Khemka 
12241d4a0697SVijay Khemka     if (*data_len > SIZE_CPU_PPIN * 2)
12251d4a0697SVijay Khemka         len = SIZE_CPU_PPIN * 2;
12261d4a0697SVijay Khemka     else
12271d4a0697SVijay Khemka         len = *data_len;
12281d4a0697SVijay Khemka     *data_len = 0;
12291d4a0697SVijay Khemka 
12301d4a0697SVijay Khemka     ppinStr = bytesToStr(req, len);
12311d4a0697SVijay Khemka     oemData[KEY_PPIN_INFO] = ppinStr.c_str();
12321d4a0697SVijay Khemka     flushOemData();
12331d4a0697SVijay Khemka 
12341d4a0697SVijay Khemka     return IPMI_CC_OK;
12351d4a0697SVijay Khemka }
12361d4a0697SVijay Khemka 
12371d4a0697SVijay Khemka //----------------------------------------------------------------------
12381d4a0697SVijay Khemka // Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER)
12391d4a0697SVijay Khemka //----------------------------------------------------------------------
1240e39f9393SWilly Tu ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1241e39f9393SWilly Tu                                 ipmi_response_t, ipmi_data_len_t data_len,
1242e39f9393SWilly Tu                                 ipmi_context_t)
12431d4a0697SVijay Khemka {
12441d4a0697SVijay Khemka     /* Do nothing, return success */
12451d4a0697SVijay Khemka     *data_len = 0;
1246e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1247e7d23d0eSVijay Khemka }
1248e7d23d0eSVijay Khemka 
1249f2246ce8SVijay Khemka // Helper function to set guid at offset in EEPROM
1250e39f9393SWilly Tu [[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid)
1251f2246ce8SVijay Khemka {
1252f2246ce8SVijay Khemka     int fd = -1;
1253f2246ce8SVijay Khemka     ssize_t len;
1254f2246ce8SVijay Khemka     int ret = 0;
1255f2246ce8SVijay Khemka 
1256f2246ce8SVijay Khemka     errno = 0;
1257f2246ce8SVijay Khemka 
1258f2246ce8SVijay Khemka     // Check if file is present
1259f2246ce8SVijay Khemka     if (access(FRU_EEPROM, F_OK) == -1)
1260f2246ce8SVijay Khemka     {
1261f2246ce8SVijay Khemka         std::cerr << "Unable to access: " << FRU_EEPROM << std::endl;
1262f2246ce8SVijay Khemka         return errno;
1263f2246ce8SVijay Khemka     }
1264f2246ce8SVijay Khemka 
1265f2246ce8SVijay Khemka     // Open the file
1266f2246ce8SVijay Khemka     fd = open(FRU_EEPROM, O_WRONLY);
1267f2246ce8SVijay Khemka     if (fd == -1)
1268f2246ce8SVijay Khemka     {
1269f2246ce8SVijay Khemka         std::cerr << "Unable to open: " << FRU_EEPROM << std::endl;
1270f2246ce8SVijay Khemka         return errno;
1271f2246ce8SVijay Khemka     }
1272f2246ce8SVijay Khemka 
1273f2246ce8SVijay Khemka     // seek to the offset
1274f2246ce8SVijay Khemka     lseek(fd, offset, SEEK_SET);
1275f2246ce8SVijay Khemka 
1276f2246ce8SVijay Khemka     // Write bytes to location
1277f2246ce8SVijay Khemka     len = write(fd, guid, GUID_SIZE);
1278f2246ce8SVijay Khemka     if (len != GUID_SIZE)
1279f2246ce8SVijay Khemka     {
1280f2246ce8SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
1281f2246ce8SVijay Khemka             "GUID write data to EEPROM failed");
1282f2246ce8SVijay Khemka         ret = errno;
1283f2246ce8SVijay Khemka     }
1284f2246ce8SVijay Khemka 
1285f2246ce8SVijay Khemka     close(fd);
1286f2246ce8SVijay Khemka     return ret;
1287f2246ce8SVijay Khemka }
1288f2246ce8SVijay Khemka 
1289f2246ce8SVijay Khemka //----------------------------------------------------------------------
1290f2246ce8SVijay Khemka // Set System GUID (CMD_OEM_SET_SYSTEM_GUID)
1291f2246ce8SVijay Khemka //----------------------------------------------------------------------
12925f8e3435SManikandan Elumalai #if BIC_ENABLED
12933f671273SBonnie Lo ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx,
12945f8e3435SManikandan Elumalai                                      std::vector<uint8_t> reqData)
12955f8e3435SManikandan Elumalai {
12965f8e3435SManikandan Elumalai     std::vector<uint8_t> respData;
12975f8e3435SManikandan Elumalai 
12985f8e3435SManikandan Elumalai     if (reqData.size() != GUID_SIZE) // 16bytes
12995f8e3435SManikandan Elumalai     {
13005f8e3435SManikandan Elumalai 
13015f8e3435SManikandan Elumalai         return ipmi::responseReqDataLenInvalid();
13025f8e3435SManikandan Elumalai     }
13035f8e3435SManikandan Elumalai 
13045f8e3435SManikandan Elumalai     uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
13055f8e3435SManikandan Elumalai 
13065f8e3435SManikandan Elumalai     if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
13075f8e3435SManikandan Elumalai         return ipmi::responseUnspecifiedError();
13085f8e3435SManikandan Elumalai 
13095f8e3435SManikandan Elumalai     return ipmi::responseSuccess();
13105f8e3435SManikandan Elumalai }
13115f8e3435SManikandan Elumalai 
13125f8e3435SManikandan Elumalai #else
1313d5353caaSPotin Lai ipmi_ret_t ipmiOemSetSystemGuid(ipmi_netfn_t, ipmi_cmd_t,
1314d5353caaSPotin Lai                                 ipmi_request_t request, ipmi_response_t,
1315d5353caaSPotin Lai                                 ipmi_data_len_t data_len, ipmi_context_t)
1316f2246ce8SVijay Khemka {
1317f2246ce8SVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
1318f2246ce8SVijay Khemka 
1319f2246ce8SVijay Khemka     if (*data_len != GUID_SIZE) // 16bytes
1320f2246ce8SVijay Khemka     {
1321f2246ce8SVijay Khemka         *data_len = 0;
1322f2246ce8SVijay Khemka         return IPMI_CC_REQ_DATA_LEN_INVALID;
1323f2246ce8SVijay Khemka     }
1324f2246ce8SVijay Khemka 
1325f2246ce8SVijay Khemka     *data_len = 0;
1326f2246ce8SVijay Khemka 
1327f2246ce8SVijay Khemka     if (setGUID(OFFSET_SYS_GUID, req))
1328f2246ce8SVijay Khemka     {
1329f2246ce8SVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
1330f2246ce8SVijay Khemka     }
1331f2246ce8SVijay Khemka     return IPMI_CC_OK;
1332f2246ce8SVijay Khemka }
13335f8e3435SManikandan Elumalai #endif
1334f2246ce8SVijay Khemka 
1335e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1336e7d23d0eSVijay Khemka // Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
1337e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1338e39f9393SWilly Tu ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1339e39f9393SWilly Tu                                    ipmi_response_t, ipmi_data_len_t data_len,
1340e39f9393SWilly Tu                                    ipmi_context_t)
1341e7d23d0eSVijay Khemka {
13421d4a0697SVijay Khemka     /* Do nothing, return success */
1343e7d23d0eSVijay Khemka     *data_len = 0;
1344e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1345e7d23d0eSVijay Khemka }
1346e7d23d0eSVijay Khemka 
1347e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1348e7d23d0eSVijay Khemka // Set PPR (CMD_OEM_SET_PPR)
1349e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1350e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1351e39f9393SWilly Tu                          ipmi_response_t, ipmi_data_len_t data_len,
1352e39f9393SWilly Tu                          ipmi_context_t)
1353e7d23d0eSVijay Khemka {
1354e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
13551d4a0697SVijay Khemka     uint8_t pprCnt, pprAct, pprIndex;
13561d4a0697SVijay Khemka     uint8_t selParam = req[0];
13571d4a0697SVijay Khemka     uint8_t len = *data_len;
13581d4a0697SVijay Khemka     std::stringstream ss;
13591d4a0697SVijay Khemka     std::string str;
1360e7d23d0eSVijay Khemka 
1361e7d23d0eSVijay Khemka     *data_len = 0;
13621d4a0697SVijay Khemka 
13631d4a0697SVijay Khemka     switch (selParam)
13641d4a0697SVijay Khemka     {
13651d4a0697SVijay Khemka         case PPR_ACTION:
13661d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) ==
13671d4a0697SVijay Khemka                 oemData[KEY_PPR].end())
13681d4a0697SVijay Khemka                 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
13691d4a0697SVijay Khemka 
13701d4a0697SVijay Khemka             pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
13711d4a0697SVijay Khemka             if (pprCnt == 0)
13721d4a0697SVijay Khemka                 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
13731d4a0697SVijay Khemka 
13741d4a0697SVijay Khemka             pprAct = req[1];
13751d4a0697SVijay Khemka             /* Check if ppr is enabled or disabled */
13761d4a0697SVijay Khemka             if (!(pprAct & 0x80))
13771d4a0697SVijay Khemka                 pprAct = 0;
13781d4a0697SVijay Khemka 
13791d4a0697SVijay Khemka             oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct;
13801d4a0697SVijay Khemka             break;
13811d4a0697SVijay Khemka         case PPR_ROW_COUNT:
13821d4a0697SVijay Khemka             if (req[1] > 100)
13831d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
13841d4a0697SVijay Khemka 
13851d4a0697SVijay Khemka             oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1];
13861d4a0697SVijay Khemka             break;
13871d4a0697SVijay Khemka         case PPR_ROW_ADDR:
13881d4a0697SVijay Khemka             pprIndex = req[1];
13891d4a0697SVijay Khemka             if (pprIndex > 100)
13901d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
13911d4a0697SVijay Khemka 
13921d4a0697SVijay Khemka             if (len < PPR_ROW_ADDR_LEN + 1)
13931d4a0697SVijay Khemka             {
13941d4a0697SVijay Khemka                 phosphor::logging::log<phosphor::logging::level::ERR>(
13951d4a0697SVijay Khemka                     "Invalid PPR Row Address length received");
13961d4a0697SVijay Khemka                 return IPMI_CC_REQ_DATA_LEN_INVALID;
13971d4a0697SVijay Khemka             }
13981d4a0697SVijay Khemka 
13991d4a0697SVijay Khemka             ss << std::hex;
14001d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
14011d4a0697SVijay Khemka 
14021d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
14031d4a0697SVijay Khemka 
14041d4a0697SVijay Khemka             str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN);
14051d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str();
14061d4a0697SVijay Khemka             break;
14071d4a0697SVijay Khemka         case PPR_HISTORY_DATA:
14081d4a0697SVijay Khemka             pprIndex = req[1];
14091d4a0697SVijay Khemka             if (pprIndex > 100)
14101d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14111d4a0697SVijay Khemka 
14121d4a0697SVijay Khemka             if (len < PPR_HST_DATA_LEN + 1)
14131d4a0697SVijay Khemka             {
14141d4a0697SVijay Khemka                 phosphor::logging::log<phosphor::logging::level::ERR>(
14151d4a0697SVijay Khemka                     "Invalid PPR history data length received");
14161d4a0697SVijay Khemka                 return IPMI_CC_REQ_DATA_LEN_INVALID;
14171d4a0697SVijay Khemka             }
14181d4a0697SVijay Khemka 
14191d4a0697SVijay Khemka             ss << std::hex;
14201d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
14211d4a0697SVijay Khemka 
14221d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
14231d4a0697SVijay Khemka 
14241d4a0697SVijay Khemka             str = bytesToStr(&req[1], PPR_HST_DATA_LEN);
14251d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str();
14261d4a0697SVijay Khemka             break;
14271d4a0697SVijay Khemka         default:
14281d4a0697SVijay Khemka             return IPMI_CC_PARM_OUT_OF_RANGE;
14291d4a0697SVijay Khemka             break;
14301d4a0697SVijay Khemka     }
14311d4a0697SVijay Khemka 
14321d4a0697SVijay Khemka     flushOemData();
14331d4a0697SVijay Khemka 
1434e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1435e7d23d0eSVijay Khemka }
1436e7d23d0eSVijay Khemka 
1437e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1438e7d23d0eSVijay Khemka // Get PPR (CMD_OEM_GET_PPR)
1439e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1440e39f9393SWilly Tu ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1441e39f9393SWilly Tu                          ipmi_response_t response, ipmi_data_len_t data_len,
1442e39f9393SWilly Tu                          ipmi_context_t)
1443e7d23d0eSVijay Khemka {
1444e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
1445e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
14461d4a0697SVijay Khemka     uint8_t pprCnt, pprIndex;
14471d4a0697SVijay Khemka     uint8_t selParam = req[0];
14481d4a0697SVijay Khemka     std::stringstream ss;
14491d4a0697SVijay Khemka     std::string str;
1450e7d23d0eSVijay Khemka 
14511d4a0697SVijay Khemka     /* Any failure will return zero length data */
14521d4a0697SVijay Khemka     *data_len = 0;
14531d4a0697SVijay Khemka 
14541d4a0697SVijay Khemka     switch (selParam)
14551d4a0697SVijay Khemka     {
14561d4a0697SVijay Khemka         case PPR_ACTION:
14571d4a0697SVijay Khemka             res[0] = 0;
1458e7d23d0eSVijay Khemka             *data_len = 1;
1459e7d23d0eSVijay Khemka 
14601d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
14611d4a0697SVijay Khemka                 oemData[KEY_PPR].end())
14621d4a0697SVijay Khemka             {
14631d4a0697SVijay Khemka                 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
14641d4a0697SVijay Khemka                 if (pprCnt != 0)
14651d4a0697SVijay Khemka                 {
14661d4a0697SVijay Khemka                     if (oemData[KEY_PPR].find(KEY_PPR_ACTION) !=
14671d4a0697SVijay Khemka                         oemData[KEY_PPR].end())
14681d4a0697SVijay Khemka                     {
14691d4a0697SVijay Khemka                         res[0] = oemData[KEY_PPR][KEY_PPR_ACTION];
14701d4a0697SVijay Khemka                     }
14711d4a0697SVijay Khemka                 }
14721d4a0697SVijay Khemka             }
14731d4a0697SVijay Khemka             break;
14741d4a0697SVijay Khemka         case PPR_ROW_COUNT:
14751d4a0697SVijay Khemka             res[0] = 0;
14761d4a0697SVijay Khemka             *data_len = 1;
14771d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
14781d4a0697SVijay Khemka                 oemData[KEY_PPR].end())
14791d4a0697SVijay Khemka                 res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
14801d4a0697SVijay Khemka             break;
14811d4a0697SVijay Khemka         case PPR_ROW_ADDR:
14821d4a0697SVijay Khemka             pprIndex = req[1];
14831d4a0697SVijay Khemka             if (pprIndex > 100)
14841d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14851d4a0697SVijay Khemka 
14861d4a0697SVijay Khemka             ss << std::hex;
14871d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
14881d4a0697SVijay Khemka 
14891d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
14901d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14911d4a0697SVijay Khemka 
14921d4a0697SVijay Khemka             if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) ==
14931d4a0697SVijay Khemka                 oemData[KEY_PPR][ss.str()].end())
14941d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14951d4a0697SVijay Khemka 
14961d4a0697SVijay Khemka             str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR];
14971d4a0697SVijay Khemka             *data_len = strToBytes(str, res);
14981d4a0697SVijay Khemka             break;
14991d4a0697SVijay Khemka         case PPR_HISTORY_DATA:
15001d4a0697SVijay Khemka             pprIndex = req[1];
15011d4a0697SVijay Khemka             if (pprIndex > 100)
15021d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
15031d4a0697SVijay Khemka 
15041d4a0697SVijay Khemka             ss << std::hex;
15051d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
15061d4a0697SVijay Khemka 
15071d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
15081d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
15091d4a0697SVijay Khemka 
15101d4a0697SVijay Khemka             if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) ==
15111d4a0697SVijay Khemka                 oemData[KEY_PPR][ss.str()].end())
15121d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
15131d4a0697SVijay Khemka 
15141d4a0697SVijay Khemka             str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA];
15151d4a0697SVijay Khemka             *data_len = strToBytes(str, res);
15161d4a0697SVijay Khemka             break;
15171d4a0697SVijay Khemka         default:
15181d4a0697SVijay Khemka             return IPMI_CC_PARM_OUT_OF_RANGE;
15191d4a0697SVijay Khemka             break;
15201d4a0697SVijay Khemka     }
15211d4a0697SVijay Khemka 
15221d4a0697SVijay Khemka     return IPMI_CC_OK;
15231d4a0697SVijay Khemka }
15241d4a0697SVijay Khemka 
15251d4a0697SVijay Khemka /* FB OEM QC Commands */
15261d4a0697SVijay Khemka 
15271d4a0697SVijay Khemka //----------------------------------------------------------------------
15281d4a0697SVijay Khemka // Set Proc Info (CMD_OEM_Q_SET_PROC_INFO)
15291d4a0697SVijay Khemka //----------------------------------------------------------------------
15301d4a0697SVijay Khemka //"Request:
15311d4a0697SVijay Khemka // Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
15321d4a0697SVijay Khemka // Byte 4 – Processor Index, 0 base
15331d4a0697SVijay Khemka // Byte 5 – Parameter Selector
15341d4a0697SVijay Khemka // Byte 6..N – Configuration parameter data (see below for Parameters
15351d4a0697SVijay Khemka // of Processor Information)
15361d4a0697SVijay Khemka // Response:
15371d4a0697SVijay Khemka // Byte 1 – Completion code
15381d4a0697SVijay Khemka //
15391d4a0697SVijay Khemka // Parameter#1: (Processor Product Name)
15401d4a0697SVijay Khemka //
15411d4a0697SVijay Khemka // Byte 1..48 –Product name(ASCII code)
15421d4a0697SVijay Khemka // Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
15431d4a0697SVijay Khemka //
15441d4a0697SVijay Khemka // Param#2: Processor Basic Information
15451d4a0697SVijay Khemka // Byte 1 – Core Number
15461d4a0697SVijay Khemka // Byte 2 – Thread Number (LSB)
15471d4a0697SVijay Khemka // Byte 3 – Thread Number (MSB)
15481d4a0697SVijay Khemka // Byte 4 – Processor frequency in MHz (LSB)
15491d4a0697SVijay Khemka // Byte 5 – Processor frequency in MHz (MSB)
15501d4a0697SVijay Khemka // Byte 6..7 – Revision
15511d4a0697SVijay Khemka //
1552d532fecaSKarthikeyan Pasupathi 
1553d532fecaSKarthikeyan Pasupathi ipmi::RspType<> ipmiOemQSetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1554d532fecaSKarthikeyan Pasupathi                                     uint8_t, uint8_t procIndex,
1555d532fecaSKarthikeyan Pasupathi                                     uint8_t paramSel,
1556d532fecaSKarthikeyan Pasupathi                                     std::vector<uint8_t> request)
15571d4a0697SVijay Khemka {
15581d4a0697SVijay Khemka     uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
15591d4a0697SVijay Khemka     std::stringstream ss;
15601d4a0697SVijay Khemka     std::string str;
1561d532fecaSKarthikeyan Pasupathi     uint8_t len = request.size();
1562d532fecaSKarthikeyan Pasupathi     auto hostId = findHost(ctx->hostIdx);
1563d532fecaSKarthikeyan Pasupathi     if (!hostId)
1564d532fecaSKarthikeyan Pasupathi     {
1565d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
1566d532fecaSKarthikeyan Pasupathi             "Invalid Host Id received");
1567d532fecaSKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
1568d532fecaSKarthikeyan Pasupathi     }
1569d532fecaSKarthikeyan Pasupathi     std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
15701d4a0697SVijay Khemka     /* check for requested data params */
1571d532fecaSKarthikeyan Pasupathi     if (len < 5 || paramSel < 1 || paramSel >= numParam)
15721d4a0697SVijay Khemka     {
15731d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
15741d4a0697SVijay Khemka             "Invalid parameter received");
1575d532fecaSKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
15761d4a0697SVijay Khemka     }
15771d4a0697SVijay Khemka     ss << std::hex;
1578d532fecaSKarthikeyan Pasupathi     ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1579d532fecaSKarthikeyan Pasupathi     oemData[procInfo][ss.str()][KEY_PROC_INDEX] = procIndex;
1580d532fecaSKarthikeyan Pasupathi     str = bytesToStr(request.data(), len);
1581d532fecaSKarthikeyan Pasupathi     oemData[procInfo][ss.str()][cpuInfoKey[paramSel]] = str.c_str();
15821d4a0697SVijay Khemka     flushOemData();
1583d532fecaSKarthikeyan Pasupathi     return ipmi::responseSuccess();
15841d4a0697SVijay Khemka }
15851d4a0697SVijay Khemka 
15861d4a0697SVijay Khemka //----------------------------------------------------------------------
15871d4a0697SVijay Khemka // Get Proc Info (CMD_OEM_Q_GET_PROC_INFO)
15881d4a0697SVijay Khemka //----------------------------------------------------------------------
15891d4a0697SVijay Khemka // Request:
15901d4a0697SVijay Khemka // Byte 1:3 –  Manufacturer ID – XXYYZZ h, LSB first
15911d4a0697SVijay Khemka // Byte 4 – Processor Index, 0 base
15921d4a0697SVijay Khemka // Byte 5 – Parameter Selector
15931d4a0697SVijay Khemka // Response:
15941d4a0697SVijay Khemka // Byte 1 – Completion code
15951d4a0697SVijay Khemka // Byte 2..N – Configuration Parameter Data (see below for Parameters
15961d4a0697SVijay Khemka // of Processor Information)
15971d4a0697SVijay Khemka //
15981d4a0697SVijay Khemka // Parameter#1: (Processor Product Name)
15991d4a0697SVijay Khemka //
16001d4a0697SVijay Khemka // Byte 1..48 –Product name(ASCII code)
16011d4a0697SVijay Khemka // Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
16021d4a0697SVijay Khemka //
16031d4a0697SVijay Khemka // Param#2: Processor Basic Information
16041d4a0697SVijay Khemka // Byte 1 – Core Number
16051d4a0697SVijay Khemka // Byte 2 – Thread Number (LSB)
16061d4a0697SVijay Khemka // Byte 3 – Thread Number (MSB)
16071d4a0697SVijay Khemka // Byte 4 – Processor frequency in MHz (LSB)
16081d4a0697SVijay Khemka // Byte 5 – Processor frequency in MHz (MSB)
16091d4a0697SVijay Khemka // Byte 6..7 – Revision
16101d4a0697SVijay Khemka //
1611d532fecaSKarthikeyan Pasupathi 
1612d532fecaSKarthikeyan Pasupathi ipmi::RspType<std::vector<uint8_t>>
1613d532fecaSKarthikeyan Pasupathi     ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1614d532fecaSKarthikeyan Pasupathi                         uint8_t procIndex, uint8_t paramSel)
16151d4a0697SVijay Khemka {
16161d4a0697SVijay Khemka     uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
16171d4a0697SVijay Khemka     std::stringstream ss;
16181d4a0697SVijay Khemka     std::string str;
1619d532fecaSKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
1620d532fecaSKarthikeyan Pasupathi     auto hostId = findHost(ctx->hostIdx);
1621d532fecaSKarthikeyan Pasupathi     if (!hostId)
1622d532fecaSKarthikeyan Pasupathi     {
1623d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
1624d532fecaSKarthikeyan Pasupathi             "Invalid Host Id received");
1625d532fecaSKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
1626d532fecaSKarthikeyan Pasupathi     }
1627d532fecaSKarthikeyan Pasupathi     std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
1628d532fecaSKarthikeyan Pasupathi     if (paramSel < 1 || paramSel >= numParam)
16291d4a0697SVijay Khemka     {
16301d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
16311d4a0697SVijay Khemka             "Invalid parameter received");
1632d532fecaSKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
16331d4a0697SVijay Khemka     }
16341d4a0697SVijay Khemka     ss << std::hex;
1635d532fecaSKarthikeyan Pasupathi     ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1636d532fecaSKarthikeyan Pasupathi     if (oemData[procInfo].find(ss.str()) == oemData[procInfo].end())
1637d532fecaSKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
1638d532fecaSKarthikeyan Pasupathi     if (oemData[procInfo][ss.str()].find(cpuInfoKey[paramSel]) ==
1639d532fecaSKarthikeyan Pasupathi         oemData[procInfo][ss.str()].end())
1640d532fecaSKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
1641d532fecaSKarthikeyan Pasupathi     str = oemData[procInfo][ss.str()][cpuInfoKey[paramSel]];
1642d532fecaSKarthikeyan Pasupathi     int dataLen = strToBytes(str, res);
1643d532fecaSKarthikeyan Pasupathi     std::vector<uint8_t> response(&res[0], &res[dataLen]);
1644d532fecaSKarthikeyan Pasupathi     return ipmi::responseSuccess(response);
16451d4a0697SVijay Khemka }
16461d4a0697SVijay Khemka 
16471d4a0697SVijay Khemka //----------------------------------------------------------------------
16481d4a0697SVijay Khemka // Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO)
16491d4a0697SVijay Khemka //----------------------------------------------------------------------
16501d4a0697SVijay Khemka // Request:
16511d4a0697SVijay Khemka // Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
16521d4a0697SVijay Khemka // Byte 4 – DIMM Index, 0 base
16531d4a0697SVijay Khemka // Byte 5 – Parameter Selector
16541d4a0697SVijay Khemka // Byte 6..N – Configuration parameter data (see below for Parameters
16551d4a0697SVijay Khemka // of DIMM Information)
16561d4a0697SVijay Khemka // Response:
16571d4a0697SVijay Khemka // Byte 1 – Completion code
16581d4a0697SVijay Khemka //
16591d4a0697SVijay Khemka // Param#1 (DIMM Location):
16601d4a0697SVijay Khemka // Byte 1 – DIMM Present
16611d4a0697SVijay Khemka // Byte 1 – DIMM Present
16621d4a0697SVijay Khemka // 01h – Present
16631d4a0697SVijay Khemka // FFh – Not Present
16641d4a0697SVijay Khemka // Byte 2 – Node Number, 0 base
16651d4a0697SVijay Khemka // Byte 3 – Channel Number , 0 base
16661d4a0697SVijay Khemka // Byte 4 – DIMM Number , 0 base
16671d4a0697SVijay Khemka //
16681d4a0697SVijay Khemka // Param#2 (DIMM Type):
16691d4a0697SVijay Khemka // Byte 1 – DIMM Type
16701d4a0697SVijay Khemka // Bit [7:6]
16711d4a0697SVijay Khemka // For DDR3
16721d4a0697SVijay Khemka //  00 – Normal Voltage (1.5V)
16731d4a0697SVijay Khemka //  01 – Ultra Low Voltage (1.25V)
16741d4a0697SVijay Khemka //  10 – Low Voltage (1.35V)
16751d4a0697SVijay Khemka //  11 – Reserved
16761d4a0697SVijay Khemka // For DDR4
16771d4a0697SVijay Khemka //  00 – Reserved
16781d4a0697SVijay Khemka //  01 – Reserved
16791d4a0697SVijay Khemka //  10 – Reserved
16801d4a0697SVijay Khemka //  11 – Normal Voltage (1.2V)
16811d4a0697SVijay Khemka // Bit [5:0]
16821d4a0697SVijay Khemka //  0x00 – SDRAM
16831d4a0697SVijay Khemka //  0x01 – DDR-1 RAM
16841d4a0697SVijay Khemka //  0x02 – Rambus
16851d4a0697SVijay Khemka //  0x03 – DDR-2 RAM
16861d4a0697SVijay Khemka //  0x04 – FBDIMM
16871d4a0697SVijay Khemka //  0x05 – DDR-3 RAM
16881d4a0697SVijay Khemka //  0x06 – DDR-4 RAM
16891d4a0697SVijay Khemka //
16901d4a0697SVijay Khemka // Param#3 (DIMM Speed):
16911d4a0697SVijay Khemka // Byte 1..2 – DIMM speed in MHz, LSB
16921d4a0697SVijay Khemka // Byte 3..6 – DIMM size in Mbytes, LSB
16931d4a0697SVijay Khemka //
16941d4a0697SVijay Khemka // Param#4 (Module Part Number):
16951d4a0697SVijay Khemka // Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
16961d4a0697SVijay Khemka //
16971d4a0697SVijay Khemka // Param#5 (Module Serial Number):
16981d4a0697SVijay Khemka // Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
16991d4a0697SVijay Khemka //
17001d4a0697SVijay Khemka // Param#6 (Module Manufacturer ID):
17011d4a0697SVijay Khemka // Byte 1 - Module Manufacturer ID, LSB
17021d4a0697SVijay Khemka // Byte 2 - Module Manufacturer ID, MSB
17031d4a0697SVijay Khemka //
170410ff3d86SKarthikeyan Pasupathi ipmi::RspType<> ipmiOemQSetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
170510ff3d86SKarthikeyan Pasupathi                                     uint8_t, uint8_t dimmIndex,
170610ff3d86SKarthikeyan Pasupathi                                     uint8_t paramSel,
170710ff3d86SKarthikeyan Pasupathi                                     std::vector<uint8_t> request)
17081d4a0697SVijay Khemka {
17091d4a0697SVijay Khemka     uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
17101d4a0697SVijay Khemka     std::stringstream ss;
17111d4a0697SVijay Khemka     std::string str;
171210ff3d86SKarthikeyan Pasupathi     uint8_t len = request.size();
171310ff3d86SKarthikeyan Pasupathi     std::string dimmType;
171410ff3d86SKarthikeyan Pasupathi     readDimmType(dimmType, dimmIndex);
17156d9e9a75SPatrick Williams     auto hostId = findHost(ctx->hostIdx);
171610ff3d86SKarthikeyan Pasupathi     if (!hostId)
171710ff3d86SKarthikeyan Pasupathi     {
171810ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
171910ff3d86SKarthikeyan Pasupathi             "Invalid Host Id received");
172010ff3d86SKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
172110ff3d86SKarthikeyan Pasupathi     }
17221d4a0697SVijay Khemka 
172310ff3d86SKarthikeyan Pasupathi     std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
17241d4a0697SVijay Khemka 
172510ff3d86SKarthikeyan Pasupathi     if (len < 3 || paramSel < 1 || paramSel >= numParam)
17261d4a0697SVijay Khemka     {
17271d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
17281d4a0697SVijay Khemka             "Invalid parameter received");
172910ff3d86SKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
17301d4a0697SVijay Khemka     }
17311d4a0697SVijay Khemka 
17321d4a0697SVijay Khemka     ss << std::hex;
173310ff3d86SKarthikeyan Pasupathi     ss << (int)dimmIndex;
173410ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][KEY_DIMM_INDEX] = dimmIndex;
173510ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
173610ff3d86SKarthikeyan Pasupathi     str = bytesToStr(request.data(), len);
173710ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]] = str.c_str();
17381d4a0697SVijay Khemka     flushOemData();
173910ff3d86SKarthikeyan Pasupathi     return ipmi::responseSuccess();
17401d4a0697SVijay Khemka }
17411d4a0697SVijay Khemka 
17421d4a0697SVijay Khemka // Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO)
17431d4a0697SVijay Khemka //----------------------------------------------------------------------
17441d4a0697SVijay Khemka // Request:
17451d4a0697SVijay Khemka // Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
17461d4a0697SVijay Khemka // Byte 4 – DIMM Index, 0 base
17471d4a0697SVijay Khemka // Byte 5 – Parameter Selector
17481d4a0697SVijay Khemka // Byte 6..N – Configuration parameter data (see below for Parameters
17491d4a0697SVijay Khemka // of DIMM Information)
17501d4a0697SVijay Khemka // Response:
17511d4a0697SVijay Khemka // Byte 1 – Completion code
17521d4a0697SVijay Khemka // Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters
17531d4a0697SVijay Khemka // of DIMM Information)
17541d4a0697SVijay Khemka //
17551d4a0697SVijay Khemka // Param#1 (DIMM Location):
17561d4a0697SVijay Khemka // Byte 1 – DIMM Present
17571d4a0697SVijay Khemka // Byte 1 – DIMM Present
17581d4a0697SVijay Khemka // 01h – Present
17591d4a0697SVijay Khemka // FFh – Not Present
17601d4a0697SVijay Khemka // Byte 2 – Node Number, 0 base
17611d4a0697SVijay Khemka // Byte 3 – Channel Number , 0 base
17621d4a0697SVijay Khemka // Byte 4 – DIMM Number , 0 base
17631d4a0697SVijay Khemka //
17641d4a0697SVijay Khemka // Param#2 (DIMM Type):
17651d4a0697SVijay Khemka // Byte 1 – DIMM Type
17661d4a0697SVijay Khemka // Bit [7:6]
17671d4a0697SVijay Khemka // For DDR3
17681d4a0697SVijay Khemka //  00 – Normal Voltage (1.5V)
17691d4a0697SVijay Khemka //  01 – Ultra Low Voltage (1.25V)
17701d4a0697SVijay Khemka //  10 – Low Voltage (1.35V)
17711d4a0697SVijay Khemka //  11 – Reserved
17721d4a0697SVijay Khemka // For DDR4
17731d4a0697SVijay Khemka //  00 – Reserved
17741d4a0697SVijay Khemka //  01 – Reserved
17751d4a0697SVijay Khemka //  10 – Reserved
17761d4a0697SVijay Khemka //  11 – Normal Voltage (1.2V)
17771d4a0697SVijay Khemka // Bit [5:0]
17781d4a0697SVijay Khemka //  0x00 – SDRAM
17791d4a0697SVijay Khemka //  0x01 – DDR-1 RAM
17801d4a0697SVijay Khemka //  0x02 – Rambus
17811d4a0697SVijay Khemka //  0x03 – DDR-2 RAM
17821d4a0697SVijay Khemka //  0x04 – FBDIMM
17831d4a0697SVijay Khemka //  0x05 – DDR-3 RAM
17841d4a0697SVijay Khemka //  0x06 – DDR-4 RAM
17851d4a0697SVijay Khemka //
17861d4a0697SVijay Khemka // Param#3 (DIMM Speed):
17871d4a0697SVijay Khemka // Byte 1..2 – DIMM speed in MHz, LSB
17881d4a0697SVijay Khemka // Byte 3..6 – DIMM size in Mbytes, LSB
17891d4a0697SVijay Khemka //
17901d4a0697SVijay Khemka // Param#4 (Module Part Number):
17911d4a0697SVijay Khemka // Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
17921d4a0697SVijay Khemka //
17931d4a0697SVijay Khemka // Param#5 (Module Serial Number):
17941d4a0697SVijay Khemka // Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
17951d4a0697SVijay Khemka //
17961d4a0697SVijay Khemka // Param#6 (Module Manufacturer ID):
17971d4a0697SVijay Khemka // Byte 1 - Module Manufacturer ID, LSB
17981d4a0697SVijay Khemka // Byte 2 - Module Manufacturer ID, MSB
17991d4a0697SVijay Khemka //
180010ff3d86SKarthikeyan Pasupathi ipmi::RspType<std::vector<uint8_t>>
180110ff3d86SKarthikeyan Pasupathi     ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
180210ff3d86SKarthikeyan Pasupathi                         uint8_t dimmIndex, uint8_t paramSel)
18031d4a0697SVijay Khemka {
18041d4a0697SVijay Khemka     uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
180510ff3d86SKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
18061d4a0697SVijay Khemka     std::stringstream ss;
18071d4a0697SVijay Khemka     std::string str;
180810ff3d86SKarthikeyan Pasupathi     std::string dimmType;
180910ff3d86SKarthikeyan Pasupathi     readDimmType(dimmType, dimmIndex);
18106d9e9a75SPatrick Williams     auto hostId = findHost(ctx->hostIdx);
181110ff3d86SKarthikeyan Pasupathi     if (!hostId)
181210ff3d86SKarthikeyan Pasupathi     {
181310ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
181410ff3d86SKarthikeyan Pasupathi             "Invalid Host Id received");
181510ff3d86SKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
181610ff3d86SKarthikeyan Pasupathi     }
181710ff3d86SKarthikeyan Pasupathi     std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
18181d4a0697SVijay Khemka 
181910ff3d86SKarthikeyan Pasupathi     if (paramSel < 1 || paramSel >= numParam)
18201d4a0697SVijay Khemka     {
18211d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
18221d4a0697SVijay Khemka             "Invalid parameter received");
182310ff3d86SKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
18241d4a0697SVijay Khemka     }
18251d4a0697SVijay Khemka     ss << std::hex;
182610ff3d86SKarthikeyan Pasupathi     ss << (int)dimmIndex;
182710ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
182810ff3d86SKarthikeyan Pasupathi     if (oemData[dimmInfo].find(ss.str()) == oemData[dimmInfo].end())
182910ff3d86SKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
183010ff3d86SKarthikeyan Pasupathi     if (oemData[dimmInfo][ss.str()].find(dimmInfoKey[paramSel]) ==
183110ff3d86SKarthikeyan Pasupathi         oemData[dimmInfo][ss.str()].end())
183210ff3d86SKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
183310ff3d86SKarthikeyan Pasupathi     str = oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]];
183410ff3d86SKarthikeyan Pasupathi     int data_length = strToBytes(str, res);
183510ff3d86SKarthikeyan Pasupathi     std::vector<uint8_t> response(&res[0], &res[data_length]);
183610ff3d86SKarthikeyan Pasupathi     return ipmi::responseSuccess(response);
18371d4a0697SVijay Khemka }
18381d4a0697SVijay Khemka 
18391d4a0697SVijay Khemka //----------------------------------------------------------------------
18401d4a0697SVijay Khemka // Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO)
18411d4a0697SVijay Khemka //----------------------------------------------------------------------
18421d4a0697SVijay Khemka // BIOS issue this command to provide HDD information to BMC.
18431d4a0697SVijay Khemka //
18441d4a0697SVijay Khemka // BIOS just can get information by standard ATA / SMART command for
18451d4a0697SVijay Khemka // OB SATA controller.
18461d4a0697SVijay Khemka // BIOS can get
18471d4a0697SVijay Khemka // 1.     Serial Number
18481d4a0697SVijay Khemka // 2.     Model Name
18491d4a0697SVijay Khemka // 3.     HDD FW Version
18501d4a0697SVijay Khemka // 4.     HDD Capacity
18511d4a0697SVijay Khemka // 5.     HDD WWN
18521d4a0697SVijay Khemka //
18531d4a0697SVijay Khemka //  Use Get HDD info Param #5 to know the MAX HDD info index.
18541d4a0697SVijay Khemka //
18551d4a0697SVijay Khemka //  Request:
18561d4a0697SVijay Khemka //  Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
18571d4a0697SVijay Khemka //  Byte 4 –
18581d4a0697SVijay Khemka //  [7:4] Reserved
18591d4a0697SVijay Khemka //  [3:0] HDD Controller Type
18601d4a0697SVijay Khemka //     0x00 – BIOS
18611d4a0697SVijay Khemka //     0x01 – Expander
18621d4a0697SVijay Khemka //     0x02 – LSI
18631d4a0697SVijay Khemka //  Byte 5 – HDD Info Index, 0 base
18641d4a0697SVijay Khemka //  Byte 6 – Parameter Selector
18651d4a0697SVijay Khemka //  Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD
18661d4a0697SVijay Khemka //  Information)
18671d4a0697SVijay Khemka //
18681d4a0697SVijay Khemka //  Response:
18691d4a0697SVijay Khemka //  Byte 1 – Completion Code
18701d4a0697SVijay Khemka //
18711d4a0697SVijay Khemka //  Param#0 (HDD Location):
18721d4a0697SVijay Khemka //  Byte 1 – Controller
18731d4a0697SVijay Khemka //    [7:3] Device Number
18741d4a0697SVijay Khemka //    [2:0] Function Number
18751d4a0697SVijay Khemka //  For Intel C610 series (Wellsburg)
18761d4a0697SVijay Khemka //    D31:F2 (0xFA) – SATA control 1
18771d4a0697SVijay Khemka //    D31:F5 (0xFD) – SATA control 2
18781d4a0697SVijay Khemka //    D17:F4 (0x8C) – sSata control
18791d4a0697SVijay Khemka //  Byte 2 – Port Number
18801d4a0697SVijay Khemka //  Byte 3 – Location (0xFF: No HDD Present)
18811d4a0697SVijay Khemka //  BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param
18821d4a0697SVijay Khemka //  #1~4, #6,  #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if
18831d4a0697SVijay Khemka //  the HDD present. BMC or other people who know the HDD location has
18841d4a0697SVijay Khemka //  responsibility for update Location info
18851d4a0697SVijay Khemka //
18861d4a0697SVijay Khemka //  Param#1 (Serial Number):
18871d4a0697SVijay Khemka //  Bytes 1..33: HDD Serial Number
18881d4a0697SVijay Khemka //
18891d4a0697SVijay Khemka //  Param#2 (Model Name):
18901d4a0697SVijay Khemka //  Byte 1..33 – HDD Model Name
18911d4a0697SVijay Khemka //
18921d4a0697SVijay Khemka //  Param#3 (HDD FW Version):
18931d4a0697SVijay Khemka //  Byte 1..17 –HDD FW version
18941d4a0697SVijay Khemka //
18951d4a0697SVijay Khemka //  Param#4 (Capacity):
18961d4a0697SVijay Khemka //  Byte 1..4 –HDD Block Size, LSB
18971d4a0697SVijay Khemka //  Byte 5..12 - HDD Block Number, LSB
18981d4a0697SVijay Khemka //  HDD Capacity = HDD Block size * HDD BLock number  (Unit Byte)
18991d4a0697SVijay Khemka //
19001d4a0697SVijay Khemka //  Param#5 (Max HDD Quantity):
19011d4a0697SVijay Khemka //  Byte 1 - Max HDD Quantity
19021d4a0697SVijay Khemka //  Max supported port numbers in this PCH
19031d4a0697SVijay Khemka //
19041d4a0697SVijay Khemka //  Param#6 (HDD Type)
19051d4a0697SVijay Khemka //  Byte 1 – HDD Type
19061d4a0697SVijay Khemka //  0h – Reserved
19071d4a0697SVijay Khemka //  1h – SAS
19081d4a0697SVijay Khemka //  2h – SATA
19091d4a0697SVijay Khemka //  3h – PCIE SSD (NVME)
19101d4a0697SVijay Khemka //
19111d4a0697SVijay Khemka //  Param#7 (HDD WWN)
19121d4a0697SVijay Khemka //  Data 1...8: HDD World Wide Name, LSB
19131d4a0697SVijay Khemka //
1914e39f9393SWilly Tu ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
1915e39f9393SWilly Tu                                 ipmi_request_t request, ipmi_response_t,
1916e39f9393SWilly Tu                                 ipmi_data_len_t data_len, ipmi_context_t)
19171d4a0697SVijay Khemka {
19181d4a0697SVijay Khemka     qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
19191d4a0697SVijay Khemka     uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
19201d4a0697SVijay Khemka     uint8_t ctrlType = req->hddCtrlType & 0x0f;
19211d4a0697SVijay Khemka     std::stringstream ss;
19221d4a0697SVijay Khemka     std::string str;
19231d4a0697SVijay Khemka     uint8_t len = *data_len;
19241d4a0697SVijay Khemka 
19251d4a0697SVijay Khemka     *data_len = 0;
19261d4a0697SVijay Khemka 
19271d4a0697SVijay Khemka     /* check for requested data params */
19281d4a0697SVijay Khemka     if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam ||
19291d4a0697SVijay Khemka         ctrlType > 2)
19301d4a0697SVijay Khemka     {
19311d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
19321d4a0697SVijay Khemka             "Invalid parameter received");
19331d4a0697SVijay Khemka         return IPMI_CC_PARM_OUT_OF_RANGE;
19341d4a0697SVijay Khemka     }
19351d4a0697SVijay Khemka 
19361d4a0697SVijay Khemka     len = len - 6; // Get Actual data length
19371d4a0697SVijay Khemka 
19381d4a0697SVijay Khemka     ss << std::hex;
19391d4a0697SVijay Khemka     ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
19401d4a0697SVijay Khemka     oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType;
19411d4a0697SVijay Khemka     oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] =
19421d4a0697SVijay Khemka         req->hddIndex;
19431d4a0697SVijay Khemka 
19441d4a0697SVijay Khemka     str = bytesToStr(req->data, len);
19451d4a0697SVijay Khemka     oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
19461d4a0697SVijay Khemka            [driveInfoKey[req->paramSel]] = str.c_str();
19471d4a0697SVijay Khemka     flushOemData();
19481d4a0697SVijay Khemka 
19491d4a0697SVijay Khemka     return IPMI_CC_OK;
19501d4a0697SVijay Khemka }
19511d4a0697SVijay Khemka 
19521d4a0697SVijay Khemka //----------------------------------------------------------------------
19531d4a0697SVijay Khemka // Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO)
19541d4a0697SVijay Khemka //----------------------------------------------------------------------
19551d4a0697SVijay Khemka // BMC needs to check HDD presented or not first. If NOT presented, return
19561d4a0697SVijay Khemka // completion code 0xD5.
19571d4a0697SVijay Khemka //
19581d4a0697SVijay Khemka // Request:
19591d4a0697SVijay Khemka // Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
19601d4a0697SVijay Khemka // Byte 4 –
19611d4a0697SVijay Khemka //[7:4] Reserved
19621d4a0697SVijay Khemka //[3:0] HDD Controller Type
19631d4a0697SVijay Khemka //   0x00 – BIOS
19641d4a0697SVijay Khemka //   0x01 – Expander
19651d4a0697SVijay Khemka //   0x02 – LSI
19661d4a0697SVijay Khemka // Byte 5 – HDD Index, 0 base
19671d4a0697SVijay Khemka // Byte 6 – Parameter Selector (See Above Set HDD Information)
19681d4a0697SVijay Khemka // Response:
19691d4a0697SVijay Khemka // Byte 1 – Completion Code
19701d4a0697SVijay Khemka //   0xD5 – Not support in current status (HDD Not Present)
19711d4a0697SVijay Khemka // Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD
19721d4a0697SVijay Khemka // Information)
19731d4a0697SVijay Khemka //
1974e39f9393SWilly Tu ipmi_ret_t ipmiOemQGetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
19751d4a0697SVijay Khemka                                 ipmi_request_t request,
19761d4a0697SVijay Khemka                                 ipmi_response_t response,
1977e39f9393SWilly Tu                                 ipmi_data_len_t data_len, ipmi_context_t)
19781d4a0697SVijay Khemka {
19791d4a0697SVijay Khemka     qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
19801d4a0697SVijay Khemka     uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
19811d4a0697SVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
19821d4a0697SVijay Khemka     uint8_t ctrlType = req->hddCtrlType & 0x0f;
19831d4a0697SVijay Khemka     std::stringstream ss;
19841d4a0697SVijay Khemka     std::string str;
19851d4a0697SVijay Khemka 
19861d4a0697SVijay Khemka     *data_len = 0;
19871d4a0697SVijay Khemka 
19881d4a0697SVijay Khemka     /* check for requested data params */
19891d4a0697SVijay Khemka     if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2)
19901d4a0697SVijay Khemka     {
19911d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
19921d4a0697SVijay Khemka             "Invalid parameter received");
19931d4a0697SVijay Khemka         return IPMI_CC_PARM_OUT_OF_RANGE;
19941d4a0697SVijay Khemka     }
19951d4a0697SVijay Khemka 
19961d4a0697SVijay Khemka     if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) ==
19971d4a0697SVijay Khemka         oemData[KEY_Q_DRIVE_INFO].end())
19981d4a0697SVijay Khemka         return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
19991d4a0697SVijay Khemka 
20001d4a0697SVijay Khemka     ss << std::hex;
20011d4a0697SVijay Khemka     ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
20021d4a0697SVijay Khemka 
20031d4a0697SVijay Khemka     if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) ==
20041d4a0697SVijay Khemka         oemData[KEY_Q_DRIVE_INFO].end())
20051d4a0697SVijay Khemka         return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
20061d4a0697SVijay Khemka 
20071d4a0697SVijay Khemka     if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find(
20081d4a0697SVijay Khemka             dimmInfoKey[req->paramSel]) ==
20091d4a0697SVijay Khemka         oemData[KEY_Q_DRIVE_INFO][ss.str()].end())
20101d4a0697SVijay Khemka         return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
20111d4a0697SVijay Khemka 
20121d4a0697SVijay Khemka     str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
20131d4a0697SVijay Khemka                  [dimmInfoKey[req->paramSel]];
20141d4a0697SVijay Khemka     *data_len = strToBytes(str, res);
20151d4a0697SVijay Khemka 
2016e7d23d0eSVijay Khemka     return IPMI_CC_OK;
2017e7d23d0eSVijay Khemka }
2018e7d23d0eSVijay Khemka 
2019e4d6fe74SLogananth Sundararaj /* Helper function for sending DCMI commands to ME/BIC and
2020e4d6fe74SLogananth Sundararaj  * getting response back
2021e4d6fe74SLogananth Sundararaj  */
2022e4d6fe74SLogananth Sundararaj ipmi::RspType<std::vector<uint8_t>>
2023e4d6fe74SLogananth Sundararaj     sendDCMICmd([[maybe_unused]] ipmi::Context::ptr ctx,
2024e4d6fe74SLogananth Sundararaj                 [[maybe_unused]] uint8_t cmd, std::vector<uint8_t>& cmdData)
2025dd14c0f7SVijay Khemka {
2026dd14c0f7SVijay Khemka     std::vector<uint8_t> respData;
2027dd14c0f7SVijay Khemka 
2028e4d6fe74SLogananth Sundararaj #if BIC_ENABLED
2029e4d6fe74SLogananth Sundararaj 
2030e4d6fe74SLogananth Sundararaj     uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
2031e4d6fe74SLogananth Sundararaj 
2032e4d6fe74SLogananth Sundararaj     if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, cmdData, respData))
2033e4d6fe74SLogananth Sundararaj     {
2034e4d6fe74SLogananth Sundararaj         return ipmi::responseUnspecifiedError();
2035e4d6fe74SLogananth Sundararaj     }
2036e4d6fe74SLogananth Sundararaj 
2037e4d6fe74SLogananth Sundararaj #else
2038e4d6fe74SLogananth Sundararaj 
2039dd14c0f7SVijay Khemka     /* Add group id as first byte to request for ME command */
2040dd14c0f7SVijay Khemka     cmdData.insert(cmdData.begin(), groupDCMI);
2041dd14c0f7SVijay Khemka 
2042dd14c0f7SVijay Khemka     if (sendMeCmd(ipmi::netFnGroup, cmd, cmdData, respData))
2043e4d6fe74SLogananth Sundararaj     {
2044dd14c0f7SVijay Khemka         return ipmi::responseUnspecifiedError();
2045e4d6fe74SLogananth Sundararaj     }
2046dd14c0f7SVijay Khemka 
2047dd14c0f7SVijay Khemka     /* Remove group id as first byte as it will be added by IPMID */
2048dd14c0f7SVijay Khemka     respData.erase(respData.begin());
2049dd14c0f7SVijay Khemka 
2050e4d6fe74SLogananth Sundararaj #endif
2051e4d6fe74SLogananth Sundararaj 
2052dd14c0f7SVijay Khemka     return ipmi::responseSuccess(std::move(respData));
2053dd14c0f7SVijay Khemka }
2054dd14c0f7SVijay Khemka 
2055dd14c0f7SVijay Khemka /* DCMI Command handellers. */
2056dd14c0f7SVijay Khemka 
2057dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2058e4d6fe74SLogananth Sundararaj     ipmiOemDCMIGetPowerReading(ipmi::Context::ptr ctx,
2059e4d6fe74SLogananth Sundararaj                                std::vector<uint8_t> reqData)
2060dd14c0f7SVijay Khemka {
2061e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerReading, reqData);
2062dd14c0f7SVijay Khemka }
2063dd14c0f7SVijay Khemka 
2064dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2065e4d6fe74SLogananth Sundararaj     ipmiOemDCMIGetPowerLimit(ipmi::Context::ptr ctx,
2066e4d6fe74SLogananth Sundararaj                              std::vector<uint8_t> reqData)
2067dd14c0f7SVijay Khemka {
2068e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerLimit, reqData);
2069dd14c0f7SVijay Khemka }
2070dd14c0f7SVijay Khemka 
2071dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2072e4d6fe74SLogananth Sundararaj     ipmiOemDCMISetPowerLimit(ipmi::Context::ptr ctx,
2073e4d6fe74SLogananth Sundararaj                              std::vector<uint8_t> reqData)
2074dd14c0f7SVijay Khemka {
2075e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdSetPowerLimit, reqData);
2076dd14c0f7SVijay Khemka }
2077dd14c0f7SVijay Khemka 
2078dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2079e4d6fe74SLogananth Sundararaj     ipmiOemDCMIApplyPowerLimit(ipmi::Context::ptr ctx,
2080e4d6fe74SLogananth Sundararaj                                std::vector<uint8_t> reqData)
2081dd14c0f7SVijay Khemka {
2082e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdActDeactivatePwrLimit, reqData);
2083dd14c0f7SVijay Khemka }
2084dd14c0f7SVijay Khemka 
2085e7d23d0eSVijay Khemka static void registerOEMFunctions(void)
2086e7d23d0eSVijay Khemka {
20871d4a0697SVijay Khemka     /* Get OEM data from json file */
20881d4a0697SVijay Khemka     std::ifstream file(JSON_OEM_DATA_FILE);
20891d4a0697SVijay Khemka     if (file)
2090feaa9811SVijay Khemka     {
20911d4a0697SVijay Khemka         file >> oemData;
2092feaa9811SVijay Khemka         file.close();
2093feaa9811SVijay Khemka     }
20941d4a0697SVijay Khemka 
2095e7d23d0eSVijay Khemka     phosphor::logging::log<phosphor::logging::level::INFO>(
2096e7d23d0eSVijay Khemka         "Registering OEM commands");
20977c0aea49SVijay Khemka 
2098e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO,
2099e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetFrameInfo,
2100e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug frame info
2101e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ,
2102e7d23d0eSVijay Khemka                          CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL,
2103e7d23d0eSVijay Khemka                          ipmiOemDbgGetUpdFrames,
2104e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug updated frames
2105e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC,
2106e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetPostDesc,
2107e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug post description
2108e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC,
2109e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetGpioDesc,
2110e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug gpio description
2111e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA,
2112e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetFrameData,
2113e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug frame data
2114e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL,
2115e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetCtrlPanel,
2116e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug control panel
2117e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL,
2118e7d23d0eSVijay Khemka                          ipmiOemSetDimmInfo,
2119e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set Dimm Info
21201d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
21211d4a0697SVijay Khemka                          ipmiOemGetBoardID,
21221d4a0697SVijay Khemka                          PRIVILEGE_USER); // Get Board ID
2123*4ae63e71SBonnie Lo     ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemOne,
2124*4ae63e71SBonnie Lo                           CMD_OEM_GET_80PORT_RECORD, ipmi::Privilege::User,
2125*4ae63e71SBonnie Lo                           ipmiOemGet80PortRecord); // Get 80 Port Record
2126e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL,
2127e7d23d0eSVijay Khemka                          ipmiOemSetMachineCfgInfo,
2128e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set Machine Config Info
2129e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL,
2130e7d23d0eSVijay Khemka                          ipmiOemSetPostStart,
2131e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set POST start
2132e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL,
2133e7d23d0eSVijay Khemka                          ipmiOemSetPostEnd,
2134e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set POST End
21351d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
21361d4a0697SVijay Khemka                          ipmiOemSetPPINInfo,
21371d4a0697SVijay Khemka                          PRIVILEGE_USER); // Set PPIN Info
21385f8e3435SManikandan Elumalai #if BIC_ENABLED
21395f8e3435SManikandan Elumalai 
21405f8e3435SManikandan Elumalai     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
21415f8e3435SManikandan Elumalai                           ipmi::cmdSetSystemGuid, ipmi::Privilege::User,
21425f8e3435SManikandan Elumalai                           ipmiOemSetSystemGuid);
21435f8e3435SManikandan Elumalai #else
21445f8e3435SManikandan Elumalai 
2145f2246ce8SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL,
2146f2246ce8SVijay Khemka                          ipmiOemSetSystemGuid,
2147f2246ce8SVijay Khemka                          PRIVILEGE_USER); // Set System GUID
21485f8e3435SManikandan Elumalai #endif
21491d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
21501d4a0697SVijay Khemka                          ipmiOemSetAdrTrigger,
21511d4a0697SVijay Khemka                          PRIVILEGE_USER); // Set ADR Trigger
2152e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL,
2153e7d23d0eSVijay Khemka                          ipmiOemSetBiosFlashInfo,
2154e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set Bios Flash Info
2155e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr,
2156e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set PPR
2157e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr,
2158e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Get PPR
21591d4a0697SVijay Khemka     /* FB OEM QC Commands */
2160d532fecaSKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2161d532fecaSKarthikeyan Pasupathi                           CMD_OEM_Q_SET_PROC_INFO, ipmi::Privilege::User,
2162d532fecaSKarthikeyan Pasupathi                           ipmiOemQSetProcInfo); // Set Proc Info
2163d532fecaSKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2164d532fecaSKarthikeyan Pasupathi                           CMD_OEM_Q_GET_PROC_INFO, ipmi::Privilege::User,
2165d532fecaSKarthikeyan Pasupathi                           ipmiOemQGetProcInfo); // Get Proc Info
216610ff3d86SKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
216710ff3d86SKarthikeyan Pasupathi                           ipmi::cmdSetQDimmInfo, ipmi::Privilege::User,
216810ff3d86SKarthikeyan Pasupathi                           ipmiOemQSetDimmInfo); // Set Dimm Info
216910ff3d86SKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
217010ff3d86SKarthikeyan Pasupathi                           ipmi::cmdGetQDimmInfo, ipmi::Privilege::User,
217110ff3d86SKarthikeyan Pasupathi                           ipmiOemQGetDimmInfo); // Get Dimm Info
21721d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL,
21731d4a0697SVijay Khemka                          ipmiOemQSetDriveInfo,
21741d4a0697SVijay Khemka                          PRIVILEGE_USER); // Set Drive Info
21751d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL,
21761d4a0697SVijay Khemka                          ipmiOemQGetDriveInfo,
21771d4a0697SVijay Khemka                          PRIVILEGE_USER); // Get Drive Info
2178dd14c0f7SVijay Khemka 
2179dd14c0f7SVijay Khemka     /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */
2180dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2181dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdGetPowerReading,
2182dd14c0f7SVijay Khemka                                ipmi::Privilege::User,
2183dd14c0f7SVijay Khemka                                ipmiOemDCMIGetPowerReading); // Get Power Reading
2184dd14c0f7SVijay Khemka 
2185dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2186dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdGetPowerLimit,
2187dd14c0f7SVijay Khemka                                ipmi::Privilege::User,
2188dd14c0f7SVijay Khemka                                ipmiOemDCMIGetPowerLimit); // Get Power Limit
2189dd14c0f7SVijay Khemka 
2190dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2191dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdSetPowerLimit,
2192dd14c0f7SVijay Khemka                                ipmi::Privilege::Operator,
2193dd14c0f7SVijay Khemka                                ipmiOemDCMISetPowerLimit); // Set Power Limit
2194dd14c0f7SVijay Khemka 
2195dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2196dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdActDeactivatePwrLimit,
2197dd14c0f7SVijay Khemka                                ipmi::Privilege::Operator,
2198dd14c0f7SVijay Khemka                                ipmiOemDCMIApplyPowerLimit); // Apply Power Limit
2199dd14c0f7SVijay Khemka 
2200f0cf6658SJayashree-D     /* FB OEM BOOT ORDER COMMANDS */
2201f0cf6658SJayashree-D     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2202f0cf6658SJayashree-D                           CMD_OEM_GET_BOOT_ORDER, ipmi::Privilege::User,
2203f0cf6658SJayashree-D                           ipmiOemGetBootOrder); // Get Boot Order
2204f0cf6658SJayashree-D 
2205f0cf6658SJayashree-D     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2206f0cf6658SJayashree-D                           CMD_OEM_SET_BOOT_ORDER, ipmi::Privilege::User,
2207f0cf6658SJayashree-D                           ipmiOemSetBootOrder); // Set Boot Order
2208f0cf6658SJayashree-D 
2209e7d23d0eSVijay Khemka     return;
2210e7d23d0eSVijay Khemka }
2211e7d23d0eSVijay Khemka 
2212e7d23d0eSVijay Khemka } // namespace ipmi
2213