blob: 080c3407521a28d2a8d3ea7fb64970eca6b0fb3a [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
Cosmo Chou99d42b62024-08-15 10:42:47 +080020#include <boost/crc.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050021#include <commandutils.hpp>
22#include <ipmid/api-types.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070023#include <ipmid/api.hpp>
Vijay Khemka1b6fae32019-03-25 17:43:01 -070024#include <ipmid/utils.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070025#include <nlohmann/json.hpp>
26#include <oemcommands.hpp>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080027#include <phosphor-logging/log.hpp>
28#include <sdbusplus/bus.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050029#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
30#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
31#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053032
Vijay Khemka63c99be2020-05-27 19:14:35 -070033#include <array>
34#include <cstring>
35#include <fstream>
36#include <iomanip>
37#include <iostream>
Patrick Williams2405ae92023-05-10 07:50:09 -050038#include <regex>
Vijay Khemka63c99be2020-05-27 19:14:35 -070039#include <sstream>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080040#include <string>
41#include <vector>
42
43#define SIZE_IANA_ID 3
44
45namespace ipmi
46{
Vijay Khemkaa7231892019-10-11 11:35:05 -070047
48using namespace phosphor::logging;
49
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053050void getSelectorPosition(size_t& position);
Vijay Khemkae7d23d02019-03-08 13:13:40 -080051static void registerOEMFunctions() __attribute__((constructor));
Patrick Williamscd315e02022-07-22 19:26:52 -050052sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
Vijay Khemkae7d23d02019-03-08 13:13:40 -080053static constexpr size_t maxFRUStringLength = 0x3F;
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053054constexpr uint8_t cmdSetSystemGuid = 0xEF;
Vijay Khemkae7d23d02019-03-08 13:13:40 -080055
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +053056constexpr uint8_t cmdSetQDimmInfo = 0x12;
57constexpr uint8_t cmdGetQDimmInfo = 0x13;
58
Cosmo Chou7ab87bb2024-06-28 10:47:44 +080059constexpr ipmi_ret_t ccInvalidParam = 0x80;
60
Vijay Khemka63c99be2020-05-27 19:14:35 -070061int plat_udbg_get_post_desc(uint8_t, uint8_t*, uint8_t, uint8_t*, uint8_t*,
62 uint8_t*);
63int plat_udbg_get_gpio_desc(uint8_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*,
64 uint8_t*);
Patrick Williams5e589482024-07-13 16:18:13 -050065int plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t*, uint8_t*, uint8_t*);
Vijay Khemka63c99be2020-05-27 19:14:35 -070066ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t*,
67 uint8_t*);
68int sendMeCmd(uint8_t, uint8_t, std::vector<uint8_t>&, std::vector<uint8_t>&);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -070069
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053070int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
71 std::vector<uint8_t>&);
72
Vijay Khemkafeaa9812019-08-27 15:08:08 -070073nlohmann::json oemData __attribute__((init_priority(101)));
Vijay Khemka1b6fae32019-03-25 17:43:01 -070074
Cosmo Chou99d42b62024-08-15 10:42:47 +080075constexpr const char* certPath = "/mnt/data/host/bios-rootcert";
76
Vijay Khemkaf2246ce2020-05-27 14:26:35 -070077static constexpr size_t GUID_SIZE = 16;
78// TODO Make offset and location runtime configurable to ensure we
79// can make each define their own locations.
80static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
81static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
Delphine CC Chiu7bb45922023-04-10 13:34:04 +080082void flushOemData();
Vijay Khemkaf2246ce2020-05-27 14:26:35 -070083
Vijay Khemka1b6fae32019-03-25 17:43:01 -070084enum class LanParam : uint8_t
85{
86 INPROGRESS = 0,
87 AUTHSUPPORT = 1,
88 AUTHENABLES = 2,
89 IP = 3,
90 IPSRC = 4,
91 MAC = 5,
92 SUBNET = 6,
93 GATEWAY = 12,
94 VLAN = 20,
95 CIPHER_SUITE_COUNT = 22,
96 CIPHER_SUITE_ENTRIES = 23,
97 IPV6 = 59,
98};
99
Vijay Khemkaa7231892019-10-11 11:35:05 -0700100namespace network
101{
102
103constexpr auto ROOT = "/xyz/openbmc_project/network";
104constexpr auto SERVICE = "xyz.openbmc_project.Network";
105constexpr auto IPV4_TYPE = "ipv4";
106constexpr auto IPV6_TYPE = "ipv6";
107constexpr auto IPV4_PREFIX = "169.254";
108constexpr auto IPV6_PREFIX = "fe80";
109constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
110constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
Potin Lai8d1a81e2022-12-20 11:13:45 +0800111constexpr auto IPV4_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
112constexpr auto IPV6_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
Vijay Khemkaa7231892019-10-11 11:35:05 -0700113
Vijay Khemka63c99be2020-05-27 19:14:35 -0700114bool isLinkLocalIP(const std::string& address)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700115{
116 return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
117}
118
Patrick Williamscd315e02022-07-22 19:26:52 -0500119DbusObjectInfo getIPObject(sdbusplus::bus_t& bus, const std::string& interface,
Vijay Khemka63c99be2020-05-27 19:14:35 -0700120 const std::string& serviceRoot,
Potin Lai8d1a81e2022-12-20 11:13:45 +0800121 const std::string& protocol,
122 const std::string& ethdev)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700123{
Potin Lai8d1a81e2022-12-20 11:13:45 +0800124 auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, ethdev);
Vijay Khemkaa7231892019-10-11 11:35:05 -0700125
126 if (objectTree.empty())
127 {
128 log<level::ERR>("No Object has implemented the IP interface",
129 entry("INTERFACE=%s", interface.c_str()));
130 }
131
132 DbusObjectInfo objectInfo;
133
Vijay Khemka63c99be2020-05-27 19:14:35 -0700134 for (auto& object : objectTree)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700135 {
Patrick Williams010dee02024-08-16 15:19:44 -0400136 auto variant =
137 ipmi::getDbusProperty(bus, object.second.begin()->first,
138 object.first, IP_INTERFACE, "Type");
Potin Lai8d1a81e2022-12-20 11:13:45 +0800139 if (std::get<std::string>(variant) != protocol)
140 {
141 continue;
142 }
143
144 variant = ipmi::getDbusProperty(bus, object.second.begin()->first,
145 object.first, IP_INTERFACE, "Address");
Vijay Khemkaa7231892019-10-11 11:35:05 -0700146
147 objectInfo = std::make_pair(object.first, object.second.begin()->first);
148
149 // if LinkLocalIP found look for Non-LinkLocalIP
150 if (isLinkLocalIP(std::get<std::string>(variant)))
151 {
152 continue;
153 }
154 else
155 {
156 break;
157 }
158 }
159 return objectInfo;
160}
161
162} // namespace network
163
Jayashree-Df0cf6652020-11-30 11:03:30 +0530164namespace boot
165{
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530166using BootSource =
167 sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources;
168using BootMode =
169 sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes;
170using BootType =
171 sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types;
Jayashree-Df0cf6652020-11-30 11:03:30 +0530172
Jayashree-Df0cf6652020-11-30 11:03:30 +0530173using IpmiValue = uint8_t;
174
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530175std::map<IpmiValue, BootSource> sourceIpmiToDbus = {
176 {0x0f, BootSource::Default}, {0x00, BootSource::RemovableMedia},
177 {0x01, BootSource::Network}, {0x02, BootSource::Disk},
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800178 {0x03, BootSource::ExternalMedia}, {0x04, BootSource::RemovableMedia},
179 {0x09, BootSource::Network}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530180
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800181std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x04, BootMode::Setup},
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530182 {0x00, BootMode::Regular}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530183
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530184std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy},
185 {0x01, BootType::EFI}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530186
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530187std::map<std::optional<BootSource>, IpmiValue> sourceDbusToIpmi = {
188 {BootSource::Default, 0x0f},
189 {BootSource::RemovableMedia, 0x00},
190 {BootSource::Network, 0x01},
191 {BootSource::Disk, 0x02},
192 {BootSource::ExternalMedia, 0x03}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530193
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530194std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = {
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800195 {BootMode::Setup, 0x04}, {BootMode::Regular, 0x00}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530196
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530197std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = {
198 {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530199
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800200static constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530201static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
202static constexpr auto bootSourceIntf =
203 "xyz.openbmc_project.Control.Boot.Source";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530204static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530205static constexpr auto bootSourceProp = "BootSource";
206static constexpr auto bootModeProp = "BootMode";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530207static constexpr auto bootTypeProp = "BootType";
Delphine CC Chiuc0f918b2023-03-22 14:48:04 +0800208static constexpr auto bootEnableProp = "Enabled";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530209
Jayashree-Df0cf6652020-11-30 11:03:30 +0530210std::tuple<std::string, std::string> objPath(size_t id)
211{
212 std::string hostName = "host" + std::to_string(id);
Patrick Williams010dee02024-08-16 15:19:44 -0400213 std::string bootObjPath =
214 "/xyz/openbmc_project/control/" + hostName + "/boot";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530215 return std::make_tuple(std::move(bootObjPath), std::move(hostName));
216}
217
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800218/* Helper functions to set boot order */
219void setBootOrder(std::string bootObjPath, const std::vector<uint8_t>& bootSeq,
220 std::string bootOrderKey)
221{
222 if (bootSeq.size() != SIZE_BOOT_ORDER)
223 {
224 phosphor::logging::log<phosphor::logging::level::ERR>(
225 "Invalid Boot order length received");
226 return;
227 }
228
229 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
230
231 uint8_t mode = bootSeq.front();
232
233 // SETTING BOOT MODE PROPERTY
234 uint8_t bootModeBit = mode & 0x04;
235 auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit);
236
237 std::string bootOption =
238 sdbusplus::message::convert_to_string<boot::BootMode>(bootValue);
239
Patrick Williams010dee02024-08-16 15:19:44 -0400240 std::string service =
241 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800242 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
243 ipmi::boot::bootModeProp, bootOption);
244
245 // SETTING BOOT SOURCE PROPERTY
246 auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(bootSeq.at(1));
247 std::string bootSource =
248 sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder);
249
250 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
251 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
252 ipmi::boot::bootSourceProp, bootSource);
253
254 // SETTING BOOT TYPE PROPERTY
255 uint8_t bootTypeBit = mode & 0x01;
256 auto bootTypeVal = ipmi::boot::typeIpmiToDbus.at(bootTypeBit);
257
258 std::string bootType =
259 sdbusplus::message::convert_to_string<boot::BootType>(bootTypeVal);
260
261 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
262
263 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
264 ipmi::boot::bootTypeProp, bootType);
265
266 // Set the valid bit to boot enabled property
267 service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
268
269 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf,
270 ipmi::boot::bootEnableProp,
271 (mode & BOOT_MODE_BOOT_FLAG) ? true : false);
272
273 nlohmann::json bootMode;
274
275 bootMode["UEFI"] = (mode & BOOT_MODE_UEFI) ? true : false;
276 bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR) ? true : false;
277 bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT) ? true : false;
278 bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG) ? true : false;
279 oemData[bootOrderKey][KEY_BOOT_MODE] = bootMode;
280
281 /* Initialize boot sequence array */
282 oemData[bootOrderKey][KEY_BOOT_SEQ] = {};
283 for (size_t i = 1; i < SIZE_BOOT_ORDER; i++)
284 {
285 if (bootSeq.at(i) >= BOOT_SEQ_ARRAY_SIZE)
286 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = "NA";
287 else
288 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] =
289 bootSeqDefine[bootSeq.at(i)];
290 }
291
292 flushOemData();
293}
294
295void getBootOrder(std::string bootObjPath, std::vector<uint8_t>& bootSeq,
296 std::string hostName)
297{
298 if (oemData.find(hostName) == oemData.end())
299 {
300 /* Return default boot order 0100090203ff */
301 bootSeq.push_back(BOOT_MODE_UEFI);
302 bootSeq.push_back(static_cast<uint8_t>(bootMap["USB_DEV"]));
303 bootSeq.push_back(static_cast<uint8_t>(bootMap["NET_IPV6"]));
304 bootSeq.push_back(static_cast<uint8_t>(bootMap["SATA_HDD"]));
305 bootSeq.push_back(static_cast<uint8_t>(bootMap["SATA_CD"]));
306 bootSeq.push_back(0xff);
307
308 phosphor::logging::log<phosphor::logging::level::INFO>(
309 "Set default boot order");
310 setBootOrder(bootObjPath, bootSeq, hostName);
311 return;
312 }
313
314 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
315
316 // GETTING PROPERTY OF MODE INTERFACE
317
Patrick Williams010dee02024-08-16 15:19:44 -0400318 std::string service =
319 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
320 Value variant =
321 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
322 ipmi::boot::bootModeProp);
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800323
324 auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>(
325 std::get<std::string>(variant));
326
327 uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
328
329 // GETTING PROPERTY OF TYPE INTERFACE
330
331 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
Patrick Williams010dee02024-08-16 15:19:44 -0400332 variant =
333 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
334 ipmi::boot::bootTypeProp);
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800335
336 auto bootType = sdbusplus::message::convert_from_string<boot::BootType>(
337 std::get<std::string>(variant));
338
339 // Get the valid bit to boot enabled property
340 service = getService(*dbus, ipmi::boot::bootEnableIntf, bootObjPath);
Patrick Williams010dee02024-08-16 15:19:44 -0400341 variant =
342 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf,
343 ipmi::boot::bootEnableProp);
Delphine CC Chiu7bb45922023-04-10 13:34:04 +0800344
345 bool validFlag = std::get<bool>(variant);
346
347 uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
348
349 bootSeq.push_back(bootOption | bootTypeVal);
350
351 if (validFlag)
352 {
353 bootSeq.front() |= BOOT_MODE_BOOT_FLAG;
354 }
355
356 nlohmann::json bootModeJson = oemData[hostName][KEY_BOOT_MODE];
357 if (bootModeJson["CMOS_CLR"])
358 bootSeq.front() |= BOOT_MODE_CMOS_CLR;
359
360 for (int i = 1; i < SIZE_BOOT_ORDER; i++)
361 {
362 std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
363 if (bootMap.find(seqStr) != bootMap.end())
364 bootSeq.push_back(bootMap[seqStr]);
365 else
366 bootSeq.push_back(0xff);
367 }
368}
369
Jayashree-Df0cf6652020-11-30 11:03:30 +0530370} // namespace boot
371
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700372//----------------------------------------------------------------------
373// Helper functions for storing oem data
374//----------------------------------------------------------------------
375
376void flushOemData()
377{
378 std::ofstream file(JSON_OEM_DATA_FILE);
379 file << oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -0700380 file.close();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700381 return;
382}
383
Vijay Khemka63c99be2020-05-27 19:14:35 -0700384std::string bytesToStr(uint8_t* byte, int len)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700385{
386 std::stringstream ss;
387 int i;
388
389 ss << std::hex;
390 for (i = 0; i < len; i++)
391 {
392 ss << std::setw(2) << std::setfill('0') << (int)byte[i];
393 }
394
395 return ss.str();
396}
397
Vijay Khemka63c99be2020-05-27 19:14:35 -0700398int strToBytes(std::string& str, uint8_t* data)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700399{
400 std::string sstr;
Willy Tue39f9392022-06-15 13:24:20 -0700401 size_t i;
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700402
403 for (i = 0; i < (str.length()) / 2; i++)
404 {
405 sstr = str.substr(i * 2, 2);
406 data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16);
407 }
408 return i;
409}
410
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530411int readDimmType(std::string& data, uint8_t param)
412{
413 nlohmann::json dimmObj;
414 /* Get dimm type names stored in json file */
415 std::ifstream file(JSON_DIMM_TYPE_FILE);
416 if (file)
417 {
418 file >> dimmObj;
419 file.close();
420 }
421 else
422 {
423 phosphor::logging::log<phosphor::logging::level::ERR>(
424 "DIMM type names file not found",
425 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
426 return -1;
427 }
428
429 std::string dimmKey = "dimm_type" + std::to_string(param);
430 auto obj = dimmObj[dimmKey]["short_name"];
431 data = obj;
432 return 0;
433}
434
Vijay Khemka63c99be2020-05-27 19:14:35 -0700435ipmi_ret_t getNetworkData(uint8_t lan_param, char* data)
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700436{
437 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Williamscd315e02022-07-22 19:26:52 -0500438 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700439
440 const std::string ethdevice = "eth0";
441
442 switch (static_cast<LanParam>(lan_param))
443 {
Vijay Khemkad1194022020-05-27 18:58:33 -0700444 case LanParam::IP:
445 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700446 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700447 auto ipObjectInfo = ipmi::network::getIPObject(
Potin Lai8d1a81e2022-12-20 11:13:45 +0800448 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
449 ipmi::network::IPV4_PROTOCOL, ethdevice);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700450
451 auto properties = ipmi::getAllDbusProperties(
452 bus, ipObjectInfo.second, ipObjectInfo.first,
453 ipmi::network::IP_INTERFACE);
454
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500455 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700456
457 std::strcpy(data, ipaddress.c_str());
458 }
459 break;
460
Vijay Khemkad1194022020-05-27 18:58:33 -0700461 case LanParam::IPV6:
462 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700463 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700464 auto ipObjectInfo = ipmi::network::getIPObject(
Potin Lai8d1a81e2022-12-20 11:13:45 +0800465 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
466 ipmi::network::IPV6_PROTOCOL, ethdevice);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700467
468 auto properties = ipmi::getAllDbusProperties(
469 bus, ipObjectInfo.second, ipObjectInfo.first,
470 ipmi::network::IP_INTERFACE);
471
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500472 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700473
474 std::strcpy(data, ipaddress.c_str());
475 }
476 break;
477
Vijay Khemkad1194022020-05-27 18:58:33 -0700478 case LanParam::MAC:
479 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700480 std::string macAddress;
481 auto macObjectInfo =
482 ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE,
483 ipmi::network::ROOT, ethdevice);
484
485 auto variant = ipmi::getDbusProperty(
486 bus, macObjectInfo.second, macObjectInfo.first,
487 ipmi::network::MAC_INTERFACE, "MACAddress");
488
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500489 macAddress = std::get<std::string>(variant);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700490
491 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
492 (data), (data + 1), (data + 2), (data + 3), (data + 4),
493 (data + 5));
494 std::strcpy(data, macAddress.c_str());
495 }
496 break;
497
498 default:
499 rc = IPMI_CC_PARM_OUT_OF_RANGE;
500 }
501 return rc;
502}
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800503
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530504bool isMultiHostPlatform()
505{
506 bool platform;
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530507 if (hostInstances == "0")
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530508 {
509 platform = false;
510 }
511 else
512 {
513 platform = true;
514 }
515 return platform;
516}
517
Daniel Hsud8d95a32024-05-27 16:05:25 +0800518// return "" equals failed
519std::string getMotherBoardFruPath()
520{
521 std::vector<std::string> paths;
522 static constexpr const auto depth = 0;
523 sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection());
524
525 auto mapperCall = dbus.new_method_call(
526 "xyz.openbmc_project.ObjectMapper",
527 "/xyz/openbmc_project/object_mapper",
528 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
529 static constexpr auto interface = {
530 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
531
532 mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface);
533 try
534 {
535 auto reply = dbus.call(mapperCall);
536 reply.read(paths);
537 }
538 catch (sdbusplus::exception_t& e)
539 {
540 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
541 return "";
542 }
543
544 for (const auto& path : paths)
545 {
546 return path;
547 }
548
549 return "";
550}
551
552// return "" equals failed
553std::string getMotherBoardFruName()
554{
555 std::string path = getMotherBoardFruPath();
556 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
557 std::string service = "xyz.openbmc_project.EntityManager";
558
559 try
560 {
561 auto value = ipmi::getDbusProperty(
562 *dbus, service, path, "xyz.openbmc_project.Inventory.Item.Board",
563 "Name");
564 return std::get<std::string>(value);
565 }
566 catch (sdbusplus::exception_t& e)
567 {
568 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
569 return "";
570 }
571}
572
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800573// return code: 0 successful
Vijay Khemka63c99be2020-05-27 19:14:35 -0700574int8_t getFruData(std::string& data, std::string& name)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800575{
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530576 size_t pos;
577 static constexpr const auto depth = 0;
578 std::vector<std::string> paths;
579 std::string machinePath;
Daniel Hsud8d95a32024-05-27 16:05:25 +0800580 std::string baseBoard = getMotherBoardFruPath();
581 baseBoard = baseBoard.empty() ? "Baseboard" : baseBoard;
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530582
583 bool platform = isMultiHostPlatform();
584 if (platform == true)
585 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530586 getSelectorPosition(pos);
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530587 }
588
589 sd_bus* bus = NULL;
590 int ret = sd_bus_default_system(&bus);
591 if (ret < 0)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800592 {
593 phosphor::logging::log<phosphor::logging::level::ERR>(
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530594 "Failed to connect to system bus",
595 phosphor::logging::entry("ERRNO=0x%X", -ret));
596 sd_bus_unref(bus);
597 return -1;
598 }
Patrick Williamscd315e02022-07-22 19:26:52 -0500599 sdbusplus::bus_t dbus(bus);
Patrick Williams010dee02024-08-16 15:19:44 -0400600 auto mapperCall = dbus.new_method_call(
601 "xyz.openbmc_project.ObjectMapper",
602 "/xyz/openbmc_project/object_mapper",
603 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530604 static constexpr std::array<const char*, 1> interface = {
605 "xyz.openbmc_project.Inventory.Decorator.Asset"};
606 mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface);
607
608 try
609 {
610 auto reply = dbus.call(mapperCall);
611 reply.read(paths);
612 }
613 catch (sdbusplus::exception_t& e)
614 {
615 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800616 return -1;
617 }
618
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530619 for (const auto& path : paths)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800620 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530621 if (platform == true)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800622 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530623 if (pos == BMC_POS)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800624 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530625 machinePath = baseBoard;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800626 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530627 else
628 {
629 machinePath = "_" + std::to_string(pos);
630 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800631 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530632 else
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800633 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530634 machinePath = baseBoard;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800635 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530636
637 auto found = path.find(machinePath);
Patrick Williams123cbcc2022-06-24 06:13:59 -0500638 if (found == std::string::npos)
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530639 {
640 continue;
641 }
642
643 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
644 std::string service = getService(
645 *dbus, "xyz.openbmc_project.Inventory.Decorator.Asset", path);
646
647 auto Value = ipmi::getDbusProperty(
648 *dbus, service, path,
649 "xyz.openbmc_project.Inventory.Decorator.Asset", name);
650
651 data = std::get<std::string>(Value);
652 return 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800653 }
654 return -1;
655}
656
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530657int8_t sysConfig(std::vector<std::string>& data, size_t pos)
658{
659 nlohmann::json sysObj;
660 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(pos);
661 std::string result, typeName;
662 uint8_t res[MAX_BUF];
663
664 /* Get sysConfig data stored in json file */
665 std::ifstream file(JSON_OEM_DATA_FILE);
666 if (file)
667 {
668 file >> sysObj;
669 file.close();
670 }
671 else
672 {
673 phosphor::logging::log<phosphor::logging::level::ERR>(
674 "oemData file not found",
675 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
676 return -1;
677 }
678
679 if (sysObj.find(dimmInfo) == sysObj.end())
680 {
681 phosphor::logging::log<phosphor::logging::level::ERR>(
682 "sysconfig key not available",
683 phosphor::logging::entry("SYS_JSON_KEY=%s", dimmInfo.c_str()));
684 return -1;
685 }
686 /* Get dimm type names stored in json file */
687 nlohmann::json dimmObj;
688 std::ifstream dimmFile(JSON_DIMM_TYPE_FILE);
689 if (file)
690 {
691 dimmFile >> dimmObj;
692 dimmFile.close();
693 }
694 else
695 {
696 phosphor::logging::log<phosphor::logging::level::ERR>(
697 "DIMM type names file not found",
698 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
699 return -1;
700 }
701 std::vector<std::string> a;
702 for (auto& j : dimmObj.items())
703 {
704 std::string name = j.key();
705 a.push_back(name);
706 }
707
708 uint8_t len = a.size();
709 for (uint8_t ii = 0; ii < len; ii++)
710 {
711 std::string indKey = std::to_string(ii);
712 std::string speedSize = sysObj[dimmInfo][indKey][DIMM_SPEED];
713 strToBytes(speedSize, res);
714 auto speed = (res[1] << 8 | res[0]);
715 size_t dimmSize = ((res[3] << 8 | res[2]) / 1000);
716
717 if (dimmSize == 0)
718 {
719 std::cerr << "Dimm information not available for slot_" +
720 std::to_string(ii)
721 << std::endl;
722 continue;
723 }
724 std::string type = sysObj[dimmInfo][indKey][DIMM_TYPE];
725 std::string dualInlineMem = sysObj[dimmInfo][indKey][KEY_DIMM_TYPE];
726 strToBytes(type, res);
727 size_t dimmType = res[0];
728 if (dimmVenMap.find(dimmType) == dimmVenMap.end())
729 {
730 typeName = "unknown";
731 }
732 else
733 {
734 typeName = dimmVenMap[dimmType];
735 }
736 result = dualInlineMem + "/" + typeName + "/" + std::to_string(speed) +
737 "MHz" + "/" + std::to_string(dimmSize) + "GB";
738 data.push_back(result);
739 }
740 return 0;
741}
742
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +0530743int8_t procInfo(std::string& result, size_t pos)
744{
745 std::vector<char> data;
746 uint8_t res[MAX_BUF];
747 std::string procIndex = "00";
748 nlohmann::json proObj;
749 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(pos);
750 /* Get processor data stored in json file */
751 std::ifstream file(JSON_OEM_DATA_FILE);
752 if (file)
753 {
754 file >> proObj;
755 file.close();
756 }
757 else
758 {
759 phosphor::logging::log<phosphor::logging::level::ERR>(
760 "oemData file not found",
761 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
762 return -1;
763 }
764 if (proObj.find(procInfo) == proObj.end())
765 {
766 phosphor::logging::log<phosphor::logging::level::ERR>(
767 "processor info key not available",
768 phosphor::logging::entry("PROC_JSON_KEY=%s", procInfo.c_str()));
769 return -1;
770 }
771 std::string procName = proObj[procInfo][procIndex][KEY_PROC_NAME];
772 std::string basicInfo = proObj[procInfo][procIndex][KEY_BASIC_INFO];
773 // Processor Product Name
774 strToBytes(procName, res);
775 data.assign(reinterpret_cast<char*>(&res),
776 reinterpret_cast<char*>(&res) + sizeof(res));
777
778 std::string s(data.begin(), data.end());
779 std::regex regex(" ");
780 std::vector<std::string> productName(
781 std::sregex_token_iterator(s.begin(), s.end(), regex, -1),
782 std::sregex_token_iterator());
783
784 // Processor core and frequency
785 strToBytes(basicInfo, res);
786 uint16_t coreNum = res[0];
787 double procFrequency = (float)(res[4] << 8 | res[3]) / 1000;
788 result = "CPU:" + productName[2] + "/" + std::to_string(procFrequency) +
789 "GHz" + "/" + std::to_string(coreNum) + "c";
790 return 0;
791}
792
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800793typedef struct
794{
795 uint8_t cur_power_state;
796 uint8_t last_power_event;
797 uint8_t misc_power_state;
798 uint8_t front_panel_button_cap_status;
799} ipmi_get_chassis_status_t;
800
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800801//----------------------------------------------------------------------
802// Get Debug Frame Info
803//----------------------------------------------------------------------
Patrick Williams010dee02024-08-16 15:19:44 -0400804ipmi_ret_t ipmiOemDbgGetFrameInfo(
805 ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
806 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800807{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700808 uint8_t* req = reinterpret_cast<uint8_t*>(request);
809 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Peter Yinb340aa22024-07-08 16:07:55 +0800810 uint8_t num_frames = debugCardFrameSize;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800811
812 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
813 res[SIZE_IANA_ID] = num_frames;
814 *data_len = SIZE_IANA_ID + 1;
815
816 return IPMI_CC_OK;
817}
818
819//----------------------------------------------------------------------
820// Get Debug Updated Frames
821//----------------------------------------------------------------------
Patrick Williams010dee02024-08-16 15:19:44 -0400822ipmi_ret_t ipmiOemDbgGetUpdFrames(
823 ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
824 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800825{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700826 uint8_t* req = reinterpret_cast<uint8_t*>(request);
827 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800828 uint8_t num_updates = 3;
829 *data_len = 4;
830
831 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
832 res[SIZE_IANA_ID] = num_updates;
833 *data_len = SIZE_IANA_ID + num_updates + 1;
834 res[SIZE_IANA_ID + 1] = 1; // info page update
835 res[SIZE_IANA_ID + 2] = 2; // cri sel update
836 res[SIZE_IANA_ID + 3] = 3; // cri sensor update
837
838 return IPMI_CC_OK;
839}
840
841//----------------------------------------------------------------------
842// Get Debug POST Description
843//----------------------------------------------------------------------
Patrick Williams010dee02024-08-16 15:19:44 -0400844ipmi_ret_t ipmiOemDbgGetPostDesc(
845 ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
846 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800847{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700848 uint8_t* req = reinterpret_cast<uint8_t*>(request);
849 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800850 uint8_t index = 0;
851 uint8_t next = 0;
852 uint8_t end = 0;
853 uint8_t phase = 0;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700854 uint8_t descLen = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800855 int ret;
856
857 index = req[3];
858 phase = req[4];
859
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700860 ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800861 if (ret)
862 {
863 memcpy(res, req, SIZE_IANA_ID); // IANA ID
864 *data_len = SIZE_IANA_ID;
865 return IPMI_CC_UNSPECIFIED_ERROR;
866 }
867
868 memcpy(res, req, SIZE_IANA_ID); // IANA ID
869 res[3] = index;
870 res[4] = next;
871 res[5] = phase;
872 res[6] = end;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700873 res[7] = descLen;
874 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800875
876 return IPMI_CC_OK;
877}
878
879//----------------------------------------------------------------------
880// Get Debug GPIO Description
881//----------------------------------------------------------------------
Patrick Williams010dee02024-08-16 15:19:44 -0400882ipmi_ret_t ipmiOemDbgGetGpioDesc(
883 ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
884 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800885{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700886 uint8_t* req = reinterpret_cast<uint8_t*>(request);
887 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800888
Vijay Khemka38183d62019-08-28 16:19:33 -0700889 uint8_t index = 0;
890 uint8_t next = 0;
891 uint8_t level = 0;
892 uint8_t pinDef = 0;
893 uint8_t descLen = 0;
894 int ret;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800895
Vijay Khemka38183d62019-08-28 16:19:33 -0700896 index = req[3];
897
898 ret = plat_udbg_get_gpio_desc(index, &next, &level, &pinDef, &descLen,
899 &res[8]);
900 if (ret)
901 {
902 memcpy(res, req, SIZE_IANA_ID); // IANA ID
903 *data_len = SIZE_IANA_ID;
904 return IPMI_CC_UNSPECIFIED_ERROR;
905 }
906
907 memcpy(res, req, SIZE_IANA_ID); // IANA ID
908 res[3] = index;
909 res[4] = next;
910 res[5] = level;
911 res[6] = pinDef;
912 res[7] = descLen;
913 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800914
915 return IPMI_CC_OK;
916}
917
918//----------------------------------------------------------------------
919// Get Debug Frame Data
920//----------------------------------------------------------------------
Patrick Williams010dee02024-08-16 15:19:44 -0400921ipmi_ret_t ipmiOemDbgGetFrameData(
922 ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
923 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800924{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700925 uint8_t* req = reinterpret_cast<uint8_t*>(request);
926 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800927 uint8_t frame;
928 uint8_t page;
929 uint8_t next;
930 uint8_t count;
931 int ret;
932
933 frame = req[3];
934 page = req[4];
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800935
936 ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]);
937 if (ret)
938 {
939 memcpy(res, req, SIZE_IANA_ID); // IANA ID
940 *data_len = SIZE_IANA_ID;
941 return IPMI_CC_UNSPECIFIED_ERROR;
942 }
943
944 memcpy(res, req, SIZE_IANA_ID); // IANA ID
945 res[3] = frame;
946 res[4] = page;
947 res[5] = next;
948 res[6] = count;
949 *data_len = SIZE_IANA_ID + 4 + count;
950
951 return IPMI_CC_OK;
952}
953
954//----------------------------------------------------------------------
955// Get Debug Control Panel
956//----------------------------------------------------------------------
Patrick Williams010dee02024-08-16 15:19:44 -0400957ipmi_ret_t ipmiOemDbgGetCtrlPanel(
958 ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
959 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800960{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700961 uint8_t* req = reinterpret_cast<uint8_t*>(request);
962 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800963
964 uint8_t panel;
965 uint8_t operation;
966 uint8_t item;
967 uint8_t count;
968 ipmi_ret_t ret;
969
970 panel = req[3];
971 operation = req[4];
972 item = req[5];
973
974 ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]);
975
976 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
977 *data_len = SIZE_IANA_ID + count;
978
979 return ret;
980}
981
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800982//----------------------------------------------------------------------
983// Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
984//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700985ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
986 ipmi_response_t, ipmi_data_len_t data_len,
987 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800988{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700989 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700990
991 uint8_t index = req[0];
992 uint8_t type = req[1];
993 uint16_t speed;
994 uint32_t size;
995
996 memcpy(&speed, &req[2], 2);
997 memcpy(&size, &req[4], 4);
998
999 std::stringstream ss;
1000 ss << std::hex;
1001 ss << std::setw(2) << std::setfill('0') << (int)index;
1002
1003 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index;
1004 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type;
1005 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed;
1006 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size;
1007
1008 flushOemData();
1009
1010 *data_len = 0;
1011
1012 return IPMI_CC_OK;
1013}
1014
1015//----------------------------------------------------------------------
1016// Get Board ID (CMD_OEM_GET_BOARD_ID)
1017//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001018ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1019 ipmi_response_t, ipmi_data_len_t data_len,
1020 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001021{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001022 /* TODO: Needs to implement this after GPIO implementation */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001023 *data_len = 0;
1024
1025 return IPMI_CC_OK;
1026}
1027
Bonnie Lo4ae63e72023-02-09 15:27:54 +08001028//----------------------------------------------------------------------
1029// Get port 80 record (CMD_OEM_GET_80PORT_RECORD)
1030//----------------------------------------------------------------------
1031ipmi::RspType<std::vector<uint8_t>>
1032 ipmiOemGet80PortRecord(ipmi::Context::ptr ctx)
1033{
1034 auto postCodeService = "xyz.openbmc_project.State.Boot.PostCode" +
1035 std::to_string(ctx->hostIdx + 1);
1036 auto postCodeObjPath = "/xyz/openbmc_project/State/Boot/PostCode" +
1037 std::to_string(ctx->hostIdx + 1);
1038 constexpr auto postCodeInterface =
1039 "xyz.openbmc_project.State.Boot.PostCode";
1040 const static uint16_t lastestPostCodeIndex = 1;
1041 constexpr const auto maxPostCodeLen =
1042 224; // The length must be lower than IPMB limitation
1043 size_t startIndex = 0;
1044
1045 std::vector<std::tuple<uint64_t, std::vector<uint8_t>>> postCodes;
1046 std::vector<uint8_t> resData;
1047
1048 auto conn = getSdBus();
1049 /* Get the post codes by calling GetPostCodes method */
Patrick Williams010dee02024-08-16 15:19:44 -04001050 auto msg =
1051 conn->new_method_call(postCodeService.c_str(), postCodeObjPath.c_str(),
1052 postCodeInterface, "GetPostCodes");
Bonnie Lo4ae63e72023-02-09 15:27:54 +08001053 msg.append(lastestPostCodeIndex);
1054
1055 try
1056 {
1057 auto reply = conn->call(msg);
1058 reply.read(postCodes);
1059 }
1060 catch (const sdbusplus::exception::SdBusError& e)
1061 {
1062 phosphor::logging::log<phosphor::logging::level::ERR>(
1063 "IPMI Get80PortRecord Failed in call method",
1064 phosphor::logging::entry("ERROR=%s", e.what()));
1065 return ipmi::responseUnspecifiedError();
1066 }
1067
1068 /* Get post code data */
1069 for (size_t i = 0; i < postCodes.size(); ++i)
1070 {
1071 uint64_t primaryPostCode = std::get<uint64_t>(postCodes[i]);
1072 for (int j = postCodeSize - 1; j >= 0; --j)
1073 {
1074 uint8_t postCode =
1075 ((primaryPostCode >> (sizeof(uint64_t) * j)) & 0xFF);
1076 resData.emplace_back(postCode);
1077 }
1078 }
1079
1080 std::vector<uint8_t> response;
1081 if (resData.size() > maxPostCodeLen)
1082 {
1083 startIndex = resData.size() - maxPostCodeLen;
1084 }
1085
1086 response.assign(resData.begin() + startIndex, resData.end());
1087
1088 return ipmi::responseSuccess(response);
1089}
1090
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001091//----------------------------------------------------------------------
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001092// Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
1093//----------------------------------------------------------------------
Jayashree-Df0cf6652020-11-30 11:03:30 +05301094ipmi::RspType<std::vector<uint8_t>>
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001095 ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> bootSeq)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001096{
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001097 size_t len = bootSeq.size();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001098
1099 if (len != SIZE_BOOT_ORDER)
1100 {
1101 phosphor::logging::log<phosphor::logging::level::ERR>(
1102 "Invalid Boot order length received");
Jayashree-Df0cf6652020-11-30 11:03:30 +05301103 return ipmi::responseReqDataLenInvalid();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001104 }
1105
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +05301106 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001107
Jayashree-Df0cf6652020-11-30 11:03:30 +05301108 if (!hostId)
1109 {
1110 phosphor::logging::log<phosphor::logging::level::ERR>(
1111 "Invalid Host Id received");
1112 return ipmi::responseInvalidCommand();
1113 }
1114 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
1115
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001116 ipmi::boot::setBootOrder(bootObjPath, bootSeq, hostName);
Jayashree-Df0cf6652020-11-30 11:03:30 +05301117
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001118 return ipmi::responseSuccess(bootSeq);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001119}
1120
1121//----------------------------------------------------------------------
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001122// Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
1123//----------------------------------------------------------------------
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001124ipmi::RspType<std::vector<uint8_t>> ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001125{
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001126 std::vector<uint8_t> bootSeq;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001127
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +05301128 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001129
Jayashree-Df0cf6652020-11-30 11:03:30 +05301130 if (!hostId)
1131 {
1132 phosphor::logging::log<phosphor::logging::level::ERR>(
1133 "Invalid Host Id received");
1134 return ipmi::responseInvalidCommand();
1135 }
1136 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
1137
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001138 ipmi::boot::getBootOrder(bootObjPath, bootSeq, hostName);
Jayashree-Df0cf6652020-11-30 11:03:30 +05301139
Delphine CC Chiu7bb45922023-04-10 13:34:04 +08001140 return ipmi::responseSuccess(bootSeq);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001141}
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001142// Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
1143//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001144ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t, ipmi_cmd_t,
1145 ipmi_request_t request, ipmi_response_t,
1146 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001147{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001148 machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001149 uint8_t len = *data_len;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001150
1151 *data_len = 0;
1152
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001153 if (len < sizeof(machineConfigInfo_t))
1154 {
1155 phosphor::logging::log<phosphor::logging::level::ERR>(
1156 "Invalid machine configuration length received");
1157 return IPMI_CC_REQ_DATA_LEN_INVALID;
1158 }
1159
Vijay Khemka63c99be2020-05-27 19:14:35 -07001160 if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001161 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN";
1162 else
1163 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] =
1164 chassisType[req->chassis_type];
1165
Vijay Khemka63c99be2020-05-27 19:14:35 -07001166 if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001167 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN";
1168 else
1169 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type];
1170
1171 oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt;
1172 oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt;
1173 oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt;
1174 oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt;
1175
Vijay Khemka63c99be2020-05-27 19:14:35 -07001176 if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001177 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN";
1178 else
1179 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type];
1180
1181 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {};
1182 int i = 0;
1183 if (req->pcie_card_loc & BIT_0)
1184 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1";
1185 if (req->pcie_card_loc & BIT_1)
1186 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2";
1187 if (req->pcie_card_loc & BIT_2)
1188 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3";
1189 if (req->pcie_card_loc & BIT_3)
1190 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4";
1191
Vijay Khemka63c99be2020-05-27 19:14:35 -07001192 if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001193 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN";
1194 else
1195 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] =
1196 pcieType[req->slot1_pcie_type];
1197
Vijay Khemka63c99be2020-05-27 19:14:35 -07001198 if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001199 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN";
1200 else
1201 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] =
1202 pcieType[req->slot2_pcie_type];
1203
Vijay Khemka63c99be2020-05-27 19:14:35 -07001204 if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001205 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN";
1206 else
1207 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] =
1208 pcieType[req->slot3_pcie_type];
1209
Vijay Khemka63c99be2020-05-27 19:14:35 -07001210 if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001211 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN";
1212 else
1213 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] =
1214 pcieType[req->slot4_pcie_type];
1215
1216 oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt;
1217
1218 flushOemData();
1219
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001220 return IPMI_CC_OK;
1221}
1222
1223//----------------------------------------------------------------------
1224// Set POST start (CMD_OEM_SET_POST_START)
1225//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001226ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1227 ipmi_response_t, ipmi_data_len_t data_len,
1228 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001229{
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001230 phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
1231
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001232 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001233 *data_len = 0;
1234 return IPMI_CC_OK;
1235}
1236
1237//----------------------------------------------------------------------
1238// Set POST End (CMD_OEM_SET_POST_END)
1239//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001240ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1241 ipmi_response_t, ipmi_data_len_t data_len,
1242 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001243{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001244 struct timespec ts;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001245
1246 phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
1247
1248 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001249
1250 // Timestamp post end time.
1251 clock_gettime(CLOCK_REALTIME, &ts);
1252 oemData[KEY_TS_SLED] = ts.tv_sec;
1253 flushOemData();
1254
1255 // Sync time with system
1256 // TODO: Add code for syncing time
1257
1258 return IPMI_CC_OK;
1259}
1260
1261//----------------------------------------------------------------------
1262// Set PPIN Info (CMD_OEM_SET_PPIN_INFO)
1263//----------------------------------------------------------------------
1264// Inform BMC about PPIN data of 8 bytes for each CPU
1265//
1266// Request:
1267// Byte 1:8 – CPU0 PPIN data
1268// Optional:
1269// Byte 9:16 – CPU1 PPIN data
1270//
1271// Response:
1272// Byte 1 – Completion Code
Willy Tue39f9392022-06-15 13:24:20 -07001273ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1274 ipmi_response_t, ipmi_data_len_t data_len,
1275 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001276{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001277 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001278 std::string ppinStr;
1279 int len;
1280
1281 if (*data_len > SIZE_CPU_PPIN * 2)
1282 len = SIZE_CPU_PPIN * 2;
1283 else
1284 len = *data_len;
1285 *data_len = 0;
1286
1287 ppinStr = bytesToStr(req, len);
1288 oemData[KEY_PPIN_INFO] = ppinStr.c_str();
1289 flushOemData();
1290
1291 return IPMI_CC_OK;
1292}
1293
1294//----------------------------------------------------------------------
1295// Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER)
1296//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001297ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1298 ipmi_response_t, ipmi_data_len_t data_len,
1299 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001300{
1301 /* Do nothing, return success */
1302 *data_len = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001303 return IPMI_CC_OK;
1304}
1305
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001306// Helper function to set guid at offset in EEPROM
Willy Tue39f9392022-06-15 13:24:20 -07001307[[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001308{
1309 int fd = -1;
1310 ssize_t len;
1311 int ret = 0;
cchouxb2ae88b2023-09-13 00:35:36 +08001312 std::string eepromPath = FRU_EEPROM;
1313
1314 // find the eeprom path of MB FRU
1315 auto device = getMbFruDevice();
1316 if (device)
1317 {
1318 auto [bus, address] = *device;
1319 std::stringstream ss;
1320 ss << "/sys/bus/i2c/devices/" << static_cast<int>(bus) << "-"
1321 << std::setw(4) << std::setfill('0') << std::hex
1322 << static_cast<int>(address) << "/eeprom";
1323 eepromPath = ss.str();
1324 }
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001325
1326 errno = 0;
1327
1328 // Check if file is present
cchouxb2ae88b2023-09-13 00:35:36 +08001329 if (access(eepromPath.c_str(), F_OK) == -1)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001330 {
cchouxb2ae88b2023-09-13 00:35:36 +08001331 std::cerr << "Unable to access: " << eepromPath << std::endl;
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001332 return errno;
1333 }
1334
1335 // Open the file
cchouxb2ae88b2023-09-13 00:35:36 +08001336 fd = open(eepromPath.c_str(), O_WRONLY);
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001337 if (fd == -1)
1338 {
cchouxb2ae88b2023-09-13 00:35:36 +08001339 std::cerr << "Unable to open: " << eepromPath << std::endl;
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001340 return errno;
1341 }
1342
1343 // seek to the offset
1344 lseek(fd, offset, SEEK_SET);
1345
1346 // Write bytes to location
1347 len = write(fd, guid, GUID_SIZE);
1348 if (len != GUID_SIZE)
1349 {
1350 phosphor::logging::log<phosphor::logging::level::ERR>(
1351 "GUID write data to EEPROM failed");
1352 ret = errno;
1353 }
1354
1355 close(fd);
1356 return ret;
1357}
1358
1359//----------------------------------------------------------------------
1360// Set System GUID (CMD_OEM_SET_SYSTEM_GUID)
1361//----------------------------------------------------------------------
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301362#if BIC_ENABLED
Bonnie Lo3f671272022-10-12 15:46:45 +08001363ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx,
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301364 std::vector<uint8_t> reqData)
1365{
1366 std::vector<uint8_t> respData;
1367
1368 if (reqData.size() != GUID_SIZE) // 16bytes
1369 {
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301370 return ipmi::responseReqDataLenInvalid();
1371 }
1372
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301373 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
1374
1375 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
1376 return ipmi::responseUnspecifiedError();
1377
1378 return ipmi::responseSuccess();
1379}
1380
1381#else
Potin Laid5353ca2022-08-11 04:52:11 +00001382ipmi_ret_t ipmiOemSetSystemGuid(ipmi_netfn_t, ipmi_cmd_t,
1383 ipmi_request_t request, ipmi_response_t,
1384 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001385{
1386 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1387
1388 if (*data_len != GUID_SIZE) // 16bytes
1389 {
1390 *data_len = 0;
1391 return IPMI_CC_REQ_DATA_LEN_INVALID;
1392 }
1393
1394 *data_len = 0;
1395
1396 if (setGUID(OFFSET_SYS_GUID, req))
1397 {
1398 return IPMI_CC_UNSPECIFIED_ERROR;
1399 }
1400 return IPMI_CC_OK;
1401}
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301402#endif
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001403
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001404//----------------------------------------------------------------------
1405// Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
1406//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001407ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1408 ipmi_response_t, ipmi_data_len_t data_len,
1409 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001410{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001411 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001412 *data_len = 0;
1413 return IPMI_CC_OK;
1414}
1415
1416//----------------------------------------------------------------------
1417// Set PPR (CMD_OEM_SET_PPR)
1418//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001419ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1420 ipmi_response_t, ipmi_data_len_t data_len,
1421 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001422{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001423 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001424 uint8_t pprCnt, pprAct, pprIndex;
1425 uint8_t selParam = req[0];
1426 uint8_t len = *data_len;
1427 std::stringstream ss;
1428 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001429
1430 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001431
1432 switch (selParam)
1433 {
1434 case PPR_ACTION:
1435 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) ==
1436 oemData[KEY_PPR].end())
1437 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1438
1439 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1440 if (pprCnt == 0)
1441 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1442
1443 pprAct = req[1];
1444 /* Check if ppr is enabled or disabled */
1445 if (!(pprAct & 0x80))
1446 pprAct = 0;
1447
1448 oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct;
1449 break;
1450 case PPR_ROW_COUNT:
1451 if (req[1] > 100)
1452 return IPMI_CC_PARM_OUT_OF_RANGE;
1453
1454 oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1];
1455 break;
1456 case PPR_ROW_ADDR:
1457 pprIndex = req[1];
1458 if (pprIndex > 100)
1459 return IPMI_CC_PARM_OUT_OF_RANGE;
1460
1461 if (len < PPR_ROW_ADDR_LEN + 1)
1462 {
1463 phosphor::logging::log<phosphor::logging::level::ERR>(
1464 "Invalid PPR Row Address length received");
1465 return IPMI_CC_REQ_DATA_LEN_INVALID;
1466 }
1467
1468 ss << std::hex;
1469 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1470
1471 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1472
1473 str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN);
1474 oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str();
1475 break;
1476 case PPR_HISTORY_DATA:
1477 pprIndex = req[1];
1478 if (pprIndex > 100)
1479 return IPMI_CC_PARM_OUT_OF_RANGE;
1480
1481 if (len < PPR_HST_DATA_LEN + 1)
1482 {
1483 phosphor::logging::log<phosphor::logging::level::ERR>(
1484 "Invalid PPR history data length received");
1485 return IPMI_CC_REQ_DATA_LEN_INVALID;
1486 }
1487
1488 ss << std::hex;
1489 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1490
1491 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1492
1493 str = bytesToStr(&req[1], PPR_HST_DATA_LEN);
1494 oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str();
1495 break;
1496 default:
1497 return IPMI_CC_PARM_OUT_OF_RANGE;
1498 break;
1499 }
1500
1501 flushOemData();
1502
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001503 return IPMI_CC_OK;
1504}
1505
1506//----------------------------------------------------------------------
1507// Get PPR (CMD_OEM_GET_PPR)
1508//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001509ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1510 ipmi_response_t response, ipmi_data_len_t data_len,
1511 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001512{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001513 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1514 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001515 uint8_t pprCnt, pprIndex;
1516 uint8_t selParam = req[0];
1517 std::stringstream ss;
1518 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001519
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001520 /* Any failure will return zero length data */
1521 *data_len = 0;
1522
1523 switch (selParam)
1524 {
1525 case PPR_ACTION:
1526 res[0] = 0;
1527 *data_len = 1;
1528
1529 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1530 oemData[KEY_PPR].end())
1531 {
1532 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1533 if (pprCnt != 0)
1534 {
1535 if (oemData[KEY_PPR].find(KEY_PPR_ACTION) !=
1536 oemData[KEY_PPR].end())
1537 {
1538 res[0] = oemData[KEY_PPR][KEY_PPR_ACTION];
1539 }
1540 }
1541 }
1542 break;
1543 case PPR_ROW_COUNT:
1544 res[0] = 0;
1545 *data_len = 1;
1546 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1547 oemData[KEY_PPR].end())
1548 res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1549 break;
1550 case PPR_ROW_ADDR:
1551 pprIndex = req[1];
1552 if (pprIndex > 100)
1553 return IPMI_CC_PARM_OUT_OF_RANGE;
1554
1555 ss << std::hex;
1556 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1557
1558 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1559 return IPMI_CC_PARM_OUT_OF_RANGE;
1560
1561 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) ==
1562 oemData[KEY_PPR][ss.str()].end())
1563 return IPMI_CC_PARM_OUT_OF_RANGE;
1564
1565 str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR];
1566 *data_len = strToBytes(str, res);
1567 break;
1568 case PPR_HISTORY_DATA:
1569 pprIndex = req[1];
1570 if (pprIndex > 100)
1571 return IPMI_CC_PARM_OUT_OF_RANGE;
1572
1573 ss << std::hex;
1574 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1575
1576 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1577 return IPMI_CC_PARM_OUT_OF_RANGE;
1578
1579 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) ==
1580 oemData[KEY_PPR][ss.str()].end())
1581 return IPMI_CC_PARM_OUT_OF_RANGE;
1582
1583 str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA];
1584 *data_len = strToBytes(str, res);
1585 break;
1586 default:
1587 return IPMI_CC_PARM_OUT_OF_RANGE;
1588 break;
1589 }
1590
1591 return IPMI_CC_OK;
1592}
1593
1594/* FB OEM QC Commands */
1595
1596//----------------------------------------------------------------------
1597// Set Proc Info (CMD_OEM_Q_SET_PROC_INFO)
1598//----------------------------------------------------------------------
1599//"Request:
1600// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1601// Byte 4 – Processor Index, 0 base
1602// Byte 5 – Parameter Selector
1603// Byte 6..N – Configuration parameter data (see below for Parameters
1604// of Processor Information)
1605// Response:
1606// Byte 1 – Completion code
1607//
1608// Parameter#1: (Processor Product Name)
1609//
1610// Byte 1..48 –Product name(ASCII code)
1611// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1612//
1613// Param#2: Processor Basic Information
1614// Byte 1 – Core Number
1615// Byte 2 – Thread Number (LSB)
1616// Byte 3 – Thread Number (MSB)
1617// Byte 4 – Processor frequency in MHz (LSB)
1618// Byte 5 – Processor frequency in MHz (MSB)
1619// Byte 6..7 – Revision
1620//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301621
Patrick Williams010dee02024-08-16 15:19:44 -04001622ipmi::RspType<> ipmiOemQSetProcInfo(
1623 ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t, uint8_t procIndex,
1624 uint8_t paramSel, std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001625{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001626 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001627 std::stringstream ss;
1628 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301629 uint8_t len = request.size();
1630 auto hostId = findHost(ctx->hostIdx);
1631 if (!hostId)
1632 {
1633 phosphor::logging::log<phosphor::logging::level::ERR>(
1634 "Invalid Host Id received");
1635 return ipmi::responseInvalidCommand();
1636 }
1637 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001638 /* check for requested data params */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301639 if (len < 5 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001640 {
1641 phosphor::logging::log<phosphor::logging::level::ERR>(
1642 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301643 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001644 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001645 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301646 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1647 oemData[procInfo][ss.str()][KEY_PROC_INDEX] = procIndex;
1648 str = bytesToStr(request.data(), len);
1649 oemData[procInfo][ss.str()][cpuInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001650 flushOemData();
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301651 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001652}
1653
1654//----------------------------------------------------------------------
1655// Get Proc Info (CMD_OEM_Q_GET_PROC_INFO)
1656//----------------------------------------------------------------------
1657// Request:
1658// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1659// Byte 4 – Processor Index, 0 base
1660// Byte 5 – Parameter Selector
1661// Response:
1662// Byte 1 – Completion code
1663// Byte 2..N – Configuration Parameter Data (see below for Parameters
1664// of Processor Information)
1665//
1666// Parameter#1: (Processor Product Name)
1667//
1668// Byte 1..48 –Product name(ASCII code)
1669// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1670//
1671// Param#2: Processor Basic Information
1672// Byte 1 – Core Number
1673// Byte 2 – Thread Number (LSB)
1674// Byte 3 – Thread Number (MSB)
1675// Byte 4 – Processor frequency in MHz (LSB)
1676// Byte 5 – Processor frequency in MHz (MSB)
1677// Byte 6..7 – Revision
1678//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301679
1680ipmi::RspType<std::vector<uint8_t>>
1681 ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1682 uint8_t procIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001683{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001684 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001685 std::stringstream ss;
1686 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301687 uint8_t res[MAX_BUF];
1688 auto hostId = findHost(ctx->hostIdx);
1689 if (!hostId)
1690 {
1691 phosphor::logging::log<phosphor::logging::level::ERR>(
1692 "Invalid Host Id received");
1693 return ipmi::responseInvalidCommand();
1694 }
1695 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
1696 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001697 {
1698 phosphor::logging::log<phosphor::logging::level::ERR>(
1699 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301700 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001701 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001702 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301703 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1704 if (oemData[procInfo].find(ss.str()) == oemData[procInfo].end())
1705 return ipmi::responseCommandNotAvailable();
1706 if (oemData[procInfo][ss.str()].find(cpuInfoKey[paramSel]) ==
1707 oemData[procInfo][ss.str()].end())
1708 return ipmi::responseCommandNotAvailable();
1709 str = oemData[procInfo][ss.str()][cpuInfoKey[paramSel]];
1710 int dataLen = strToBytes(str, res);
1711 std::vector<uint8_t> response(&res[0], &res[dataLen]);
1712 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001713}
1714
1715//----------------------------------------------------------------------
1716// Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO)
1717//----------------------------------------------------------------------
1718// Request:
1719// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1720// Byte 4 – DIMM Index, 0 base
1721// Byte 5 – Parameter Selector
1722// Byte 6..N – Configuration parameter data (see below for Parameters
1723// of DIMM Information)
1724// Response:
1725// Byte 1 – Completion code
1726//
1727// Param#1 (DIMM Location):
1728// Byte 1 – DIMM Present
1729// Byte 1 – DIMM Present
1730// 01h – Present
1731// FFh – Not Present
1732// Byte 2 – Node Number, 0 base
1733// Byte 3 – Channel Number , 0 base
1734// Byte 4 – DIMM Number , 0 base
1735//
1736// Param#2 (DIMM Type):
1737// Byte 1 – DIMM Type
1738// Bit [7:6]
1739// For DDR3
1740// 00 – Normal Voltage (1.5V)
1741// 01 – Ultra Low Voltage (1.25V)
1742// 10 – Low Voltage (1.35V)
1743// 11 – Reserved
1744// For DDR4
1745// 00 – Reserved
1746// 01 – Reserved
1747// 10 – Reserved
1748// 11 – Normal Voltage (1.2V)
1749// Bit [5:0]
1750// 0x00 – SDRAM
1751// 0x01 – DDR-1 RAM
1752// 0x02 – Rambus
1753// 0x03 – DDR-2 RAM
1754// 0x04 – FBDIMM
1755// 0x05 – DDR-3 RAM
1756// 0x06 – DDR-4 RAM
1757//
1758// Param#3 (DIMM Speed):
1759// Byte 1..2 – DIMM speed in MHz, LSB
1760// Byte 3..6 – DIMM size in Mbytes, LSB
1761//
1762// Param#4 (Module Part Number):
1763// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1764//
1765// Param#5 (Module Serial Number):
1766// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1767//
1768// Param#6 (Module Manufacturer ID):
1769// Byte 1 - Module Manufacturer ID, LSB
1770// Byte 2 - Module Manufacturer ID, MSB
1771//
Patrick Williams010dee02024-08-16 15:19:44 -04001772ipmi::RspType<> ipmiOemQSetDimmInfo(
1773 ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t, uint8_t dimmIndex,
1774 uint8_t paramSel, std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001775{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001776 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001777 std::stringstream ss;
1778 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301779 uint8_t len = request.size();
1780 std::string dimmType;
1781 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001782 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301783 if (!hostId)
1784 {
1785 phosphor::logging::log<phosphor::logging::level::ERR>(
1786 "Invalid Host Id received");
1787 return ipmi::responseInvalidCommand();
1788 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001789
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301790 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001791
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301792 if (len < 3 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001793 {
1794 phosphor::logging::log<phosphor::logging::level::ERR>(
1795 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301796 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001797 }
1798
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001799 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301800 ss << (int)dimmIndex;
1801 oemData[dimmInfo][ss.str()][KEY_DIMM_INDEX] = dimmIndex;
1802 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1803 str = bytesToStr(request.data(), len);
1804 oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001805 flushOemData();
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301806 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001807}
1808
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001809// Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO)
1810//----------------------------------------------------------------------
1811// Request:
1812// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1813// Byte 4 – DIMM Index, 0 base
1814// Byte 5 – Parameter Selector
1815// Byte 6..N – Configuration parameter data (see below for Parameters
1816// of DIMM Information)
1817// Response:
1818// Byte 1 – Completion code
1819// Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters
1820// of DIMM Information)
1821//
1822// Param#1 (DIMM Location):
1823// Byte 1 – DIMM Present
1824// Byte 1 – DIMM Present
1825// 01h – Present
1826// FFh – Not Present
1827// Byte 2 – Node Number, 0 base
1828// Byte 3 – Channel Number , 0 base
1829// Byte 4 – DIMM Number , 0 base
1830//
1831// Param#2 (DIMM Type):
1832// Byte 1 – DIMM Type
1833// Bit [7:6]
1834// For DDR3
1835// 00 – Normal Voltage (1.5V)
1836// 01 – Ultra Low Voltage (1.25V)
1837// 10 – Low Voltage (1.35V)
1838// 11 – Reserved
1839// For DDR4
1840// 00 – Reserved
1841// 01 – Reserved
1842// 10 – Reserved
1843// 11 – Normal Voltage (1.2V)
1844// Bit [5:0]
1845// 0x00 – SDRAM
1846// 0x01 – DDR-1 RAM
1847// 0x02 – Rambus
1848// 0x03 – DDR-2 RAM
1849// 0x04 – FBDIMM
1850// 0x05 – DDR-3 RAM
1851// 0x06 – DDR-4 RAM
1852//
1853// Param#3 (DIMM Speed):
1854// Byte 1..2 – DIMM speed in MHz, LSB
1855// Byte 3..6 – DIMM size in Mbytes, LSB
1856//
1857// Param#4 (Module Part Number):
1858// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1859//
1860// Param#5 (Module Serial Number):
1861// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1862//
1863// Param#6 (Module Manufacturer ID):
1864// Byte 1 - Module Manufacturer ID, LSB
1865// Byte 2 - Module Manufacturer ID, MSB
1866//
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301867ipmi::RspType<std::vector<uint8_t>>
1868 ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1869 uint8_t dimmIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001870{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001871 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301872 uint8_t res[MAX_BUF];
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001873 std::stringstream ss;
1874 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301875 std::string dimmType;
1876 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001877 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301878 if (!hostId)
1879 {
1880 phosphor::logging::log<phosphor::logging::level::ERR>(
1881 "Invalid Host Id received");
1882 return ipmi::responseInvalidCommand();
1883 }
1884 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001885
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301886 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001887 {
1888 phosphor::logging::log<phosphor::logging::level::ERR>(
1889 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301890 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001891 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001892 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301893 ss << (int)dimmIndex;
1894 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1895 if (oemData[dimmInfo].find(ss.str()) == oemData[dimmInfo].end())
1896 return ipmi::responseCommandNotAvailable();
1897 if (oemData[dimmInfo][ss.str()].find(dimmInfoKey[paramSel]) ==
1898 oemData[dimmInfo][ss.str()].end())
1899 return ipmi::responseCommandNotAvailable();
1900 str = oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]];
1901 int data_length = strToBytes(str, res);
1902 std::vector<uint8_t> response(&res[0], &res[data_length]);
1903 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001904}
1905
1906//----------------------------------------------------------------------
1907// Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO)
1908//----------------------------------------------------------------------
1909// BIOS issue this command to provide HDD information to BMC.
1910//
1911// BIOS just can get information by standard ATA / SMART command for
1912// OB SATA controller.
1913// BIOS can get
1914// 1. Serial Number
1915// 2. Model Name
1916// 3. HDD FW Version
1917// 4. HDD Capacity
1918// 5. HDD WWN
1919//
1920// Use Get HDD info Param #5 to know the MAX HDD info index.
1921//
1922// Request:
1923// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1924// Byte 4 –
1925// [7:4] Reserved
1926// [3:0] HDD Controller Type
1927// 0x00 – BIOS
1928// 0x01 – Expander
1929// 0x02 – LSI
1930// Byte 5 – HDD Info Index, 0 base
1931// Byte 6 – Parameter Selector
1932// Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD
1933// Information)
1934//
1935// Response:
1936// Byte 1 – Completion Code
1937//
1938// Param#0 (HDD Location):
1939// Byte 1 – Controller
1940// [7:3] Device Number
1941// [2:0] Function Number
1942// For Intel C610 series (Wellsburg)
1943// D31:F2 (0xFA) – SATA control 1
1944// D31:F5 (0xFD) – SATA control 2
1945// D17:F4 (0x8C) – sSata control
1946// Byte 2 – Port Number
1947// Byte 3 – Location (0xFF: No HDD Present)
1948// BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param
1949// #1~4, #6, #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if
1950// the HDD present. BMC or other people who know the HDD location has
1951// responsibility for update Location info
1952//
1953// Param#1 (Serial Number):
1954// Bytes 1..33: HDD Serial Number
1955//
1956// Param#2 (Model Name):
1957// Byte 1..33 – HDD Model Name
1958//
1959// Param#3 (HDD FW Version):
1960// Byte 1..17 –HDD FW version
1961//
1962// Param#4 (Capacity):
1963// Byte 1..4 –HDD Block Size, LSB
1964// Byte 5..12 - HDD Block Number, LSB
1965// HDD Capacity = HDD Block size * HDD BLock number (Unit Byte)
1966//
1967// Param#5 (Max HDD Quantity):
1968// Byte 1 - Max HDD Quantity
1969// Max supported port numbers in this PCH
1970//
1971// Param#6 (HDD Type)
1972// Byte 1 – HDD Type
1973// 0h – Reserved
1974// 1h – SAS
1975// 2h – SATA
1976// 3h – PCIE SSD (NVME)
1977//
1978// Param#7 (HDD WWN)
1979// Data 1...8: HDD World Wide Name, LSB
1980//
Willy Tue39f9392022-06-15 13:24:20 -07001981ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
1982 ipmi_request_t request, ipmi_response_t,
1983 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001984{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001985 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1986 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001987 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1988 std::stringstream ss;
1989 std::string str;
1990 uint8_t len = *data_len;
1991
1992 *data_len = 0;
1993
1994 /* check for requested data params */
1995 if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam ||
1996 ctrlType > 2)
1997 {
1998 phosphor::logging::log<phosphor::logging::level::ERR>(
1999 "Invalid parameter received");
2000 return IPMI_CC_PARM_OUT_OF_RANGE;
2001 }
2002
2003 len = len - 6; // Get Actual data length
2004
2005 ss << std::hex;
2006 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
2007 oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType;
2008 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] =
2009 req->hddIndex;
2010
2011 str = bytesToStr(req->data, len);
2012 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
2013 [driveInfoKey[req->paramSel]] = str.c_str();
2014 flushOemData();
2015
2016 return IPMI_CC_OK;
2017}
2018
2019//----------------------------------------------------------------------
2020// Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO)
2021//----------------------------------------------------------------------
2022// BMC needs to check HDD presented or not first. If NOT presented, return
2023// completion code 0xD5.
2024//
2025// Request:
2026// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
2027// Byte 4 –
2028//[7:4] Reserved
2029//[3:0] HDD Controller Type
2030// 0x00 – BIOS
2031// 0x01 – Expander
2032// 0x02 – LSI
2033// Byte 5 – HDD Index, 0 base
2034// Byte 6 – Parameter Selector (See Above Set HDD Information)
2035// Response:
2036// Byte 1 – Completion Code
2037// 0xD5 – Not support in current status (HDD Not Present)
2038// Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD
2039// Information)
2040//
Patrick Williams010dee02024-08-16 15:19:44 -04002041ipmi_ret_t ipmiOemQGetDriveInfo(
2042 ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request, ipmi_response_t response,
2043 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002044{
Vijay Khemka63c99be2020-05-27 19:14:35 -07002045 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
2046 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
2047 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002048 uint8_t ctrlType = req->hddCtrlType & 0x0f;
2049 std::stringstream ss;
2050 std::string str;
2051
2052 *data_len = 0;
2053
2054 /* check for requested data params */
2055 if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2)
2056 {
2057 phosphor::logging::log<phosphor::logging::level::ERR>(
2058 "Invalid parameter received");
2059 return IPMI_CC_PARM_OUT_OF_RANGE;
2060 }
2061
2062 if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) ==
2063 oemData[KEY_Q_DRIVE_INFO].end())
2064 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
2065
2066 ss << std::hex;
2067 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
2068
2069 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) ==
2070 oemData[KEY_Q_DRIVE_INFO].end())
2071 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
2072
2073 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find(
2074 dimmInfoKey[req->paramSel]) ==
2075 oemData[KEY_Q_DRIVE_INFO][ss.str()].end())
2076 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
2077
2078 str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
2079 [dimmInfoKey[req->paramSel]];
2080 *data_len = strToBytes(str, res);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002081
2082 return IPMI_CC_OK;
2083}
2084
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302085/* Helper function for sending DCMI commands to ME/BIC and
2086 * getting response back
2087 */
2088ipmi::RspType<std::vector<uint8_t>>
2089 sendDCMICmd([[maybe_unused]] ipmi::Context::ptr ctx,
2090 [[maybe_unused]] uint8_t cmd, std::vector<uint8_t>& cmdData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002091{
2092 std::vector<uint8_t> respData;
2093
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302094#if BIC_ENABLED
2095
2096 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
2097
2098 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, cmdData, respData))
2099 {
2100 return ipmi::responseUnspecifiedError();
2101 }
2102
2103#else
2104
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002105 /* Add group id as first byte to request for ME command */
2106 cmdData.insert(cmdData.begin(), groupDCMI);
2107
2108 if (sendMeCmd(ipmi::netFnGroup, cmd, cmdData, respData))
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302109 {
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002110 return ipmi::responseUnspecifiedError();
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302111 }
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002112
2113 /* Remove group id as first byte as it will be added by IPMID */
2114 respData.erase(respData.begin());
2115
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302116#endif
2117
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002118 return ipmi::responseSuccess(std::move(respData));
2119}
2120
2121/* DCMI Command handellers. */
2122
Patrick Williams010dee02024-08-16 15:19:44 -04002123ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMIGetPowerReading(
2124 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002125{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302126 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerReading, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002127}
2128
Patrick Williams010dee02024-08-16 15:19:44 -04002129ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMIGetPowerLimit(
2130 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002131{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302132 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002133}
2134
Patrick Williams010dee02024-08-16 15:19:44 -04002135ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMISetPowerLimit(
2136 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002137{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302138 return sendDCMICmd(ctx, ipmi::dcmi::cmdSetPowerLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002139}
2140
Patrick Williams010dee02024-08-16 15:19:44 -04002141ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMIApplyPowerLimit(
2142 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002143{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302144 return sendDCMICmd(ctx, ipmi::dcmi::cmdActDeactivatePwrLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002145}
2146
Cosmo Chou99d42b62024-08-15 10:42:47 +08002147// Https Boot related functions
Patrick Williams010dee02024-08-16 15:19:44 -04002148ipmi::RspType<std::vector<uint8_t>> ipmiOemGetHttpsData(
2149 [[maybe_unused]] ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Cosmo Chou99d42b62024-08-15 10:42:47 +08002150{
2151 if (reqData.size() < sizeof(HttpsDataReq))
2152 return ipmi::responseReqDataLenInvalid();
2153
2154 const auto* pReq = reinterpret_cast<const HttpsDataReq*>(reqData.data());
2155 std::error_code ec;
2156 auto fileSize = std::filesystem::file_size(certPath, ec);
2157 if (ec)
2158 return ipmi::responseUnspecifiedError();
2159
2160 if (pReq->offset >= fileSize)
2161 return ipmi::responseInvalidFieldRequest();
2162
2163 std::ifstream file(certPath, std::ios::binary);
2164 if (!file)
2165 return ipmi::responseUnspecifiedError();
2166
2167 auto readLen = std::min<uint16_t>(pReq->length, fileSize - pReq->offset);
2168 std::vector<uint8_t> resData(readLen + 1);
2169 resData[0] = readLen;
2170 file.seekg(pReq->offset);
2171 file.read(reinterpret_cast<char*>(resData.data() + 1), readLen);
2172
2173 return ipmi::responseSuccess(resData);
2174}
2175
Patrick Williams010dee02024-08-16 15:19:44 -04002176ipmi::RspType<std::vector<uint8_t>> ipmiOemGetHttpsAttr(
2177 [[maybe_unused]] ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Cosmo Chou99d42b62024-08-15 10:42:47 +08002178{
2179 if (reqData.size() < sizeof(HttpsBootAttr))
2180 return ipmi::responseReqDataLenInvalid();
2181
2182 std::vector<uint8_t> resData;
2183
2184 switch (static_cast<HttpsBootAttr>(reqData[0]))
2185 {
2186 case HttpsBootAttr::certSize:
2187 {
2188 std::error_code ec;
2189 auto fileSize = std::filesystem::file_size(certPath, ec);
2190 if (ec || fileSize > std::numeric_limits<uint16_t>::max())
2191 return ipmi::responseUnspecifiedError();
2192
2193 uint16_t size = static_cast<uint16_t>(fileSize);
2194 resData.resize(sizeof(uint16_t));
2195 std::memcpy(resData.data(), &size, sizeof(uint16_t));
2196 break;
2197 }
2198 case HttpsBootAttr::certCrc:
2199 {
2200 std::ifstream file(certPath, std::ios::binary);
2201 if (!file)
2202 return ipmi::responseUnspecifiedError();
2203
2204 boost::crc_32_type result;
2205 char data[1024];
2206 while (file.read(data, sizeof(data)))
2207 result.process_bytes(data, file.gcount());
2208 if (file.gcount() > 0)
2209 result.process_bytes(data, file.gcount());
2210
2211 uint32_t crc = result.checksum();
2212 resData.resize(sizeof(uint32_t));
2213 std::memcpy(resData.data(), &crc, sizeof(uint32_t));
2214 break;
2215 }
2216 default:
2217 return ipmi::responseInvalidFieldRequest();
2218 }
2219
2220 return ipmi::responseSuccess(resData);
2221}
2222
Cosmo Chou7ab87bb2024-06-28 10:47:44 +08002223// OEM Crashdump related functions
2224static ipmi_ret_t setDumpState(CrdState& currState, CrdState newState)
2225{
2226 switch (newState)
2227 {
2228 case CrdState::waitData:
2229 if (currState == CrdState::packing)
2230 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
2231 break;
2232 case CrdState::packing:
2233 if (currState != CrdState::waitData)
2234 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
2235 break;
2236 case CrdState::free:
2237 break;
2238 default:
2239 return IPMI_CC_UNSPECIFIED_ERROR;
2240 }
2241 currState = newState;
2242
2243 return IPMI_CC_OK;
2244}
2245
2246static ipmi_ret_t handleMcaBank(const CrashDumpHdr& hdr,
2247 std::span<const uint8_t> data,
2248 CrdState& currState, std::stringstream& ss)
2249{
2250 if (data.size() < sizeof(CrdMcaBank))
2251 return IPMI_CC_REQ_DATA_LEN_INVALID;
2252
2253 ipmi_ret_t res = setDumpState(currState, CrdState::waitData);
2254 if (res)
2255 return res;
2256
2257 const auto* pBank = reinterpret_cast<const CrdMcaBank*>(data.data());
2258 ss << std::format(" Bank ID : 0x{:02X}, Core ID : 0x{:02X}\n",
2259 hdr.bankHdr.bankId, hdr.bankHdr.coreId);
2260 ss << std::format(" MCA_CTRL : 0x{:016X}\n", pBank->mcaCtrl);
2261 ss << std::format(" MCA_STATUS : 0x{:016X}\n", pBank->mcaSts);
2262 ss << std::format(" MCA_ADDR : 0x{:016X}\n", pBank->mcaAddr);
2263 ss << std::format(" MCA_MISC0 : 0x{:016X}\n", pBank->mcaMisc0);
2264 ss << std::format(" MCA_CTRL_MASK : 0x{:016X}\n", pBank->mcaCtrlMask);
2265 ss << std::format(" MCA_CONFIG : 0x{:016X}\n", pBank->mcaConfig);
2266 ss << std::format(" MCA_IPID : 0x{:016X}\n", pBank->mcaIpid);
2267 ss << std::format(" MCA_SYND : 0x{:016X}\n", pBank->mcaSynd);
2268 ss << std::format(" MCA_DESTAT : 0x{:016X}\n", pBank->mcaDestat);
2269 ss << std::format(" MCA_DEADDR : 0x{:016X}\n", pBank->mcaDeaddr);
2270 ss << std::format(" MCA_MISC1 : 0x{:016X}\n", pBank->mcaMisc1);
2271 ss << "\n";
2272
2273 return IPMI_CC_OK;
2274}
2275
2276template <typename T>
2277static ipmi_ret_t handleVirtualBank(std::span<const uint8_t> data,
2278 CrdState& currState, std::stringstream& ss)
2279{
2280 if (data.size() < sizeof(T))
2281 return IPMI_CC_REQ_DATA_LEN_INVALID;
2282
2283 const auto* pBank = reinterpret_cast<const T*>(data.data());
2284
2285 if (data.size() < sizeof(T) + sizeof(BankCorePair) * pBank->mcaCount)
2286 return IPMI_CC_REQ_DATA_LEN_INVALID;
2287
2288 ipmi_ret_t res = setDumpState(currState, CrdState::waitData);
2289 if (res)
2290 return res;
2291
2292 ss << " Virtual Bank\n";
2293 ss << std::format(" S5_RESET_STATUS : 0x{:08X}\n", pBank->s5ResetSts);
2294 ss << std::format(" PM_BREAKEVENT : 0x{:08X}\n", pBank->breakevent);
2295 if constexpr (std::is_same_v<T, CrdVirtualBankV3>)
2296 {
2297 ss << std::format(" WARMCOLDRSTSTATUS : 0x{:08X}\n", pBank->rstSts);
2298 }
2299 ss << std::format(" PROCESSOR NUMBER : 0x{:04X}\n", pBank->procNum);
2300 ss << std::format(" APIC ID : 0x{:08X}\n", pBank->apicId);
2301 ss << std::format(" EAX : 0x{:08X}\n", pBank->eax);
2302 ss << std::format(" EBX : 0x{:08X}\n", pBank->ebx);
2303 ss << std::format(" ECX : 0x{:08X}\n", pBank->ecx);
2304 ss << std::format(" EDX : 0x{:08X}\n", pBank->edx);
2305 ss << " VALID LIST : ";
2306 for (size_t i = 0; i < pBank->mcaCount; i++)
2307 {
2308 ss << std::format("(0x{:02X},0x{:02X}) ", pBank->mcaList[i].bankId,
2309 pBank->mcaList[i].coreId);
2310 }
2311 ss << "\n\n";
2312
2313 return IPMI_CC_OK;
2314}
2315
2316static ipmi_ret_t handleCpuWdtBank(std::span<const uint8_t> data,
2317 CrdState& currState, std::stringstream& ss)
2318{
2319 if (data.size() < sizeof(CrdCpuWdtBank))
2320 return IPMI_CC_REQ_DATA_LEN_INVALID;
2321
2322 ipmi_ret_t res = setDumpState(currState, CrdState::waitData);
2323 if (res)
2324 return res;
2325
2326 const auto* pBank = reinterpret_cast<const CrdCpuWdtBank*>(data.data());
2327 for (size_t i = 0; i < ccmNum; i++)
2328 {
2329 ss << std::format(" [CCM{}]\n", i);
2330 ss << std::format(" HwAssertStsHi : 0x{:08X}\n",
2331 pBank->hwAssertStsHi[i]);
2332 ss << std::format(" HwAssertStsLo : 0x{:08X}\n",
2333 pBank->hwAssertStsLo[i]);
2334 ss << std::format(" OrigWdtAddrLogHi : 0x{:08X}\n",
2335 pBank->origWdtAddrLogHi[i]);
2336 ss << std::format(" OrigWdtAddrLogLo : 0x{:08X}\n",
2337 pBank->origWdtAddrLogLo[i]);
2338 ss << std::format(" HwAssertMskHi : 0x{:08X}\n",
2339 pBank->hwAssertMskHi[i]);
2340 ss << std::format(" HwAssertMskLo : 0x{:08X}\n",
2341 pBank->hwAssertMskLo[i]);
2342 ss << std::format(" OrigWdtAddrLogStat : 0x{:08X}\n",
2343 pBank->origWdtAddrLogStat[i]);
2344 }
2345 ss << "\n";
2346
2347 return IPMI_CC_OK;
2348}
2349
2350template <size_t N>
Patrick Williams010dee02024-08-16 15:19:44 -04002351static ipmi_ret_t
2352 handleHwAssertBank(const char* name, std::span<const uint8_t> data,
2353 CrdState& currState, std::stringstream& ss)
Cosmo Chou7ab87bb2024-06-28 10:47:44 +08002354{
2355 if (data.size() < sizeof(CrdHwAssertBank<N>))
2356 return IPMI_CC_REQ_DATA_LEN_INVALID;
2357
2358 ipmi_ret_t res = setDumpState(currState, CrdState::waitData);
2359 if (res)
2360 return res;
2361
2362 const CrdHwAssertBank<N>* pBank =
2363 reinterpret_cast<const CrdHwAssertBank<N>*>(data.data());
2364
2365 for (size_t i = 0; i < N; i++)
2366 {
2367 ss << std::format(" [{}{}]\n", name, i);
2368 ss << std::format(" HwAssertStsHi : 0x{:08X}\n",
2369 pBank->hwAssertStsHi[i]);
2370 ss << std::format(" HwAssertStsLo : 0x{:08X}\n",
2371 pBank->hwAssertStsLo[i]);
2372 ss << std::format(" HwAssertMskHi : 0x{:08X}\n",
2373 pBank->hwAssertMskHi[i]);
2374 ss << std::format(" HwAssertMskLo : 0x{:08X}\n",
2375 pBank->hwAssertMskLo[i]);
2376 }
2377 ss << "\n";
2378
2379 return IPMI_CC_OK;
2380}
2381
2382static ipmi_ret_t handlePcieAerBank(std::span<const uint8_t> data,
2383 CrdState& currState, std::stringstream& ss)
2384{
2385 if (data.size() < sizeof(CrdPcieAerBank))
2386 return IPMI_CC_REQ_DATA_LEN_INVALID;
2387
2388 ipmi_ret_t res = setDumpState(currState, CrdState::waitData);
2389 if (res)
2390 return res;
2391
2392 const auto* pBank = reinterpret_cast<const CrdPcieAerBank*>(data.data());
2393 ss << std::format(" [Bus{} Dev{} Fun{}]\n", pBank->bus, pBank->dev,
2394 pBank->fun);
2395 ss << std::format(" Command : 0x{:04X}\n",
2396 pBank->cmd);
2397 ss << std::format(" Status : 0x{:04X}\n",
2398 pBank->sts);
2399 ss << std::format(" Slot : 0x{:04X}\n",
2400 pBank->slot);
2401 ss << std::format(" Secondary Bus : 0x{:02X}\n",
2402 pBank->secondBus);
2403 ss << std::format(" Vendor ID : 0x{:04X}\n",
2404 pBank->vendorId);
2405 ss << std::format(" Device ID : 0x{:04X}\n",
2406 pBank->devId);
2407 ss << std::format(" Class Code : 0x{:02X}{:04X}\n",
2408 pBank->classCodeHi, pBank->classCodeLo);
2409 ss << std::format(" Bridge: Secondary Status : 0x{:04X}\n",
2410 pBank->secondSts);
2411 ss << std::format(" Bridge: Control : 0x{:04X}\n",
2412 pBank->ctrl);
2413 ss << std::format(" Uncorrectable Error Status : 0x{:08X}\n",
2414 pBank->uncorrErrSts);
2415 ss << std::format(" Uncorrectable Error Mask : 0x{:08X}\n",
2416 pBank->uncorrErrMsk);
2417 ss << std::format(" Uncorrectable Error Severity : 0x{:08X}\n",
2418 pBank->uncorrErrSeverity);
2419 ss << std::format(" Correctable Error Status : 0x{:08X}\n",
2420 pBank->corrErrSts);
2421 ss << std::format(" Correctable Error Mask : 0x{:08X}\n",
2422 pBank->corrErrMsk);
2423 ss << std::format(" Header Log DW0 : 0x{:08X}\n",
2424 pBank->hdrLogDw0);
2425 ss << std::format(" Header Log DW1 : 0x{:08X}\n",
2426 pBank->hdrLogDw1);
2427 ss << std::format(" Header Log DW2 : 0x{:08X}\n",
2428 pBank->hdrLogDw2);
2429 ss << std::format(" Header Log DW3 : 0x{:08X}\n",
2430 pBank->hdrLogDw3);
2431 ss << std::format(" Root Error Status : 0x{:08X}\n",
2432 pBank->rootErrSts);
2433 ss << std::format(" Correctable Error Source ID : 0x{:04X}\n",
2434 pBank->corrErrSrcId);
2435 ss << std::format(" Error Source ID : 0x{:04X}\n",
2436 pBank->errSrcId);
2437 ss << std::format(" Lane Error Status : 0x{:08X}\n",
2438 pBank->laneErrSts);
2439 ss << "\n";
2440
2441 return IPMI_CC_OK;
2442}
2443
2444static ipmi_ret_t handleWdtRegBank(std::span<const uint8_t> data,
2445 CrdState& currState, std::stringstream& ss)
2446{
2447 if (data.size() < sizeof(CrdWdtRegBank))
2448 return IPMI_CC_REQ_DATA_LEN_INVALID;
2449
2450 const auto* pBank = reinterpret_cast<const CrdWdtRegBank*>(data.data());
2451 if (data.size() < sizeof(CrdWdtRegBank) + sizeof(uint32_t) * pBank->count)
2452 return IPMI_CC_REQ_DATA_LEN_INVALID;
2453
2454 ipmi_ret_t res = setDumpState(currState, CrdState::waitData);
2455 if (res)
2456 return res;
2457
2458 ss << std::format(" [NBIO{}] {}\n", pBank->nbio, pBank->name);
2459 ss << std::format(" Address: 0x{:08X}\n", pBank->addr);
2460 ss << std::format(" Data Count: {}\n", pBank->count);
2461 ss << " Data:\n";
2462 for (size_t i = 0; i < pBank->count; i++)
2463 {
2464 ss << std::format(" {}: 0x{:08X}\n", i, pBank->data[i]);
2465 }
2466 ss << "\n";
2467
2468 return IPMI_CC_OK;
2469}
2470
2471static ipmi_ret_t handleCrdHdrBank(std::span<const uint8_t> data,
2472 CrdState& currState, std::stringstream& ss)
2473{
2474 if (data.size() < sizeof(CrdHdrBank))
2475 return IPMI_CC_REQ_DATA_LEN_INVALID;
2476
2477 ipmi_ret_t res = setDumpState(currState, CrdState::waitData);
2478 if (res)
2479 return res;
2480
2481 const auto* pBank = reinterpret_cast<const CrdHdrBank*>(data.data());
2482 ss << " Crashdump Header\n";
2483 ss << std::format(" CPU PPIN : 0x{:016X}\n", pBank->ppin);
2484 ss << std::format(" UCODE VERSION : 0x{:08X}\n", pBank->ucodeVer);
2485 ss << std::format(" PMIO 80h : 0x{:08X}\n", pBank->pmio);
2486 ss << std::format(
2487 " BIT0 - SMN Parity/SMN Timeouts PSP/SMU Parity and ECC/SMN On-Package Link Error : {}\n",
2488 pBank->pmio & 0x1);
2489 ss << std::format(" BIT2 - PSP Parity and ECC : {}\n",
2490 (pBank->pmio & 0x4) >> 2);
2491 ss << std::format(" BIT3 - SMN Timeouts SMU : {}\n",
2492 (pBank->pmio & 0x8) >> 3);
2493 ss << std::format(" BIT4 - SMN Off-Package Link Packet Error : {}\n",
2494 (pBank->pmio & 0x10) >> 4);
2495 ss << "\n";
2496
2497 return IPMI_CC_OK;
2498}
2499
2500static std::string getFilename(const std::filesystem::path& dir,
2501 const std::string& prefix)
2502{
2503 std::vector<int> indices;
2504 std::regex pattern(prefix + "(\\d+)\\.txt");
2505
2506 for (const auto& entry : std::filesystem::directory_iterator(dir))
2507 {
2508 std::string filename = entry.path().filename().string();
2509 std::smatch match;
2510 if (std::regex_match(filename, match, pattern))
2511 indices.push_back(std::stoi(match[1]));
2512 }
2513
2514 std::sort(indices.rbegin(), indices.rend());
2515 while (indices.size() > 2) // keep 3 files, so remove if more than 2
2516 {
2517 std::filesystem::remove(
2518 dir / (prefix + std::to_string(indices.back()) + ".txt"));
2519 indices.pop_back();
2520 }
2521
2522 int nextIndex = indices.empty() ? 1 : indices.front() + 1;
2523 return prefix + std::to_string(nextIndex) + ".txt";
2524}
2525
2526static ipmi_ret_t handleCtrlBank(std::span<const uint8_t> data,
2527 CrdState& currState, std::stringstream& ss)
2528{
2529 if (data.empty())
2530 return IPMI_CC_REQ_DATA_LEN_INVALID;
2531
2532 switch (static_cast<CrdCtrl>(data[0]))
2533 {
2534 case CrdCtrl::getState:
2535 break;
2536 case CrdCtrl::finish:
2537 {
2538 ipmi_ret_t res = setDumpState(currState, CrdState::packing);
2539 if (res)
2540 return res;
2541
2542 const std::filesystem::path dumpDir = "/var/lib/fb-ipmi-oem";
2543 std::string filename = getFilename(dumpDir, "crashdump_");
2544 std::ofstream outFile(dumpDir / filename);
2545 if (!outFile.is_open())
2546 return IPMI_CC_UNSPECIFIED_ERROR;
2547
2548 auto now = std::chrono::system_clock::to_time_t(
2549 std::chrono::system_clock::now());
2550 outFile << "Crash Dump generated at: "
2551 << std::put_time(std::localtime(&now), "%Y-%m-%d %H:%M:%S")
2552 << "\n\n";
2553 outFile << ss.str();
2554 outFile.close();
2555 ss.str("");
2556 ss.clear();
2557 setDumpState(currState, CrdState::free);
2558 break;
2559 }
2560 default:
2561 return ccInvalidParam;
2562 }
2563
2564 return IPMI_CC_OK;
2565}
2566
Patrick Williams010dee02024-08-16 15:19:44 -04002567ipmi::RspType<std::vector<uint8_t>> ipmiOemCrashdump(
2568 [[maybe_unused]] ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
Cosmo Chou7ab87bb2024-06-28 10:47:44 +08002569{
2570 static CrdState dumpState = CrdState::free;
2571 static std::stringstream ss;
2572
2573 if (reqData.size() < sizeof(CrashDumpHdr))
2574 return ipmi::responseReqDataLenInvalid();
2575
2576 const auto* pHdr = reinterpret_cast<const CrashDumpHdr*>(reqData.data());
2577 std::span<const uint8_t> bData{reqData.data() + sizeof(CrashDumpHdr),
2578 reqData.size() - sizeof(CrashDumpHdr)};
2579 ipmi_ret_t res;
2580
2581 switch (pHdr->bankHdr.bankType)
2582 {
2583 case BankType::mca:
2584 res = handleMcaBank(*pHdr, bData, dumpState, ss);
2585 break;
2586 case BankType::virt:
2587 if (pHdr->bankHdr.version >= 3)
2588 {
2589 res = handleVirtualBank<CrdVirtualBankV3>(bData, dumpState, ss);
2590 break;
2591 }
2592 res = handleVirtualBank<CrdVirtualBankV2>(bData, dumpState, ss);
2593 break;
2594 case BankType::cpuWdt:
2595 res = handleCpuWdtBank(bData, dumpState, ss);
2596 break;
2597 case BankType::tcdx:
2598 res = handleHwAssertBank<tcdxNum>("TCDX", bData, dumpState, ss);
2599 break;
2600 case BankType::cake:
2601 res = handleHwAssertBank<cakeNum>("CAKE", bData, dumpState, ss);
2602 break;
2603 case BankType::pie0:
2604 res = handleHwAssertBank<pie0Num>("PIE", bData, dumpState, ss);
2605 break;
2606 case BankType::iom:
2607 res = handleHwAssertBank<iomNum>("IOM", bData, dumpState, ss);
2608 break;
2609 case BankType::ccix:
2610 res = handleHwAssertBank<ccixNum>("CCIX", bData, dumpState, ss);
2611 break;
2612 case BankType::cs:
2613 res = handleHwAssertBank<csNum>("CS", bData, dumpState, ss);
2614 break;
2615 case BankType::pcieAer:
2616 res = handlePcieAerBank(bData, dumpState, ss);
2617 break;
2618 case BankType::wdtReg:
2619 res = handleWdtRegBank(bData, dumpState, ss);
2620 break;
2621 case BankType::ctrl:
2622 res = handleCtrlBank(bData, dumpState, ss);
2623 if (res == IPMI_CC_OK &&
2624 static_cast<CrdCtrl>(bData[0]) == CrdCtrl::getState)
2625 {
2626 return ipmi::responseSuccess(
2627 std::vector<uint8_t>{static_cast<uint8_t>(dumpState)});
2628 }
2629 break;
2630 case BankType::crdHdr:
2631 res = handleCrdHdrBank(bData, dumpState, ss);
2632 break;
2633 default:
2634 return ipmi::responseInvalidFieldRequest();
2635 }
2636
2637 return ipmi::response(res);
2638}
2639
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002640static void registerOEMFunctions(void)
2641{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002642 /* Get OEM data from json file */
2643 std::ifstream file(JSON_OEM_DATA_FILE);
2644 if (file)
Vijay Khemkafeaa9812019-08-27 15:08:08 -07002645 {
Peter Yinac597172024-11-05 16:15:50 +08002646 try
2647 {
2648 file >> oemData;
2649 }
2650 // If parsing fails, initialize oemData as an empty JSON and
2651 // overwrite the file
2652 catch (const nlohmann::json::parse_error& e)
2653 {
2654 lg2::error("Error parsing JSON file: {ERROR}", "ERROR", e);
2655 oemData = nlohmann::json::object();
2656 std::ofstream outFile(JSON_OEM_DATA_FILE, std::ofstream::trunc);
2657 outFile << oemData.dump(4); // Write empty JSON object to the file
2658 outFile.close();
2659 }
Vijay Khemkafeaa9812019-08-27 15:08:08 -07002660 file.close();
2661 }
Peter Yinac597172024-11-05 16:15:50 +08002662 else
2663 {
2664 lg2::info("Failed to open JSON file.");
2665 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002666
Peter Yinac597172024-11-05 16:15:50 +08002667 lg2::info("Registering OEM commands.");
Vijay Khemka7c0aea42020-03-05 13:31:53 -08002668
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002669 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO,
2670 NULL, ipmiOemDbgGetFrameInfo,
2671 PRIVILEGE_USER); // get debug frame info
2672 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ,
2673 CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL,
2674 ipmiOemDbgGetUpdFrames,
2675 PRIVILEGE_USER); // get debug updated frames
2676 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC,
2677 NULL, ipmiOemDbgGetPostDesc,
2678 PRIVILEGE_USER); // get debug post description
2679 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC,
2680 NULL, ipmiOemDbgGetGpioDesc,
2681 PRIVILEGE_USER); // get debug gpio description
2682 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA,
2683 NULL, ipmiOemDbgGetFrameData,
2684 PRIVILEGE_USER); // get debug frame data
2685 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL,
2686 NULL, ipmiOemDbgGetCtrlPanel,
2687 PRIVILEGE_USER); // get debug control panel
2688 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL,
2689 ipmiOemSetDimmInfo,
2690 PRIVILEGE_USER); // Set Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002691 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
2692 ipmiOemGetBoardID,
2693 PRIVILEGE_USER); // Get Board ID
Bonnie Lo4ae63e72023-02-09 15:27:54 +08002694 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemOne,
2695 CMD_OEM_GET_80PORT_RECORD, ipmi::Privilege::User,
2696 ipmiOemGet80PortRecord); // Get 80 Port Record
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002697 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL,
2698 ipmiOemSetMachineCfgInfo,
2699 PRIVILEGE_USER); // Set Machine Config Info
2700 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL,
2701 ipmiOemSetPostStart,
2702 PRIVILEGE_USER); // Set POST start
2703 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL,
2704 ipmiOemSetPostEnd,
2705 PRIVILEGE_USER); // Set POST End
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002706 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
2707 ipmiOemSetPPINInfo,
2708 PRIVILEGE_USER); // Set PPIN Info
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302709#if BIC_ENABLED
2710
2711 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2712 ipmi::cmdSetSystemGuid, ipmi::Privilege::User,
2713 ipmiOemSetSystemGuid);
2714#else
2715
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07002716 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL,
2717 ipmiOemSetSystemGuid,
2718 PRIVILEGE_USER); // Set System GUID
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302719#endif
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002720 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
2721 ipmiOemSetAdrTrigger,
2722 PRIVILEGE_USER); // Set ADR Trigger
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002723 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL,
2724 ipmiOemSetBiosFlashInfo,
2725 PRIVILEGE_USER); // Set Bios Flash Info
2726 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr,
2727 PRIVILEGE_USER); // Set PPR
2728 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr,
2729 PRIVILEGE_USER); // Get PPR
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002730 /* FB OEM QC Commands */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05302731 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2732 CMD_OEM_Q_SET_PROC_INFO, ipmi::Privilege::User,
2733 ipmiOemQSetProcInfo); // Set Proc Info
2734 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2735 CMD_OEM_Q_GET_PROC_INFO, ipmi::Privilege::User,
2736 ipmiOemQGetProcInfo); // Get Proc Info
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05302737 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2738 ipmi::cmdSetQDimmInfo, ipmi::Privilege::User,
2739 ipmiOemQSetDimmInfo); // Set Dimm Info
2740 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2741 ipmi::cmdGetQDimmInfo, ipmi::Privilege::User,
2742 ipmiOemQGetDimmInfo); // Get Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002743 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL,
2744 ipmiOemQSetDriveInfo,
2745 PRIVILEGE_USER); // Set Drive Info
2746 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL,
2747 ipmiOemQGetDriveInfo,
2748 PRIVILEGE_USER); // Get Drive Info
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002749
2750 /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */
Patrick Williams010dee02024-08-16 15:19:44 -04002751 ipmi::registerGroupHandler(
2752 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdGetPowerReading,
2753 ipmi::Privilege::User,
2754 ipmiOemDCMIGetPowerReading); // Get Power Reading
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002755
Patrick Williams010dee02024-08-16 15:19:44 -04002756 ipmi::registerGroupHandler(
2757 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdGetPowerLimit,
2758 ipmi::Privilege::User,
2759 ipmiOemDCMIGetPowerLimit); // Get Power Limit
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002760
Patrick Williams010dee02024-08-16 15:19:44 -04002761 ipmi::registerGroupHandler(
2762 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdSetPowerLimit,
2763 ipmi::Privilege::Operator,
2764 ipmiOemDCMISetPowerLimit); // Set Power Limit
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002765
Patrick Williams010dee02024-08-16 15:19:44 -04002766 ipmi::registerGroupHandler(
2767 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdActDeactivatePwrLimit,
2768 ipmi::Privilege::Operator,
2769 ipmiOemDCMIApplyPowerLimit); // Apply Power Limit
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002770
Jayashree-Df0cf6652020-11-30 11:03:30 +05302771 /* FB OEM BOOT ORDER COMMANDS */
2772 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2773 CMD_OEM_GET_BOOT_ORDER, ipmi::Privilege::User,
2774 ipmiOemGetBootOrder); // Get Boot Order
2775
2776 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2777 CMD_OEM_SET_BOOT_ORDER, ipmi::Privilege::User,
2778 ipmiOemSetBootOrder); // Set Boot Order
2779
Cosmo Chou7ab87bb2024-06-28 10:47:44 +08002780 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
Cosmo Chou99d42b62024-08-15 10:42:47 +08002781 CMD_OEM_GET_HTTPS_BOOT_DATA, ipmi::Privilege::User,
2782 ipmiOemGetHttpsData);
2783
2784 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2785 CMD_OEM_GET_HTTPS_BOOT_ATTR, ipmi::Privilege::User,
2786 ipmiOemGetHttpsAttr);
2787
2788 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
Cosmo Chou7ab87bb2024-06-28 10:47:44 +08002789 CMD_OEM_CRASHDUMP, ipmi::Privilege::User,
2790 ipmiOemCrashdump);
2791
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002792 return;
2793}
2794
2795} // namespace ipmi