1 /*
2 * Copyright (c) 2018 Intel Corporation.
3 * Copyright (c) 2018-present Facebook.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "xyz/openbmc_project/Common/error.hpp"
19
20 #include <boost/crc.hpp>
21 #include <commandutils.hpp>
22 #include <ipmid/api-types.hpp>
23 #include <ipmid/api.hpp>
24 #include <ipmid/utils.hpp>
25 #include <nlohmann/json.hpp>
26 #include <oemcommands.hpp>
27 #include <phosphor-logging/log.hpp>
28 #include <sdbusplus/bus.hpp>
29 #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>
32
33 #include <array>
34 #include <cstring>
35 #include <fstream>
36 #include <iomanip>
37 #include <iostream>
38 #include <regex>
39 #include <sstream>
40 #include <string>
41 #include <vector>
42
43 #define SIZE_IANA_ID 3
44
45 namespace ipmi
46 {
47
48 using namespace phosphor::logging;
49
50 void getSelectorPosition(size_t& position);
51 static void registerOEMFunctions() __attribute__((constructor));
52 sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
53 static constexpr size_t maxFRUStringLength = 0x3F;
54 constexpr uint8_t cmdSetSystemGuid = 0xEF;
55
56 constexpr uint8_t cmdSetQDimmInfo = 0x12;
57 constexpr uint8_t cmdGetQDimmInfo = 0x13;
58
59 constexpr ipmi_ret_t ccInvalidParam = 0x80;
60
61 int plat_udbg_get_post_desc(uint8_t, uint8_t*, uint8_t, uint8_t*, uint8_t*,
62 uint8_t*);
63 int plat_udbg_get_gpio_desc(uint8_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*,
64 uint8_t*);
65 int plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t*, uint8_t*, uint8_t*);
66 ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t*,
67 uint8_t*);
68 int sendMeCmd(uint8_t, uint8_t, std::vector<uint8_t>&, std::vector<uint8_t>&);
69
70 int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
71 std::vector<uint8_t>&);
72
73 nlohmann::json oemData __attribute__((init_priority(101)));
74
75 constexpr const char* certPath = "/mnt/data/host/bios-rootcert";
76
77 static 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.
80 static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
81 static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
82 void flushOemData();
83
84 enum 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
100 namespace network
101 {
102
103 constexpr auto ROOT = "/xyz/openbmc_project/network";
104 constexpr auto SERVICE = "xyz.openbmc_project.Network";
105 constexpr auto IPV4_TYPE = "ipv4";
106 constexpr auto IPV6_TYPE = "ipv6";
107 constexpr auto IPV4_PREFIX = "169.254";
108 constexpr auto IPV6_PREFIX = "fe80";
109 constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
110 constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
111 constexpr auto IPV4_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
112 constexpr auto IPV6_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
113
isLinkLocalIP(const std::string & address)114 bool isLinkLocalIP(const std::string& address)
115 {
116 return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
117 }
118
getIPObject(sdbusplus::bus_t & bus,const std::string & interface,const std::string & serviceRoot,const std::string & protocol,const std::string & ethdev)119 DbusObjectInfo getIPObject(sdbusplus::bus_t& bus, const std::string& interface,
120 const std::string& serviceRoot,
121 const std::string& protocol,
122 const std::string& ethdev)
123 {
124 auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, ethdev);
125
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
134 for (auto& object : objectTree)
135 {
136 auto variant =
137 ipmi::getDbusProperty(bus, object.second.begin()->first,
138 object.first, IP_INTERFACE, "Type");
139 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");
146
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
164 namespace boot
165 {
166 using BootSource =
167 sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources;
168 using BootMode =
169 sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes;
170 using BootType =
171 sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types;
172
173 using IpmiValue = uint8_t;
174
175 std::map<IpmiValue, BootSource> sourceIpmiToDbus = {
176 {0x0f, BootSource::Default}, {0x00, BootSource::RemovableMedia},
177 {0x01, BootSource::Network}, {0x02, BootSource::Disk},
178 {0x03, BootSource::ExternalMedia}, {0x04, BootSource::RemovableMedia},
179 {0x09, BootSource::Network}};
180
181 std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x04, BootMode::Setup},
182 {0x00, BootMode::Regular}};
183
184 std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy},
185 {0x01, BootType::EFI}};
186
187 std::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}};
193
194 std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = {
195 {BootMode::Setup, 0x04}, {BootMode::Regular, 0x00}};
196
197 std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = {
198 {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}};
199
200 static constexpr auto bootEnableIntf = "xyz.openbmc_project.Object.Enable";
201 static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
202 static constexpr auto bootSourceIntf =
203 "xyz.openbmc_project.Control.Boot.Source";
204 static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
205 static constexpr auto bootSourceProp = "BootSource";
206 static constexpr auto bootModeProp = "BootMode";
207 static constexpr auto bootTypeProp = "BootType";
208 static constexpr auto bootEnableProp = "Enabled";
209
objPath(size_t id)210 std::tuple<std::string, std::string> objPath(size_t id)
211 {
212 std::string hostName = "host" + std::to_string(id);
213 std::string bootObjPath =
214 "/xyz/openbmc_project/control/" + hostName + "/boot";
215 return std::make_tuple(std::move(bootObjPath), std::move(hostName));
216 }
217
218 /* Helper functions to set boot order */
setBootOrder(std::string bootObjPath,const std::vector<uint8_t> & bootSeq,std::string bootOrderKey)219 void 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
240 std::string service =
241 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
242 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
getBootOrder(std::string bootObjPath,std::vector<uint8_t> & bootSeq,std::string hostName)295 void 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
318 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);
323
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);
332 variant =
333 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
334 ipmi::boot::bootTypeProp);
335
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);
341 variant =
342 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootEnableIntf,
343 ipmi::boot::bootEnableProp);
344
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
370 } // namespace boot
371
372 //----------------------------------------------------------------------
373 // Helper functions for storing oem data
374 //----------------------------------------------------------------------
375
flushOemData()376 void flushOemData()
377 {
378 std::ofstream file(JSON_OEM_DATA_FILE);
379 file << oemData;
380 file.close();
381 return;
382 }
383
bytesToStr(uint8_t * byte,int len)384 std::string bytesToStr(uint8_t* byte, int len)
385 {
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
strToBytes(std::string & str,uint8_t * data)398 int strToBytes(std::string& str, uint8_t* data)
399 {
400 std::string sstr;
401 size_t i;
402
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
readDimmType(std::string & data,uint8_t param)411 int 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
getNetworkData(uint8_t lan_param,char * data)435 ipmi_ret_t getNetworkData(uint8_t lan_param, char* data)
436 {
437 ipmi_ret_t rc = IPMI_CC_OK;
438 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
439
440 const std::string ethdevice = "eth0";
441
442 switch (static_cast<LanParam>(lan_param))
443 {
444 case LanParam::IP:
445 {
446 std::string ipaddress;
447 auto ipObjectInfo = ipmi::network::getIPObject(
448 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
449 ipmi::network::IPV4_PROTOCOL, ethdevice);
450
451 auto properties = ipmi::getAllDbusProperties(
452 bus, ipObjectInfo.second, ipObjectInfo.first,
453 ipmi::network::IP_INTERFACE);
454
455 ipaddress = std::get<std::string>(properties["Address"]);
456
457 std::strcpy(data, ipaddress.c_str());
458 }
459 break;
460
461 case LanParam::IPV6:
462 {
463 std::string ipaddress;
464 auto ipObjectInfo = ipmi::network::getIPObject(
465 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
466 ipmi::network::IPV6_PROTOCOL, ethdevice);
467
468 auto properties = ipmi::getAllDbusProperties(
469 bus, ipObjectInfo.second, ipObjectInfo.first,
470 ipmi::network::IP_INTERFACE);
471
472 ipaddress = std::get<std::string>(properties["Address"]);
473
474 std::strcpy(data, ipaddress.c_str());
475 }
476 break;
477
478 case LanParam::MAC:
479 {
480 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
489 macAddress = std::get<std::string>(variant);
490
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 }
503
isMultiHostPlatform()504 bool isMultiHostPlatform()
505 {
506 bool platform;
507 if (hostInstances == "0")
508 {
509 platform = false;
510 }
511 else
512 {
513 platform = true;
514 }
515 return platform;
516 }
517
518 // return "" equals failed
getMotherBoardFruPath()519 std::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
getMotherBoardFruName()553 std::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
573 // return code: 0 successful
getFruData(std::string & data,std::string & name)574 int8_t getFruData(std::string& data, std::string& name)
575 {
576 size_t pos;
577 static constexpr const auto depth = 0;
578 std::vector<std::string> paths;
579 std::string machinePath;
580 std::string baseBoard = getMotherBoardFruPath();
581 baseBoard = baseBoard.empty() ? "Baseboard" : baseBoard;
582
583 bool platform = isMultiHostPlatform();
584 if (platform == true)
585 {
586 getSelectorPosition(pos);
587 }
588
589 sd_bus* bus = NULL;
590 int ret = sd_bus_default_system(&bus);
591 if (ret < 0)
592 {
593 phosphor::logging::log<phosphor::logging::level::ERR>(
594 "Failed to connect to system bus",
595 phosphor::logging::entry("ERRNO=0x%X", -ret));
596 sd_bus_unref(bus);
597 return -1;
598 }
599 sdbusplus::bus_t dbus(bus);
600 auto mapperCall = dbus.new_method_call(
601 "xyz.openbmc_project.ObjectMapper",
602 "/xyz/openbmc_project/object_mapper",
603 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
604 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());
616 return -1;
617 }
618
619 for (const auto& path : paths)
620 {
621 if (platform == true)
622 {
623 if (pos == BMC_POS)
624 {
625 machinePath = baseBoard;
626 }
627 else
628 {
629 machinePath = "_" + std::to_string(pos);
630 }
631 }
632 else
633 {
634 machinePath = baseBoard;
635 }
636
637 auto found = path.find(machinePath);
638 if (found == std::string::npos)
639 {
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;
653 }
654 return -1;
655 }
656
sysConfig(std::vector<std::string> & data,size_t pos)657 int8_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
procInfo(std::string & result,size_t pos)743 int8_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
793 typedef 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
801 //----------------------------------------------------------------------
802 // Get Debug Frame Info
803 //----------------------------------------------------------------------
ipmiOemDbgGetFrameInfo(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)804 ipmi_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)
807 {
808 uint8_t* req = reinterpret_cast<uint8_t*>(request);
809 uint8_t* res = reinterpret_cast<uint8_t*>(response);
810 uint8_t num_frames = debugCardFrameSize;
811
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 //----------------------------------------------------------------------
ipmiOemDbgGetUpdFrames(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)822 ipmi_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)
825 {
826 uint8_t* req = reinterpret_cast<uint8_t*>(request);
827 uint8_t* res = reinterpret_cast<uint8_t*>(response);
828 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 //----------------------------------------------------------------------
ipmiOemDbgGetPostDesc(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)844 ipmi_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)
847 {
848 uint8_t* req = reinterpret_cast<uint8_t*>(request);
849 uint8_t* res = reinterpret_cast<uint8_t*>(response);
850 uint8_t index = 0;
851 uint8_t next = 0;
852 uint8_t end = 0;
853 uint8_t phase = 0;
854 uint8_t descLen = 0;
855 int ret;
856
857 index = req[3];
858 phase = req[4];
859
860 ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
861 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;
873 res[7] = descLen;
874 *data_len = SIZE_IANA_ID + 5 + descLen;
875
876 return IPMI_CC_OK;
877 }
878
879 //----------------------------------------------------------------------
880 // Get Debug GPIO Description
881 //----------------------------------------------------------------------
ipmiOemDbgGetGpioDesc(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)882 ipmi_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)
885 {
886 uint8_t* req = reinterpret_cast<uint8_t*>(request);
887 uint8_t* res = reinterpret_cast<uint8_t*>(response);
888
889 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;
895
896 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;
914
915 return IPMI_CC_OK;
916 }
917
918 //----------------------------------------------------------------------
919 // Get Debug Frame Data
920 //----------------------------------------------------------------------
ipmiOemDbgGetFrameData(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)921 ipmi_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)
924 {
925 uint8_t* req = reinterpret_cast<uint8_t*>(request);
926 uint8_t* res = reinterpret_cast<uint8_t*>(response);
927 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];
935
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 //----------------------------------------------------------------------
ipmiOemDbgGetCtrlPanel(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)957 ipmi_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)
960 {
961 uint8_t* req = reinterpret_cast<uint8_t*>(request);
962 uint8_t* res = reinterpret_cast<uint8_t*>(response);
963
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
982 //----------------------------------------------------------------------
983 // Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
984 //----------------------------------------------------------------------
ipmiOemSetDimmInfo(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)985 ipmi_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)
988 {
989 uint8_t* req = reinterpret_cast<uint8_t*>(request);
990
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 //----------------------------------------------------------------------
ipmiOemGetBoardID(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1018 ipmi_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)
1021 {
1022 /* TODO: Needs to implement this after GPIO implementation */
1023 *data_len = 0;
1024
1025 return IPMI_CC_OK;
1026 }
1027
1028 //----------------------------------------------------------------------
1029 // Get port 80 record (CMD_OEM_GET_80PORT_RECORD)
1030 //----------------------------------------------------------------------
1031 ipmi::RspType<std::vector<uint8_t>>
ipmiOemGet80PortRecord(ipmi::Context::ptr ctx)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 */
1050 auto msg =
1051 conn->new_method_call(postCodeService.c_str(), postCodeObjPath.c_str(),
1052 postCodeInterface, "GetPostCodes");
1053 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
1091 //----------------------------------------------------------------------
1092 // Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
1093 //----------------------------------------------------------------------
1094 ipmi::RspType<std::vector<uint8_t>>
ipmiOemSetBootOrder(ipmi::Context::ptr ctx,std::vector<uint8_t> bootSeq)1095 ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> bootSeq)
1096 {
1097 size_t len = bootSeq.size();
1098
1099 if (len != SIZE_BOOT_ORDER)
1100 {
1101 phosphor::logging::log<phosphor::logging::level::ERR>(
1102 "Invalid Boot order length received");
1103 return ipmi::responseReqDataLenInvalid();
1104 }
1105
1106 std::optional<size_t> hostId = findHost(ctx->hostIdx);
1107
1108 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
1116 ipmi::boot::setBootOrder(bootObjPath, bootSeq, hostName);
1117
1118 return ipmi::responseSuccess(bootSeq);
1119 }
1120
1121 //----------------------------------------------------------------------
1122 // Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
1123 //----------------------------------------------------------------------
ipmiOemGetBootOrder(ipmi::Context::ptr ctx)1124 ipmi::RspType<std::vector<uint8_t>> ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
1125 {
1126 std::vector<uint8_t> bootSeq;
1127
1128 std::optional<size_t> hostId = findHost(ctx->hostIdx);
1129
1130 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
1138 ipmi::boot::getBootOrder(bootObjPath, bootSeq, hostName);
1139
1140 return ipmi::responseSuccess(bootSeq);
1141 }
1142 // Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
1143 //----------------------------------------------------------------------
ipmiOemSetMachineCfgInfo(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1144 ipmi_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)
1147 {
1148 machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request);
1149 uint8_t len = *data_len;
1150
1151 *data_len = 0;
1152
1153 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
1160 if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*))
1161 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
1166 if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*))
1167 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
1176 if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*))
1177 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
1192 if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
1193 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
1198 if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
1199 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
1204 if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
1205 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
1210 if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
1211 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
1220 return IPMI_CC_OK;
1221 }
1222
1223 //----------------------------------------------------------------------
1224 // Set POST start (CMD_OEM_SET_POST_START)
1225 //----------------------------------------------------------------------
ipmiOemSetPostStart(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1226 ipmi_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)
1229 {
1230 phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
1231
1232 /* Do nothing, return success */
1233 *data_len = 0;
1234 return IPMI_CC_OK;
1235 }
1236
1237 //----------------------------------------------------------------------
1238 // Set POST End (CMD_OEM_SET_POST_END)
1239 //----------------------------------------------------------------------
ipmiOemSetPostEnd(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1240 ipmi_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)
1243 {
1244 struct timespec ts;
1245
1246 phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
1247
1248 *data_len = 0;
1249
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
ipmiOemSetPPINInfo(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1273 ipmi_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)
1276 {
1277 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1278 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 //----------------------------------------------------------------------
ipmiOemSetAdrTrigger(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1297 ipmi_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)
1300 {
1301 /* Do nothing, return success */
1302 *data_len = 0;
1303 return IPMI_CC_OK;
1304 }
1305
1306 // Helper function to set guid at offset in EEPROM
setGUID(off_t offset,uint8_t * guid)1307 [[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid)
1308 {
1309 int fd = -1;
1310 ssize_t len;
1311 int ret = 0;
1312 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 }
1325
1326 errno = 0;
1327
1328 // Check if file is present
1329 if (access(eepromPath.c_str(), F_OK) == -1)
1330 {
1331 std::cerr << "Unable to access: " << eepromPath << std::endl;
1332 return errno;
1333 }
1334
1335 // Open the file
1336 fd = open(eepromPath.c_str(), O_WRONLY);
1337 if (fd == -1)
1338 {
1339 std::cerr << "Unable to open: " << eepromPath << std::endl;
1340 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 //----------------------------------------------------------------------
1362 #if BIC_ENABLED
ipmiOemSetSystemGuid(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)1363 ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx,
1364 std::vector<uint8_t> reqData)
1365 {
1366 std::vector<uint8_t> respData;
1367
1368 if (reqData.size() != GUID_SIZE) // 16bytes
1369 {
1370 return ipmi::responseReqDataLenInvalid();
1371 }
1372
1373 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
ipmiOemSetSystemGuid(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1382 ipmi_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)
1385 {
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 }
1402 #endif
1403
1404 //----------------------------------------------------------------------
1405 // Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
1406 //----------------------------------------------------------------------
ipmiOemSetBiosFlashInfo(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1407 ipmi_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)
1410 {
1411 /* Do nothing, return success */
1412 *data_len = 0;
1413 return IPMI_CC_OK;
1414 }
1415
1416 //----------------------------------------------------------------------
1417 // Set PPR (CMD_OEM_SET_PPR)
1418 //----------------------------------------------------------------------
ipmiOemSetPpr(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1419 ipmi_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)
1422 {
1423 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1424 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;
1429
1430 *data_len = 0;
1431
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
1503 return IPMI_CC_OK;
1504 }
1505
1506 //----------------------------------------------------------------------
1507 // Get PPR (CMD_OEM_GET_PPR)
1508 //----------------------------------------------------------------------
ipmiOemGetPpr(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)1509 ipmi_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)
1512 {
1513 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1514 uint8_t* res = reinterpret_cast<uint8_t*>(response);
1515 uint8_t pprCnt, pprIndex;
1516 uint8_t selParam = req[0];
1517 std::stringstream ss;
1518 std::string str;
1519
1520 /* 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 //
1621
ipmiOemQSetProcInfo(ipmi::Context::ptr ctx,uint8_t,uint8_t,uint8_t,uint8_t procIndex,uint8_t paramSel,std::vector<uint8_t> request)1622 ipmi::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)
1625 {
1626 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
1627 std::stringstream ss;
1628 std::string str;
1629 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);
1638 /* check for requested data params */
1639 if (len < 5 || paramSel < 1 || paramSel >= numParam)
1640 {
1641 phosphor::logging::log<phosphor::logging::level::ERR>(
1642 "Invalid parameter received");
1643 return ipmi::responseParmOutOfRange();
1644 }
1645 ss << std::hex;
1646 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();
1650 flushOemData();
1651 return ipmi::responseSuccess();
1652 }
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 //
1679
1680 ipmi::RspType<std::vector<uint8_t>>
ipmiOemQGetProcInfo(ipmi::Context::ptr ctx,uint8_t,uint8_t,uint8_t,uint8_t procIndex,uint8_t paramSel)1681 ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1682 uint8_t procIndex, uint8_t paramSel)
1683 {
1684 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
1685 std::stringstream ss;
1686 std::string str;
1687 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)
1697 {
1698 phosphor::logging::log<phosphor::logging::level::ERR>(
1699 "Invalid parameter received");
1700 return ipmi::responseParmOutOfRange();
1701 }
1702 ss << std::hex;
1703 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);
1713 }
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 //
ipmiOemQSetDimmInfo(ipmi::Context::ptr ctx,uint8_t,uint8_t,uint8_t,uint8_t dimmIndex,uint8_t paramSel,std::vector<uint8_t> request)1772 ipmi::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)
1775 {
1776 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
1777 std::stringstream ss;
1778 std::string str;
1779 uint8_t len = request.size();
1780 std::string dimmType;
1781 readDimmType(dimmType, dimmIndex);
1782 auto hostId = findHost(ctx->hostIdx);
1783 if (!hostId)
1784 {
1785 phosphor::logging::log<phosphor::logging::level::ERR>(
1786 "Invalid Host Id received");
1787 return ipmi::responseInvalidCommand();
1788 }
1789
1790 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
1791
1792 if (len < 3 || paramSel < 1 || paramSel >= numParam)
1793 {
1794 phosphor::logging::log<phosphor::logging::level::ERR>(
1795 "Invalid parameter received");
1796 return ipmi::responseParmOutOfRange();
1797 }
1798
1799 ss << std::hex;
1800 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();
1805 flushOemData();
1806 return ipmi::responseSuccess();
1807 }
1808
1809 // 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 //
1867 ipmi::RspType<std::vector<uint8_t>>
ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx,uint8_t,uint8_t,uint8_t,uint8_t dimmIndex,uint8_t paramSel)1868 ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1869 uint8_t dimmIndex, uint8_t paramSel)
1870 {
1871 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
1872 uint8_t res[MAX_BUF];
1873 std::stringstream ss;
1874 std::string str;
1875 std::string dimmType;
1876 readDimmType(dimmType, dimmIndex);
1877 auto hostId = findHost(ctx->hostIdx);
1878 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);
1885
1886 if (paramSel < 1 || paramSel >= numParam)
1887 {
1888 phosphor::logging::log<phosphor::logging::level::ERR>(
1889 "Invalid parameter received");
1890 return ipmi::responseParmOutOfRange();
1891 }
1892 ss << std::hex;
1893 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);
1904 }
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 //
ipmiOemQSetDriveInfo(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t,ipmi_data_len_t data_len,ipmi_context_t)1981 ipmi_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)
1984 {
1985 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1986 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
1987 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 //
ipmiOemQGetDriveInfo(ipmi_netfn_t,ipmi_cmd_t,ipmi_request_t request,ipmi_response_t response,ipmi_data_len_t data_len,ipmi_context_t)2041 ipmi_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)
2044 {
2045 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);
2048 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);
2081
2082 return IPMI_CC_OK;
2083 }
2084
2085 /* Helper function for sending DCMI commands to ME/BIC and
2086 * getting response back
2087 */
2088 ipmi::RspType<std::vector<uint8_t>>
sendDCMICmd(ipmi::Context::ptr ctx,uint8_t cmd,std::vector<uint8_t> & cmdData)2089 sendDCMICmd([[maybe_unused]] ipmi::Context::ptr ctx,
2090 [[maybe_unused]] uint8_t cmd, std::vector<uint8_t>& cmdData)
2091 {
2092 std::vector<uint8_t> respData;
2093
2094 #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
2105 /* 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))
2109 {
2110 return ipmi::responseUnspecifiedError();
2111 }
2112
2113 /* Remove group id as first byte as it will be added by IPMID */
2114 respData.erase(respData.begin());
2115
2116 #endif
2117
2118 return ipmi::responseSuccess(std::move(respData));
2119 }
2120
2121 /* DCMI Command handellers. */
2122
ipmiOemDCMIGetPowerReading(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)2123 ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMIGetPowerReading(
2124 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
2125 {
2126 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerReading, reqData);
2127 }
2128
ipmiOemDCMIGetPowerLimit(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)2129 ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMIGetPowerLimit(
2130 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
2131 {
2132 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerLimit, reqData);
2133 }
2134
ipmiOemDCMISetPowerLimit(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)2135 ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMISetPowerLimit(
2136 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
2137 {
2138 return sendDCMICmd(ctx, ipmi::dcmi::cmdSetPowerLimit, reqData);
2139 }
2140
ipmiOemDCMIApplyPowerLimit(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)2141 ipmi::RspType<std::vector<uint8_t>> ipmiOemDCMIApplyPowerLimit(
2142 ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
2143 {
2144 return sendDCMICmd(ctx, ipmi::dcmi::cmdActDeactivatePwrLimit, reqData);
2145 }
2146
2147 // Https Boot related functions
ipmiOemGetHttpsData(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)2148 ipmi::RspType<std::vector<uint8_t>> ipmiOemGetHttpsData(
2149 [[maybe_unused]] ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
2150 {
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
ipmiOemGetHttpsAttr(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)2176 ipmi::RspType<std::vector<uint8_t>> ipmiOemGetHttpsAttr(
2177 [[maybe_unused]] ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
2178 {
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
2223 // OEM Crashdump related functions
setDumpState(CrdState & currState,CrdState newState)2224 static 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
handleMcaBank(const CrashDumpHdr & hdr,std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2246 static 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
2276 template <typename T>
handleVirtualBank(std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2277 static 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
handleCpuWdtBank(std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2316 static 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
2350 template <size_t N>
2351 static ipmi_ret_t
handleHwAssertBank(const char * name,std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2352 handleHwAssertBank(const char* name, std::span<const uint8_t> data,
2353 CrdState& currState, std::stringstream& ss)
2354 {
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
handlePcieAerBank(std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2382 static 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
handleWdtRegBank(std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2444 static 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
handleCrdHdrBank(std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2471 static 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
getFilename(const std::filesystem::path & dir,const std::string & prefix)2500 static 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
handleCtrlBank(std::span<const uint8_t> data,CrdState & currState,std::stringstream & ss)2526 static 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
ipmiOemCrashdump(ipmi::Context::ptr ctx,std::vector<uint8_t> reqData)2567 ipmi::RspType<std::vector<uint8_t>> ipmiOemCrashdump(
2568 [[maybe_unused]] ipmi::Context::ptr ctx, std::vector<uint8_t> reqData)
2569 {
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
registerOEMFunctions(void)2640 static void registerOEMFunctions(void)
2641 {
2642 /* Get OEM data from json file */
2643 std::ifstream file(JSON_OEM_DATA_FILE);
2644 if (file)
2645 {
2646 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 }
2660 file.close();
2661 }
2662 else
2663 {
2664 lg2::info("Failed to open JSON file.");
2665 }
2666
2667 lg2::info("Registering OEM commands.");
2668
2669 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
2691 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
2692 ipmiOemGetBoardID,
2693 PRIVILEGE_USER); // Get Board ID
2694 ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnOemOne,
2695 CMD_OEM_GET_80PORT_RECORD, ipmi::Privilege::User,
2696 ipmiOemGet80PortRecord); // Get 80 Port Record
2697 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
2706 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
2707 ipmiOemSetPPINInfo,
2708 PRIVILEGE_USER); // Set PPIN Info
2709 #if BIC_ENABLED
2710
2711 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2712 ipmi::cmdSetSystemGuid, ipmi::Privilege::User,
2713 ipmiOemSetSystemGuid);
2714 #else
2715
2716 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL,
2717 ipmiOemSetSystemGuid,
2718 PRIVILEGE_USER); // Set System GUID
2719 #endif
2720 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
2721 ipmiOemSetAdrTrigger,
2722 PRIVILEGE_USER); // Set ADR Trigger
2723 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
2730 /* FB OEM QC Commands */
2731 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
2737 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
2743 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
2749
2750 /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */
2751 ipmi::registerGroupHandler(
2752 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdGetPowerReading,
2753 ipmi::Privilege::User,
2754 ipmiOemDCMIGetPowerReading); // Get Power Reading
2755
2756 ipmi::registerGroupHandler(
2757 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdGetPowerLimit,
2758 ipmi::Privilege::User,
2759 ipmiOemDCMIGetPowerLimit); // Get Power Limit
2760
2761 ipmi::registerGroupHandler(
2762 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdSetPowerLimit,
2763 ipmi::Privilege::Operator,
2764 ipmiOemDCMISetPowerLimit); // Set Power Limit
2765
2766 ipmi::registerGroupHandler(
2767 ipmi::prioOpenBmcBase, groupDCMI, ipmi::dcmi::cmdActDeactivatePwrLimit,
2768 ipmi::Privilege::Operator,
2769 ipmiOemDCMIApplyPowerLimit); // Apply Power Limit
2770
2771 /* 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
2780 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2781 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,
2789 CMD_OEM_CRASHDUMP, ipmi::Privilege::User,
2790 ipmiOemCrashdump);
2791
2792 return;
2793 }
2794
2795 } // namespace ipmi
2796