xref: /openbmc/fb-ipmi-oem/src/oemcommands.cpp (revision 2405ae98b39a97e9d7753d8dc5c673a4a8885b85)
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"
19e7d23d0eSVijay Khemka 
20*2405ae98SPatrick Williams #include <commandutils.hpp>
21*2405ae98SPatrick Williams #include <ipmid/api-types.hpp>
2263c99be4SVijay Khemka #include <ipmid/api.hpp>
231b6fae3fSVijay Khemka #include <ipmid/utils.hpp>
2463c99be4SVijay Khemka #include <nlohmann/json.hpp>
2563c99be4SVijay Khemka #include <oemcommands.hpp>
26e7d23d0eSVijay Khemka #include <phosphor-logging/log.hpp>
27e7d23d0eSVijay Khemka #include <sdbusplus/bus.hpp>
28*2405ae98SPatrick Williams #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
29*2405ae98SPatrick Williams #include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
30*2405ae98SPatrick Williams #include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
315f8e3435SManikandan Elumalai 
3263c99be4SVijay Khemka #include <array>
3363c99be4SVijay Khemka #include <cstring>
3463c99be4SVijay Khemka #include <fstream>
3563c99be4SVijay Khemka #include <iomanip>
3663c99be4SVijay Khemka #include <iostream>
37*2405ae98SPatrick Williams #include <regex>
3863c99be4SVijay Khemka #include <sstream>
39e7d23d0eSVijay Khemka #include <string>
40e7d23d0eSVijay Khemka #include <vector>
41e7d23d0eSVijay Khemka 
42e7d23d0eSVijay Khemka #define SIZE_IANA_ID 3
43e7d23d0eSVijay Khemka 
44e7d23d0eSVijay Khemka namespace ipmi
45e7d23d0eSVijay Khemka {
46a7231893SVijay Khemka 
47a7231893SVijay Khemka using namespace phosphor::logging;
48a7231893SVijay Khemka 
49e1ff81faSKarthikeyan Pasupathi void getSelectorPosition(size_t& position);
50e7d23d0eSVijay Khemka static void registerOEMFunctions() __attribute__((constructor));
51cd315e07SPatrick Williams sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
52e7d23d0eSVijay Khemka static constexpr size_t maxFRUStringLength = 0x3F;
535f8e3435SManikandan Elumalai constexpr uint8_t cmdSetSystemGuid = 0xEF;
54e7d23d0eSVijay Khemka 
5510ff3d86SKarthikeyan Pasupathi constexpr uint8_t cmdSetQDimmInfo = 0x12;
5610ff3d86SKarthikeyan Pasupathi constexpr uint8_t cmdGetQDimmInfo = 0x13;
5710ff3d86SKarthikeyan Pasupathi 
58cc0d6d92SVijay Khemka int plat_udbg_get_post_desc(uint8_t, uint8_t*, uint8_t, uint8_t*, uint8_t*,
59cc0d6d92SVijay Khemka                             uint8_t*);
6038183d66SVijay Khemka int plat_udbg_get_gpio_desc(uint8_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*,
6138183d66SVijay Khemka                             uint8_t*);
62e7d23d0eSVijay Khemka ipmi_ret_t plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t*, uint8_t*,
63e7d23d0eSVijay Khemka                                     uint8_t*);
64e7d23d0eSVijay Khemka ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t*,
65e7d23d0eSVijay Khemka                                    uint8_t*);
66dd14c0f7SVijay Khemka int sendMeCmd(uint8_t, uint8_t, std::vector<uint8_t>&, std::vector<uint8_t>&);
67dd14c0f7SVijay Khemka 
685f8e3435SManikandan Elumalai int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
695f8e3435SManikandan Elumalai                std::vector<uint8_t>&);
705f8e3435SManikandan Elumalai 
71feaa9811SVijay Khemka nlohmann::json oemData __attribute__((init_priority(101)));
721b6fae3fSVijay Khemka 
73f2246ce8SVijay Khemka static constexpr size_t GUID_SIZE = 16;
74f2246ce8SVijay Khemka // TODO Make offset and location runtime configurable to ensure we
75f2246ce8SVijay Khemka // can make each define their own locations.
76f2246ce8SVijay Khemka static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
77f2246ce8SVijay Khemka static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
78f2246ce8SVijay Khemka 
791b6fae3fSVijay Khemka enum class LanParam : uint8_t
801b6fae3fSVijay Khemka {
811b6fae3fSVijay Khemka     INPROGRESS = 0,
821b6fae3fSVijay Khemka     AUTHSUPPORT = 1,
831b6fae3fSVijay Khemka     AUTHENABLES = 2,
841b6fae3fSVijay Khemka     IP = 3,
851b6fae3fSVijay Khemka     IPSRC = 4,
861b6fae3fSVijay Khemka     MAC = 5,
871b6fae3fSVijay Khemka     SUBNET = 6,
881b6fae3fSVijay Khemka     GATEWAY = 12,
891b6fae3fSVijay Khemka     VLAN = 20,
901b6fae3fSVijay Khemka     CIPHER_SUITE_COUNT = 22,
911b6fae3fSVijay Khemka     CIPHER_SUITE_ENTRIES = 23,
921b6fae3fSVijay Khemka     IPV6 = 59,
931b6fae3fSVijay Khemka };
941b6fae3fSVijay Khemka 
95a7231893SVijay Khemka namespace network
96a7231893SVijay Khemka {
97a7231893SVijay Khemka 
98a7231893SVijay Khemka constexpr auto ROOT = "/xyz/openbmc_project/network";
99a7231893SVijay Khemka constexpr auto SERVICE = "xyz.openbmc_project.Network";
100a7231893SVijay Khemka constexpr auto IPV4_TYPE = "ipv4";
101a7231893SVijay Khemka constexpr auto IPV6_TYPE = "ipv6";
102a7231893SVijay Khemka constexpr auto IPV4_PREFIX = "169.254";
103a7231893SVijay Khemka constexpr auto IPV6_PREFIX = "fe80";
104a7231893SVijay Khemka constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
105a7231893SVijay Khemka constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
1068d1a81e8SPotin Lai constexpr auto IPV4_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
1078d1a81e8SPotin Lai constexpr auto IPV6_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
108a7231893SVijay Khemka 
109a7231893SVijay Khemka bool isLinkLocalIP(const std::string& address)
110a7231893SVijay Khemka {
111a7231893SVijay Khemka     return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
112a7231893SVijay Khemka }
113a7231893SVijay Khemka 
114cd315e07SPatrick Williams DbusObjectInfo getIPObject(sdbusplus::bus_t& bus, const std::string& interface,
115a7231893SVijay Khemka                            const std::string& serviceRoot,
1168d1a81e8SPotin Lai                            const std::string& protocol,
1178d1a81e8SPotin Lai                            const std::string& ethdev)
118a7231893SVijay Khemka {
1198d1a81e8SPotin Lai     auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, ethdev);
120a7231893SVijay Khemka 
121a7231893SVijay Khemka     if (objectTree.empty())
122a7231893SVijay Khemka     {
123a7231893SVijay Khemka         log<level::ERR>("No Object has implemented the IP interface",
124a7231893SVijay Khemka                         entry("INTERFACE=%s", interface.c_str()));
125a7231893SVijay Khemka     }
126a7231893SVijay Khemka 
127a7231893SVijay Khemka     DbusObjectInfo objectInfo;
128a7231893SVijay Khemka 
129a7231893SVijay Khemka     for (auto& object : objectTree)
130a7231893SVijay Khemka     {
131*2405ae98SPatrick Williams         auto variant = ipmi::getDbusProperty(bus, object.second.begin()->first,
132*2405ae98SPatrick Williams                                              object.first, IP_INTERFACE,
133*2405ae98SPatrick Williams                                              "Type");
1348d1a81e8SPotin Lai         if (std::get<std::string>(variant) != protocol)
1358d1a81e8SPotin Lai         {
1368d1a81e8SPotin Lai             continue;
1378d1a81e8SPotin Lai         }
1388d1a81e8SPotin Lai 
1398d1a81e8SPotin Lai         variant = ipmi::getDbusProperty(bus, object.second.begin()->first,
140a7231893SVijay Khemka                                         object.first, IP_INTERFACE, "Address");
141a7231893SVijay Khemka 
142a7231893SVijay Khemka         objectInfo = std::make_pair(object.first, object.second.begin()->first);
143a7231893SVijay Khemka 
144a7231893SVijay Khemka         // if LinkLocalIP found look for Non-LinkLocalIP
145a7231893SVijay Khemka         if (isLinkLocalIP(std::get<std::string>(variant)))
146a7231893SVijay Khemka         {
147a7231893SVijay Khemka             continue;
148a7231893SVijay Khemka         }
149a7231893SVijay Khemka         else
150a7231893SVijay Khemka         {
151a7231893SVijay Khemka             break;
152a7231893SVijay Khemka         }
153a7231893SVijay Khemka     }
154a7231893SVijay Khemka     return objectInfo;
155a7231893SVijay Khemka }
156a7231893SVijay Khemka 
157a7231893SVijay Khemka } // namespace network
158a7231893SVijay Khemka 
159f0cf6658SJayashree-D namespace boot
160f0cf6658SJayashree-D {
16177ee489fSJayashree Dhanapal using BootSource =
16277ee489fSJayashree Dhanapal     sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources;
16377ee489fSJayashree Dhanapal using BootMode =
16477ee489fSJayashree Dhanapal     sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes;
16577ee489fSJayashree Dhanapal using BootType =
16677ee489fSJayashree Dhanapal     sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types;
167f0cf6658SJayashree-D 
168f0cf6658SJayashree-D using IpmiValue = uint8_t;
169f0cf6658SJayashree-D 
17077ee489fSJayashree Dhanapal std::map<IpmiValue, BootSource> sourceIpmiToDbus = {
17177ee489fSJayashree Dhanapal     {0x0f, BootSource::Default},       {0x00, BootSource::RemovableMedia},
17277ee489fSJayashree Dhanapal     {0x01, BootSource::Network},       {0x02, BootSource::Disk},
17377ee489fSJayashree Dhanapal     {0x03, BootSource::ExternalMedia}, {0x09, BootSource::Network}};
174f0cf6658SJayashree-D 
175c0f918b5SDelphine CC Chiu std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x04, BootMode::Setup},
17677ee489fSJayashree Dhanapal                                                 {0x00, BootMode::Regular}};
177f0cf6658SJayashree-D 
17877ee489fSJayashree Dhanapal std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy},
17977ee489fSJayashree Dhanapal                                                 {0x01, BootType::EFI}};
180778147daSJayashree Dhanapal 
18177ee489fSJayashree Dhanapal std::map<std::optional<BootSource>, IpmiValue> sourceDbusToIpmi = {
18277ee489fSJayashree Dhanapal     {BootSource::Default, 0x0f},
18377ee489fSJayashree Dhanapal     {BootSource::RemovableMedia, 0x00},
18477ee489fSJayashree Dhanapal     {BootSource::Network, 0x01},
18577ee489fSJayashree Dhanapal     {BootSource::Disk, 0x02},
18677ee489fSJayashree Dhanapal     {BootSource::ExternalMedia, 0x03}};
187f0cf6658SJayashree-D 
18877ee489fSJayashree Dhanapal std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = {
189c0f918b5SDelphine CC Chiu     {BootMode::Setup, 0x04}, {BootMode::Regular, 0x00}};
190f0cf6658SJayashree-D 
19177ee489fSJayashree Dhanapal std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = {
19277ee489fSJayashree Dhanapal     {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}};
193778147daSJayashree Dhanapal 
194c0f918b5SDelphine CC Chiu static constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
195f0cf6658SJayashree-D static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
196f0cf6658SJayashree-D static constexpr auto bootSourceIntf =
197f0cf6658SJayashree-D     "xyz.openbmc_project.Control.Boot.Source";
198778147daSJayashree Dhanapal static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
199f0cf6658SJayashree-D static constexpr auto bootSourceProp = "BootSource";
200f0cf6658SJayashree-D static constexpr auto bootModeProp = "BootMode";
201778147daSJayashree Dhanapal static constexpr auto bootTypeProp = "BootType";
202c0f918b5SDelphine CC Chiu static constexpr auto bootEnableProp = "Enabled";
203f0cf6658SJayashree-D 
204f0cf6658SJayashree-D std::tuple<std::string, std::string> objPath(size_t id)
205f0cf6658SJayashree-D {
206f0cf6658SJayashree-D     std::string hostName = "host" + std::to_string(id);
207*2405ae98SPatrick Williams     std::string bootObjPath = "/xyz/openbmc_project/control/" + hostName +
208*2405ae98SPatrick Williams                               "/boot";
209f0cf6658SJayashree-D     return std::make_tuple(std::move(bootObjPath), std::move(hostName));
210f0cf6658SJayashree-D }
211f0cf6658SJayashree-D 
212f0cf6658SJayashree-D } // namespace boot
213f0cf6658SJayashree-D 
2141d4a0697SVijay Khemka //----------------------------------------------------------------------
2151d4a0697SVijay Khemka // Helper functions for storing oem data
2161d4a0697SVijay Khemka //----------------------------------------------------------------------
2171d4a0697SVijay Khemka 
2181d4a0697SVijay Khemka void flushOemData()
2191d4a0697SVijay Khemka {
2201d4a0697SVijay Khemka     std::ofstream file(JSON_OEM_DATA_FILE);
2211d4a0697SVijay Khemka     file << oemData;
222feaa9811SVijay Khemka     file.close();
2231d4a0697SVijay Khemka     return;
2241d4a0697SVijay Khemka }
2251d4a0697SVijay Khemka 
2261d4a0697SVijay Khemka std::string bytesToStr(uint8_t* byte, int len)
2271d4a0697SVijay Khemka {
2281d4a0697SVijay Khemka     std::stringstream ss;
2291d4a0697SVijay Khemka     int i;
2301d4a0697SVijay Khemka 
2311d4a0697SVijay Khemka     ss << std::hex;
2321d4a0697SVijay Khemka     for (i = 0; i < len; i++)
2331d4a0697SVijay Khemka     {
2341d4a0697SVijay Khemka         ss << std::setw(2) << std::setfill('0') << (int)byte[i];
2351d4a0697SVijay Khemka     }
2361d4a0697SVijay Khemka 
2371d4a0697SVijay Khemka     return ss.str();
2381d4a0697SVijay Khemka }
2391d4a0697SVijay Khemka 
2401d4a0697SVijay Khemka int strToBytes(std::string& str, uint8_t* data)
2411d4a0697SVijay Khemka {
2421d4a0697SVijay Khemka     std::string sstr;
243e39f9393SWilly Tu     size_t i;
2441d4a0697SVijay Khemka 
2451d4a0697SVijay Khemka     for (i = 0; i < (str.length()) / 2; i++)
2461d4a0697SVijay Khemka     {
2471d4a0697SVijay Khemka         sstr = str.substr(i * 2, 2);
2481d4a0697SVijay Khemka         data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16);
2491d4a0697SVijay Khemka     }
2501d4a0697SVijay Khemka     return i;
2511d4a0697SVijay Khemka }
2521d4a0697SVijay Khemka 
25310ff3d86SKarthikeyan Pasupathi int readDimmType(std::string& data, uint8_t param)
25410ff3d86SKarthikeyan Pasupathi {
25510ff3d86SKarthikeyan Pasupathi     nlohmann::json dimmObj;
25610ff3d86SKarthikeyan Pasupathi     /* Get dimm type names stored in json file */
25710ff3d86SKarthikeyan Pasupathi     std::ifstream file(JSON_DIMM_TYPE_FILE);
25810ff3d86SKarthikeyan Pasupathi     if (file)
25910ff3d86SKarthikeyan Pasupathi     {
26010ff3d86SKarthikeyan Pasupathi         file >> dimmObj;
26110ff3d86SKarthikeyan Pasupathi         file.close();
26210ff3d86SKarthikeyan Pasupathi     }
26310ff3d86SKarthikeyan Pasupathi     else
26410ff3d86SKarthikeyan Pasupathi     {
26510ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
26610ff3d86SKarthikeyan Pasupathi             "DIMM type names file not found",
26710ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
26810ff3d86SKarthikeyan Pasupathi         return -1;
26910ff3d86SKarthikeyan Pasupathi     }
27010ff3d86SKarthikeyan Pasupathi 
27110ff3d86SKarthikeyan Pasupathi     std::string dimmKey = "dimm_type" + std::to_string(param);
27210ff3d86SKarthikeyan Pasupathi     auto obj = dimmObj[dimmKey]["short_name"];
27310ff3d86SKarthikeyan Pasupathi     data = obj;
27410ff3d86SKarthikeyan Pasupathi     return 0;
27510ff3d86SKarthikeyan Pasupathi }
27610ff3d86SKarthikeyan Pasupathi 
2771b6fae3fSVijay Khemka ipmi_ret_t getNetworkData(uint8_t lan_param, char* data)
2781b6fae3fSVijay Khemka {
2791b6fae3fSVijay Khemka     ipmi_ret_t rc = IPMI_CC_OK;
280cd315e07SPatrick Williams     sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
2811b6fae3fSVijay Khemka 
2821b6fae3fSVijay Khemka     const std::string ethdevice = "eth0";
2831b6fae3fSVijay Khemka 
2841b6fae3fSVijay Khemka     switch (static_cast<LanParam>(lan_param))
2851b6fae3fSVijay Khemka     {
286d1194024SVijay Khemka         case LanParam::IP:
287d1194024SVijay Khemka         {
2881b6fae3fSVijay Khemka             std::string ipaddress;
289a7231893SVijay Khemka             auto ipObjectInfo = ipmi::network::getIPObject(
2908d1a81e8SPotin Lai                 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
2918d1a81e8SPotin Lai                 ipmi::network::IPV4_PROTOCOL, ethdevice);
2921b6fae3fSVijay Khemka 
2931b6fae3fSVijay Khemka             auto properties = ipmi::getAllDbusProperties(
2941b6fae3fSVijay Khemka                 bus, ipObjectInfo.second, ipObjectInfo.first,
2951b6fae3fSVijay Khemka                 ipmi::network::IP_INTERFACE);
2961b6fae3fSVijay Khemka 
297ef0efbc4SPatrick Williams             ipaddress = std::get<std::string>(properties["Address"]);
2981b6fae3fSVijay Khemka 
2991b6fae3fSVijay Khemka             std::strcpy(data, ipaddress.c_str());
3001b6fae3fSVijay Khemka         }
3011b6fae3fSVijay Khemka         break;
3021b6fae3fSVijay Khemka 
303d1194024SVijay Khemka         case LanParam::IPV6:
304d1194024SVijay Khemka         {
3051b6fae3fSVijay Khemka             std::string ipaddress;
306a7231893SVijay Khemka             auto ipObjectInfo = ipmi::network::getIPObject(
3078d1a81e8SPotin Lai                 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
3088d1a81e8SPotin Lai                 ipmi::network::IPV6_PROTOCOL, ethdevice);
3091b6fae3fSVijay Khemka 
3101b6fae3fSVijay Khemka             auto properties = ipmi::getAllDbusProperties(
3111b6fae3fSVijay Khemka                 bus, ipObjectInfo.second, ipObjectInfo.first,
3121b6fae3fSVijay Khemka                 ipmi::network::IP_INTERFACE);
3131b6fae3fSVijay Khemka 
314ef0efbc4SPatrick Williams             ipaddress = std::get<std::string>(properties["Address"]);
3151b6fae3fSVijay Khemka 
3161b6fae3fSVijay Khemka             std::strcpy(data, ipaddress.c_str());
3171b6fae3fSVijay Khemka         }
3181b6fae3fSVijay Khemka         break;
3191b6fae3fSVijay Khemka 
320d1194024SVijay Khemka         case LanParam::MAC:
321d1194024SVijay Khemka         {
3221b6fae3fSVijay Khemka             std::string macAddress;
3231b6fae3fSVijay Khemka             auto macObjectInfo =
3241b6fae3fSVijay Khemka                 ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE,
3251b6fae3fSVijay Khemka                                     ipmi::network::ROOT, ethdevice);
3261b6fae3fSVijay Khemka 
3271b6fae3fSVijay Khemka             auto variant = ipmi::getDbusProperty(
3281b6fae3fSVijay Khemka                 bus, macObjectInfo.second, macObjectInfo.first,
3291b6fae3fSVijay Khemka                 ipmi::network::MAC_INTERFACE, "MACAddress");
3301b6fae3fSVijay Khemka 
331ef0efbc4SPatrick Williams             macAddress = std::get<std::string>(variant);
3321b6fae3fSVijay Khemka 
3331b6fae3fSVijay Khemka             sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
3341b6fae3fSVijay Khemka                    (data), (data + 1), (data + 2), (data + 3), (data + 4),
3351b6fae3fSVijay Khemka                    (data + 5));
3361b6fae3fSVijay Khemka             std::strcpy(data, macAddress.c_str());
3371b6fae3fSVijay Khemka         }
3381b6fae3fSVijay Khemka         break;
3391b6fae3fSVijay Khemka 
3401b6fae3fSVijay Khemka         default:
3411b6fae3fSVijay Khemka             rc = IPMI_CC_PARM_OUT_OF_RANGE;
3421b6fae3fSVijay Khemka     }
3431b6fae3fSVijay Khemka     return rc;
3441b6fae3fSVijay Khemka }
345e7d23d0eSVijay Khemka 
34639836ffaSKarthikeyan Pasupathi bool isMultiHostPlatform()
34739836ffaSKarthikeyan Pasupathi {
34839836ffaSKarthikeyan Pasupathi     bool platform;
3494ec80567SJayashree Dhanapal     if (hostInstances == "0")
35039836ffaSKarthikeyan Pasupathi     {
35139836ffaSKarthikeyan Pasupathi         platform = false;
35239836ffaSKarthikeyan Pasupathi     }
35339836ffaSKarthikeyan Pasupathi     else
35439836ffaSKarthikeyan Pasupathi     {
35539836ffaSKarthikeyan Pasupathi         platform = true;
35639836ffaSKarthikeyan Pasupathi     }
35739836ffaSKarthikeyan Pasupathi     return platform;
35839836ffaSKarthikeyan Pasupathi }
35939836ffaSKarthikeyan Pasupathi 
360e7d23d0eSVijay Khemka // return code: 0 successful
361e7d23d0eSVijay Khemka int8_t getFruData(std::string& data, std::string& name)
362e7d23d0eSVijay Khemka {
36398aabdb1SKarthikeyan Pasupathi     size_t pos;
36498aabdb1SKarthikeyan Pasupathi     static constexpr const auto depth = 0;
36598aabdb1SKarthikeyan Pasupathi     std::vector<std::string> paths;
36698aabdb1SKarthikeyan Pasupathi     std::string machinePath;
36798aabdb1SKarthikeyan Pasupathi     std::string baseBoard = "Baseboard";
36898aabdb1SKarthikeyan Pasupathi 
36998aabdb1SKarthikeyan Pasupathi     bool platform = isMultiHostPlatform();
37098aabdb1SKarthikeyan Pasupathi     if (platform == true)
37198aabdb1SKarthikeyan Pasupathi     {
372e1ff81faSKarthikeyan Pasupathi         getSelectorPosition(pos);
37398aabdb1SKarthikeyan Pasupathi     }
37498aabdb1SKarthikeyan Pasupathi 
37598aabdb1SKarthikeyan Pasupathi     sd_bus* bus = NULL;
37698aabdb1SKarthikeyan Pasupathi     int ret = sd_bus_default_system(&bus);
37798aabdb1SKarthikeyan Pasupathi     if (ret < 0)
378e7d23d0eSVijay Khemka     {
379e7d23d0eSVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
38098aabdb1SKarthikeyan Pasupathi             "Failed to connect to system bus",
38198aabdb1SKarthikeyan Pasupathi             phosphor::logging::entry("ERRNO=0x%X", -ret));
38298aabdb1SKarthikeyan Pasupathi         sd_bus_unref(bus);
383e7d23d0eSVijay Khemka         return -1;
384e7d23d0eSVijay Khemka     }
385cd315e07SPatrick Williams     sdbusplus::bus_t dbus(bus);
38698aabdb1SKarthikeyan Pasupathi     auto mapperCall = dbus.new_method_call("xyz.openbmc_project.ObjectMapper",
38798aabdb1SKarthikeyan Pasupathi                                            "/xyz/openbmc_project/object_mapper",
38898aabdb1SKarthikeyan Pasupathi                                            "xyz.openbmc_project.ObjectMapper",
38998aabdb1SKarthikeyan Pasupathi                                            "GetSubTreePaths");
39098aabdb1SKarthikeyan Pasupathi     static constexpr std::array<const char*, 1> interface = {
39198aabdb1SKarthikeyan Pasupathi         "xyz.openbmc_project.Inventory.Decorator.Asset"};
39298aabdb1SKarthikeyan Pasupathi     mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface);
393e7d23d0eSVijay Khemka 
394e7d23d0eSVijay Khemka     try
395e7d23d0eSVijay Khemka     {
39698aabdb1SKarthikeyan Pasupathi         auto reply = dbus.call(mapperCall);
39798aabdb1SKarthikeyan Pasupathi         reply.read(paths);
398e7d23d0eSVijay Khemka     }
39998aabdb1SKarthikeyan Pasupathi     catch (sdbusplus::exception_t& e)
400e7d23d0eSVijay Khemka     {
401e7d23d0eSVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
402e7d23d0eSVijay Khemka         return -1;
403e7d23d0eSVijay Khemka     }
40498aabdb1SKarthikeyan Pasupathi 
40598aabdb1SKarthikeyan Pasupathi     for (const auto& path : paths)
40698aabdb1SKarthikeyan Pasupathi     {
40798aabdb1SKarthikeyan Pasupathi         if (platform == true)
40898aabdb1SKarthikeyan Pasupathi         {
40998aabdb1SKarthikeyan Pasupathi             if (pos == BMC_POS)
41098aabdb1SKarthikeyan Pasupathi             {
41198aabdb1SKarthikeyan Pasupathi                 machinePath = baseBoard;
41298aabdb1SKarthikeyan Pasupathi             }
41398aabdb1SKarthikeyan Pasupathi             else
41498aabdb1SKarthikeyan Pasupathi             {
41598aabdb1SKarthikeyan Pasupathi                 machinePath = "_" + std::to_string(pos);
41698aabdb1SKarthikeyan Pasupathi             }
41798aabdb1SKarthikeyan Pasupathi         }
41898aabdb1SKarthikeyan Pasupathi         else
41998aabdb1SKarthikeyan Pasupathi         {
42098aabdb1SKarthikeyan Pasupathi             machinePath = baseBoard;
42198aabdb1SKarthikeyan Pasupathi         }
42298aabdb1SKarthikeyan Pasupathi 
42398aabdb1SKarthikeyan Pasupathi         auto found = path.find(machinePath);
424123cbcc4SPatrick Williams         if (found == std::string::npos)
42598aabdb1SKarthikeyan Pasupathi         {
42698aabdb1SKarthikeyan Pasupathi             continue;
42798aabdb1SKarthikeyan Pasupathi         }
42898aabdb1SKarthikeyan Pasupathi 
42998aabdb1SKarthikeyan Pasupathi         std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
43098aabdb1SKarthikeyan Pasupathi         std::string service = getService(
43198aabdb1SKarthikeyan Pasupathi             *dbus, "xyz.openbmc_project.Inventory.Decorator.Asset", path);
43298aabdb1SKarthikeyan Pasupathi 
43398aabdb1SKarthikeyan Pasupathi         auto Value = ipmi::getDbusProperty(
43498aabdb1SKarthikeyan Pasupathi             *dbus, service, path,
43598aabdb1SKarthikeyan Pasupathi             "xyz.openbmc_project.Inventory.Decorator.Asset", name);
43698aabdb1SKarthikeyan Pasupathi 
43798aabdb1SKarthikeyan Pasupathi         data = std::get<std::string>(Value);
43898aabdb1SKarthikeyan Pasupathi         return 0;
439e7d23d0eSVijay Khemka     }
440e7d23d0eSVijay Khemka     return -1;
441e7d23d0eSVijay Khemka }
442e7d23d0eSVijay Khemka 
44310ff3d86SKarthikeyan Pasupathi int8_t sysConfig(std::vector<std::string>& data, size_t pos)
44410ff3d86SKarthikeyan Pasupathi {
44510ff3d86SKarthikeyan Pasupathi     nlohmann::json sysObj;
44610ff3d86SKarthikeyan Pasupathi     std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(pos);
44710ff3d86SKarthikeyan Pasupathi     std::string result, typeName;
44810ff3d86SKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
44910ff3d86SKarthikeyan Pasupathi 
45010ff3d86SKarthikeyan Pasupathi     /* Get sysConfig data stored in json file */
45110ff3d86SKarthikeyan Pasupathi     std::ifstream file(JSON_OEM_DATA_FILE);
45210ff3d86SKarthikeyan Pasupathi     if (file)
45310ff3d86SKarthikeyan Pasupathi     {
45410ff3d86SKarthikeyan Pasupathi         file >> sysObj;
45510ff3d86SKarthikeyan Pasupathi         file.close();
45610ff3d86SKarthikeyan Pasupathi     }
45710ff3d86SKarthikeyan Pasupathi     else
45810ff3d86SKarthikeyan Pasupathi     {
45910ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
46010ff3d86SKarthikeyan Pasupathi             "oemData file not found",
46110ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
46210ff3d86SKarthikeyan Pasupathi         return -1;
46310ff3d86SKarthikeyan Pasupathi     }
46410ff3d86SKarthikeyan Pasupathi 
46510ff3d86SKarthikeyan Pasupathi     if (sysObj.find(dimmInfo) == sysObj.end())
46610ff3d86SKarthikeyan Pasupathi     {
46710ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
46810ff3d86SKarthikeyan Pasupathi             "sysconfig key not available",
46910ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("SYS_JSON_KEY=%s", dimmInfo.c_str()));
47010ff3d86SKarthikeyan Pasupathi         return -1;
47110ff3d86SKarthikeyan Pasupathi     }
47210ff3d86SKarthikeyan Pasupathi     /* Get dimm type names stored in json file */
47310ff3d86SKarthikeyan Pasupathi     nlohmann::json dimmObj;
47410ff3d86SKarthikeyan Pasupathi     std::ifstream dimmFile(JSON_DIMM_TYPE_FILE);
47510ff3d86SKarthikeyan Pasupathi     if (file)
47610ff3d86SKarthikeyan Pasupathi     {
47710ff3d86SKarthikeyan Pasupathi         dimmFile >> dimmObj;
47810ff3d86SKarthikeyan Pasupathi         dimmFile.close();
47910ff3d86SKarthikeyan Pasupathi     }
48010ff3d86SKarthikeyan Pasupathi     else
48110ff3d86SKarthikeyan Pasupathi     {
48210ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
48310ff3d86SKarthikeyan Pasupathi             "DIMM type names file not found",
48410ff3d86SKarthikeyan Pasupathi             phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
48510ff3d86SKarthikeyan Pasupathi         return -1;
48610ff3d86SKarthikeyan Pasupathi     }
48710ff3d86SKarthikeyan Pasupathi     std::vector<std::string> a;
48810ff3d86SKarthikeyan Pasupathi     for (auto& j : dimmObj.items())
48910ff3d86SKarthikeyan Pasupathi     {
49010ff3d86SKarthikeyan Pasupathi         std::string name = j.key();
49110ff3d86SKarthikeyan Pasupathi         a.push_back(name);
49210ff3d86SKarthikeyan Pasupathi     }
49310ff3d86SKarthikeyan Pasupathi 
49410ff3d86SKarthikeyan Pasupathi     uint8_t len = a.size();
49510ff3d86SKarthikeyan Pasupathi     for (uint8_t ii = 0; ii < len; ii++)
49610ff3d86SKarthikeyan Pasupathi     {
49710ff3d86SKarthikeyan Pasupathi         std::string indKey = std::to_string(ii);
49810ff3d86SKarthikeyan Pasupathi         std::string speedSize = sysObj[dimmInfo][indKey][DIMM_SPEED];
49910ff3d86SKarthikeyan Pasupathi         strToBytes(speedSize, res);
50010ff3d86SKarthikeyan Pasupathi         auto speed = (res[1] << 8 | res[0]);
50110ff3d86SKarthikeyan Pasupathi         size_t dimmSize = ((res[3] << 8 | res[2]) / 1000);
50210ff3d86SKarthikeyan Pasupathi 
50310ff3d86SKarthikeyan Pasupathi         if (dimmSize == 0)
50410ff3d86SKarthikeyan Pasupathi         {
50510ff3d86SKarthikeyan Pasupathi             std::cerr << "Dimm information not available for slot_" +
50610ff3d86SKarthikeyan Pasupathi                              std::to_string(ii)
50710ff3d86SKarthikeyan Pasupathi                       << std::endl;
50810ff3d86SKarthikeyan Pasupathi             continue;
50910ff3d86SKarthikeyan Pasupathi         }
51010ff3d86SKarthikeyan Pasupathi         std::string type = sysObj[dimmInfo][indKey][DIMM_TYPE];
51110ff3d86SKarthikeyan Pasupathi         std::string dualInlineMem = sysObj[dimmInfo][indKey][KEY_DIMM_TYPE];
51210ff3d86SKarthikeyan Pasupathi         strToBytes(type, res);
51310ff3d86SKarthikeyan Pasupathi         size_t dimmType = res[0];
51410ff3d86SKarthikeyan Pasupathi         if (dimmVenMap.find(dimmType) == dimmVenMap.end())
51510ff3d86SKarthikeyan Pasupathi         {
51610ff3d86SKarthikeyan Pasupathi             typeName = "unknown";
51710ff3d86SKarthikeyan Pasupathi         }
51810ff3d86SKarthikeyan Pasupathi         else
51910ff3d86SKarthikeyan Pasupathi         {
52010ff3d86SKarthikeyan Pasupathi             typeName = dimmVenMap[dimmType];
52110ff3d86SKarthikeyan Pasupathi         }
52210ff3d86SKarthikeyan Pasupathi         result = dualInlineMem + "/" + typeName + "/" + std::to_string(speed) +
52310ff3d86SKarthikeyan Pasupathi                  "MHz" + "/" + std::to_string(dimmSize) + "GB";
52410ff3d86SKarthikeyan Pasupathi         data.push_back(result);
52510ff3d86SKarthikeyan Pasupathi     }
52610ff3d86SKarthikeyan Pasupathi     return 0;
52710ff3d86SKarthikeyan Pasupathi }
52810ff3d86SKarthikeyan Pasupathi 
529d532fecaSKarthikeyan Pasupathi int8_t procInfo(std::string& result, size_t pos)
530d532fecaSKarthikeyan Pasupathi {
531d532fecaSKarthikeyan Pasupathi     std::vector<char> data;
532d532fecaSKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
533d532fecaSKarthikeyan Pasupathi     std::string procIndex = "00";
534d532fecaSKarthikeyan Pasupathi     nlohmann::json proObj;
535d532fecaSKarthikeyan Pasupathi     std::string procInfo = KEY_Q_PROC_INFO + std::to_string(pos);
536d532fecaSKarthikeyan Pasupathi     /* Get processor data stored in json file */
537d532fecaSKarthikeyan Pasupathi     std::ifstream file(JSON_OEM_DATA_FILE);
538d532fecaSKarthikeyan Pasupathi     if (file)
539d532fecaSKarthikeyan Pasupathi     {
540d532fecaSKarthikeyan Pasupathi         file >> proObj;
541d532fecaSKarthikeyan Pasupathi         file.close();
542d532fecaSKarthikeyan Pasupathi     }
543d532fecaSKarthikeyan Pasupathi     else
544d532fecaSKarthikeyan Pasupathi     {
545d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
546d532fecaSKarthikeyan Pasupathi             "oemData file not found",
547d532fecaSKarthikeyan Pasupathi             phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
548d532fecaSKarthikeyan Pasupathi         return -1;
549d532fecaSKarthikeyan Pasupathi     }
550d532fecaSKarthikeyan Pasupathi     if (proObj.find(procInfo) == proObj.end())
551d532fecaSKarthikeyan Pasupathi     {
552d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
553d532fecaSKarthikeyan Pasupathi             "processor info key not available",
554d532fecaSKarthikeyan Pasupathi             phosphor::logging::entry("PROC_JSON_KEY=%s", procInfo.c_str()));
555d532fecaSKarthikeyan Pasupathi         return -1;
556d532fecaSKarthikeyan Pasupathi     }
557d532fecaSKarthikeyan Pasupathi     std::string procName = proObj[procInfo][procIndex][KEY_PROC_NAME];
558d532fecaSKarthikeyan Pasupathi     std::string basicInfo = proObj[procInfo][procIndex][KEY_BASIC_INFO];
559d532fecaSKarthikeyan Pasupathi     // Processor Product Name
560d532fecaSKarthikeyan Pasupathi     strToBytes(procName, res);
561d532fecaSKarthikeyan Pasupathi     data.assign(reinterpret_cast<char*>(&res),
562d532fecaSKarthikeyan Pasupathi                 reinterpret_cast<char*>(&res) + sizeof(res));
563d532fecaSKarthikeyan Pasupathi 
564d532fecaSKarthikeyan Pasupathi     std::string s(data.begin(), data.end());
565d532fecaSKarthikeyan Pasupathi     std::regex regex(" ");
566d532fecaSKarthikeyan Pasupathi     std::vector<std::string> productName(
567d532fecaSKarthikeyan Pasupathi         std::sregex_token_iterator(s.begin(), s.end(), regex, -1),
568d532fecaSKarthikeyan Pasupathi         std::sregex_token_iterator());
569d532fecaSKarthikeyan Pasupathi 
570d532fecaSKarthikeyan Pasupathi     // Processor core and frequency
571d532fecaSKarthikeyan Pasupathi     strToBytes(basicInfo, res);
572d532fecaSKarthikeyan Pasupathi     uint16_t coreNum = res[0];
573d532fecaSKarthikeyan Pasupathi     double procFrequency = (float)(res[4] << 8 | res[3]) / 1000;
574d532fecaSKarthikeyan Pasupathi     result = "CPU:" + productName[2] + "/" + std::to_string(procFrequency) +
575d532fecaSKarthikeyan Pasupathi              "GHz" + "/" + std::to_string(coreNum) + "c";
576d532fecaSKarthikeyan Pasupathi     return 0;
577d532fecaSKarthikeyan Pasupathi }
578d532fecaSKarthikeyan Pasupathi 
579e7d23d0eSVijay Khemka typedef struct
580e7d23d0eSVijay Khemka {
581e7d23d0eSVijay Khemka     uint8_t cur_power_state;
582e7d23d0eSVijay Khemka     uint8_t last_power_event;
583e7d23d0eSVijay Khemka     uint8_t misc_power_state;
584e7d23d0eSVijay Khemka     uint8_t front_panel_button_cap_status;
585e7d23d0eSVijay Khemka } ipmi_get_chassis_status_t;
586e7d23d0eSVijay Khemka 
587e7d23d0eSVijay Khemka //----------------------------------------------------------------------
588e7d23d0eSVijay Khemka // Get Debug Frame Info
589e7d23d0eSVijay Khemka //----------------------------------------------------------------------
590e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetFrameInfo(ipmi_netfn_t, ipmi_cmd_t,
591e7d23d0eSVijay Khemka                                   ipmi_request_t request,
592e7d23d0eSVijay Khemka                                   ipmi_response_t response,
593e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
594e7d23d0eSVijay Khemka {
595e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
596e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
597e7d23d0eSVijay Khemka     uint8_t num_frames = 3;
598e7d23d0eSVijay Khemka 
599e7d23d0eSVijay Khemka     std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
600e7d23d0eSVijay Khemka     res[SIZE_IANA_ID] = num_frames;
601e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + 1;
602e7d23d0eSVijay Khemka 
603e7d23d0eSVijay Khemka     return IPMI_CC_OK;
604e7d23d0eSVijay Khemka }
605e7d23d0eSVijay Khemka 
606e7d23d0eSVijay Khemka //----------------------------------------------------------------------
607e7d23d0eSVijay Khemka // Get Debug Updated Frames
608e7d23d0eSVijay Khemka //----------------------------------------------------------------------
609e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetUpdFrames(ipmi_netfn_t, ipmi_cmd_t,
610e7d23d0eSVijay Khemka                                   ipmi_request_t request,
611e7d23d0eSVijay Khemka                                   ipmi_response_t response,
612e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
613e7d23d0eSVijay Khemka {
614e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
615e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
616e7d23d0eSVijay Khemka     uint8_t num_updates = 3;
617e7d23d0eSVijay Khemka     *data_len = 4;
618e7d23d0eSVijay Khemka 
619e7d23d0eSVijay Khemka     std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
620e7d23d0eSVijay Khemka     res[SIZE_IANA_ID] = num_updates;
621e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + num_updates + 1;
622e7d23d0eSVijay Khemka     res[SIZE_IANA_ID + 1] = 1; // info page update
623e7d23d0eSVijay Khemka     res[SIZE_IANA_ID + 2] = 2; // cri sel update
624e7d23d0eSVijay Khemka     res[SIZE_IANA_ID + 3] = 3; // cri sensor update
625e7d23d0eSVijay Khemka 
626e7d23d0eSVijay Khemka     return IPMI_CC_OK;
627e7d23d0eSVijay Khemka }
628e7d23d0eSVijay Khemka 
629e7d23d0eSVijay Khemka //----------------------------------------------------------------------
630e7d23d0eSVijay Khemka // Get Debug POST Description
631e7d23d0eSVijay Khemka //----------------------------------------------------------------------
632e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetPostDesc(ipmi_netfn_t, ipmi_cmd_t,
633e7d23d0eSVijay Khemka                                  ipmi_request_t request,
634e7d23d0eSVijay Khemka                                  ipmi_response_t response,
635e39f9393SWilly Tu                                  ipmi_data_len_t data_len, ipmi_context_t)
636e7d23d0eSVijay Khemka {
637e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
638e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
639e7d23d0eSVijay Khemka     uint8_t index = 0;
640e7d23d0eSVijay Khemka     uint8_t next = 0;
641e7d23d0eSVijay Khemka     uint8_t end = 0;
642e7d23d0eSVijay Khemka     uint8_t phase = 0;
643cc0d6d92SVijay Khemka     uint8_t descLen = 0;
644e7d23d0eSVijay Khemka     int ret;
645e7d23d0eSVijay Khemka 
646e7d23d0eSVijay Khemka     index = req[3];
647e7d23d0eSVijay Khemka     phase = req[4];
648e7d23d0eSVijay Khemka 
649cc0d6d92SVijay Khemka     ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
650e7d23d0eSVijay Khemka     if (ret)
651e7d23d0eSVijay Khemka     {
652e7d23d0eSVijay Khemka         memcpy(res, req, SIZE_IANA_ID); // IANA ID
653e7d23d0eSVijay Khemka         *data_len = SIZE_IANA_ID;
654e7d23d0eSVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
655e7d23d0eSVijay Khemka     }
656e7d23d0eSVijay Khemka 
657e7d23d0eSVijay Khemka     memcpy(res, req, SIZE_IANA_ID); // IANA ID
658e7d23d0eSVijay Khemka     res[3] = index;
659e7d23d0eSVijay Khemka     res[4] = next;
660e7d23d0eSVijay Khemka     res[5] = phase;
661e7d23d0eSVijay Khemka     res[6] = end;
662cc0d6d92SVijay Khemka     res[7] = descLen;
663cc0d6d92SVijay Khemka     *data_len = SIZE_IANA_ID + 5 + descLen;
664e7d23d0eSVijay Khemka 
665e7d23d0eSVijay Khemka     return IPMI_CC_OK;
666e7d23d0eSVijay Khemka }
667e7d23d0eSVijay Khemka 
668e7d23d0eSVijay Khemka //----------------------------------------------------------------------
669e7d23d0eSVijay Khemka // Get Debug GPIO Description
670e7d23d0eSVijay Khemka //----------------------------------------------------------------------
671e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetGpioDesc(ipmi_netfn_t, ipmi_cmd_t,
672e7d23d0eSVijay Khemka                                  ipmi_request_t request,
673e7d23d0eSVijay Khemka                                  ipmi_response_t response,
674e39f9393SWilly Tu                                  ipmi_data_len_t data_len, ipmi_context_t)
675e7d23d0eSVijay Khemka {
676e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
677e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
678e7d23d0eSVijay Khemka 
67938183d66SVijay Khemka     uint8_t index = 0;
68038183d66SVijay Khemka     uint8_t next = 0;
68138183d66SVijay Khemka     uint8_t level = 0;
68238183d66SVijay Khemka     uint8_t pinDef = 0;
68338183d66SVijay Khemka     uint8_t descLen = 0;
68438183d66SVijay Khemka     int ret;
685e7d23d0eSVijay Khemka 
68638183d66SVijay Khemka     index = req[3];
68738183d66SVijay Khemka 
68838183d66SVijay Khemka     ret = plat_udbg_get_gpio_desc(index, &next, &level, &pinDef, &descLen,
68938183d66SVijay Khemka                                   &res[8]);
69038183d66SVijay Khemka     if (ret)
69138183d66SVijay Khemka     {
69238183d66SVijay Khemka         memcpy(res, req, SIZE_IANA_ID); // IANA ID
69338183d66SVijay Khemka         *data_len = SIZE_IANA_ID;
69438183d66SVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
69538183d66SVijay Khemka     }
69638183d66SVijay Khemka 
69738183d66SVijay Khemka     memcpy(res, req, SIZE_IANA_ID); // IANA ID
69838183d66SVijay Khemka     res[3] = index;
69938183d66SVijay Khemka     res[4] = next;
70038183d66SVijay Khemka     res[5] = level;
70138183d66SVijay Khemka     res[6] = pinDef;
70238183d66SVijay Khemka     res[7] = descLen;
70338183d66SVijay Khemka     *data_len = SIZE_IANA_ID + 5 + descLen;
704e7d23d0eSVijay Khemka 
705e7d23d0eSVijay Khemka     return IPMI_CC_OK;
706e7d23d0eSVijay Khemka }
707e7d23d0eSVijay Khemka 
708e7d23d0eSVijay Khemka //----------------------------------------------------------------------
709e7d23d0eSVijay Khemka // Get Debug Frame Data
710e7d23d0eSVijay Khemka //----------------------------------------------------------------------
711e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetFrameData(ipmi_netfn_t, ipmi_cmd_t,
712e7d23d0eSVijay Khemka                                   ipmi_request_t request,
713e7d23d0eSVijay Khemka                                   ipmi_response_t response,
714e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
715e7d23d0eSVijay Khemka {
716e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
717e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
718e7d23d0eSVijay Khemka     uint8_t frame;
719e7d23d0eSVijay Khemka     uint8_t page;
720e7d23d0eSVijay Khemka     uint8_t next;
721e7d23d0eSVijay Khemka     uint8_t count;
722e7d23d0eSVijay Khemka     int ret;
723e7d23d0eSVijay Khemka 
724e7d23d0eSVijay Khemka     frame = req[3];
725e7d23d0eSVijay Khemka     page = req[4];
726e7d23d0eSVijay Khemka 
727e7d23d0eSVijay Khemka     ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]);
728e7d23d0eSVijay Khemka     if (ret)
729e7d23d0eSVijay Khemka     {
730e7d23d0eSVijay Khemka         memcpy(res, req, SIZE_IANA_ID); // IANA ID
731e7d23d0eSVijay Khemka         *data_len = SIZE_IANA_ID;
732e7d23d0eSVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
733e7d23d0eSVijay Khemka     }
734e7d23d0eSVijay Khemka 
735e7d23d0eSVijay Khemka     memcpy(res, req, SIZE_IANA_ID); // IANA ID
736e7d23d0eSVijay Khemka     res[3] = frame;
737e7d23d0eSVijay Khemka     res[4] = page;
738e7d23d0eSVijay Khemka     res[5] = next;
739e7d23d0eSVijay Khemka     res[6] = count;
740e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + 4 + count;
741e7d23d0eSVijay Khemka 
742e7d23d0eSVijay Khemka     return IPMI_CC_OK;
743e7d23d0eSVijay Khemka }
744e7d23d0eSVijay Khemka 
745e7d23d0eSVijay Khemka //----------------------------------------------------------------------
746e7d23d0eSVijay Khemka // Get Debug Control Panel
747e7d23d0eSVijay Khemka //----------------------------------------------------------------------
748e39f9393SWilly Tu ipmi_ret_t ipmiOemDbgGetCtrlPanel(ipmi_netfn_t, ipmi_cmd_t,
749e7d23d0eSVijay Khemka                                   ipmi_request_t request,
750e7d23d0eSVijay Khemka                                   ipmi_response_t response,
751e39f9393SWilly Tu                                   ipmi_data_len_t data_len, ipmi_context_t)
752e7d23d0eSVijay Khemka {
753e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
754e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
755e7d23d0eSVijay Khemka 
756e7d23d0eSVijay Khemka     uint8_t panel;
757e7d23d0eSVijay Khemka     uint8_t operation;
758e7d23d0eSVijay Khemka     uint8_t item;
759e7d23d0eSVijay Khemka     uint8_t count;
760e7d23d0eSVijay Khemka     ipmi_ret_t ret;
761e7d23d0eSVijay Khemka 
762e7d23d0eSVijay Khemka     panel = req[3];
763e7d23d0eSVijay Khemka     operation = req[4];
764e7d23d0eSVijay Khemka     item = req[5];
765e7d23d0eSVijay Khemka 
766e7d23d0eSVijay Khemka     ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]);
767e7d23d0eSVijay Khemka 
768e7d23d0eSVijay Khemka     std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
769e7d23d0eSVijay Khemka     *data_len = SIZE_IANA_ID + count;
770e7d23d0eSVijay Khemka 
771e7d23d0eSVijay Khemka     return ret;
772e7d23d0eSVijay Khemka }
773e7d23d0eSVijay Khemka 
774e7d23d0eSVijay Khemka //----------------------------------------------------------------------
775e7d23d0eSVijay Khemka // Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
776e7d23d0eSVijay Khemka //----------------------------------------------------------------------
777e39f9393SWilly Tu ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
778e39f9393SWilly Tu                               ipmi_response_t, ipmi_data_len_t data_len,
779e39f9393SWilly Tu                               ipmi_context_t)
780e7d23d0eSVijay Khemka {
781e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
7821d4a0697SVijay Khemka 
7831d4a0697SVijay Khemka     uint8_t index = req[0];
7841d4a0697SVijay Khemka     uint8_t type = req[1];
7851d4a0697SVijay Khemka     uint16_t speed;
7861d4a0697SVijay Khemka     uint32_t size;
7871d4a0697SVijay Khemka 
7881d4a0697SVijay Khemka     memcpy(&speed, &req[2], 2);
7891d4a0697SVijay Khemka     memcpy(&size, &req[4], 4);
7901d4a0697SVijay Khemka 
7911d4a0697SVijay Khemka     std::stringstream ss;
7921d4a0697SVijay Khemka     ss << std::hex;
7931d4a0697SVijay Khemka     ss << std::setw(2) << std::setfill('0') << (int)index;
7941d4a0697SVijay Khemka 
7951d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index;
7961d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type;
7971d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed;
7981d4a0697SVijay Khemka     oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size;
7991d4a0697SVijay Khemka 
8001d4a0697SVijay Khemka     flushOemData();
8011d4a0697SVijay Khemka 
8021d4a0697SVijay Khemka     *data_len = 0;
8031d4a0697SVijay Khemka 
8041d4a0697SVijay Khemka     return IPMI_CC_OK;
8051d4a0697SVijay Khemka }
8061d4a0697SVijay Khemka 
8071d4a0697SVijay Khemka //----------------------------------------------------------------------
8081d4a0697SVijay Khemka // Get Board ID (CMD_OEM_GET_BOARD_ID)
8091d4a0697SVijay Khemka //----------------------------------------------------------------------
810e39f9393SWilly Tu ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
811e39f9393SWilly Tu                              ipmi_response_t, ipmi_data_len_t data_len,
812e39f9393SWilly Tu                              ipmi_context_t)
8131d4a0697SVijay Khemka {
8141d4a0697SVijay Khemka     /* TODO: Needs to implement this after GPIO implementation */
815e7d23d0eSVijay Khemka     *data_len = 0;
816e7d23d0eSVijay Khemka 
817e7d23d0eSVijay Khemka     return IPMI_CC_OK;
818e7d23d0eSVijay Khemka }
819e7d23d0eSVijay Khemka 
8204ae63e71SBonnie Lo //----------------------------------------------------------------------
8214ae63e71SBonnie Lo // Get port 80 record (CMD_OEM_GET_80PORT_RECORD)
8224ae63e71SBonnie Lo //----------------------------------------------------------------------
8234ae63e71SBonnie Lo ipmi::RspType<std::vector<uint8_t>>
8244ae63e71SBonnie Lo     ipmiOemGet80PortRecord(ipmi::Context::ptr ctx)
8254ae63e71SBonnie Lo {
8264ae63e71SBonnie Lo     auto postCodeService = "xyz.openbmc_project.State.Boot.PostCode" +
8274ae63e71SBonnie Lo                            std::to_string(ctx->hostIdx + 1);
8284ae63e71SBonnie Lo     auto postCodeObjPath = "/xyz/openbmc_project/State/Boot/PostCode" +
8294ae63e71SBonnie Lo                            std::to_string(ctx->hostIdx + 1);
8304ae63e71SBonnie Lo     constexpr auto postCodeInterface =
8314ae63e71SBonnie Lo         "xyz.openbmc_project.State.Boot.PostCode";
8324ae63e71SBonnie Lo     const static uint16_t lastestPostCodeIndex = 1;
8334ae63e71SBonnie Lo     constexpr const auto maxPostCodeLen =
8344ae63e71SBonnie Lo         224; // The length must be lower than IPMB limitation
8354ae63e71SBonnie Lo     size_t startIndex = 0;
8364ae63e71SBonnie Lo 
8374ae63e71SBonnie Lo     std::vector<std::tuple<uint64_t, std::vector<uint8_t>>> postCodes;
8384ae63e71SBonnie Lo     std::vector<uint8_t> resData;
8394ae63e71SBonnie Lo 
8404ae63e71SBonnie Lo     auto conn = getSdBus();
8414ae63e71SBonnie Lo     /* Get the post codes by calling GetPostCodes method */
842*2405ae98SPatrick Williams     auto msg = conn->new_method_call(postCodeService.c_str(),
843*2405ae98SPatrick Williams                                      postCodeObjPath.c_str(), postCodeInterface,
844*2405ae98SPatrick Williams                                      "GetPostCodes");
8454ae63e71SBonnie Lo     msg.append(lastestPostCodeIndex);
8464ae63e71SBonnie Lo 
8474ae63e71SBonnie Lo     try
8484ae63e71SBonnie Lo     {
8494ae63e71SBonnie Lo         auto reply = conn->call(msg);
8504ae63e71SBonnie Lo         reply.read(postCodes);
8514ae63e71SBonnie Lo     }
8524ae63e71SBonnie Lo     catch (const sdbusplus::exception::SdBusError& e)
8534ae63e71SBonnie Lo     {
8544ae63e71SBonnie Lo         phosphor::logging::log<phosphor::logging::level::ERR>(
8554ae63e71SBonnie Lo             "IPMI Get80PortRecord Failed in call method",
8564ae63e71SBonnie Lo             phosphor::logging::entry("ERROR=%s", e.what()));
8574ae63e71SBonnie Lo         return ipmi::responseUnspecifiedError();
8584ae63e71SBonnie Lo     }
8594ae63e71SBonnie Lo 
8604ae63e71SBonnie Lo     /* Get post code data */
8614ae63e71SBonnie Lo     for (size_t i = 0; i < postCodes.size(); ++i)
8624ae63e71SBonnie Lo     {
8634ae63e71SBonnie Lo         uint64_t primaryPostCode = std::get<uint64_t>(postCodes[i]);
8644ae63e71SBonnie Lo         for (int j = postCodeSize - 1; j >= 0; --j)
8654ae63e71SBonnie Lo         {
8664ae63e71SBonnie Lo             uint8_t postCode =
8674ae63e71SBonnie Lo                 ((primaryPostCode >> (sizeof(uint64_t) * j)) & 0xFF);
8684ae63e71SBonnie Lo             resData.emplace_back(postCode);
8694ae63e71SBonnie Lo         }
8704ae63e71SBonnie Lo     }
8714ae63e71SBonnie Lo 
8724ae63e71SBonnie Lo     std::vector<uint8_t> response;
8734ae63e71SBonnie Lo     if (resData.size() > maxPostCodeLen)
8744ae63e71SBonnie Lo     {
8754ae63e71SBonnie Lo         startIndex = resData.size() - maxPostCodeLen;
8764ae63e71SBonnie Lo     }
8774ae63e71SBonnie Lo 
8784ae63e71SBonnie Lo     response.assign(resData.begin() + startIndex, resData.end());
8794ae63e71SBonnie Lo 
8804ae63e71SBonnie Lo     return ipmi::responseSuccess(response);
8814ae63e71SBonnie Lo }
8824ae63e71SBonnie Lo 
883877d5dd9SVijay Khemka /* Helper functions to set boot order */
884f0cf6658SJayashree-D void setBootOrder(std::string bootObjPath, uint8_t* data,
885f0cf6658SJayashree-D                   std::string bootOrderKey)
886877d5dd9SVijay Khemka {
887f0cf6658SJayashree-D     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
888f0cf6658SJayashree-D 
889f0cf6658SJayashree-D     // SETTING BOOT MODE PROPERTY
890c0f918b5SDelphine CC Chiu     uint8_t bootModeBit = data[0] & 0x04;
89177ee489fSJayashree Dhanapal     auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit);
892778147daSJayashree Dhanapal 
893f0cf6658SJayashree-D     std::string bootOption =
89477ee489fSJayashree Dhanapal         sdbusplus::message::convert_to_string<boot::BootMode>(bootValue);
895f0cf6658SJayashree-D 
896*2405ae98SPatrick Williams     std::string service = getService(*dbus, ipmi::boot::bootModeIntf,
897*2405ae98SPatrick Williams                                      bootObjPath);
898f0cf6658SJayashree-D     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
899f0cf6658SJayashree-D                     ipmi::boot::bootModeProp, bootOption);
900f0cf6658SJayashree-D 
901f0cf6658SJayashree-D     // SETTING BOOT SOURCE PROPERTY
90277ee489fSJayashree Dhanapal     auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]);
903f0cf6658SJayashree-D     std::string bootSource =
90477ee489fSJayashree Dhanapal         sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder);
905f0cf6658SJayashree-D 
906f0cf6658SJayashree-D     service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
907f0cf6658SJayashree-D     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
908f0cf6658SJayashree-D                     ipmi::boot::bootSourceProp, bootSource);
909f0cf6658SJayashree-D 
910778147daSJayashree Dhanapal     // SETTING BOOT TYPE PROPERTY
911778147daSJayashree Dhanapal     uint8_t bootTypeBit = data[0] & 0x01;
91277ee489fSJayashree Dhanapal     auto bootTypeVal = ipmi::boot::typeIpmiToDbus.at(bootTypeBit);
91377ee489fSJayashree Dhanapal 
914778147daSJayashree Dhanapal     std::string bootType =
91577ee489fSJayashree Dhanapal         sdbusplus::message::convert_to_string<boot::BootType>(bootTypeVal);
916778147daSJayashree Dhanapal 
917778147daSJayashree Dhanapal     service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
918778147daSJayashree Dhanapal 
919778147daSJayashree Dhanapal     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
920778147daSJayashree Dhanapal                     ipmi::boot::bootTypeProp, bootType);
921778147daSJayashree Dhanapal 
922c0f918b5SDelphine CC Chiu     // Set the valid bit to boot enabled property
923c0f918b5SDelphine CC Chiu     service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
924c0f918b5SDelphine CC Chiu 
925c0f918b5SDelphine CC Chiu     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf,
926c0f918b5SDelphine CC Chiu                     ipmi::boot::bootEnableProp,
927c0f918b5SDelphine CC Chiu                     (data[0] & BOOT_MODE_BOOT_FLAG) ? true : false);
928c0f918b5SDelphine CC Chiu 
929877d5dd9SVijay Khemka     nlohmann::json bootMode;
930877d5dd9SVijay Khemka     uint8_t mode = data[0];
931877d5dd9SVijay Khemka     int i;
932877d5dd9SVijay Khemka 
933877d5dd9SVijay Khemka     bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
934877d5dd9SVijay Khemka     bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
935877d5dd9SVijay Khemka     bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
936877d5dd9SVijay Khemka     bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);
937f0cf6658SJayashree-D     oemData[bootOrderKey][KEY_BOOT_MODE] = bootMode;
938877d5dd9SVijay Khemka 
939877d5dd9SVijay Khemka     /* Initialize boot sequence array */
940f0cf6658SJayashree-D     oemData[bootOrderKey][KEY_BOOT_SEQ] = {};
941877d5dd9SVijay Khemka     for (i = 1; i < SIZE_BOOT_ORDER; i++)
942877d5dd9SVijay Khemka     {
943877d5dd9SVijay Khemka         if (data[i] >= BOOT_SEQ_ARRAY_SIZE)
944f0cf6658SJayashree-D             oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = "NA";
945877d5dd9SVijay Khemka         else
946f0cf6658SJayashree-D             oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = bootSeq[data[i]];
947877d5dd9SVijay Khemka     }
948877d5dd9SVijay Khemka 
949877d5dd9SVijay Khemka     flushOemData();
950877d5dd9SVijay Khemka }
951877d5dd9SVijay Khemka 
952e7d23d0eSVijay Khemka //----------------------------------------------------------------------
9531d4a0697SVijay Khemka // Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
9541d4a0697SVijay Khemka //----------------------------------------------------------------------
955f0cf6658SJayashree-D ipmi::RspType<std::vector<uint8_t>>
956f0cf6658SJayashree-D     ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data)
9571d4a0697SVijay Khemka {
958f0cf6658SJayashree-D     uint8_t bootSeq[SIZE_BOOT_ORDER];
959f0cf6658SJayashree-D     size_t len = data.size();
9601d4a0697SVijay Khemka 
9611d4a0697SVijay Khemka     if (len != SIZE_BOOT_ORDER)
9621d4a0697SVijay Khemka     {
9631d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
9641d4a0697SVijay Khemka             "Invalid Boot order length received");
965f0cf6658SJayashree-D         return ipmi::responseReqDataLenInvalid();
9661d4a0697SVijay Khemka     }
9671d4a0697SVijay Khemka 
968f0cf6658SJayashree-D     std::copy(std::begin(data), std::end(data), bootSeq);
9694ec80567SJayashree Dhanapal     std::optional<size_t> hostId = findHost(ctx->hostIdx);
9701d4a0697SVijay Khemka 
971f0cf6658SJayashree-D     if (!hostId)
972f0cf6658SJayashree-D     {
973f0cf6658SJayashree-D         phosphor::logging::log<phosphor::logging::level::ERR>(
974f0cf6658SJayashree-D             "Invalid Host Id received");
975f0cf6658SJayashree-D         return ipmi::responseInvalidCommand();
976f0cf6658SJayashree-D     }
977f0cf6658SJayashree-D     auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
978f0cf6658SJayashree-D 
979f0cf6658SJayashree-D     setBootOrder(bootObjPath, bootSeq, hostName);
980f0cf6658SJayashree-D 
981f0cf6658SJayashree-D     return ipmi::responseSuccess(data);
9821d4a0697SVijay Khemka }
9831d4a0697SVijay Khemka 
9841d4a0697SVijay Khemka //----------------------------------------------------------------------
985e7d23d0eSVijay Khemka // Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
986e7d23d0eSVijay Khemka //----------------------------------------------------------------------
987f0cf6658SJayashree-D ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
988f0cf6658SJayashree-D     ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
989e7d23d0eSVijay Khemka {
990f0cf6658SJayashree-D     uint8_t bootSeq[SIZE_BOOT_ORDER];
9911d4a0697SVijay Khemka     uint8_t mode = 0;
992e7d23d0eSVijay Khemka 
9934ec80567SJayashree Dhanapal     std::optional<size_t> hostId = findHost(ctx->hostIdx);
9941d4a0697SVijay Khemka 
995f0cf6658SJayashree-D     if (!hostId)
996f0cf6658SJayashree-D     {
997f0cf6658SJayashree-D         phosphor::logging::log<phosphor::logging::level::ERR>(
998f0cf6658SJayashree-D             "Invalid Host Id received");
999f0cf6658SJayashree-D         return ipmi::responseInvalidCommand();
1000f0cf6658SJayashree-D     }
1001f0cf6658SJayashree-D     auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
1002f0cf6658SJayashree-D 
1003f0cf6658SJayashree-D     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1004f0cf6658SJayashree-D 
100577ee489fSJayashree Dhanapal     // GETTING PROPERTY OF MODE INTERFACE
100677ee489fSJayashree Dhanapal 
1007*2405ae98SPatrick Williams     std::string service = getService(*dbus, ipmi::boot::bootModeIntf,
1008*2405ae98SPatrick Williams                                      bootObjPath);
1009*2405ae98SPatrick Williams     Value variant = getDbusProperty(*dbus, service, bootObjPath,
1010*2405ae98SPatrick Williams                                     ipmi::boot::bootModeIntf,
1011f0cf6658SJayashree-D                                     ipmi::boot::bootModeProp);
1012f0cf6658SJayashree-D 
101377ee489fSJayashree Dhanapal     auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>(
1014f0cf6658SJayashree-D         std::get<std::string>(variant));
1015f0cf6658SJayashree-D 
1016778147daSJayashree Dhanapal     uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
1017f0cf6658SJayashree-D 
1018778147daSJayashree Dhanapal     // GETTING PROPERTY OF TYPE INTERFACE
1019778147daSJayashree Dhanapal 
1020778147daSJayashree Dhanapal     service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
1021*2405ae98SPatrick Williams     variant = getDbusProperty(*dbus, service, bootObjPath,
1022*2405ae98SPatrick Williams                               ipmi::boot::bootTypeIntf,
1023778147daSJayashree Dhanapal                               ipmi::boot::bootTypeProp);
102477ee489fSJayashree Dhanapal 
102577ee489fSJayashree Dhanapal     auto bootType = sdbusplus::message::convert_from_string<boot::BootType>(
1026778147daSJayashree Dhanapal         std::get<std::string>(variant));
1027778147daSJayashree Dhanapal 
1028c0f918b5SDelphine CC Chiu     // Get the valid bit from boot enabled property
1029c0f918b5SDelphine CC Chiu     service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
1030*2405ae98SPatrick Williams     variant = getDbusProperty(*dbus, service, bootObjPath,
1031*2405ae98SPatrick Williams                               ipmi::boot::bootEnableIntf,
1032c0f918b5SDelphine CC Chiu                               ipmi::boot::bootEnableProp);
1033c0f918b5SDelphine CC Chiu 
1034c0f918b5SDelphine CC Chiu     bool validFlag = std::get<bool>(variant);
1035c0f918b5SDelphine CC Chiu 
1036778147daSJayashree Dhanapal     uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
1037778147daSJayashree Dhanapal 
1038778147daSJayashree Dhanapal     uint8_t bootVal = bootOption | bootTypeVal;
1039f0cf6658SJayashree-D 
1040c0f918b5SDelphine CC Chiu     if (validFlag)
1041c0f918b5SDelphine CC Chiu     {
1042c0f918b5SDelphine CC Chiu         bootVal |= BOOT_MODE_BOOT_FLAG;
1043c0f918b5SDelphine CC Chiu     }
1044c0f918b5SDelphine CC Chiu 
1045f0cf6658SJayashree-D     if (oemData.find(hostName) == oemData.end())
1046877d5dd9SVijay Khemka     {
1047877d5dd9SVijay Khemka         /* Return default boot order 0100090203ff */
1048877d5dd9SVijay Khemka         uint8_t defaultBoot[SIZE_BOOT_ORDER] = {
1049e39f9393SWilly Tu             BOOT_MODE_UEFI,
1050e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["USB_DEV"]),
1051e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["NET_IPV6"]),
1052e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["SATA_HDD"]),
1053e39f9393SWilly Tu             static_cast<uint8_t>(bootMap["SATA_CD"]),
1054e39f9393SWilly Tu             0xff};
1055877d5dd9SVijay Khemka 
1056f0cf6658SJayashree-D         memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER);
1057877d5dd9SVijay Khemka         phosphor::logging::log<phosphor::logging::level::INFO>(
1058877d5dd9SVijay Khemka             "Set default boot order");
1059f0cf6658SJayashree-D         setBootOrder(bootObjPath, defaultBoot, hostName);
1060877d5dd9SVijay Khemka     }
1061877d5dd9SVijay Khemka     else
1062877d5dd9SVijay Khemka     {
1063f0cf6658SJayashree-D         nlohmann::json bootMode = oemData[hostName][KEY_BOOT_MODE];
10641d4a0697SVijay Khemka         if (bootMode["CMOS_CLR"])
1065c0f918b5SDelphine CC Chiu             bootVal |= BOOT_MODE_CMOS_CLR;
10661d4a0697SVijay Khemka 
1067f0cf6658SJayashree-D         bootSeq[0] = mode;
10681d4a0697SVijay Khemka 
1069f0cf6658SJayashree-D         for (int i = 1; i < SIZE_BOOT_ORDER; i++)
1070877d5dd9SVijay Khemka         {
1071f0cf6658SJayashree-D             std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
1072877d5dd9SVijay Khemka             if (bootMap.find(seqStr) != bootMap.end())
1073f0cf6658SJayashree-D                 bootSeq[i] = bootMap[seqStr];
1074877d5dd9SVijay Khemka             else
1075f0cf6658SJayashree-D                 bootSeq[i] = 0xff;
1076877d5dd9SVijay Khemka         }
1077877d5dd9SVijay Khemka     }
1078e7d23d0eSVijay Khemka 
1079c0f918b5SDelphine CC Chiu     return ipmi::responseSuccess(bootVal, bootSeq[1], bootSeq[2], bootSeq[3],
1080f0cf6658SJayashree-D                                  bootSeq[4], bootSeq[5]);
1081e7d23d0eSVijay Khemka }
1082e7d23d0eSVijay Khemka // Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
1083e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1084e39f9393SWilly Tu ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t, ipmi_cmd_t,
1085e39f9393SWilly Tu                                     ipmi_request_t request, ipmi_response_t,
1086e39f9393SWilly Tu                                     ipmi_data_len_t data_len, ipmi_context_t)
1087e7d23d0eSVijay Khemka {
10881d4a0697SVijay Khemka     machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request);
10891d4a0697SVijay Khemka     uint8_t len = *data_len;
1090e7d23d0eSVijay Khemka 
1091e7d23d0eSVijay Khemka     *data_len = 0;
1092e7d23d0eSVijay Khemka 
10931d4a0697SVijay Khemka     if (len < sizeof(machineConfigInfo_t))
10941d4a0697SVijay Khemka     {
10951d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
10961d4a0697SVijay Khemka             "Invalid machine configuration length received");
10971d4a0697SVijay Khemka         return IPMI_CC_REQ_DATA_LEN_INVALID;
10981d4a0697SVijay Khemka     }
10991d4a0697SVijay Khemka 
11001d4a0697SVijay Khemka     if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*))
11011d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN";
11021d4a0697SVijay Khemka     else
11031d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] =
11041d4a0697SVijay Khemka             chassisType[req->chassis_type];
11051d4a0697SVijay Khemka 
11061d4a0697SVijay Khemka     if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*))
11071d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN";
11081d4a0697SVijay Khemka     else
11091d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type];
11101d4a0697SVijay Khemka 
11111d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt;
11121d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt;
11131d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt;
11141d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt;
11151d4a0697SVijay Khemka 
11161d4a0697SVijay Khemka     if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*))
11171d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN";
11181d4a0697SVijay Khemka     else
11191d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type];
11201d4a0697SVijay Khemka 
11211d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {};
11221d4a0697SVijay Khemka     int i = 0;
11231d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_0)
11241d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1";
11251d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_1)
11261d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2";
11271d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_2)
11281d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3";
11291d4a0697SVijay Khemka     if (req->pcie_card_loc & BIT_3)
11301d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4";
11311d4a0697SVijay Khemka 
11321d4a0697SVijay Khemka     if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11331d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN";
11341d4a0697SVijay Khemka     else
11351d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] =
11361d4a0697SVijay Khemka             pcieType[req->slot1_pcie_type];
11371d4a0697SVijay Khemka 
11381d4a0697SVijay Khemka     if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11391d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN";
11401d4a0697SVijay Khemka     else
11411d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] =
11421d4a0697SVijay Khemka             pcieType[req->slot2_pcie_type];
11431d4a0697SVijay Khemka 
11441d4a0697SVijay Khemka     if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11451d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN";
11461d4a0697SVijay Khemka     else
11471d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] =
11481d4a0697SVijay Khemka             pcieType[req->slot3_pcie_type];
11491d4a0697SVijay Khemka 
11501d4a0697SVijay Khemka     if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
11511d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN";
11521d4a0697SVijay Khemka     else
11531d4a0697SVijay Khemka         oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] =
11541d4a0697SVijay Khemka             pcieType[req->slot4_pcie_type];
11551d4a0697SVijay Khemka 
11561d4a0697SVijay Khemka     oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt;
11571d4a0697SVijay Khemka 
11581d4a0697SVijay Khemka     flushOemData();
11591d4a0697SVijay Khemka 
1160e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1161e7d23d0eSVijay Khemka }
1162e7d23d0eSVijay Khemka 
1163e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1164e7d23d0eSVijay Khemka // Set POST start (CMD_OEM_SET_POST_START)
1165e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1166e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1167e39f9393SWilly Tu                                ipmi_response_t, ipmi_data_len_t data_len,
1168e39f9393SWilly Tu                                ipmi_context_t)
1169e7d23d0eSVijay Khemka {
1170e7d23d0eSVijay Khemka     phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
1171e7d23d0eSVijay Khemka 
11721d4a0697SVijay Khemka     /* Do nothing, return success */
1173e7d23d0eSVijay Khemka     *data_len = 0;
1174e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1175e7d23d0eSVijay Khemka }
1176e7d23d0eSVijay Khemka 
1177e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1178e7d23d0eSVijay Khemka // Set POST End (CMD_OEM_SET_POST_END)
1179e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1180e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1181e39f9393SWilly Tu                              ipmi_response_t, ipmi_data_len_t data_len,
1182e39f9393SWilly Tu                              ipmi_context_t)
1183e7d23d0eSVijay Khemka {
11841d4a0697SVijay Khemka     struct timespec ts;
1185e7d23d0eSVijay Khemka 
1186e7d23d0eSVijay Khemka     phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
1187e7d23d0eSVijay Khemka 
1188e7d23d0eSVijay Khemka     *data_len = 0;
11891d4a0697SVijay Khemka 
11901d4a0697SVijay Khemka     // Timestamp post end time.
11911d4a0697SVijay Khemka     clock_gettime(CLOCK_REALTIME, &ts);
11921d4a0697SVijay Khemka     oemData[KEY_TS_SLED] = ts.tv_sec;
11931d4a0697SVijay Khemka     flushOemData();
11941d4a0697SVijay Khemka 
11951d4a0697SVijay Khemka     // Sync time with system
11961d4a0697SVijay Khemka     // TODO: Add code for syncing time
11971d4a0697SVijay Khemka 
11981d4a0697SVijay Khemka     return IPMI_CC_OK;
11991d4a0697SVijay Khemka }
12001d4a0697SVijay Khemka 
12011d4a0697SVijay Khemka //----------------------------------------------------------------------
12021d4a0697SVijay Khemka // Set PPIN Info (CMD_OEM_SET_PPIN_INFO)
12031d4a0697SVijay Khemka //----------------------------------------------------------------------
12041d4a0697SVijay Khemka // Inform BMC about PPIN data of 8 bytes for each CPU
12051d4a0697SVijay Khemka //
12061d4a0697SVijay Khemka // Request:
12071d4a0697SVijay Khemka // Byte 1:8 – CPU0 PPIN data
12081d4a0697SVijay Khemka // Optional:
12091d4a0697SVijay Khemka // Byte 9:16 – CPU1 PPIN data
12101d4a0697SVijay Khemka //
12111d4a0697SVijay Khemka // Response:
12121d4a0697SVijay Khemka // Byte 1 – Completion Code
1213e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1214e39f9393SWilly Tu                               ipmi_response_t, ipmi_data_len_t data_len,
1215e39f9393SWilly Tu                               ipmi_context_t)
12161d4a0697SVijay Khemka {
12171d4a0697SVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
12181d4a0697SVijay Khemka     std::string ppinStr;
12191d4a0697SVijay Khemka     int len;
12201d4a0697SVijay Khemka 
12211d4a0697SVijay Khemka     if (*data_len > SIZE_CPU_PPIN * 2)
12221d4a0697SVijay Khemka         len = SIZE_CPU_PPIN * 2;
12231d4a0697SVijay Khemka     else
12241d4a0697SVijay Khemka         len = *data_len;
12251d4a0697SVijay Khemka     *data_len = 0;
12261d4a0697SVijay Khemka 
12271d4a0697SVijay Khemka     ppinStr = bytesToStr(req, len);
12281d4a0697SVijay Khemka     oemData[KEY_PPIN_INFO] = ppinStr.c_str();
12291d4a0697SVijay Khemka     flushOemData();
12301d4a0697SVijay Khemka 
12311d4a0697SVijay Khemka     return IPMI_CC_OK;
12321d4a0697SVijay Khemka }
12331d4a0697SVijay Khemka 
12341d4a0697SVijay Khemka //----------------------------------------------------------------------
12351d4a0697SVijay Khemka // Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER)
12361d4a0697SVijay Khemka //----------------------------------------------------------------------
1237e39f9393SWilly Tu ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1238e39f9393SWilly Tu                                 ipmi_response_t, ipmi_data_len_t data_len,
1239e39f9393SWilly Tu                                 ipmi_context_t)
12401d4a0697SVijay Khemka {
12411d4a0697SVijay Khemka     /* Do nothing, return success */
12421d4a0697SVijay Khemka     *data_len = 0;
1243e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1244e7d23d0eSVijay Khemka }
1245e7d23d0eSVijay Khemka 
1246f2246ce8SVijay Khemka // Helper function to set guid at offset in EEPROM
1247e39f9393SWilly Tu [[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid)
1248f2246ce8SVijay Khemka {
1249f2246ce8SVijay Khemka     int fd = -1;
1250f2246ce8SVijay Khemka     ssize_t len;
1251f2246ce8SVijay Khemka     int ret = 0;
1252f2246ce8SVijay Khemka 
1253f2246ce8SVijay Khemka     errno = 0;
1254f2246ce8SVijay Khemka 
1255f2246ce8SVijay Khemka     // Check if file is present
1256f2246ce8SVijay Khemka     if (access(FRU_EEPROM, F_OK) == -1)
1257f2246ce8SVijay Khemka     {
1258f2246ce8SVijay Khemka         std::cerr << "Unable to access: " << FRU_EEPROM << std::endl;
1259f2246ce8SVijay Khemka         return errno;
1260f2246ce8SVijay Khemka     }
1261f2246ce8SVijay Khemka 
1262f2246ce8SVijay Khemka     // Open the file
1263f2246ce8SVijay Khemka     fd = open(FRU_EEPROM, O_WRONLY);
1264f2246ce8SVijay Khemka     if (fd == -1)
1265f2246ce8SVijay Khemka     {
1266f2246ce8SVijay Khemka         std::cerr << "Unable to open: " << FRU_EEPROM << std::endl;
1267f2246ce8SVijay Khemka         return errno;
1268f2246ce8SVijay Khemka     }
1269f2246ce8SVijay Khemka 
1270f2246ce8SVijay Khemka     // seek to the offset
1271f2246ce8SVijay Khemka     lseek(fd, offset, SEEK_SET);
1272f2246ce8SVijay Khemka 
1273f2246ce8SVijay Khemka     // Write bytes to location
1274f2246ce8SVijay Khemka     len = write(fd, guid, GUID_SIZE);
1275f2246ce8SVijay Khemka     if (len != GUID_SIZE)
1276f2246ce8SVijay Khemka     {
1277f2246ce8SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
1278f2246ce8SVijay Khemka             "GUID write data to EEPROM failed");
1279f2246ce8SVijay Khemka         ret = errno;
1280f2246ce8SVijay Khemka     }
1281f2246ce8SVijay Khemka 
1282f2246ce8SVijay Khemka     close(fd);
1283f2246ce8SVijay Khemka     return ret;
1284f2246ce8SVijay Khemka }
1285f2246ce8SVijay Khemka 
1286f2246ce8SVijay Khemka //----------------------------------------------------------------------
1287f2246ce8SVijay Khemka // Set System GUID (CMD_OEM_SET_SYSTEM_GUID)
1288f2246ce8SVijay Khemka //----------------------------------------------------------------------
12895f8e3435SManikandan Elumalai #if BIC_ENABLED
12903f671273SBonnie Lo ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx,
12915f8e3435SManikandan Elumalai                                      std::vector<uint8_t> reqData)
12925f8e3435SManikandan Elumalai {
12935f8e3435SManikandan Elumalai     std::vector<uint8_t> respData;
12945f8e3435SManikandan Elumalai 
12955f8e3435SManikandan Elumalai     if (reqData.size() != GUID_SIZE) // 16bytes
12965f8e3435SManikandan Elumalai     {
12975f8e3435SManikandan Elumalai         return ipmi::responseReqDataLenInvalid();
12985f8e3435SManikandan Elumalai     }
12995f8e3435SManikandan Elumalai 
13005f8e3435SManikandan Elumalai     uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
13015f8e3435SManikandan Elumalai 
13025f8e3435SManikandan Elumalai     if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
13035f8e3435SManikandan Elumalai         return ipmi::responseUnspecifiedError();
13045f8e3435SManikandan Elumalai 
13055f8e3435SManikandan Elumalai     return ipmi::responseSuccess();
13065f8e3435SManikandan Elumalai }
13075f8e3435SManikandan Elumalai 
13085f8e3435SManikandan Elumalai #else
1309d5353caaSPotin Lai ipmi_ret_t ipmiOemSetSystemGuid(ipmi_netfn_t, ipmi_cmd_t,
1310d5353caaSPotin Lai                                 ipmi_request_t request, ipmi_response_t,
1311d5353caaSPotin Lai                                 ipmi_data_len_t data_len, ipmi_context_t)
1312f2246ce8SVijay Khemka {
1313f2246ce8SVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
1314f2246ce8SVijay Khemka 
1315f2246ce8SVijay Khemka     if (*data_len != GUID_SIZE) // 16bytes
1316f2246ce8SVijay Khemka     {
1317f2246ce8SVijay Khemka         *data_len = 0;
1318f2246ce8SVijay Khemka         return IPMI_CC_REQ_DATA_LEN_INVALID;
1319f2246ce8SVijay Khemka     }
1320f2246ce8SVijay Khemka 
1321f2246ce8SVijay Khemka     *data_len = 0;
1322f2246ce8SVijay Khemka 
1323f2246ce8SVijay Khemka     if (setGUID(OFFSET_SYS_GUID, req))
1324f2246ce8SVijay Khemka     {
1325f2246ce8SVijay Khemka         return IPMI_CC_UNSPECIFIED_ERROR;
1326f2246ce8SVijay Khemka     }
1327f2246ce8SVijay Khemka     return IPMI_CC_OK;
1328f2246ce8SVijay Khemka }
13295f8e3435SManikandan Elumalai #endif
1330f2246ce8SVijay Khemka 
1331e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1332e7d23d0eSVijay Khemka // Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
1333e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1334e39f9393SWilly Tu ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1335e39f9393SWilly Tu                                    ipmi_response_t, ipmi_data_len_t data_len,
1336e39f9393SWilly Tu                                    ipmi_context_t)
1337e7d23d0eSVijay Khemka {
13381d4a0697SVijay Khemka     /* Do nothing, return success */
1339e7d23d0eSVijay Khemka     *data_len = 0;
1340e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1341e7d23d0eSVijay Khemka }
1342e7d23d0eSVijay Khemka 
1343e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1344e7d23d0eSVijay Khemka // Set PPR (CMD_OEM_SET_PPR)
1345e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1346e39f9393SWilly Tu ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1347e39f9393SWilly Tu                          ipmi_response_t, ipmi_data_len_t data_len,
1348e39f9393SWilly Tu                          ipmi_context_t)
1349e7d23d0eSVijay Khemka {
1350e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
13511d4a0697SVijay Khemka     uint8_t pprCnt, pprAct, pprIndex;
13521d4a0697SVijay Khemka     uint8_t selParam = req[0];
13531d4a0697SVijay Khemka     uint8_t len = *data_len;
13541d4a0697SVijay Khemka     std::stringstream ss;
13551d4a0697SVijay Khemka     std::string str;
1356e7d23d0eSVijay Khemka 
1357e7d23d0eSVijay Khemka     *data_len = 0;
13581d4a0697SVijay Khemka 
13591d4a0697SVijay Khemka     switch (selParam)
13601d4a0697SVijay Khemka     {
13611d4a0697SVijay Khemka         case PPR_ACTION:
13621d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) ==
13631d4a0697SVijay Khemka                 oemData[KEY_PPR].end())
13641d4a0697SVijay Khemka                 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
13651d4a0697SVijay Khemka 
13661d4a0697SVijay Khemka             pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
13671d4a0697SVijay Khemka             if (pprCnt == 0)
13681d4a0697SVijay Khemka                 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
13691d4a0697SVijay Khemka 
13701d4a0697SVijay Khemka             pprAct = req[1];
13711d4a0697SVijay Khemka             /* Check if ppr is enabled or disabled */
13721d4a0697SVijay Khemka             if (!(pprAct & 0x80))
13731d4a0697SVijay Khemka                 pprAct = 0;
13741d4a0697SVijay Khemka 
13751d4a0697SVijay Khemka             oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct;
13761d4a0697SVijay Khemka             break;
13771d4a0697SVijay Khemka         case PPR_ROW_COUNT:
13781d4a0697SVijay Khemka             if (req[1] > 100)
13791d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
13801d4a0697SVijay Khemka 
13811d4a0697SVijay Khemka             oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1];
13821d4a0697SVijay Khemka             break;
13831d4a0697SVijay Khemka         case PPR_ROW_ADDR:
13841d4a0697SVijay Khemka             pprIndex = req[1];
13851d4a0697SVijay Khemka             if (pprIndex > 100)
13861d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
13871d4a0697SVijay Khemka 
13881d4a0697SVijay Khemka             if (len < PPR_ROW_ADDR_LEN + 1)
13891d4a0697SVijay Khemka             {
13901d4a0697SVijay Khemka                 phosphor::logging::log<phosphor::logging::level::ERR>(
13911d4a0697SVijay Khemka                     "Invalid PPR Row Address length received");
13921d4a0697SVijay Khemka                 return IPMI_CC_REQ_DATA_LEN_INVALID;
13931d4a0697SVijay Khemka             }
13941d4a0697SVijay Khemka 
13951d4a0697SVijay Khemka             ss << std::hex;
13961d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
13971d4a0697SVijay Khemka 
13981d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
13991d4a0697SVijay Khemka 
14001d4a0697SVijay Khemka             str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN);
14011d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str();
14021d4a0697SVijay Khemka             break;
14031d4a0697SVijay Khemka         case PPR_HISTORY_DATA:
14041d4a0697SVijay Khemka             pprIndex = req[1];
14051d4a0697SVijay Khemka             if (pprIndex > 100)
14061d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14071d4a0697SVijay Khemka 
14081d4a0697SVijay Khemka             if (len < PPR_HST_DATA_LEN + 1)
14091d4a0697SVijay Khemka             {
14101d4a0697SVijay Khemka                 phosphor::logging::log<phosphor::logging::level::ERR>(
14111d4a0697SVijay Khemka                     "Invalid PPR history data length received");
14121d4a0697SVijay Khemka                 return IPMI_CC_REQ_DATA_LEN_INVALID;
14131d4a0697SVijay Khemka             }
14141d4a0697SVijay Khemka 
14151d4a0697SVijay Khemka             ss << std::hex;
14161d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
14171d4a0697SVijay Khemka 
14181d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
14191d4a0697SVijay Khemka 
14201d4a0697SVijay Khemka             str = bytesToStr(&req[1], PPR_HST_DATA_LEN);
14211d4a0697SVijay Khemka             oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str();
14221d4a0697SVijay Khemka             break;
14231d4a0697SVijay Khemka         default:
14241d4a0697SVijay Khemka             return IPMI_CC_PARM_OUT_OF_RANGE;
14251d4a0697SVijay Khemka             break;
14261d4a0697SVijay Khemka     }
14271d4a0697SVijay Khemka 
14281d4a0697SVijay Khemka     flushOemData();
14291d4a0697SVijay Khemka 
1430e7d23d0eSVijay Khemka     return IPMI_CC_OK;
1431e7d23d0eSVijay Khemka }
1432e7d23d0eSVijay Khemka 
1433e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1434e7d23d0eSVijay Khemka // Get PPR (CMD_OEM_GET_PPR)
1435e7d23d0eSVijay Khemka //----------------------------------------------------------------------
1436e39f9393SWilly Tu ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1437e39f9393SWilly Tu                          ipmi_response_t response, ipmi_data_len_t data_len,
1438e39f9393SWilly Tu                          ipmi_context_t)
1439e7d23d0eSVijay Khemka {
1440e7d23d0eSVijay Khemka     uint8_t* req = reinterpret_cast<uint8_t*>(request);
1441e7d23d0eSVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
14421d4a0697SVijay Khemka     uint8_t pprCnt, pprIndex;
14431d4a0697SVijay Khemka     uint8_t selParam = req[0];
14441d4a0697SVijay Khemka     std::stringstream ss;
14451d4a0697SVijay Khemka     std::string str;
1446e7d23d0eSVijay Khemka 
14471d4a0697SVijay Khemka     /* Any failure will return zero length data */
14481d4a0697SVijay Khemka     *data_len = 0;
14491d4a0697SVijay Khemka 
14501d4a0697SVijay Khemka     switch (selParam)
14511d4a0697SVijay Khemka     {
14521d4a0697SVijay Khemka         case PPR_ACTION:
14531d4a0697SVijay Khemka             res[0] = 0;
1454e7d23d0eSVijay Khemka             *data_len = 1;
1455e7d23d0eSVijay Khemka 
14561d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
14571d4a0697SVijay Khemka                 oemData[KEY_PPR].end())
14581d4a0697SVijay Khemka             {
14591d4a0697SVijay Khemka                 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
14601d4a0697SVijay Khemka                 if (pprCnt != 0)
14611d4a0697SVijay Khemka                 {
14621d4a0697SVijay Khemka                     if (oemData[KEY_PPR].find(KEY_PPR_ACTION) !=
14631d4a0697SVijay Khemka                         oemData[KEY_PPR].end())
14641d4a0697SVijay Khemka                     {
14651d4a0697SVijay Khemka                         res[0] = oemData[KEY_PPR][KEY_PPR_ACTION];
14661d4a0697SVijay Khemka                     }
14671d4a0697SVijay Khemka                 }
14681d4a0697SVijay Khemka             }
14691d4a0697SVijay Khemka             break;
14701d4a0697SVijay Khemka         case PPR_ROW_COUNT:
14711d4a0697SVijay Khemka             res[0] = 0;
14721d4a0697SVijay Khemka             *data_len = 1;
14731d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
14741d4a0697SVijay Khemka                 oemData[KEY_PPR].end())
14751d4a0697SVijay Khemka                 res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
14761d4a0697SVijay Khemka             break;
14771d4a0697SVijay Khemka         case PPR_ROW_ADDR:
14781d4a0697SVijay Khemka             pprIndex = req[1];
14791d4a0697SVijay Khemka             if (pprIndex > 100)
14801d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14811d4a0697SVijay Khemka 
14821d4a0697SVijay Khemka             ss << std::hex;
14831d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
14841d4a0697SVijay Khemka 
14851d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
14861d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14871d4a0697SVijay Khemka 
14881d4a0697SVijay Khemka             if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) ==
14891d4a0697SVijay Khemka                 oemData[KEY_PPR][ss.str()].end())
14901d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14911d4a0697SVijay Khemka 
14921d4a0697SVijay Khemka             str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR];
14931d4a0697SVijay Khemka             *data_len = strToBytes(str, res);
14941d4a0697SVijay Khemka             break;
14951d4a0697SVijay Khemka         case PPR_HISTORY_DATA:
14961d4a0697SVijay Khemka             pprIndex = req[1];
14971d4a0697SVijay Khemka             if (pprIndex > 100)
14981d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
14991d4a0697SVijay Khemka 
15001d4a0697SVijay Khemka             ss << std::hex;
15011d4a0697SVijay Khemka             ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
15021d4a0697SVijay Khemka 
15031d4a0697SVijay Khemka             if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
15041d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
15051d4a0697SVijay Khemka 
15061d4a0697SVijay Khemka             if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) ==
15071d4a0697SVijay Khemka                 oemData[KEY_PPR][ss.str()].end())
15081d4a0697SVijay Khemka                 return IPMI_CC_PARM_OUT_OF_RANGE;
15091d4a0697SVijay Khemka 
15101d4a0697SVijay Khemka             str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA];
15111d4a0697SVijay Khemka             *data_len = strToBytes(str, res);
15121d4a0697SVijay Khemka             break;
15131d4a0697SVijay Khemka         default:
15141d4a0697SVijay Khemka             return IPMI_CC_PARM_OUT_OF_RANGE;
15151d4a0697SVijay Khemka             break;
15161d4a0697SVijay Khemka     }
15171d4a0697SVijay Khemka 
15181d4a0697SVijay Khemka     return IPMI_CC_OK;
15191d4a0697SVijay Khemka }
15201d4a0697SVijay Khemka 
15211d4a0697SVijay Khemka /* FB OEM QC Commands */
15221d4a0697SVijay Khemka 
15231d4a0697SVijay Khemka //----------------------------------------------------------------------
15241d4a0697SVijay Khemka // Set Proc Info (CMD_OEM_Q_SET_PROC_INFO)
15251d4a0697SVijay Khemka //----------------------------------------------------------------------
15261d4a0697SVijay Khemka //"Request:
15271d4a0697SVijay Khemka // Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
15281d4a0697SVijay Khemka // Byte 4 – Processor Index, 0 base
15291d4a0697SVijay Khemka // Byte 5 – Parameter Selector
15301d4a0697SVijay Khemka // Byte 6..N – Configuration parameter data (see below for Parameters
15311d4a0697SVijay Khemka // of Processor Information)
15321d4a0697SVijay Khemka // Response:
15331d4a0697SVijay Khemka // Byte 1 – Completion code
15341d4a0697SVijay Khemka //
15351d4a0697SVijay Khemka // Parameter#1: (Processor Product Name)
15361d4a0697SVijay Khemka //
15371d4a0697SVijay Khemka // Byte 1..48 –Product name(ASCII code)
15381d4a0697SVijay Khemka // Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
15391d4a0697SVijay Khemka //
15401d4a0697SVijay Khemka // Param#2: Processor Basic Information
15411d4a0697SVijay Khemka // Byte 1 – Core Number
15421d4a0697SVijay Khemka // Byte 2 – Thread Number (LSB)
15431d4a0697SVijay Khemka // Byte 3 – Thread Number (MSB)
15441d4a0697SVijay Khemka // Byte 4 – Processor frequency in MHz (LSB)
15451d4a0697SVijay Khemka // Byte 5 – Processor frequency in MHz (MSB)
15461d4a0697SVijay Khemka // Byte 6..7 – Revision
15471d4a0697SVijay Khemka //
1548d532fecaSKarthikeyan Pasupathi 
1549d532fecaSKarthikeyan Pasupathi ipmi::RspType<> ipmiOemQSetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1550d532fecaSKarthikeyan Pasupathi                                     uint8_t, uint8_t procIndex,
1551d532fecaSKarthikeyan Pasupathi                                     uint8_t paramSel,
1552d532fecaSKarthikeyan Pasupathi                                     std::vector<uint8_t> request)
15531d4a0697SVijay Khemka {
15541d4a0697SVijay Khemka     uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
15551d4a0697SVijay Khemka     std::stringstream ss;
15561d4a0697SVijay Khemka     std::string str;
1557d532fecaSKarthikeyan Pasupathi     uint8_t len = request.size();
1558d532fecaSKarthikeyan Pasupathi     auto hostId = findHost(ctx->hostIdx);
1559d532fecaSKarthikeyan Pasupathi     if (!hostId)
1560d532fecaSKarthikeyan Pasupathi     {
1561d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
1562d532fecaSKarthikeyan Pasupathi             "Invalid Host Id received");
1563d532fecaSKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
1564d532fecaSKarthikeyan Pasupathi     }
1565d532fecaSKarthikeyan Pasupathi     std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
15661d4a0697SVijay Khemka     /* check for requested data params */
1567d532fecaSKarthikeyan Pasupathi     if (len < 5 || paramSel < 1 || paramSel >= numParam)
15681d4a0697SVijay Khemka     {
15691d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
15701d4a0697SVijay Khemka             "Invalid parameter received");
1571d532fecaSKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
15721d4a0697SVijay Khemka     }
15731d4a0697SVijay Khemka     ss << std::hex;
1574d532fecaSKarthikeyan Pasupathi     ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1575d532fecaSKarthikeyan Pasupathi     oemData[procInfo][ss.str()][KEY_PROC_INDEX] = procIndex;
1576d532fecaSKarthikeyan Pasupathi     str = bytesToStr(request.data(), len);
1577d532fecaSKarthikeyan Pasupathi     oemData[procInfo][ss.str()][cpuInfoKey[paramSel]] = str.c_str();
15781d4a0697SVijay Khemka     flushOemData();
1579d532fecaSKarthikeyan Pasupathi     return ipmi::responseSuccess();
15801d4a0697SVijay Khemka }
15811d4a0697SVijay Khemka 
15821d4a0697SVijay Khemka //----------------------------------------------------------------------
15831d4a0697SVijay Khemka // Get Proc Info (CMD_OEM_Q_GET_PROC_INFO)
15841d4a0697SVijay Khemka //----------------------------------------------------------------------
15851d4a0697SVijay Khemka // Request:
15861d4a0697SVijay Khemka // Byte 1:3 –  Manufacturer ID – XXYYZZ h, LSB first
15871d4a0697SVijay Khemka // Byte 4 – Processor Index, 0 base
15881d4a0697SVijay Khemka // Byte 5 – Parameter Selector
15891d4a0697SVijay Khemka // Response:
15901d4a0697SVijay Khemka // Byte 1 – Completion code
15911d4a0697SVijay Khemka // Byte 2..N – Configuration Parameter Data (see below for Parameters
15921d4a0697SVijay Khemka // of Processor Information)
15931d4a0697SVijay Khemka //
15941d4a0697SVijay Khemka // Parameter#1: (Processor Product Name)
15951d4a0697SVijay Khemka //
15961d4a0697SVijay Khemka // Byte 1..48 –Product name(ASCII code)
15971d4a0697SVijay Khemka // Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
15981d4a0697SVijay Khemka //
15991d4a0697SVijay Khemka // Param#2: Processor Basic Information
16001d4a0697SVijay Khemka // Byte 1 – Core Number
16011d4a0697SVijay Khemka // Byte 2 – Thread Number (LSB)
16021d4a0697SVijay Khemka // Byte 3 – Thread Number (MSB)
16031d4a0697SVijay Khemka // Byte 4 – Processor frequency in MHz (LSB)
16041d4a0697SVijay Khemka // Byte 5 – Processor frequency in MHz (MSB)
16051d4a0697SVijay Khemka // Byte 6..7 – Revision
16061d4a0697SVijay Khemka //
1607d532fecaSKarthikeyan Pasupathi 
1608d532fecaSKarthikeyan Pasupathi ipmi::RspType<std::vector<uint8_t>>
1609d532fecaSKarthikeyan Pasupathi     ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1610d532fecaSKarthikeyan Pasupathi                         uint8_t procIndex, uint8_t paramSel)
16111d4a0697SVijay Khemka {
16121d4a0697SVijay Khemka     uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
16131d4a0697SVijay Khemka     std::stringstream ss;
16141d4a0697SVijay Khemka     std::string str;
1615d532fecaSKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
1616d532fecaSKarthikeyan Pasupathi     auto hostId = findHost(ctx->hostIdx);
1617d532fecaSKarthikeyan Pasupathi     if (!hostId)
1618d532fecaSKarthikeyan Pasupathi     {
1619d532fecaSKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
1620d532fecaSKarthikeyan Pasupathi             "Invalid Host Id received");
1621d532fecaSKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
1622d532fecaSKarthikeyan Pasupathi     }
1623d532fecaSKarthikeyan Pasupathi     std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
1624d532fecaSKarthikeyan Pasupathi     if (paramSel < 1 || paramSel >= numParam)
16251d4a0697SVijay Khemka     {
16261d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
16271d4a0697SVijay Khemka             "Invalid parameter received");
1628d532fecaSKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
16291d4a0697SVijay Khemka     }
16301d4a0697SVijay Khemka     ss << std::hex;
1631d532fecaSKarthikeyan Pasupathi     ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1632d532fecaSKarthikeyan Pasupathi     if (oemData[procInfo].find(ss.str()) == oemData[procInfo].end())
1633d532fecaSKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
1634d532fecaSKarthikeyan Pasupathi     if (oemData[procInfo][ss.str()].find(cpuInfoKey[paramSel]) ==
1635d532fecaSKarthikeyan Pasupathi         oemData[procInfo][ss.str()].end())
1636d532fecaSKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
1637d532fecaSKarthikeyan Pasupathi     str = oemData[procInfo][ss.str()][cpuInfoKey[paramSel]];
1638d532fecaSKarthikeyan Pasupathi     int dataLen = strToBytes(str, res);
1639d532fecaSKarthikeyan Pasupathi     std::vector<uint8_t> response(&res[0], &res[dataLen]);
1640d532fecaSKarthikeyan Pasupathi     return ipmi::responseSuccess(response);
16411d4a0697SVijay Khemka }
16421d4a0697SVijay Khemka 
16431d4a0697SVijay Khemka //----------------------------------------------------------------------
16441d4a0697SVijay Khemka // Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO)
16451d4a0697SVijay Khemka //----------------------------------------------------------------------
16461d4a0697SVijay Khemka // Request:
16471d4a0697SVijay Khemka // Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
16481d4a0697SVijay Khemka // Byte 4 – DIMM Index, 0 base
16491d4a0697SVijay Khemka // Byte 5 – Parameter Selector
16501d4a0697SVijay Khemka // Byte 6..N – Configuration parameter data (see below for Parameters
16511d4a0697SVijay Khemka // of DIMM Information)
16521d4a0697SVijay Khemka // Response:
16531d4a0697SVijay Khemka // Byte 1 – Completion code
16541d4a0697SVijay Khemka //
16551d4a0697SVijay Khemka // Param#1 (DIMM Location):
16561d4a0697SVijay Khemka // Byte 1 – DIMM Present
16571d4a0697SVijay Khemka // Byte 1 – DIMM Present
16581d4a0697SVijay Khemka // 01h – Present
16591d4a0697SVijay Khemka // FFh – Not Present
16601d4a0697SVijay Khemka // Byte 2 – Node Number, 0 base
16611d4a0697SVijay Khemka // Byte 3 – Channel Number , 0 base
16621d4a0697SVijay Khemka // Byte 4 – DIMM Number , 0 base
16631d4a0697SVijay Khemka //
16641d4a0697SVijay Khemka // Param#2 (DIMM Type):
16651d4a0697SVijay Khemka // Byte 1 – DIMM Type
16661d4a0697SVijay Khemka // Bit [7:6]
16671d4a0697SVijay Khemka // For DDR3
16681d4a0697SVijay Khemka //  00 – Normal Voltage (1.5V)
16691d4a0697SVijay Khemka //  01 – Ultra Low Voltage (1.25V)
16701d4a0697SVijay Khemka //  10 – Low Voltage (1.35V)
16711d4a0697SVijay Khemka //  11 – Reserved
16721d4a0697SVijay Khemka // For DDR4
16731d4a0697SVijay Khemka //  00 – Reserved
16741d4a0697SVijay Khemka //  01 – Reserved
16751d4a0697SVijay Khemka //  10 – Reserved
16761d4a0697SVijay Khemka //  11 – Normal Voltage (1.2V)
16771d4a0697SVijay Khemka // Bit [5:0]
16781d4a0697SVijay Khemka //  0x00 – SDRAM
16791d4a0697SVijay Khemka //  0x01 – DDR-1 RAM
16801d4a0697SVijay Khemka //  0x02 – Rambus
16811d4a0697SVijay Khemka //  0x03 – DDR-2 RAM
16821d4a0697SVijay Khemka //  0x04 – FBDIMM
16831d4a0697SVijay Khemka //  0x05 – DDR-3 RAM
16841d4a0697SVijay Khemka //  0x06 – DDR-4 RAM
16851d4a0697SVijay Khemka //
16861d4a0697SVijay Khemka // Param#3 (DIMM Speed):
16871d4a0697SVijay Khemka // Byte 1..2 – DIMM speed in MHz, LSB
16881d4a0697SVijay Khemka // Byte 3..6 – DIMM size in Mbytes, LSB
16891d4a0697SVijay Khemka //
16901d4a0697SVijay Khemka // Param#4 (Module Part Number):
16911d4a0697SVijay Khemka // Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
16921d4a0697SVijay Khemka //
16931d4a0697SVijay Khemka // Param#5 (Module Serial Number):
16941d4a0697SVijay Khemka // Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
16951d4a0697SVijay Khemka //
16961d4a0697SVijay Khemka // Param#6 (Module Manufacturer ID):
16971d4a0697SVijay Khemka // Byte 1 - Module Manufacturer ID, LSB
16981d4a0697SVijay Khemka // Byte 2 - Module Manufacturer ID, MSB
16991d4a0697SVijay Khemka //
170010ff3d86SKarthikeyan Pasupathi ipmi::RspType<> ipmiOemQSetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
170110ff3d86SKarthikeyan Pasupathi                                     uint8_t, uint8_t dimmIndex,
170210ff3d86SKarthikeyan Pasupathi                                     uint8_t paramSel,
170310ff3d86SKarthikeyan Pasupathi                                     std::vector<uint8_t> request)
17041d4a0697SVijay Khemka {
17051d4a0697SVijay Khemka     uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
17061d4a0697SVijay Khemka     std::stringstream ss;
17071d4a0697SVijay Khemka     std::string str;
170810ff3d86SKarthikeyan Pasupathi     uint8_t len = request.size();
170910ff3d86SKarthikeyan Pasupathi     std::string dimmType;
171010ff3d86SKarthikeyan Pasupathi     readDimmType(dimmType, dimmIndex);
17116d9e9a75SPatrick Williams     auto hostId = findHost(ctx->hostIdx);
171210ff3d86SKarthikeyan Pasupathi     if (!hostId)
171310ff3d86SKarthikeyan Pasupathi     {
171410ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
171510ff3d86SKarthikeyan Pasupathi             "Invalid Host Id received");
171610ff3d86SKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
171710ff3d86SKarthikeyan Pasupathi     }
17181d4a0697SVijay Khemka 
171910ff3d86SKarthikeyan Pasupathi     std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
17201d4a0697SVijay Khemka 
172110ff3d86SKarthikeyan Pasupathi     if (len < 3 || paramSel < 1 || paramSel >= numParam)
17221d4a0697SVijay Khemka     {
17231d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
17241d4a0697SVijay Khemka             "Invalid parameter received");
172510ff3d86SKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
17261d4a0697SVijay Khemka     }
17271d4a0697SVijay Khemka 
17281d4a0697SVijay Khemka     ss << std::hex;
172910ff3d86SKarthikeyan Pasupathi     ss << (int)dimmIndex;
173010ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][KEY_DIMM_INDEX] = dimmIndex;
173110ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
173210ff3d86SKarthikeyan Pasupathi     str = bytesToStr(request.data(), len);
173310ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]] = str.c_str();
17341d4a0697SVijay Khemka     flushOemData();
173510ff3d86SKarthikeyan Pasupathi     return ipmi::responseSuccess();
17361d4a0697SVijay Khemka }
17371d4a0697SVijay Khemka 
17381d4a0697SVijay Khemka // Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO)
17391d4a0697SVijay Khemka //----------------------------------------------------------------------
17401d4a0697SVijay Khemka // Request:
17411d4a0697SVijay Khemka // Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
17421d4a0697SVijay Khemka // Byte 4 – DIMM Index, 0 base
17431d4a0697SVijay Khemka // Byte 5 – Parameter Selector
17441d4a0697SVijay Khemka // Byte 6..N – Configuration parameter data (see below for Parameters
17451d4a0697SVijay Khemka // of DIMM Information)
17461d4a0697SVijay Khemka // Response:
17471d4a0697SVijay Khemka // Byte 1 – Completion code
17481d4a0697SVijay Khemka // Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters
17491d4a0697SVijay Khemka // of DIMM Information)
17501d4a0697SVijay Khemka //
17511d4a0697SVijay Khemka // Param#1 (DIMM Location):
17521d4a0697SVijay Khemka // Byte 1 – DIMM Present
17531d4a0697SVijay Khemka // Byte 1 – DIMM Present
17541d4a0697SVijay Khemka // 01h – Present
17551d4a0697SVijay Khemka // FFh – Not Present
17561d4a0697SVijay Khemka // Byte 2 – Node Number, 0 base
17571d4a0697SVijay Khemka // Byte 3 – Channel Number , 0 base
17581d4a0697SVijay Khemka // Byte 4 – DIMM Number , 0 base
17591d4a0697SVijay Khemka //
17601d4a0697SVijay Khemka // Param#2 (DIMM Type):
17611d4a0697SVijay Khemka // Byte 1 – DIMM Type
17621d4a0697SVijay Khemka // Bit [7:6]
17631d4a0697SVijay Khemka // For DDR3
17641d4a0697SVijay Khemka //  00 – Normal Voltage (1.5V)
17651d4a0697SVijay Khemka //  01 – Ultra Low Voltage (1.25V)
17661d4a0697SVijay Khemka //  10 – Low Voltage (1.35V)
17671d4a0697SVijay Khemka //  11 – Reserved
17681d4a0697SVijay Khemka // For DDR4
17691d4a0697SVijay Khemka //  00 – Reserved
17701d4a0697SVijay Khemka //  01 – Reserved
17711d4a0697SVijay Khemka //  10 – Reserved
17721d4a0697SVijay Khemka //  11 – Normal Voltage (1.2V)
17731d4a0697SVijay Khemka // Bit [5:0]
17741d4a0697SVijay Khemka //  0x00 – SDRAM
17751d4a0697SVijay Khemka //  0x01 – DDR-1 RAM
17761d4a0697SVijay Khemka //  0x02 – Rambus
17771d4a0697SVijay Khemka //  0x03 – DDR-2 RAM
17781d4a0697SVijay Khemka //  0x04 – FBDIMM
17791d4a0697SVijay Khemka //  0x05 – DDR-3 RAM
17801d4a0697SVijay Khemka //  0x06 – DDR-4 RAM
17811d4a0697SVijay Khemka //
17821d4a0697SVijay Khemka // Param#3 (DIMM Speed):
17831d4a0697SVijay Khemka // Byte 1..2 – DIMM speed in MHz, LSB
17841d4a0697SVijay Khemka // Byte 3..6 – DIMM size in Mbytes, LSB
17851d4a0697SVijay Khemka //
17861d4a0697SVijay Khemka // Param#4 (Module Part Number):
17871d4a0697SVijay Khemka // Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
17881d4a0697SVijay Khemka //
17891d4a0697SVijay Khemka // Param#5 (Module Serial Number):
17901d4a0697SVijay Khemka // Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
17911d4a0697SVijay Khemka //
17921d4a0697SVijay Khemka // Param#6 (Module Manufacturer ID):
17931d4a0697SVijay Khemka // Byte 1 - Module Manufacturer ID, LSB
17941d4a0697SVijay Khemka // Byte 2 - Module Manufacturer ID, MSB
17951d4a0697SVijay Khemka //
179610ff3d86SKarthikeyan Pasupathi ipmi::RspType<std::vector<uint8_t>>
179710ff3d86SKarthikeyan Pasupathi     ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
179810ff3d86SKarthikeyan Pasupathi                         uint8_t dimmIndex, uint8_t paramSel)
17991d4a0697SVijay Khemka {
18001d4a0697SVijay Khemka     uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
180110ff3d86SKarthikeyan Pasupathi     uint8_t res[MAX_BUF];
18021d4a0697SVijay Khemka     std::stringstream ss;
18031d4a0697SVijay Khemka     std::string str;
180410ff3d86SKarthikeyan Pasupathi     std::string dimmType;
180510ff3d86SKarthikeyan Pasupathi     readDimmType(dimmType, dimmIndex);
18066d9e9a75SPatrick Williams     auto hostId = findHost(ctx->hostIdx);
180710ff3d86SKarthikeyan Pasupathi     if (!hostId)
180810ff3d86SKarthikeyan Pasupathi     {
180910ff3d86SKarthikeyan Pasupathi         phosphor::logging::log<phosphor::logging::level::ERR>(
181010ff3d86SKarthikeyan Pasupathi             "Invalid Host Id received");
181110ff3d86SKarthikeyan Pasupathi         return ipmi::responseInvalidCommand();
181210ff3d86SKarthikeyan Pasupathi     }
181310ff3d86SKarthikeyan Pasupathi     std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
18141d4a0697SVijay Khemka 
181510ff3d86SKarthikeyan Pasupathi     if (paramSel < 1 || paramSel >= numParam)
18161d4a0697SVijay Khemka     {
18171d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
18181d4a0697SVijay Khemka             "Invalid parameter received");
181910ff3d86SKarthikeyan Pasupathi         return ipmi::responseParmOutOfRange();
18201d4a0697SVijay Khemka     }
18211d4a0697SVijay Khemka     ss << std::hex;
182210ff3d86SKarthikeyan Pasupathi     ss << (int)dimmIndex;
182310ff3d86SKarthikeyan Pasupathi     oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
182410ff3d86SKarthikeyan Pasupathi     if (oemData[dimmInfo].find(ss.str()) == oemData[dimmInfo].end())
182510ff3d86SKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
182610ff3d86SKarthikeyan Pasupathi     if (oemData[dimmInfo][ss.str()].find(dimmInfoKey[paramSel]) ==
182710ff3d86SKarthikeyan Pasupathi         oemData[dimmInfo][ss.str()].end())
182810ff3d86SKarthikeyan Pasupathi         return ipmi::responseCommandNotAvailable();
182910ff3d86SKarthikeyan Pasupathi     str = oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]];
183010ff3d86SKarthikeyan Pasupathi     int data_length = strToBytes(str, res);
183110ff3d86SKarthikeyan Pasupathi     std::vector<uint8_t> response(&res[0], &res[data_length]);
183210ff3d86SKarthikeyan Pasupathi     return ipmi::responseSuccess(response);
18331d4a0697SVijay Khemka }
18341d4a0697SVijay Khemka 
18351d4a0697SVijay Khemka //----------------------------------------------------------------------
18361d4a0697SVijay Khemka // Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO)
18371d4a0697SVijay Khemka //----------------------------------------------------------------------
18381d4a0697SVijay Khemka // BIOS issue this command to provide HDD information to BMC.
18391d4a0697SVijay Khemka //
18401d4a0697SVijay Khemka // BIOS just can get information by standard ATA / SMART command for
18411d4a0697SVijay Khemka // OB SATA controller.
18421d4a0697SVijay Khemka // BIOS can get
18431d4a0697SVijay Khemka // 1.     Serial Number
18441d4a0697SVijay Khemka // 2.     Model Name
18451d4a0697SVijay Khemka // 3.     HDD FW Version
18461d4a0697SVijay Khemka // 4.     HDD Capacity
18471d4a0697SVijay Khemka // 5.     HDD WWN
18481d4a0697SVijay Khemka //
18491d4a0697SVijay Khemka //  Use Get HDD info Param #5 to know the MAX HDD info index.
18501d4a0697SVijay Khemka //
18511d4a0697SVijay Khemka //  Request:
18521d4a0697SVijay Khemka //  Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
18531d4a0697SVijay Khemka //  Byte 4 –
18541d4a0697SVijay Khemka //  [7:4] Reserved
18551d4a0697SVijay Khemka //  [3:0] HDD Controller Type
18561d4a0697SVijay Khemka //     0x00 – BIOS
18571d4a0697SVijay Khemka //     0x01 – Expander
18581d4a0697SVijay Khemka //     0x02 – LSI
18591d4a0697SVijay Khemka //  Byte 5 – HDD Info Index, 0 base
18601d4a0697SVijay Khemka //  Byte 6 – Parameter Selector
18611d4a0697SVijay Khemka //  Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD
18621d4a0697SVijay Khemka //  Information)
18631d4a0697SVijay Khemka //
18641d4a0697SVijay Khemka //  Response:
18651d4a0697SVijay Khemka //  Byte 1 – Completion Code
18661d4a0697SVijay Khemka //
18671d4a0697SVijay Khemka //  Param#0 (HDD Location):
18681d4a0697SVijay Khemka //  Byte 1 – Controller
18691d4a0697SVijay Khemka //    [7:3] Device Number
18701d4a0697SVijay Khemka //    [2:0] Function Number
18711d4a0697SVijay Khemka //  For Intel C610 series (Wellsburg)
18721d4a0697SVijay Khemka //    D31:F2 (0xFA) – SATA control 1
18731d4a0697SVijay Khemka //    D31:F5 (0xFD) – SATA control 2
18741d4a0697SVijay Khemka //    D17:F4 (0x8C) – sSata control
18751d4a0697SVijay Khemka //  Byte 2 – Port Number
18761d4a0697SVijay Khemka //  Byte 3 – Location (0xFF: No HDD Present)
18771d4a0697SVijay Khemka //  BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param
18781d4a0697SVijay Khemka //  #1~4, #6,  #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if
18791d4a0697SVijay Khemka //  the HDD present. BMC or other people who know the HDD location has
18801d4a0697SVijay Khemka //  responsibility for update Location info
18811d4a0697SVijay Khemka //
18821d4a0697SVijay Khemka //  Param#1 (Serial Number):
18831d4a0697SVijay Khemka //  Bytes 1..33: HDD Serial Number
18841d4a0697SVijay Khemka //
18851d4a0697SVijay Khemka //  Param#2 (Model Name):
18861d4a0697SVijay Khemka //  Byte 1..33 – HDD Model Name
18871d4a0697SVijay Khemka //
18881d4a0697SVijay Khemka //  Param#3 (HDD FW Version):
18891d4a0697SVijay Khemka //  Byte 1..17 –HDD FW version
18901d4a0697SVijay Khemka //
18911d4a0697SVijay Khemka //  Param#4 (Capacity):
18921d4a0697SVijay Khemka //  Byte 1..4 –HDD Block Size, LSB
18931d4a0697SVijay Khemka //  Byte 5..12 - HDD Block Number, LSB
18941d4a0697SVijay Khemka //  HDD Capacity = HDD Block size * HDD BLock number  (Unit Byte)
18951d4a0697SVijay Khemka //
18961d4a0697SVijay Khemka //  Param#5 (Max HDD Quantity):
18971d4a0697SVijay Khemka //  Byte 1 - Max HDD Quantity
18981d4a0697SVijay Khemka //  Max supported port numbers in this PCH
18991d4a0697SVijay Khemka //
19001d4a0697SVijay Khemka //  Param#6 (HDD Type)
19011d4a0697SVijay Khemka //  Byte 1 – HDD Type
19021d4a0697SVijay Khemka //  0h – Reserved
19031d4a0697SVijay Khemka //  1h – SAS
19041d4a0697SVijay Khemka //  2h – SATA
19051d4a0697SVijay Khemka //  3h – PCIE SSD (NVME)
19061d4a0697SVijay Khemka //
19071d4a0697SVijay Khemka //  Param#7 (HDD WWN)
19081d4a0697SVijay Khemka //  Data 1...8: HDD World Wide Name, LSB
19091d4a0697SVijay Khemka //
1910e39f9393SWilly Tu ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
1911e39f9393SWilly Tu                                 ipmi_request_t request, ipmi_response_t,
1912e39f9393SWilly Tu                                 ipmi_data_len_t data_len, ipmi_context_t)
19131d4a0697SVijay Khemka {
19141d4a0697SVijay Khemka     qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
19151d4a0697SVijay Khemka     uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
19161d4a0697SVijay Khemka     uint8_t ctrlType = req->hddCtrlType & 0x0f;
19171d4a0697SVijay Khemka     std::stringstream ss;
19181d4a0697SVijay Khemka     std::string str;
19191d4a0697SVijay Khemka     uint8_t len = *data_len;
19201d4a0697SVijay Khemka 
19211d4a0697SVijay Khemka     *data_len = 0;
19221d4a0697SVijay Khemka 
19231d4a0697SVijay Khemka     /* check for requested data params */
19241d4a0697SVijay Khemka     if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam ||
19251d4a0697SVijay Khemka         ctrlType > 2)
19261d4a0697SVijay Khemka     {
19271d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
19281d4a0697SVijay Khemka             "Invalid parameter received");
19291d4a0697SVijay Khemka         return IPMI_CC_PARM_OUT_OF_RANGE;
19301d4a0697SVijay Khemka     }
19311d4a0697SVijay Khemka 
19321d4a0697SVijay Khemka     len = len - 6; // Get Actual data length
19331d4a0697SVijay Khemka 
19341d4a0697SVijay Khemka     ss << std::hex;
19351d4a0697SVijay Khemka     ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
19361d4a0697SVijay Khemka     oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType;
19371d4a0697SVijay Khemka     oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] =
19381d4a0697SVijay Khemka         req->hddIndex;
19391d4a0697SVijay Khemka 
19401d4a0697SVijay Khemka     str = bytesToStr(req->data, len);
19411d4a0697SVijay Khemka     oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
19421d4a0697SVijay Khemka            [driveInfoKey[req->paramSel]] = str.c_str();
19431d4a0697SVijay Khemka     flushOemData();
19441d4a0697SVijay Khemka 
19451d4a0697SVijay Khemka     return IPMI_CC_OK;
19461d4a0697SVijay Khemka }
19471d4a0697SVijay Khemka 
19481d4a0697SVijay Khemka //----------------------------------------------------------------------
19491d4a0697SVijay Khemka // Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO)
19501d4a0697SVijay Khemka //----------------------------------------------------------------------
19511d4a0697SVijay Khemka // BMC needs to check HDD presented or not first. If NOT presented, return
19521d4a0697SVijay Khemka // completion code 0xD5.
19531d4a0697SVijay Khemka //
19541d4a0697SVijay Khemka // Request:
19551d4a0697SVijay Khemka // Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
19561d4a0697SVijay Khemka // Byte 4 –
19571d4a0697SVijay Khemka //[7:4] Reserved
19581d4a0697SVijay Khemka //[3:0] HDD Controller Type
19591d4a0697SVijay Khemka //   0x00 – BIOS
19601d4a0697SVijay Khemka //   0x01 – Expander
19611d4a0697SVijay Khemka //   0x02 – LSI
19621d4a0697SVijay Khemka // Byte 5 – HDD Index, 0 base
19631d4a0697SVijay Khemka // Byte 6 – Parameter Selector (See Above Set HDD Information)
19641d4a0697SVijay Khemka // Response:
19651d4a0697SVijay Khemka // Byte 1 – Completion Code
19661d4a0697SVijay Khemka //   0xD5 – Not support in current status (HDD Not Present)
19671d4a0697SVijay Khemka // Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD
19681d4a0697SVijay Khemka // Information)
19691d4a0697SVijay Khemka //
1970e39f9393SWilly Tu ipmi_ret_t ipmiOemQGetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
19711d4a0697SVijay Khemka                                 ipmi_request_t request,
19721d4a0697SVijay Khemka                                 ipmi_response_t response,
1973e39f9393SWilly Tu                                 ipmi_data_len_t data_len, ipmi_context_t)
19741d4a0697SVijay Khemka {
19751d4a0697SVijay Khemka     qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
19761d4a0697SVijay Khemka     uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
19771d4a0697SVijay Khemka     uint8_t* res = reinterpret_cast<uint8_t*>(response);
19781d4a0697SVijay Khemka     uint8_t ctrlType = req->hddCtrlType & 0x0f;
19791d4a0697SVijay Khemka     std::stringstream ss;
19801d4a0697SVijay Khemka     std::string str;
19811d4a0697SVijay Khemka 
19821d4a0697SVijay Khemka     *data_len = 0;
19831d4a0697SVijay Khemka 
19841d4a0697SVijay Khemka     /* check for requested data params */
19851d4a0697SVijay Khemka     if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2)
19861d4a0697SVijay Khemka     {
19871d4a0697SVijay Khemka         phosphor::logging::log<phosphor::logging::level::ERR>(
19881d4a0697SVijay Khemka             "Invalid parameter received");
19891d4a0697SVijay Khemka         return IPMI_CC_PARM_OUT_OF_RANGE;
19901d4a0697SVijay Khemka     }
19911d4a0697SVijay Khemka 
19921d4a0697SVijay Khemka     if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) ==
19931d4a0697SVijay Khemka         oemData[KEY_Q_DRIVE_INFO].end())
19941d4a0697SVijay Khemka         return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
19951d4a0697SVijay Khemka 
19961d4a0697SVijay Khemka     ss << std::hex;
19971d4a0697SVijay Khemka     ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
19981d4a0697SVijay Khemka 
19991d4a0697SVijay Khemka     if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) ==
20001d4a0697SVijay Khemka         oemData[KEY_Q_DRIVE_INFO].end())
20011d4a0697SVijay Khemka         return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
20021d4a0697SVijay Khemka 
20031d4a0697SVijay Khemka     if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find(
20041d4a0697SVijay Khemka             dimmInfoKey[req->paramSel]) ==
20051d4a0697SVijay Khemka         oemData[KEY_Q_DRIVE_INFO][ss.str()].end())
20061d4a0697SVijay Khemka         return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
20071d4a0697SVijay Khemka 
20081d4a0697SVijay Khemka     str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
20091d4a0697SVijay Khemka                  [dimmInfoKey[req->paramSel]];
20101d4a0697SVijay Khemka     *data_len = strToBytes(str, res);
20111d4a0697SVijay Khemka 
2012e7d23d0eSVijay Khemka     return IPMI_CC_OK;
2013e7d23d0eSVijay Khemka }
2014e7d23d0eSVijay Khemka 
2015e4d6fe74SLogananth Sundararaj /* Helper function for sending DCMI commands to ME/BIC and
2016e4d6fe74SLogananth Sundararaj  * getting response back
2017e4d6fe74SLogananth Sundararaj  */
2018e4d6fe74SLogananth Sundararaj ipmi::RspType<std::vector<uint8_t>>
2019e4d6fe74SLogananth Sundararaj     sendDCMICmd([[maybe_unused]] ipmi::Context::ptr ctx,
2020e4d6fe74SLogananth Sundararaj                 [[maybe_unused]] uint8_t cmd, std::vector<uint8_t>& cmdData)
2021dd14c0f7SVijay Khemka {
2022dd14c0f7SVijay Khemka     std::vector<uint8_t> respData;
2023dd14c0f7SVijay Khemka 
2024e4d6fe74SLogananth Sundararaj #if BIC_ENABLED
2025e4d6fe74SLogananth Sundararaj 
2026e4d6fe74SLogananth Sundararaj     uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
2027e4d6fe74SLogananth Sundararaj 
2028e4d6fe74SLogananth Sundararaj     if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, cmdData, respData))
2029e4d6fe74SLogananth Sundararaj     {
2030e4d6fe74SLogananth Sundararaj         return ipmi::responseUnspecifiedError();
2031e4d6fe74SLogananth Sundararaj     }
2032e4d6fe74SLogananth Sundararaj 
2033e4d6fe74SLogananth Sundararaj #else
2034e4d6fe74SLogananth Sundararaj 
2035dd14c0f7SVijay Khemka     /* Add group id as first byte to request for ME command */
2036dd14c0f7SVijay Khemka     cmdData.insert(cmdData.begin(), groupDCMI);
2037dd14c0f7SVijay Khemka 
2038dd14c0f7SVijay Khemka     if (sendMeCmd(ipmi::netFnGroup, cmd, cmdData, respData))
2039e4d6fe74SLogananth Sundararaj     {
2040dd14c0f7SVijay Khemka         return ipmi::responseUnspecifiedError();
2041e4d6fe74SLogananth Sundararaj     }
2042dd14c0f7SVijay Khemka 
2043dd14c0f7SVijay Khemka     /* Remove group id as first byte as it will be added by IPMID */
2044dd14c0f7SVijay Khemka     respData.erase(respData.begin());
2045dd14c0f7SVijay Khemka 
2046e4d6fe74SLogananth Sundararaj #endif
2047e4d6fe74SLogananth Sundararaj 
2048dd14c0f7SVijay Khemka     return ipmi::responseSuccess(std::move(respData));
2049dd14c0f7SVijay Khemka }
2050dd14c0f7SVijay Khemka 
2051dd14c0f7SVijay Khemka /* DCMI Command handellers. */
2052dd14c0f7SVijay Khemka 
2053dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2054e4d6fe74SLogananth Sundararaj     ipmiOemDCMIGetPowerReading(ipmi::Context::ptr ctx,
2055e4d6fe74SLogananth Sundararaj                                std::vector<uint8_t> reqData)
2056dd14c0f7SVijay Khemka {
2057e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerReading, reqData);
2058dd14c0f7SVijay Khemka }
2059dd14c0f7SVijay Khemka 
2060dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2061e4d6fe74SLogananth Sundararaj     ipmiOemDCMIGetPowerLimit(ipmi::Context::ptr ctx,
2062e4d6fe74SLogananth Sundararaj                              std::vector<uint8_t> reqData)
2063dd14c0f7SVijay Khemka {
2064e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerLimit, reqData);
2065dd14c0f7SVijay Khemka }
2066dd14c0f7SVijay Khemka 
2067dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2068e4d6fe74SLogananth Sundararaj     ipmiOemDCMISetPowerLimit(ipmi::Context::ptr ctx,
2069e4d6fe74SLogananth Sundararaj                              std::vector<uint8_t> reqData)
2070dd14c0f7SVijay Khemka {
2071e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdSetPowerLimit, reqData);
2072dd14c0f7SVijay Khemka }
2073dd14c0f7SVijay Khemka 
2074dd14c0f7SVijay Khemka ipmi::RspType<std::vector<uint8_t>>
2075e4d6fe74SLogananth Sundararaj     ipmiOemDCMIApplyPowerLimit(ipmi::Context::ptr ctx,
2076e4d6fe74SLogananth Sundararaj                                std::vector<uint8_t> reqData)
2077dd14c0f7SVijay Khemka {
2078e4d6fe74SLogananth Sundararaj     return sendDCMICmd(ctx, ipmi::dcmi::cmdActDeactivatePwrLimit, reqData);
2079dd14c0f7SVijay Khemka }
2080dd14c0f7SVijay Khemka 
2081e7d23d0eSVijay Khemka static void registerOEMFunctions(void)
2082e7d23d0eSVijay Khemka {
20831d4a0697SVijay Khemka     /* Get OEM data from json file */
20841d4a0697SVijay Khemka     std::ifstream file(JSON_OEM_DATA_FILE);
20851d4a0697SVijay Khemka     if (file)
2086feaa9811SVijay Khemka     {
20871d4a0697SVijay Khemka         file >> oemData;
2088feaa9811SVijay Khemka         file.close();
2089feaa9811SVijay Khemka     }
20901d4a0697SVijay Khemka 
2091e7d23d0eSVijay Khemka     phosphor::logging::log<phosphor::logging::level::INFO>(
2092e7d23d0eSVijay Khemka         "Registering OEM commands");
20937c0aea49SVijay Khemka 
2094e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO,
2095e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetFrameInfo,
2096e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug frame info
2097e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ,
2098e7d23d0eSVijay Khemka                          CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL,
2099e7d23d0eSVijay Khemka                          ipmiOemDbgGetUpdFrames,
2100e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug updated frames
2101e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC,
2102e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetPostDesc,
2103e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug post description
2104e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC,
2105e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetGpioDesc,
2106e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug gpio description
2107e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA,
2108e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetFrameData,
2109e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug frame data
2110e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL,
2111e7d23d0eSVijay Khemka                          NULL, ipmiOemDbgGetCtrlPanel,
2112e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // get debug control panel
2113e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL,
2114e7d23d0eSVijay Khemka                          ipmiOemSetDimmInfo,
2115e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set Dimm Info
21161d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
21171d4a0697SVijay Khemka                          ipmiOemGetBoardID,
21181d4a0697SVijay Khemka                          PRIVILEGE_USER); // Get Board ID
21194ae63e71SBonnie Lo     ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemOne,
21204ae63e71SBonnie Lo                           CMD_OEM_GET_80PORT_RECORD, ipmi::Privilege::User,
21214ae63e71SBonnie Lo                           ipmiOemGet80PortRecord); // Get 80 Port Record
2122e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL,
2123e7d23d0eSVijay Khemka                          ipmiOemSetMachineCfgInfo,
2124e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set Machine Config Info
2125e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL,
2126e7d23d0eSVijay Khemka                          ipmiOemSetPostStart,
2127e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set POST start
2128e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL,
2129e7d23d0eSVijay Khemka                          ipmiOemSetPostEnd,
2130e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set POST End
21311d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
21321d4a0697SVijay Khemka                          ipmiOemSetPPINInfo,
21331d4a0697SVijay Khemka                          PRIVILEGE_USER); // Set PPIN Info
21345f8e3435SManikandan Elumalai #if BIC_ENABLED
21355f8e3435SManikandan Elumalai 
21365f8e3435SManikandan Elumalai     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
21375f8e3435SManikandan Elumalai                           ipmi::cmdSetSystemGuid, ipmi::Privilege::User,
21385f8e3435SManikandan Elumalai                           ipmiOemSetSystemGuid);
21395f8e3435SManikandan Elumalai #else
21405f8e3435SManikandan Elumalai 
2141f2246ce8SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL,
2142f2246ce8SVijay Khemka                          ipmiOemSetSystemGuid,
2143f2246ce8SVijay Khemka                          PRIVILEGE_USER); // Set System GUID
21445f8e3435SManikandan Elumalai #endif
21451d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
21461d4a0697SVijay Khemka                          ipmiOemSetAdrTrigger,
21471d4a0697SVijay Khemka                          PRIVILEGE_USER); // Set ADR Trigger
2148e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL,
2149e7d23d0eSVijay Khemka                          ipmiOemSetBiosFlashInfo,
2150e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set Bios Flash Info
2151e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr,
2152e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Set PPR
2153e7d23d0eSVijay Khemka     ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr,
2154e7d23d0eSVijay Khemka                          PRIVILEGE_USER); // Get PPR
21551d4a0697SVijay Khemka     /* FB OEM QC Commands */
2156d532fecaSKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2157d532fecaSKarthikeyan Pasupathi                           CMD_OEM_Q_SET_PROC_INFO, ipmi::Privilege::User,
2158d532fecaSKarthikeyan Pasupathi                           ipmiOemQSetProcInfo); // Set Proc Info
2159d532fecaSKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2160d532fecaSKarthikeyan Pasupathi                           CMD_OEM_Q_GET_PROC_INFO, ipmi::Privilege::User,
2161d532fecaSKarthikeyan Pasupathi                           ipmiOemQGetProcInfo); // Get Proc Info
216210ff3d86SKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
216310ff3d86SKarthikeyan Pasupathi                           ipmi::cmdSetQDimmInfo, ipmi::Privilege::User,
216410ff3d86SKarthikeyan Pasupathi                           ipmiOemQSetDimmInfo); // Set Dimm Info
216510ff3d86SKarthikeyan Pasupathi     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
216610ff3d86SKarthikeyan Pasupathi                           ipmi::cmdGetQDimmInfo, ipmi::Privilege::User,
216710ff3d86SKarthikeyan Pasupathi                           ipmiOemQGetDimmInfo); // Get Dimm Info
21681d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL,
21691d4a0697SVijay Khemka                          ipmiOemQSetDriveInfo,
21701d4a0697SVijay Khemka                          PRIVILEGE_USER); // Set Drive Info
21711d4a0697SVijay Khemka     ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL,
21721d4a0697SVijay Khemka                          ipmiOemQGetDriveInfo,
21731d4a0697SVijay Khemka                          PRIVILEGE_USER); // Get Drive Info
2174dd14c0f7SVijay Khemka 
2175dd14c0f7SVijay Khemka     /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */
2176dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2177dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdGetPowerReading,
2178dd14c0f7SVijay Khemka                                ipmi::Privilege::User,
2179dd14c0f7SVijay Khemka                                ipmiOemDCMIGetPowerReading); // Get Power Reading
2180dd14c0f7SVijay Khemka 
2181dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2182dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdGetPowerLimit,
2183dd14c0f7SVijay Khemka                                ipmi::Privilege::User,
2184dd14c0f7SVijay Khemka                                ipmiOemDCMIGetPowerLimit); // Get Power Limit
2185dd14c0f7SVijay Khemka 
2186dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2187dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdSetPowerLimit,
2188dd14c0f7SVijay Khemka                                ipmi::Privilege::Operator,
2189dd14c0f7SVijay Khemka                                ipmiOemDCMISetPowerLimit); // Set Power Limit
2190dd14c0f7SVijay Khemka 
2191dd14c0f7SVijay Khemka     ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2192dd14c0f7SVijay Khemka                                ipmi::dcmi::cmdActDeactivatePwrLimit,
2193dd14c0f7SVijay Khemka                                ipmi::Privilege::Operator,
2194dd14c0f7SVijay Khemka                                ipmiOemDCMIApplyPowerLimit); // Apply Power Limit
2195dd14c0f7SVijay Khemka 
2196f0cf6658SJayashree-D     /* FB OEM BOOT ORDER COMMANDS */
2197f0cf6658SJayashree-D     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2198f0cf6658SJayashree-D                           CMD_OEM_GET_BOOT_ORDER, ipmi::Privilege::User,
2199f0cf6658SJayashree-D                           ipmiOemGetBootOrder); // Get Boot Order
2200f0cf6658SJayashree-D 
2201f0cf6658SJayashree-D     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2202f0cf6658SJayashree-D                           CMD_OEM_SET_BOOT_ORDER, ipmi::Privilege::User,
2203f0cf6658SJayashree-D                           ipmiOemSetBootOrder); // Set Boot Order
2204f0cf6658SJayashree-D 
2205e7d23d0eSVijay Khemka     return;
2206e7d23d0eSVijay Khemka }
2207e7d23d0eSVijay Khemka 
2208e7d23d0eSVijay Khemka } // namespace ipmi
2209