blob: 118b715bb512e69d7743519725eb49b95341f26d [file] [log] [blame]
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001/*
2 * Copyright (c) 2018 Intel Corporation.
3 * Copyright (c) 2018-present Facebook.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "xyz/openbmc_project/Common/error.hpp"
Vijay Khemkae7d23d02019-03-08 13:13:40 -080019
Patrick Williams2405ae92023-05-10 07:50:09 -050020#include <commandutils.hpp>
21#include <ipmid/api-types.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070022#include <ipmid/api.hpp>
Vijay Khemka1b6fae32019-03-25 17:43:01 -070023#include <ipmid/utils.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070024#include <nlohmann/json.hpp>
25#include <oemcommands.hpp>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080026#include <phosphor-logging/log.hpp>
27#include <sdbusplus/bus.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050028#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
29#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
30#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053031
Vijay Khemka63c99be2020-05-27 19:14:35 -070032#include <array>
33#include <cstring>
34#include <fstream>
35#include <iomanip>
36#include <iostream>
Patrick Williams2405ae92023-05-10 07:50:09 -050037#include <regex>
Vijay Khemka63c99be2020-05-27 19:14:35 -070038#include <sstream>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080039#include <string>
40#include <vector>
41
42#define SIZE_IANA_ID 3
43
44namespace ipmi
45{
Vijay Khemkaa7231892019-10-11 11:35:05 -070046
47using namespace phosphor::logging;
48
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053049void getSelectorPosition(size_t& position);
Vijay Khemkae7d23d02019-03-08 13:13:40 -080050static void registerOEMFunctions() __attribute__((constructor));
Patrick Williamscd315e02022-07-22 19:26:52 -050051sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
Vijay Khemkae7d23d02019-03-08 13:13:40 -080052static constexpr size_t maxFRUStringLength = 0x3F;
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053053constexpr uint8_t cmdSetSystemGuid = 0xEF;
Vijay Khemkae7d23d02019-03-08 13:13:40 -080054
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +053055constexpr uint8_t cmdSetQDimmInfo = 0x12;
56constexpr uint8_t cmdGetQDimmInfo = 0x13;
57
Vijay Khemka63c99be2020-05-27 19:14:35 -070058int plat_udbg_get_post_desc(uint8_t, uint8_t*, uint8_t, uint8_t*, uint8_t*,
59 uint8_t*);
60int plat_udbg_get_gpio_desc(uint8_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*,
61 uint8_t*);
62ipmi_ret_t plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t*, uint8_t*,
63 uint8_t*);
64ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t*,
65 uint8_t*);
66int sendMeCmd(uint8_t, uint8_t, std::vector<uint8_t>&, std::vector<uint8_t>&);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -070067
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053068int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
69 std::vector<uint8_t>&);
70
Vijay Khemkafeaa9812019-08-27 15:08:08 -070071nlohmann::json oemData __attribute__((init_priority(101)));
Vijay Khemka1b6fae32019-03-25 17:43:01 -070072
Vijay Khemkaf2246ce2020-05-27 14:26:35 -070073static constexpr size_t GUID_SIZE = 16;
74// TODO Make offset and location runtime configurable to ensure we
75// can make each define their own locations.
76static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
77static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
78
Vijay Khemka1b6fae32019-03-25 17:43:01 -070079enum class LanParam : uint8_t
80{
81 INPROGRESS = 0,
82 AUTHSUPPORT = 1,
83 AUTHENABLES = 2,
84 IP = 3,
85 IPSRC = 4,
86 MAC = 5,
87 SUBNET = 6,
88 GATEWAY = 12,
89 VLAN = 20,
90 CIPHER_SUITE_COUNT = 22,
91 CIPHER_SUITE_ENTRIES = 23,
92 IPV6 = 59,
93};
94
Vijay Khemkaa7231892019-10-11 11:35:05 -070095namespace network
96{
97
98constexpr auto ROOT = "/xyz/openbmc_project/network";
99constexpr auto SERVICE = "xyz.openbmc_project.Network";
100constexpr auto IPV4_TYPE = "ipv4";
101constexpr auto IPV6_TYPE = "ipv6";
102constexpr auto IPV4_PREFIX = "169.254";
103constexpr auto IPV6_PREFIX = "fe80";
104constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
105constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
Potin Lai8d1a81e2022-12-20 11:13:45 +0800106constexpr auto IPV4_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
107constexpr auto IPV6_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
Vijay Khemkaa7231892019-10-11 11:35:05 -0700108
Vijay Khemka63c99be2020-05-27 19:14:35 -0700109bool isLinkLocalIP(const std::string& address)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700110{
111 return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
112}
113
Patrick Williamscd315e02022-07-22 19:26:52 -0500114DbusObjectInfo getIPObject(sdbusplus::bus_t& bus, const std::string& interface,
Vijay Khemka63c99be2020-05-27 19:14:35 -0700115 const std::string& serviceRoot,
Potin Lai8d1a81e2022-12-20 11:13:45 +0800116 const std::string& protocol,
117 const std::string& ethdev)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700118{
Potin Lai8d1a81e2022-12-20 11:13:45 +0800119 auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, ethdev);
Vijay Khemkaa7231892019-10-11 11:35:05 -0700120
121 if (objectTree.empty())
122 {
123 log<level::ERR>("No Object has implemented the IP interface",
124 entry("INTERFACE=%s", interface.c_str()));
125 }
126
127 DbusObjectInfo objectInfo;
128
Vijay Khemka63c99be2020-05-27 19:14:35 -0700129 for (auto& object : objectTree)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700130 {
Patrick Williams2405ae92023-05-10 07:50:09 -0500131 auto variant = ipmi::getDbusProperty(bus, object.second.begin()->first,
132 object.first, IP_INTERFACE,
133 "Type");
Potin Lai8d1a81e2022-12-20 11:13:45 +0800134 if (std::get<std::string>(variant) != protocol)
135 {
136 continue;
137 }
138
139 variant = ipmi::getDbusProperty(bus, object.second.begin()->first,
140 object.first, IP_INTERFACE, "Address");
Vijay Khemkaa7231892019-10-11 11:35:05 -0700141
142 objectInfo = std::make_pair(object.first, object.second.begin()->first);
143
144 // if LinkLocalIP found look for Non-LinkLocalIP
145 if (isLinkLocalIP(std::get<std::string>(variant)))
146 {
147 continue;
148 }
149 else
150 {
151 break;
152 }
153 }
154 return objectInfo;
155}
156
157} // namespace network
158
Jayashree-Df0cf6652020-11-30 11:03:30 +0530159namespace boot
160{
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530161using BootSource =
162 sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources;
163using BootMode =
164 sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes;
165using BootType =
166 sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types;
Jayashree-Df0cf6652020-11-30 11:03:30 +0530167
Jayashree-Df0cf6652020-11-30 11:03:30 +0530168using IpmiValue = uint8_t;
169
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530170std::map<IpmiValue, BootSource> sourceIpmiToDbus = {
171 {0x0f, BootSource::Default}, {0x00, BootSource::RemovableMedia},
172 {0x01, BootSource::Network}, {0x02, BootSource::Disk},
173 {0x03, BootSource::ExternalMedia}, {0x09, BootSource::Network}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530174
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800175std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x04, BootMode::Setup},
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530176 {0x00, BootMode::Regular}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530177
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530178std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy},
179 {0x01, BootType::EFI}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530180
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530181std::map<std::optional<BootSource>, IpmiValue> sourceDbusToIpmi = {
182 {BootSource::Default, 0x0f},
183 {BootSource::RemovableMedia, 0x00},
184 {BootSource::Network, 0x01},
185 {BootSource::Disk, 0x02},
186 {BootSource::ExternalMedia, 0x03}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530187
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530188std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = {
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800189 {BootMode::Setup, 0x04}, {BootMode::Regular, 0x00}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530190
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530191std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = {
192 {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530193
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800194static constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530195static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
196static constexpr auto bootSourceIntf =
197 "xyz.openbmc_project.Control.Boot.Source";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530198static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530199static constexpr auto bootSourceProp = "BootSource";
200static constexpr auto bootModeProp = "BootMode";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530201static constexpr auto bootTypeProp = "BootType";
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800202static constexpr auto bootEnableProp = "Enabled";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530203
Jayashree-Df0cf6652020-11-30 11:03:30 +0530204std::tuple<std::string, std::string> objPath(size_t id)
205{
206 std::string hostName = "host" + std::to_string(id);
Patrick Williams2405ae92023-05-10 07:50:09 -0500207 std::string bootObjPath = "/xyz/openbmc_project/control/" + hostName +
208 "/boot";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530209 return std::make_tuple(std::move(bootObjPath), std::move(hostName));
210}
211
212} // namespace boot
213
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700214//----------------------------------------------------------------------
215// Helper functions for storing oem data
216//----------------------------------------------------------------------
217
218void flushOemData()
219{
220 std::ofstream file(JSON_OEM_DATA_FILE);
221 file << oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -0700222 file.close();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700223 return;
224}
225
Vijay Khemka63c99be2020-05-27 19:14:35 -0700226std::string bytesToStr(uint8_t* byte, int len)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700227{
228 std::stringstream ss;
229 int i;
230
231 ss << std::hex;
232 for (i = 0; i < len; i++)
233 {
234 ss << std::setw(2) << std::setfill('0') << (int)byte[i];
235 }
236
237 return ss.str();
238}
239
Vijay Khemka63c99be2020-05-27 19:14:35 -0700240int strToBytes(std::string& str, uint8_t* data)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700241{
242 std::string sstr;
Willy Tue39f9392022-06-15 13:24:20 -0700243 size_t i;
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700244
245 for (i = 0; i < (str.length()) / 2; i++)
246 {
247 sstr = str.substr(i * 2, 2);
248 data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16);
249 }
250 return i;
251}
252
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530253int readDimmType(std::string& data, uint8_t param)
254{
255 nlohmann::json dimmObj;
256 /* Get dimm type names stored in json file */
257 std::ifstream file(JSON_DIMM_TYPE_FILE);
258 if (file)
259 {
260 file >> dimmObj;
261 file.close();
262 }
263 else
264 {
265 phosphor::logging::log<phosphor::logging::level::ERR>(
266 "DIMM type names file not found",
267 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
268 return -1;
269 }
270
271 std::string dimmKey = "dimm_type" + std::to_string(param);
272 auto obj = dimmObj[dimmKey]["short_name"];
273 data = obj;
274 return 0;
275}
276
Vijay Khemka63c99be2020-05-27 19:14:35 -0700277ipmi_ret_t getNetworkData(uint8_t lan_param, char* data)
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700278{
279 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Williamscd315e02022-07-22 19:26:52 -0500280 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700281
282 const std::string ethdevice = "eth0";
283
284 switch (static_cast<LanParam>(lan_param))
285 {
Vijay Khemkad1194022020-05-27 18:58:33 -0700286 case LanParam::IP:
287 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700288 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700289 auto ipObjectInfo = ipmi::network::getIPObject(
Potin Lai8d1a81e2022-12-20 11:13:45 +0800290 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
291 ipmi::network::IPV4_PROTOCOL, ethdevice);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700292
293 auto properties = ipmi::getAllDbusProperties(
294 bus, ipObjectInfo.second, ipObjectInfo.first,
295 ipmi::network::IP_INTERFACE);
296
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500297 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700298
299 std::strcpy(data, ipaddress.c_str());
300 }
301 break;
302
Vijay Khemkad1194022020-05-27 18:58:33 -0700303 case LanParam::IPV6:
304 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700305 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700306 auto ipObjectInfo = ipmi::network::getIPObject(
Potin Lai8d1a81e2022-12-20 11:13:45 +0800307 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
308 ipmi::network::IPV6_PROTOCOL, ethdevice);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700309
310 auto properties = ipmi::getAllDbusProperties(
311 bus, ipObjectInfo.second, ipObjectInfo.first,
312 ipmi::network::IP_INTERFACE);
313
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500314 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700315
316 std::strcpy(data, ipaddress.c_str());
317 }
318 break;
319
Vijay Khemkad1194022020-05-27 18:58:33 -0700320 case LanParam::MAC:
321 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700322 std::string macAddress;
323 auto macObjectInfo =
324 ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE,
325 ipmi::network::ROOT, ethdevice);
326
327 auto variant = ipmi::getDbusProperty(
328 bus, macObjectInfo.second, macObjectInfo.first,
329 ipmi::network::MAC_INTERFACE, "MACAddress");
330
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500331 macAddress = std::get<std::string>(variant);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700332
333 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
334 (data), (data + 1), (data + 2), (data + 3), (data + 4),
335 (data + 5));
336 std::strcpy(data, macAddress.c_str());
337 }
338 break;
339
340 default:
341 rc = IPMI_CC_PARM_OUT_OF_RANGE;
342 }
343 return rc;
344}
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800345
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530346bool isMultiHostPlatform()
347{
348 bool platform;
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530349 if (hostInstances == "0")
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530350 {
351 platform = false;
352 }
353 else
354 {
355 platform = true;
356 }
357 return platform;
358}
359
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800360// return code: 0 successful
Vijay Khemka63c99be2020-05-27 19:14:35 -0700361int8_t getFruData(std::string& data, std::string& name)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800362{
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530363 size_t pos;
364 static constexpr const auto depth = 0;
365 std::vector<std::string> paths;
366 std::string machinePath;
367 std::string baseBoard = "Baseboard";
368
369 bool platform = isMultiHostPlatform();
370 if (platform == true)
371 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530372 getSelectorPosition(pos);
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530373 }
374
375 sd_bus* bus = NULL;
376 int ret = sd_bus_default_system(&bus);
377 if (ret < 0)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800378 {
379 phosphor::logging::log<phosphor::logging::level::ERR>(
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530380 "Failed to connect to system bus",
381 phosphor::logging::entry("ERRNO=0x%X", -ret));
382 sd_bus_unref(bus);
383 return -1;
384 }
Patrick Williamscd315e02022-07-22 19:26:52 -0500385 sdbusplus::bus_t dbus(bus);
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530386 auto mapperCall = dbus.new_method_call("xyz.openbmc_project.ObjectMapper",
387 "/xyz/openbmc_project/object_mapper",
388 "xyz.openbmc_project.ObjectMapper",
389 "GetSubTreePaths");
390 static constexpr std::array<const char*, 1> interface = {
391 "xyz.openbmc_project.Inventory.Decorator.Asset"};
392 mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface);
393
394 try
395 {
396 auto reply = dbus.call(mapperCall);
397 reply.read(paths);
398 }
399 catch (sdbusplus::exception_t& e)
400 {
401 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800402 return -1;
403 }
404
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530405 for (const auto& path : paths)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800406 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530407 if (platform == true)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800408 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530409 if (pos == BMC_POS)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800410 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530411 machinePath = baseBoard;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800412 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530413 else
414 {
415 machinePath = "_" + std::to_string(pos);
416 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800417 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530418 else
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800419 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530420 machinePath = baseBoard;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800421 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530422
423 auto found = path.find(machinePath);
Patrick Williams123cbcc2022-06-24 06:13:59 -0500424 if (found == std::string::npos)
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530425 {
426 continue;
427 }
428
429 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
430 std::string service = getService(
431 *dbus, "xyz.openbmc_project.Inventory.Decorator.Asset", path);
432
433 auto Value = ipmi::getDbusProperty(
434 *dbus, service, path,
435 "xyz.openbmc_project.Inventory.Decorator.Asset", name);
436
437 data = std::get<std::string>(Value);
438 return 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800439 }
440 return -1;
441}
442
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530443int8_t sysConfig(std::vector<std::string>& data, size_t pos)
444{
445 nlohmann::json sysObj;
446 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(pos);
447 std::string result, typeName;
448 uint8_t res[MAX_BUF];
449
450 /* Get sysConfig data stored in json file */
451 std::ifstream file(JSON_OEM_DATA_FILE);
452 if (file)
453 {
454 file >> sysObj;
455 file.close();
456 }
457 else
458 {
459 phosphor::logging::log<phosphor::logging::level::ERR>(
460 "oemData file not found",
461 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
462 return -1;
463 }
464
465 if (sysObj.find(dimmInfo) == sysObj.end())
466 {
467 phosphor::logging::log<phosphor::logging::level::ERR>(
468 "sysconfig key not available",
469 phosphor::logging::entry("SYS_JSON_KEY=%s", dimmInfo.c_str()));
470 return -1;
471 }
472 /* Get dimm type names stored in json file */
473 nlohmann::json dimmObj;
474 std::ifstream dimmFile(JSON_DIMM_TYPE_FILE);
475 if (file)
476 {
477 dimmFile >> dimmObj;
478 dimmFile.close();
479 }
480 else
481 {
482 phosphor::logging::log<phosphor::logging::level::ERR>(
483 "DIMM type names file not found",
484 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
485 return -1;
486 }
487 std::vector<std::string> a;
488 for (auto& j : dimmObj.items())
489 {
490 std::string name = j.key();
491 a.push_back(name);
492 }
493
494 uint8_t len = a.size();
495 for (uint8_t ii = 0; ii < len; ii++)
496 {
497 std::string indKey = std::to_string(ii);
498 std::string speedSize = sysObj[dimmInfo][indKey][DIMM_SPEED];
499 strToBytes(speedSize, res);
500 auto speed = (res[1] << 8 | res[0]);
501 size_t dimmSize = ((res[3] << 8 | res[2]) / 1000);
502
503 if (dimmSize == 0)
504 {
505 std::cerr << "Dimm information not available for slot_" +
506 std::to_string(ii)
507 << std::endl;
508 continue;
509 }
510 std::string type = sysObj[dimmInfo][indKey][DIMM_TYPE];
511 std::string dualInlineMem = sysObj[dimmInfo][indKey][KEY_DIMM_TYPE];
512 strToBytes(type, res);
513 size_t dimmType = res[0];
514 if (dimmVenMap.find(dimmType) == dimmVenMap.end())
515 {
516 typeName = "unknown";
517 }
518 else
519 {
520 typeName = dimmVenMap[dimmType];
521 }
522 result = dualInlineMem + "/" + typeName + "/" + std::to_string(speed) +
523 "MHz" + "/" + std::to_string(dimmSize) + "GB";
524 data.push_back(result);
525 }
526 return 0;
527}
528
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +0530529int8_t procInfo(std::string& result, size_t pos)
530{
531 std::vector<char> data;
532 uint8_t res[MAX_BUF];
533 std::string procIndex = "00";
534 nlohmann::json proObj;
535 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(pos);
536 /* Get processor data stored in json file */
537 std::ifstream file(JSON_OEM_DATA_FILE);
538 if (file)
539 {
540 file >> proObj;
541 file.close();
542 }
543 else
544 {
545 phosphor::logging::log<phosphor::logging::level::ERR>(
546 "oemData file not found",
547 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
548 return -1;
549 }
550 if (proObj.find(procInfo) == proObj.end())
551 {
552 phosphor::logging::log<phosphor::logging::level::ERR>(
553 "processor info key not available",
554 phosphor::logging::entry("PROC_JSON_KEY=%s", procInfo.c_str()));
555 return -1;
556 }
557 std::string procName = proObj[procInfo][procIndex][KEY_PROC_NAME];
558 std::string basicInfo = proObj[procInfo][procIndex][KEY_BASIC_INFO];
559 // Processor Product Name
560 strToBytes(procName, res);
561 data.assign(reinterpret_cast<char*>(&res),
562 reinterpret_cast<char*>(&res) + sizeof(res));
563
564 std::string s(data.begin(), data.end());
565 std::regex regex(" ");
566 std::vector<std::string> productName(
567 std::sregex_token_iterator(s.begin(), s.end(), regex, -1),
568 std::sregex_token_iterator());
569
570 // Processor core and frequency
571 strToBytes(basicInfo, res);
572 uint16_t coreNum = res[0];
573 double procFrequency = (float)(res[4] << 8 | res[3]) / 1000;
574 result = "CPU:" + productName[2] + "/" + std::to_string(procFrequency) +
575 "GHz" + "/" + std::to_string(coreNum) + "c";
576 return 0;
577}
578
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800579typedef struct
580{
581 uint8_t cur_power_state;
582 uint8_t last_power_event;
583 uint8_t misc_power_state;
584 uint8_t front_panel_button_cap_status;
585} ipmi_get_chassis_status_t;
586
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800587//----------------------------------------------------------------------
588// Get Debug Frame Info
589//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700590ipmi_ret_t ipmiOemDbgGetFrameInfo(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800591 ipmi_request_t request,
592 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700593 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800594{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700595 uint8_t* req = reinterpret_cast<uint8_t*>(request);
596 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800597 uint8_t num_frames = 3;
598
599 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
600 res[SIZE_IANA_ID] = num_frames;
601 *data_len = SIZE_IANA_ID + 1;
602
603 return IPMI_CC_OK;
604}
605
606//----------------------------------------------------------------------
607// Get Debug Updated Frames
608//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700609ipmi_ret_t ipmiOemDbgGetUpdFrames(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800610 ipmi_request_t request,
611 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700612 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800613{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700614 uint8_t* req = reinterpret_cast<uint8_t*>(request);
615 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800616 uint8_t num_updates = 3;
617 *data_len = 4;
618
619 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
620 res[SIZE_IANA_ID] = num_updates;
621 *data_len = SIZE_IANA_ID + num_updates + 1;
622 res[SIZE_IANA_ID + 1] = 1; // info page update
623 res[SIZE_IANA_ID + 2] = 2; // cri sel update
624 res[SIZE_IANA_ID + 3] = 3; // cri sensor update
625
626 return IPMI_CC_OK;
627}
628
629//----------------------------------------------------------------------
630// Get Debug POST Description
631//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700632ipmi_ret_t ipmiOemDbgGetPostDesc(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800633 ipmi_request_t request,
634 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700635 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800636{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700637 uint8_t* req = reinterpret_cast<uint8_t*>(request);
638 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800639 uint8_t index = 0;
640 uint8_t next = 0;
641 uint8_t end = 0;
642 uint8_t phase = 0;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700643 uint8_t descLen = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800644 int ret;
645
646 index = req[3];
647 phase = req[4];
648
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700649 ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800650 if (ret)
651 {
652 memcpy(res, req, SIZE_IANA_ID); // IANA ID
653 *data_len = SIZE_IANA_ID;
654 return IPMI_CC_UNSPECIFIED_ERROR;
655 }
656
657 memcpy(res, req, SIZE_IANA_ID); // IANA ID
658 res[3] = index;
659 res[4] = next;
660 res[5] = phase;
661 res[6] = end;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700662 res[7] = descLen;
663 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800664
665 return IPMI_CC_OK;
666}
667
668//----------------------------------------------------------------------
669// Get Debug GPIO Description
670//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700671ipmi_ret_t ipmiOemDbgGetGpioDesc(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800672 ipmi_request_t request,
673 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700674 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800675{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700676 uint8_t* req = reinterpret_cast<uint8_t*>(request);
677 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800678
Vijay Khemka38183d62019-08-28 16:19:33 -0700679 uint8_t index = 0;
680 uint8_t next = 0;
681 uint8_t level = 0;
682 uint8_t pinDef = 0;
683 uint8_t descLen = 0;
684 int ret;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800685
Vijay Khemka38183d62019-08-28 16:19:33 -0700686 index = req[3];
687
688 ret = plat_udbg_get_gpio_desc(index, &next, &level, &pinDef, &descLen,
689 &res[8]);
690 if (ret)
691 {
692 memcpy(res, req, SIZE_IANA_ID); // IANA ID
693 *data_len = SIZE_IANA_ID;
694 return IPMI_CC_UNSPECIFIED_ERROR;
695 }
696
697 memcpy(res, req, SIZE_IANA_ID); // IANA ID
698 res[3] = index;
699 res[4] = next;
700 res[5] = level;
701 res[6] = pinDef;
702 res[7] = descLen;
703 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800704
705 return IPMI_CC_OK;
706}
707
708//----------------------------------------------------------------------
709// Get Debug Frame Data
710//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700711ipmi_ret_t ipmiOemDbgGetFrameData(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800712 ipmi_request_t request,
713 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700714 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800715{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700716 uint8_t* req = reinterpret_cast<uint8_t*>(request);
717 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800718 uint8_t frame;
719 uint8_t page;
720 uint8_t next;
721 uint8_t count;
722 int ret;
723
724 frame = req[3];
725 page = req[4];
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800726
727 ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]);
728 if (ret)
729 {
730 memcpy(res, req, SIZE_IANA_ID); // IANA ID
731 *data_len = SIZE_IANA_ID;
732 return IPMI_CC_UNSPECIFIED_ERROR;
733 }
734
735 memcpy(res, req, SIZE_IANA_ID); // IANA ID
736 res[3] = frame;
737 res[4] = page;
738 res[5] = next;
739 res[6] = count;
740 *data_len = SIZE_IANA_ID + 4 + count;
741
742 return IPMI_CC_OK;
743}
744
745//----------------------------------------------------------------------
746// Get Debug Control Panel
747//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700748ipmi_ret_t ipmiOemDbgGetCtrlPanel(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800749 ipmi_request_t request,
750 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700751 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800752{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700753 uint8_t* req = reinterpret_cast<uint8_t*>(request);
754 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800755
756 uint8_t panel;
757 uint8_t operation;
758 uint8_t item;
759 uint8_t count;
760 ipmi_ret_t ret;
761
762 panel = req[3];
763 operation = req[4];
764 item = req[5];
765
766 ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]);
767
768 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
769 *data_len = SIZE_IANA_ID + count;
770
771 return ret;
772}
773
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800774//----------------------------------------------------------------------
775// Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
776//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700777ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
778 ipmi_response_t, ipmi_data_len_t data_len,
779 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800780{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700781 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700782
783 uint8_t index = req[0];
784 uint8_t type = req[1];
785 uint16_t speed;
786 uint32_t size;
787
788 memcpy(&speed, &req[2], 2);
789 memcpy(&size, &req[4], 4);
790
791 std::stringstream ss;
792 ss << std::hex;
793 ss << std::setw(2) << std::setfill('0') << (int)index;
794
795 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index;
796 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type;
797 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed;
798 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size;
799
800 flushOemData();
801
802 *data_len = 0;
803
804 return IPMI_CC_OK;
805}
806
807//----------------------------------------------------------------------
808// Get Board ID (CMD_OEM_GET_BOARD_ID)
809//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700810ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
811 ipmi_response_t, ipmi_data_len_t data_len,
812 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700813{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700814 /* TODO: Needs to implement this after GPIO implementation */
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800815 *data_len = 0;
816
817 return IPMI_CC_OK;
818}
819
Bonnie Lo4ae63e72023-02-09 15:27:54 +0800820//----------------------------------------------------------------------
821// Get port 80 record (CMD_OEM_GET_80PORT_RECORD)
822//----------------------------------------------------------------------
823ipmi::RspType<std::vector<uint8_t>>
824 ipmiOemGet80PortRecord(ipmi::Context::ptr ctx)
825{
826 auto postCodeService = "xyz.openbmc_project.State.Boot.PostCode" +
827 std::to_string(ctx->hostIdx + 1);
828 auto postCodeObjPath = "/xyz/openbmc_project/State/Boot/PostCode" +
829 std::to_string(ctx->hostIdx + 1);
830 constexpr auto postCodeInterface =
831 "xyz.openbmc_project.State.Boot.PostCode";
832 const static uint16_t lastestPostCodeIndex = 1;
833 constexpr const auto maxPostCodeLen =
834 224; // The length must be lower than IPMB limitation
835 size_t startIndex = 0;
836
837 std::vector<std::tuple<uint64_t, std::vector<uint8_t>>> postCodes;
838 std::vector<uint8_t> resData;
839
840 auto conn = getSdBus();
841 /* Get the post codes by calling GetPostCodes method */
Patrick Williams2405ae92023-05-10 07:50:09 -0500842 auto msg = conn->new_method_call(postCodeService.c_str(),
843 postCodeObjPath.c_str(), postCodeInterface,
844 "GetPostCodes");
Bonnie Lo4ae63e72023-02-09 15:27:54 +0800845 msg.append(lastestPostCodeIndex);
846
847 try
848 {
849 auto reply = conn->call(msg);
850 reply.read(postCodes);
851 }
852 catch (const sdbusplus::exception::SdBusError& e)
853 {
854 phosphor::logging::log<phosphor::logging::level::ERR>(
855 "IPMI Get80PortRecord Failed in call method",
856 phosphor::logging::entry("ERROR=%s", e.what()));
857 return ipmi::responseUnspecifiedError();
858 }
859
860 /* Get post code data */
861 for (size_t i = 0; i < postCodes.size(); ++i)
862 {
863 uint64_t primaryPostCode = std::get<uint64_t>(postCodes[i]);
864 for (int j = postCodeSize - 1; j >= 0; --j)
865 {
866 uint8_t postCode =
867 ((primaryPostCode >> (sizeof(uint64_t) * j)) & 0xFF);
868 resData.emplace_back(postCode);
869 }
870 }
871
872 std::vector<uint8_t> response;
873 if (resData.size() > maxPostCodeLen)
874 {
875 startIndex = resData.size() - maxPostCodeLen;
876 }
877
878 response.assign(resData.begin() + startIndex, resData.end());
879
880 return ipmi::responseSuccess(response);
881}
882
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800883/* Helper functions to set boot order */
Jayashree-Df0cf6652020-11-30 11:03:30 +0530884void setBootOrder(std::string bootObjPath, uint8_t* data,
885 std::string bootOrderKey)
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800886{
Jayashree-Df0cf6652020-11-30 11:03:30 +0530887 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
888
889 // SETTING BOOT MODE PROPERTY
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800890 uint8_t bootModeBit = data[0] & 0x04;
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530891 auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit);
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530892
Jayashree-Df0cf6652020-11-30 11:03:30 +0530893 std::string bootOption =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530894 sdbusplus::message::convert_to_string<boot::BootMode>(bootValue);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530895
Patrick Williams2405ae92023-05-10 07:50:09 -0500896 std::string service = getService(*dbus, ipmi::boot::bootModeIntf,
897 bootObjPath);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530898 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
899 ipmi::boot::bootModeProp, bootOption);
900
901 // SETTING BOOT SOURCE PROPERTY
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530902 auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530903 std::string bootSource =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530904 sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530905
906 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
907 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
908 ipmi::boot::bootSourceProp, bootSource);
909
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530910 // SETTING BOOT TYPE PROPERTY
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530911 uint8_t bootTypeBit = data[0] & 0x01;
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530912 auto bootTypeVal = ipmi::boot::typeIpmiToDbus.at(bootTypeBit);
913
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530914 std::string bootType =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530915 sdbusplus::message::convert_to_string<boot::BootType>(bootTypeVal);
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530916
917 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
918
919 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
920 ipmi::boot::bootTypeProp, bootType);
921
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800922 // Set the valid bit to boot enabled property
923 service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
924
925 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf,
926 ipmi::boot::bootEnableProp,
927 (data[0] & BOOT_MODE_BOOT_FLAG) ? true : false);
928
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800929 nlohmann::json bootMode;
930 uint8_t mode = data[0];
931 int i;
932
933 bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
934 bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
935 bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
936 bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530937 oemData[bootOrderKey][KEY_BOOT_MODE] = bootMode;
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800938
939 /* Initialize boot sequence array */
Jayashree-Df0cf6652020-11-30 11:03:30 +0530940 oemData[bootOrderKey][KEY_BOOT_SEQ] = {};
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800941 for (i = 1; i < SIZE_BOOT_ORDER; i++)
942 {
943 if (data[i] >= BOOT_SEQ_ARRAY_SIZE)
Jayashree-Df0cf6652020-11-30 11:03:30 +0530944 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = "NA";
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800945 else
Jayashree-Df0cf6652020-11-30 11:03:30 +0530946 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = bootSeq[data[i]];
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800947 }
948
949 flushOemData();
950}
951
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800952//----------------------------------------------------------------------
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700953// Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
954//----------------------------------------------------------------------
Jayashree-Df0cf6652020-11-30 11:03:30 +0530955ipmi::RspType<std::vector<uint8_t>>
956 ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700957{
Jayashree-Df0cf6652020-11-30 11:03:30 +0530958 uint8_t bootSeq[SIZE_BOOT_ORDER];
959 size_t len = data.size();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700960
961 if (len != SIZE_BOOT_ORDER)
962 {
963 phosphor::logging::log<phosphor::logging::level::ERR>(
964 "Invalid Boot order length received");
Jayashree-Df0cf6652020-11-30 11:03:30 +0530965 return ipmi::responseReqDataLenInvalid();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700966 }
967
Jayashree-Df0cf6652020-11-30 11:03:30 +0530968 std::copy(std::begin(data), std::end(data), bootSeq);
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530969 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700970
Jayashree-Df0cf6652020-11-30 11:03:30 +0530971 if (!hostId)
972 {
973 phosphor::logging::log<phosphor::logging::level::ERR>(
974 "Invalid Host Id received");
975 return ipmi::responseInvalidCommand();
976 }
977 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
978
979 setBootOrder(bootObjPath, bootSeq, hostName);
980
981 return ipmi::responseSuccess(data);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700982}
983
984//----------------------------------------------------------------------
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800985// Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
986//----------------------------------------------------------------------
Jayashree-Df0cf6652020-11-30 11:03:30 +0530987ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
988 ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800989{
Jayashree-Df0cf6652020-11-30 11:03:30 +0530990 uint8_t bootSeq[SIZE_BOOT_ORDER];
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700991 uint8_t mode = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800992
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530993 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700994
Jayashree-Df0cf6652020-11-30 11:03:30 +0530995 if (!hostId)
996 {
997 phosphor::logging::log<phosphor::logging::level::ERR>(
998 "Invalid Host Id received");
999 return ipmi::responseInvalidCommand();
1000 }
1001 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
1002
Jayashree-Df0cf6652020-11-30 11:03:30 +05301003 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1004
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +05301005 // GETTING PROPERTY OF MODE INTERFACE
1006
Patrick Williams2405ae92023-05-10 07:50:09 -05001007 std::string service = getService(*dbus, ipmi::boot::bootModeIntf,
1008 bootObjPath);
1009 Value variant = getDbusProperty(*dbus, service, bootObjPath,
1010 ipmi::boot::bootModeIntf,
1011 ipmi::boot::bootModeProp);
Jayashree-Df0cf6652020-11-30 11:03:30 +05301012
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +05301013 auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>(
Jayashree-Df0cf6652020-11-30 11:03:30 +05301014 std::get<std::string>(variant));
1015
Jayashree Dhanapal778147d2022-03-30 16:48:53 +05301016 uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
Jayashree-Df0cf6652020-11-30 11:03:30 +05301017
Jayashree Dhanapal778147d2022-03-30 16:48:53 +05301018 // GETTING PROPERTY OF TYPE INTERFACE
1019
1020 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
Patrick Williams2405ae92023-05-10 07:50:09 -05001021 variant = getDbusProperty(*dbus, service, bootObjPath,
1022 ipmi::boot::bootTypeIntf,
1023 ipmi::boot::bootTypeProp);
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +05301024
1025 auto bootType = sdbusplus::message::convert_from_string<boot::BootType>(
Jayashree Dhanapal778147d2022-03-30 16:48:53 +05301026 std::get<std::string>(variant));
1027
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +08001028 // Get the valid bit from boot enabled property
1029 service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
Patrick Williams2405ae92023-05-10 07:50:09 -05001030 variant = getDbusProperty(*dbus, service, bootObjPath,
1031 ipmi::boot::bootEnableIntf,
1032 ipmi::boot::bootEnableProp);
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +08001033
1034 bool validFlag = std::get<bool>(variant);
1035
Jayashree Dhanapal778147d2022-03-30 16:48:53 +05301036 uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
1037
1038 uint8_t bootVal = bootOption | bootTypeVal;
Jayashree-Df0cf6652020-11-30 11:03:30 +05301039
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +08001040 if (validFlag)
1041 {
1042 bootVal |= BOOT_MODE_BOOT_FLAG;
1043 }
1044
Jayashree-Df0cf6652020-11-30 11:03:30 +05301045 if (oemData.find(hostName) == oemData.end())
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001046 {
1047 /* Return default boot order 0100090203ff */
1048 uint8_t defaultBoot[SIZE_BOOT_ORDER] = {
Willy Tue39f9392022-06-15 13:24:20 -07001049 BOOT_MODE_UEFI,
1050 static_cast<uint8_t>(bootMap["USB_DEV"]),
1051 static_cast<uint8_t>(bootMap["NET_IPV6"]),
1052 static_cast<uint8_t>(bootMap["SATA_HDD"]),
1053 static_cast<uint8_t>(bootMap["SATA_CD"]),
1054 0xff};
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001055
Jayashree-Df0cf6652020-11-30 11:03:30 +05301056 memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER);
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001057 phosphor::logging::log<phosphor::logging::level::INFO>(
1058 "Set default boot order");
Jayashree-Df0cf6652020-11-30 11:03:30 +05301059 setBootOrder(bootObjPath, defaultBoot, hostName);
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001060 }
1061 else
1062 {
Jayashree-Df0cf6652020-11-30 11:03:30 +05301063 nlohmann::json bootMode = oemData[hostName][KEY_BOOT_MODE];
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001064 if (bootMode["CMOS_CLR"])
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +08001065 bootVal |= BOOT_MODE_CMOS_CLR;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001066
Jayashree-Df0cf6652020-11-30 11:03:30 +05301067 bootSeq[0] = mode;
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001068
Jayashree-Df0cf6652020-11-30 11:03:30 +05301069 for (int i = 1; i < SIZE_BOOT_ORDER; i++)
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001070 {
Jayashree-Df0cf6652020-11-30 11:03:30 +05301071 std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001072 if (bootMap.find(seqStr) != bootMap.end())
Jayashree-Df0cf6652020-11-30 11:03:30 +05301073 bootSeq[i] = bootMap[seqStr];
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001074 else
Jayashree-Df0cf6652020-11-30 11:03:30 +05301075 bootSeq[i] = 0xff;
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001076 }
1077 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001078
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +08001079 return ipmi::responseSuccess(bootVal, bootSeq[1], bootSeq[2], bootSeq[3],
Jayashree-Df0cf6652020-11-30 11:03:30 +05301080 bootSeq[4], bootSeq[5]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001081}
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001082// Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
1083//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001084ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t, ipmi_cmd_t,
1085 ipmi_request_t request, ipmi_response_t,
1086 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001087{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001088 machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001089 uint8_t len = *data_len;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001090
1091 *data_len = 0;
1092
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001093 if (len < sizeof(machineConfigInfo_t))
1094 {
1095 phosphor::logging::log<phosphor::logging::level::ERR>(
1096 "Invalid machine configuration length received");
1097 return IPMI_CC_REQ_DATA_LEN_INVALID;
1098 }
1099
Vijay Khemka63c99be2020-05-27 19:14:35 -07001100 if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001101 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN";
1102 else
1103 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] =
1104 chassisType[req->chassis_type];
1105
Vijay Khemka63c99be2020-05-27 19:14:35 -07001106 if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001107 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN";
1108 else
1109 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type];
1110
1111 oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt;
1112 oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt;
1113 oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt;
1114 oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt;
1115
Vijay Khemka63c99be2020-05-27 19:14:35 -07001116 if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001117 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN";
1118 else
1119 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type];
1120
1121 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {};
1122 int i = 0;
1123 if (req->pcie_card_loc & BIT_0)
1124 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1";
1125 if (req->pcie_card_loc & BIT_1)
1126 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2";
1127 if (req->pcie_card_loc & BIT_2)
1128 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3";
1129 if (req->pcie_card_loc & BIT_3)
1130 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4";
1131
Vijay Khemka63c99be2020-05-27 19:14:35 -07001132 if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001133 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN";
1134 else
1135 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] =
1136 pcieType[req->slot1_pcie_type];
1137
Vijay Khemka63c99be2020-05-27 19:14:35 -07001138 if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001139 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN";
1140 else
1141 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] =
1142 pcieType[req->slot2_pcie_type];
1143
Vijay Khemka63c99be2020-05-27 19:14:35 -07001144 if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001145 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN";
1146 else
1147 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] =
1148 pcieType[req->slot3_pcie_type];
1149
Vijay Khemka63c99be2020-05-27 19:14:35 -07001150 if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001151 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN";
1152 else
1153 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] =
1154 pcieType[req->slot4_pcie_type];
1155
1156 oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt;
1157
1158 flushOemData();
1159
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001160 return IPMI_CC_OK;
1161}
1162
1163//----------------------------------------------------------------------
1164// Set POST start (CMD_OEM_SET_POST_START)
1165//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001166ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1167 ipmi_response_t, ipmi_data_len_t data_len,
1168 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001169{
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001170 phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
1171
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001172 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001173 *data_len = 0;
1174 return IPMI_CC_OK;
1175}
1176
1177//----------------------------------------------------------------------
1178// Set POST End (CMD_OEM_SET_POST_END)
1179//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001180ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1181 ipmi_response_t, ipmi_data_len_t data_len,
1182 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001183{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001184 struct timespec ts;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001185
1186 phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
1187
1188 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001189
1190 // Timestamp post end time.
1191 clock_gettime(CLOCK_REALTIME, &ts);
1192 oemData[KEY_TS_SLED] = ts.tv_sec;
1193 flushOemData();
1194
1195 // Sync time with system
1196 // TODO: Add code for syncing time
1197
1198 return IPMI_CC_OK;
1199}
1200
1201//----------------------------------------------------------------------
1202// Set PPIN Info (CMD_OEM_SET_PPIN_INFO)
1203//----------------------------------------------------------------------
1204// Inform BMC about PPIN data of 8 bytes for each CPU
1205//
1206// Request:
1207// Byte 1:8 – CPU0 PPIN data
1208// Optional:
1209// Byte 9:16 – CPU1 PPIN data
1210//
1211// Response:
1212// Byte 1 – Completion Code
Willy Tue39f9392022-06-15 13:24:20 -07001213ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1214 ipmi_response_t, ipmi_data_len_t data_len,
1215 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001216{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001217 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001218 std::string ppinStr;
1219 int len;
1220
1221 if (*data_len > SIZE_CPU_PPIN * 2)
1222 len = SIZE_CPU_PPIN * 2;
1223 else
1224 len = *data_len;
1225 *data_len = 0;
1226
1227 ppinStr = bytesToStr(req, len);
1228 oemData[KEY_PPIN_INFO] = ppinStr.c_str();
1229 flushOemData();
1230
1231 return IPMI_CC_OK;
1232}
1233
1234//----------------------------------------------------------------------
1235// Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER)
1236//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001237ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1238 ipmi_response_t, ipmi_data_len_t data_len,
1239 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001240{
1241 /* Do nothing, return success */
1242 *data_len = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001243 return IPMI_CC_OK;
1244}
1245
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001246// Helper function to set guid at offset in EEPROM
Willy Tue39f9392022-06-15 13:24:20 -07001247[[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001248{
1249 int fd = -1;
1250 ssize_t len;
1251 int ret = 0;
1252
1253 errno = 0;
1254
1255 // Check if file is present
1256 if (access(FRU_EEPROM, F_OK) == -1)
1257 {
1258 std::cerr << "Unable to access: " << FRU_EEPROM << std::endl;
1259 return errno;
1260 }
1261
1262 // Open the file
1263 fd = open(FRU_EEPROM, O_WRONLY);
1264 if (fd == -1)
1265 {
1266 std::cerr << "Unable to open: " << FRU_EEPROM << std::endl;
1267 return errno;
1268 }
1269
1270 // seek to the offset
1271 lseek(fd, offset, SEEK_SET);
1272
1273 // Write bytes to location
1274 len = write(fd, guid, GUID_SIZE);
1275 if (len != GUID_SIZE)
1276 {
1277 phosphor::logging::log<phosphor::logging::level::ERR>(
1278 "GUID write data to EEPROM failed");
1279 ret = errno;
1280 }
1281
1282 close(fd);
1283 return ret;
1284}
1285
1286//----------------------------------------------------------------------
1287// Set System GUID (CMD_OEM_SET_SYSTEM_GUID)
1288//----------------------------------------------------------------------
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301289#if BIC_ENABLED
Bonnie Lo3f671272022-10-12 15:46:45 +08001290ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx,
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301291 std::vector<uint8_t> reqData)
1292{
1293 std::vector<uint8_t> respData;
1294
1295 if (reqData.size() != GUID_SIZE) // 16bytes
1296 {
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301297 return ipmi::responseReqDataLenInvalid();
1298 }
1299
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301300 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
1301
1302 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
1303 return ipmi::responseUnspecifiedError();
1304
1305 return ipmi::responseSuccess();
1306}
1307
1308#else
Potin Laid5353ca2022-08-11 04:52:11 +00001309ipmi_ret_t ipmiOemSetSystemGuid(ipmi_netfn_t, ipmi_cmd_t,
1310 ipmi_request_t request, ipmi_response_t,
1311 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001312{
1313 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1314
1315 if (*data_len != GUID_SIZE) // 16bytes
1316 {
1317 *data_len = 0;
1318 return IPMI_CC_REQ_DATA_LEN_INVALID;
1319 }
1320
1321 *data_len = 0;
1322
1323 if (setGUID(OFFSET_SYS_GUID, req))
1324 {
1325 return IPMI_CC_UNSPECIFIED_ERROR;
1326 }
1327 return IPMI_CC_OK;
1328}
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301329#endif
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001330
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001331//----------------------------------------------------------------------
1332// Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
1333//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001334ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1335 ipmi_response_t, ipmi_data_len_t data_len,
1336 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001337{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001338 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001339 *data_len = 0;
1340 return IPMI_CC_OK;
1341}
1342
1343//----------------------------------------------------------------------
1344// Set PPR (CMD_OEM_SET_PPR)
1345//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001346ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1347 ipmi_response_t, ipmi_data_len_t data_len,
1348 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001349{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001350 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001351 uint8_t pprCnt, pprAct, pprIndex;
1352 uint8_t selParam = req[0];
1353 uint8_t len = *data_len;
1354 std::stringstream ss;
1355 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001356
1357 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001358
1359 switch (selParam)
1360 {
1361 case PPR_ACTION:
1362 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) ==
1363 oemData[KEY_PPR].end())
1364 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1365
1366 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1367 if (pprCnt == 0)
1368 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1369
1370 pprAct = req[1];
1371 /* Check if ppr is enabled or disabled */
1372 if (!(pprAct & 0x80))
1373 pprAct = 0;
1374
1375 oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct;
1376 break;
1377 case PPR_ROW_COUNT:
1378 if (req[1] > 100)
1379 return IPMI_CC_PARM_OUT_OF_RANGE;
1380
1381 oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1];
1382 break;
1383 case PPR_ROW_ADDR:
1384 pprIndex = req[1];
1385 if (pprIndex > 100)
1386 return IPMI_CC_PARM_OUT_OF_RANGE;
1387
1388 if (len < PPR_ROW_ADDR_LEN + 1)
1389 {
1390 phosphor::logging::log<phosphor::logging::level::ERR>(
1391 "Invalid PPR Row Address length received");
1392 return IPMI_CC_REQ_DATA_LEN_INVALID;
1393 }
1394
1395 ss << std::hex;
1396 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1397
1398 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1399
1400 str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN);
1401 oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str();
1402 break;
1403 case PPR_HISTORY_DATA:
1404 pprIndex = req[1];
1405 if (pprIndex > 100)
1406 return IPMI_CC_PARM_OUT_OF_RANGE;
1407
1408 if (len < PPR_HST_DATA_LEN + 1)
1409 {
1410 phosphor::logging::log<phosphor::logging::level::ERR>(
1411 "Invalid PPR history data length received");
1412 return IPMI_CC_REQ_DATA_LEN_INVALID;
1413 }
1414
1415 ss << std::hex;
1416 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1417
1418 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1419
1420 str = bytesToStr(&req[1], PPR_HST_DATA_LEN);
1421 oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str();
1422 break;
1423 default:
1424 return IPMI_CC_PARM_OUT_OF_RANGE;
1425 break;
1426 }
1427
1428 flushOemData();
1429
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001430 return IPMI_CC_OK;
1431}
1432
1433//----------------------------------------------------------------------
1434// Get PPR (CMD_OEM_GET_PPR)
1435//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001436ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1437 ipmi_response_t response, ipmi_data_len_t data_len,
1438 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001439{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001440 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1441 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001442 uint8_t pprCnt, pprIndex;
1443 uint8_t selParam = req[0];
1444 std::stringstream ss;
1445 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001446
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001447 /* Any failure will return zero length data */
1448 *data_len = 0;
1449
1450 switch (selParam)
1451 {
1452 case PPR_ACTION:
1453 res[0] = 0;
1454 *data_len = 1;
1455
1456 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1457 oemData[KEY_PPR].end())
1458 {
1459 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1460 if (pprCnt != 0)
1461 {
1462 if (oemData[KEY_PPR].find(KEY_PPR_ACTION) !=
1463 oemData[KEY_PPR].end())
1464 {
1465 res[0] = oemData[KEY_PPR][KEY_PPR_ACTION];
1466 }
1467 }
1468 }
1469 break;
1470 case PPR_ROW_COUNT:
1471 res[0] = 0;
1472 *data_len = 1;
1473 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1474 oemData[KEY_PPR].end())
1475 res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1476 break;
1477 case PPR_ROW_ADDR:
1478 pprIndex = req[1];
1479 if (pprIndex > 100)
1480 return IPMI_CC_PARM_OUT_OF_RANGE;
1481
1482 ss << std::hex;
1483 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1484
1485 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1486 return IPMI_CC_PARM_OUT_OF_RANGE;
1487
1488 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) ==
1489 oemData[KEY_PPR][ss.str()].end())
1490 return IPMI_CC_PARM_OUT_OF_RANGE;
1491
1492 str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR];
1493 *data_len = strToBytes(str, res);
1494 break;
1495 case PPR_HISTORY_DATA:
1496 pprIndex = req[1];
1497 if (pprIndex > 100)
1498 return IPMI_CC_PARM_OUT_OF_RANGE;
1499
1500 ss << std::hex;
1501 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1502
1503 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1504 return IPMI_CC_PARM_OUT_OF_RANGE;
1505
1506 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) ==
1507 oemData[KEY_PPR][ss.str()].end())
1508 return IPMI_CC_PARM_OUT_OF_RANGE;
1509
1510 str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA];
1511 *data_len = strToBytes(str, res);
1512 break;
1513 default:
1514 return IPMI_CC_PARM_OUT_OF_RANGE;
1515 break;
1516 }
1517
1518 return IPMI_CC_OK;
1519}
1520
1521/* FB OEM QC Commands */
1522
1523//----------------------------------------------------------------------
1524// Set Proc Info (CMD_OEM_Q_SET_PROC_INFO)
1525//----------------------------------------------------------------------
1526//"Request:
1527// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1528// Byte 4 – Processor Index, 0 base
1529// Byte 5 – Parameter Selector
1530// Byte 6..N – Configuration parameter data (see below for Parameters
1531// of Processor Information)
1532// Response:
1533// Byte 1 – Completion code
1534//
1535// Parameter#1: (Processor Product Name)
1536//
1537// Byte 1..48 –Product name(ASCII code)
1538// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1539//
1540// Param#2: Processor Basic Information
1541// Byte 1 – Core Number
1542// Byte 2 – Thread Number (LSB)
1543// Byte 3 – Thread Number (MSB)
1544// Byte 4 – Processor frequency in MHz (LSB)
1545// Byte 5 – Processor frequency in MHz (MSB)
1546// Byte 6..7 – Revision
1547//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301548
1549ipmi::RspType<> ipmiOemQSetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1550 uint8_t, uint8_t procIndex,
1551 uint8_t paramSel,
1552 std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001553{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001554 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001555 std::stringstream ss;
1556 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301557 uint8_t len = request.size();
1558 auto hostId = findHost(ctx->hostIdx);
1559 if (!hostId)
1560 {
1561 phosphor::logging::log<phosphor::logging::level::ERR>(
1562 "Invalid Host Id received");
1563 return ipmi::responseInvalidCommand();
1564 }
1565 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001566 /* check for requested data params */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301567 if (len < 5 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001568 {
1569 phosphor::logging::log<phosphor::logging::level::ERR>(
1570 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301571 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001572 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001573 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301574 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1575 oemData[procInfo][ss.str()][KEY_PROC_INDEX] = procIndex;
1576 str = bytesToStr(request.data(), len);
1577 oemData[procInfo][ss.str()][cpuInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001578 flushOemData();
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301579 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001580}
1581
1582//----------------------------------------------------------------------
1583// Get Proc Info (CMD_OEM_Q_GET_PROC_INFO)
1584//----------------------------------------------------------------------
1585// Request:
1586// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1587// Byte 4 – Processor Index, 0 base
1588// Byte 5 – Parameter Selector
1589// Response:
1590// Byte 1 – Completion code
1591// Byte 2..N – Configuration Parameter Data (see below for Parameters
1592// of Processor Information)
1593//
1594// Parameter#1: (Processor Product Name)
1595//
1596// Byte 1..48 –Product name(ASCII code)
1597// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1598//
1599// Param#2: Processor Basic Information
1600// Byte 1 – Core Number
1601// Byte 2 – Thread Number (LSB)
1602// Byte 3 – Thread Number (MSB)
1603// Byte 4 – Processor frequency in MHz (LSB)
1604// Byte 5 – Processor frequency in MHz (MSB)
1605// Byte 6..7 – Revision
1606//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301607
1608ipmi::RspType<std::vector<uint8_t>>
1609 ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1610 uint8_t procIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001611{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001612 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001613 std::stringstream ss;
1614 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301615 uint8_t res[MAX_BUF];
1616 auto hostId = findHost(ctx->hostIdx);
1617 if (!hostId)
1618 {
1619 phosphor::logging::log<phosphor::logging::level::ERR>(
1620 "Invalid Host Id received");
1621 return ipmi::responseInvalidCommand();
1622 }
1623 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
1624 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001625 {
1626 phosphor::logging::log<phosphor::logging::level::ERR>(
1627 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301628 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001629 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001630 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301631 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1632 if (oemData[procInfo].find(ss.str()) == oemData[procInfo].end())
1633 return ipmi::responseCommandNotAvailable();
1634 if (oemData[procInfo][ss.str()].find(cpuInfoKey[paramSel]) ==
1635 oemData[procInfo][ss.str()].end())
1636 return ipmi::responseCommandNotAvailable();
1637 str = oemData[procInfo][ss.str()][cpuInfoKey[paramSel]];
1638 int dataLen = strToBytes(str, res);
1639 std::vector<uint8_t> response(&res[0], &res[dataLen]);
1640 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001641}
1642
1643//----------------------------------------------------------------------
1644// Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO)
1645//----------------------------------------------------------------------
1646// Request:
1647// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1648// Byte 4 – DIMM Index, 0 base
1649// Byte 5 – Parameter Selector
1650// Byte 6..N – Configuration parameter data (see below for Parameters
1651// of DIMM Information)
1652// Response:
1653// Byte 1 – Completion code
1654//
1655// Param#1 (DIMM Location):
1656// Byte 1 – DIMM Present
1657// Byte 1 – DIMM Present
1658// 01h – Present
1659// FFh – Not Present
1660// Byte 2 – Node Number, 0 base
1661// Byte 3 – Channel Number , 0 base
1662// Byte 4 – DIMM Number , 0 base
1663//
1664// Param#2 (DIMM Type):
1665// Byte 1 – DIMM Type
1666// Bit [7:6]
1667// For DDR3
1668// 00 – Normal Voltage (1.5V)
1669// 01 – Ultra Low Voltage (1.25V)
1670// 10 – Low Voltage (1.35V)
1671// 11 – Reserved
1672// For DDR4
1673// 00 – Reserved
1674// 01 – Reserved
1675// 10 – Reserved
1676// 11 – Normal Voltage (1.2V)
1677// Bit [5:0]
1678// 0x00 – SDRAM
1679// 0x01 – DDR-1 RAM
1680// 0x02 – Rambus
1681// 0x03 – DDR-2 RAM
1682// 0x04 – FBDIMM
1683// 0x05 – DDR-3 RAM
1684// 0x06 – DDR-4 RAM
1685//
1686// Param#3 (DIMM Speed):
1687// Byte 1..2 – DIMM speed in MHz, LSB
1688// Byte 3..6 – DIMM size in Mbytes, LSB
1689//
1690// Param#4 (Module Part Number):
1691// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1692//
1693// Param#5 (Module Serial Number):
1694// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1695//
1696// Param#6 (Module Manufacturer ID):
1697// Byte 1 - Module Manufacturer ID, LSB
1698// Byte 2 - Module Manufacturer ID, MSB
1699//
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301700ipmi::RspType<> ipmiOemQSetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1701 uint8_t, uint8_t dimmIndex,
1702 uint8_t paramSel,
1703 std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001704{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001705 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001706 std::stringstream ss;
1707 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301708 uint8_t len = request.size();
1709 std::string dimmType;
1710 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001711 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301712 if (!hostId)
1713 {
1714 phosphor::logging::log<phosphor::logging::level::ERR>(
1715 "Invalid Host Id received");
1716 return ipmi::responseInvalidCommand();
1717 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001718
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301719 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001720
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301721 if (len < 3 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001722 {
1723 phosphor::logging::log<phosphor::logging::level::ERR>(
1724 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301725 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001726 }
1727
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001728 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301729 ss << (int)dimmIndex;
1730 oemData[dimmInfo][ss.str()][KEY_DIMM_INDEX] = dimmIndex;
1731 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1732 str = bytesToStr(request.data(), len);
1733 oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001734 flushOemData();
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301735 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001736}
1737
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001738// Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO)
1739//----------------------------------------------------------------------
1740// Request:
1741// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1742// Byte 4 – DIMM Index, 0 base
1743// Byte 5 – Parameter Selector
1744// Byte 6..N – Configuration parameter data (see below for Parameters
1745// of DIMM Information)
1746// Response:
1747// Byte 1 – Completion code
1748// Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters
1749// of DIMM Information)
1750//
1751// Param#1 (DIMM Location):
1752// Byte 1 – DIMM Present
1753// Byte 1 – DIMM Present
1754// 01h – Present
1755// FFh – Not Present
1756// Byte 2 – Node Number, 0 base
1757// Byte 3 – Channel Number , 0 base
1758// Byte 4 – DIMM Number , 0 base
1759//
1760// Param#2 (DIMM Type):
1761// Byte 1 – DIMM Type
1762// Bit [7:6]
1763// For DDR3
1764// 00 – Normal Voltage (1.5V)
1765// 01 – Ultra Low Voltage (1.25V)
1766// 10 – Low Voltage (1.35V)
1767// 11 – Reserved
1768// For DDR4
1769// 00 – Reserved
1770// 01 – Reserved
1771// 10 – Reserved
1772// 11 – Normal Voltage (1.2V)
1773// Bit [5:0]
1774// 0x00 – SDRAM
1775// 0x01 – DDR-1 RAM
1776// 0x02 – Rambus
1777// 0x03 – DDR-2 RAM
1778// 0x04 – FBDIMM
1779// 0x05 – DDR-3 RAM
1780// 0x06 – DDR-4 RAM
1781//
1782// Param#3 (DIMM Speed):
1783// Byte 1..2 – DIMM speed in MHz, LSB
1784// Byte 3..6 – DIMM size in Mbytes, LSB
1785//
1786// Param#4 (Module Part Number):
1787// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1788//
1789// Param#5 (Module Serial Number):
1790// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1791//
1792// Param#6 (Module Manufacturer ID):
1793// Byte 1 - Module Manufacturer ID, LSB
1794// Byte 2 - Module Manufacturer ID, MSB
1795//
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301796ipmi::RspType<std::vector<uint8_t>>
1797 ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1798 uint8_t dimmIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001799{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001800 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301801 uint8_t res[MAX_BUF];
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001802 std::stringstream ss;
1803 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301804 std::string dimmType;
1805 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001806 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301807 if (!hostId)
1808 {
1809 phosphor::logging::log<phosphor::logging::level::ERR>(
1810 "Invalid Host Id received");
1811 return ipmi::responseInvalidCommand();
1812 }
1813 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001814
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301815 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001816 {
1817 phosphor::logging::log<phosphor::logging::level::ERR>(
1818 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301819 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001820 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001821 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301822 ss << (int)dimmIndex;
1823 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1824 if (oemData[dimmInfo].find(ss.str()) == oemData[dimmInfo].end())
1825 return ipmi::responseCommandNotAvailable();
1826 if (oemData[dimmInfo][ss.str()].find(dimmInfoKey[paramSel]) ==
1827 oemData[dimmInfo][ss.str()].end())
1828 return ipmi::responseCommandNotAvailable();
1829 str = oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]];
1830 int data_length = strToBytes(str, res);
1831 std::vector<uint8_t> response(&res[0], &res[data_length]);
1832 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001833}
1834
1835//----------------------------------------------------------------------
1836// Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO)
1837//----------------------------------------------------------------------
1838// BIOS issue this command to provide HDD information to BMC.
1839//
1840// BIOS just can get information by standard ATA / SMART command for
1841// OB SATA controller.
1842// BIOS can get
1843// 1. Serial Number
1844// 2. Model Name
1845// 3. HDD FW Version
1846// 4. HDD Capacity
1847// 5. HDD WWN
1848//
1849// Use Get HDD info Param #5 to know the MAX HDD info index.
1850//
1851// Request:
1852// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1853// Byte 4 –
1854// [7:4] Reserved
1855// [3:0] HDD Controller Type
1856// 0x00 – BIOS
1857// 0x01 – Expander
1858// 0x02 – LSI
1859// Byte 5 – HDD Info Index, 0 base
1860// Byte 6 – Parameter Selector
1861// Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD
1862// Information)
1863//
1864// Response:
1865// Byte 1 – Completion Code
1866//
1867// Param#0 (HDD Location):
1868// Byte 1 – Controller
1869// [7:3] Device Number
1870// [2:0] Function Number
1871// For Intel C610 series (Wellsburg)
1872// D31:F2 (0xFA) – SATA control 1
1873// D31:F5 (0xFD) – SATA control 2
1874// D17:F4 (0x8C) – sSata control
1875// Byte 2 – Port Number
1876// Byte 3 – Location (0xFF: No HDD Present)
1877// BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param
1878// #1~4, #6, #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if
1879// the HDD present. BMC or other people who know the HDD location has
1880// responsibility for update Location info
1881//
1882// Param#1 (Serial Number):
1883// Bytes 1..33: HDD Serial Number
1884//
1885// Param#2 (Model Name):
1886// Byte 1..33 – HDD Model Name
1887//
1888// Param#3 (HDD FW Version):
1889// Byte 1..17 –HDD FW version
1890//
1891// Param#4 (Capacity):
1892// Byte 1..4 –HDD Block Size, LSB
1893// Byte 5..12 - HDD Block Number, LSB
1894// HDD Capacity = HDD Block size * HDD BLock number (Unit Byte)
1895//
1896// Param#5 (Max HDD Quantity):
1897// Byte 1 - Max HDD Quantity
1898// Max supported port numbers in this PCH
1899//
1900// Param#6 (HDD Type)
1901// Byte 1 – HDD Type
1902// 0h – Reserved
1903// 1h – SAS
1904// 2h – SATA
1905// 3h – PCIE SSD (NVME)
1906//
1907// Param#7 (HDD WWN)
1908// Data 1...8: HDD World Wide Name, LSB
1909//
Willy Tue39f9392022-06-15 13:24:20 -07001910ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
1911 ipmi_request_t request, ipmi_response_t,
1912 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001913{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001914 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1915 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001916 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1917 std::stringstream ss;
1918 std::string str;
1919 uint8_t len = *data_len;
1920
1921 *data_len = 0;
1922
1923 /* check for requested data params */
1924 if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam ||
1925 ctrlType > 2)
1926 {
1927 phosphor::logging::log<phosphor::logging::level::ERR>(
1928 "Invalid parameter received");
1929 return IPMI_CC_PARM_OUT_OF_RANGE;
1930 }
1931
1932 len = len - 6; // Get Actual data length
1933
1934 ss << std::hex;
1935 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1936 oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType;
1937 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] =
1938 req->hddIndex;
1939
1940 str = bytesToStr(req->data, len);
1941 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
1942 [driveInfoKey[req->paramSel]] = str.c_str();
1943 flushOemData();
1944
1945 return IPMI_CC_OK;
1946}
1947
1948//----------------------------------------------------------------------
1949// Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO)
1950//----------------------------------------------------------------------
1951// BMC needs to check HDD presented or not first. If NOT presented, return
1952// completion code 0xD5.
1953//
1954// Request:
1955// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1956// Byte 4 –
1957//[7:4] Reserved
1958//[3:0] HDD Controller Type
1959// 0x00 – BIOS
1960// 0x01 – Expander
1961// 0x02 – LSI
1962// Byte 5 – HDD Index, 0 base
1963// Byte 6 – Parameter Selector (See Above Set HDD Information)
1964// Response:
1965// Byte 1 – Completion Code
1966// 0xD5 – Not support in current status (HDD Not Present)
1967// Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD
1968// Information)
1969//
Willy Tue39f9392022-06-15 13:24:20 -07001970ipmi_ret_t ipmiOemQGetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001971 ipmi_request_t request,
1972 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -07001973 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001974{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001975 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1976 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
1977 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001978 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1979 std::stringstream ss;
1980 std::string str;
1981
1982 *data_len = 0;
1983
1984 /* check for requested data params */
1985 if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2)
1986 {
1987 phosphor::logging::log<phosphor::logging::level::ERR>(
1988 "Invalid parameter received");
1989 return IPMI_CC_PARM_OUT_OF_RANGE;
1990 }
1991
1992 if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) ==
1993 oemData[KEY_Q_DRIVE_INFO].end())
1994 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1995
1996 ss << std::hex;
1997 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1998
1999 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) ==
2000 oemData[KEY_Q_DRIVE_INFO].end())
2001 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
2002
2003 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find(
2004 dimmInfoKey[req->paramSel]) ==
2005 oemData[KEY_Q_DRIVE_INFO][ss.str()].end())
2006 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
2007
2008 str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
2009 [dimmInfoKey[req->paramSel]];
2010 *data_len = strToBytes(str, res);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002011
2012 return IPMI_CC_OK;
2013}
2014
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302015/* Helper function for sending DCMI commands to ME/BIC and
2016 * getting response back
2017 */
2018ipmi::RspType<std::vector<uint8_t>>
2019 sendDCMICmd([[maybe_unused]] ipmi::Context::ptr ctx,
2020 [[maybe_unused]] uint8_t cmd, std::vector<uint8_t>& cmdData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002021{
2022 std::vector<uint8_t> respData;
2023
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302024#if BIC_ENABLED
2025
2026 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
2027
2028 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, cmdData, respData))
2029 {
2030 return ipmi::responseUnspecifiedError();
2031 }
2032
2033#else
2034
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002035 /* Add group id as first byte to request for ME command */
2036 cmdData.insert(cmdData.begin(), groupDCMI);
2037
2038 if (sendMeCmd(ipmi::netFnGroup, cmd, cmdData, respData))
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302039 {
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002040 return ipmi::responseUnspecifiedError();
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302041 }
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002042
2043 /* Remove group id as first byte as it will be added by IPMID */
2044 respData.erase(respData.begin());
2045
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302046#endif
2047
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002048 return ipmi::responseSuccess(std::move(respData));
2049}
2050
2051/* DCMI Command handellers. */
2052
2053ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302054 ipmiOemDCMIGetPowerReading(ipmi::Context::ptr ctx,
2055 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002056{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302057 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerReading, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002058}
2059
2060ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302061 ipmiOemDCMIGetPowerLimit(ipmi::Context::ptr ctx,
2062 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002063{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302064 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002065}
2066
2067ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302068 ipmiOemDCMISetPowerLimit(ipmi::Context::ptr ctx,
2069 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002070{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302071 return sendDCMICmd(ctx, ipmi::dcmi::cmdSetPowerLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002072}
2073
2074ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302075 ipmiOemDCMIApplyPowerLimit(ipmi::Context::ptr ctx,
2076 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002077{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302078 return sendDCMICmd(ctx, ipmi::dcmi::cmdActDeactivatePwrLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002079}
2080
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002081static void registerOEMFunctions(void)
2082{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002083 /* Get OEM data from json file */
2084 std::ifstream file(JSON_OEM_DATA_FILE);
2085 if (file)
Vijay Khemkafeaa9812019-08-27 15:08:08 -07002086 {
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002087 file >> oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -07002088 file.close();
2089 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002090
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002091 phosphor::logging::log<phosphor::logging::level::INFO>(
2092 "Registering OEM commands");
Vijay Khemka7c0aea42020-03-05 13:31:53 -08002093
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002094 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO,
2095 NULL, ipmiOemDbgGetFrameInfo,
2096 PRIVILEGE_USER); // get debug frame info
2097 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ,
2098 CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL,
2099 ipmiOemDbgGetUpdFrames,
2100 PRIVILEGE_USER); // get debug updated frames
2101 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC,
2102 NULL, ipmiOemDbgGetPostDesc,
2103 PRIVILEGE_USER); // get debug post description
2104 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC,
2105 NULL, ipmiOemDbgGetGpioDesc,
2106 PRIVILEGE_USER); // get debug gpio description
2107 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA,
2108 NULL, ipmiOemDbgGetFrameData,
2109 PRIVILEGE_USER); // get debug frame data
2110 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL,
2111 NULL, ipmiOemDbgGetCtrlPanel,
2112 PRIVILEGE_USER); // get debug control panel
2113 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL,
2114 ipmiOemSetDimmInfo,
2115 PRIVILEGE_USER); // Set Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002116 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
2117 ipmiOemGetBoardID,
2118 PRIVILEGE_USER); // Get Board ID
Bonnie Lo4ae63e72023-02-09 15:27:54 +08002119 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemOne,
2120 CMD_OEM_GET_80PORT_RECORD, ipmi::Privilege::User,
2121 ipmiOemGet80PortRecord); // Get 80 Port Record
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002122 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL,
2123 ipmiOemSetMachineCfgInfo,
2124 PRIVILEGE_USER); // Set Machine Config Info
2125 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL,
2126 ipmiOemSetPostStart,
2127 PRIVILEGE_USER); // Set POST start
2128 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL,
2129 ipmiOemSetPostEnd,
2130 PRIVILEGE_USER); // Set POST End
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002131 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
2132 ipmiOemSetPPINInfo,
2133 PRIVILEGE_USER); // Set PPIN Info
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302134#if BIC_ENABLED
2135
2136 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2137 ipmi::cmdSetSystemGuid, ipmi::Privilege::User,
2138 ipmiOemSetSystemGuid);
2139#else
2140
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07002141 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL,
2142 ipmiOemSetSystemGuid,
2143 PRIVILEGE_USER); // Set System GUID
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302144#endif
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002145 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
2146 ipmiOemSetAdrTrigger,
2147 PRIVILEGE_USER); // Set ADR Trigger
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002148 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL,
2149 ipmiOemSetBiosFlashInfo,
2150 PRIVILEGE_USER); // Set Bios Flash Info
2151 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr,
2152 PRIVILEGE_USER); // Set PPR
2153 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr,
2154 PRIVILEGE_USER); // Get PPR
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002155 /* FB OEM QC Commands */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05302156 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2157 CMD_OEM_Q_SET_PROC_INFO, ipmi::Privilege::User,
2158 ipmiOemQSetProcInfo); // Set Proc Info
2159 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2160 CMD_OEM_Q_GET_PROC_INFO, ipmi::Privilege::User,
2161 ipmiOemQGetProcInfo); // Get Proc Info
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05302162 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2163 ipmi::cmdSetQDimmInfo, ipmi::Privilege::User,
2164 ipmiOemQSetDimmInfo); // Set Dimm Info
2165 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2166 ipmi::cmdGetQDimmInfo, ipmi::Privilege::User,
2167 ipmiOemQGetDimmInfo); // Get Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002168 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL,
2169 ipmiOemQSetDriveInfo,
2170 PRIVILEGE_USER); // Set Drive Info
2171 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL,
2172 ipmiOemQGetDriveInfo,
2173 PRIVILEGE_USER); // Get Drive Info
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002174
2175 /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */
2176 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2177 ipmi::dcmi::cmdGetPowerReading,
2178 ipmi::Privilege::User,
2179 ipmiOemDCMIGetPowerReading); // Get Power Reading
2180
2181 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2182 ipmi::dcmi::cmdGetPowerLimit,
2183 ipmi::Privilege::User,
2184 ipmiOemDCMIGetPowerLimit); // Get Power Limit
2185
2186 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2187 ipmi::dcmi::cmdSetPowerLimit,
2188 ipmi::Privilege::Operator,
2189 ipmiOemDCMISetPowerLimit); // Set Power Limit
2190
2191 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2192 ipmi::dcmi::cmdActDeactivatePwrLimit,
2193 ipmi::Privilege::Operator,
2194 ipmiOemDCMIApplyPowerLimit); // Apply Power Limit
2195
Jayashree-Df0cf6652020-11-30 11:03:30 +05302196 /* FB OEM BOOT ORDER COMMANDS */
2197 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2198 CMD_OEM_GET_BOOT_ORDER, ipmi::Privilege::User,
2199 ipmiOemGetBootOrder); // Get Boot Order
2200
2201 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2202 CMD_OEM_SET_BOOT_ORDER, ipmi::Privilege::User,
2203 ipmiOemSetBootOrder); // Set Boot Order
2204
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002205 return;
2206}
2207
2208} // namespace ipmi