blob: 3ccfafd3545eb95ad2762f23c974e2787159a0c1 [file] [log] [blame]
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001/*
2 * Copyright (c) 2018 Intel Corporation.
3 * Copyright (c) 2018-present Facebook.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "xyz/openbmc_project/Common/error.hpp"
Jayashree-Df0cf6652020-11-30 11:03:30 +053019#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
20#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
Jayashree Dhanapal778147d2022-03-30 16:48:53 +053021#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080022
Vijay Khemka63c99be2020-05-27 19:14:35 -070023#include <ipmid/api.hpp>
Vijay Khemka1b6fae32019-03-25 17:43:01 -070024#include <ipmid/utils.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070025#include <commandutils.hpp>
26#include <nlohmann/json.hpp>
27#include <oemcommands.hpp>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080028#include <phosphor-logging/log.hpp>
29#include <sdbusplus/bus.hpp>
Vijay Khemka63c99be2020-05-27 19:14:35 -070030
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053031#include <ipmid/api.hpp>
32#include <ipmid/api-types.hpp>
33
Vijay Khemka63c99be2020-05-27 19:14:35 -070034#include <array>
35#include <cstring>
36#include <fstream>
37#include <iomanip>
38#include <iostream>
39#include <sstream>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080040#include <string>
41#include <vector>
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +053042#include <regex>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080043
44#define SIZE_IANA_ID 3
45
46namespace ipmi
47{
Vijay Khemkaa7231892019-10-11 11:35:05 -070048
49using namespace phosphor::logging;
50
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053051void getSelectorPosition(size_t& position);
Vijay Khemkae7d23d02019-03-08 13:13:40 -080052static void registerOEMFunctions() __attribute__((constructor));
Patrick Williamscd315e02022-07-22 19:26:52 -050053sdbusplus::bus_t dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
Vijay Khemkae7d23d02019-03-08 13:13:40 -080054static constexpr size_t maxFRUStringLength = 0x3F;
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053055constexpr uint8_t cmdSetSystemGuid = 0xEF;
Vijay Khemkae7d23d02019-03-08 13:13:40 -080056
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +053057constexpr uint8_t cmdSetQDimmInfo = 0x12;
58constexpr uint8_t cmdGetQDimmInfo = 0x13;
59
Vijay Khemka63c99be2020-05-27 19:14:35 -070060int plat_udbg_get_post_desc(uint8_t, uint8_t*, uint8_t, uint8_t*, uint8_t*,
61 uint8_t*);
62int plat_udbg_get_gpio_desc(uint8_t, uint8_t*, uint8_t*, uint8_t*, uint8_t*,
63 uint8_t*);
64ipmi_ret_t plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t*, uint8_t*,
65 uint8_t*);
66ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t*,
67 uint8_t*);
68int sendMeCmd(uint8_t, uint8_t, std::vector<uint8_t>&, std::vector<uint8_t>&);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -070069
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +053070int sendBicCmd(uint8_t, uint8_t, uint8_t, std::vector<uint8_t>&,
71 std::vector<uint8_t>&);
72
Vijay Khemkafeaa9812019-08-27 15:08:08 -070073nlohmann::json oemData __attribute__((init_priority(101)));
Vijay Khemka1b6fae32019-03-25 17:43:01 -070074
Vijay Khemkaf2246ce2020-05-27 14:26:35 -070075static constexpr size_t GUID_SIZE = 16;
76// TODO Make offset and location runtime configurable to ensure we
77// can make each define their own locations.
78static constexpr off_t OFFSET_SYS_GUID = 0x17F0;
79static constexpr const char* FRU_EEPROM = "/sys/bus/i2c/devices/6-0054/eeprom";
80
Vijay Khemka1b6fae32019-03-25 17:43:01 -070081enum class LanParam : uint8_t
82{
83 INPROGRESS = 0,
84 AUTHSUPPORT = 1,
85 AUTHENABLES = 2,
86 IP = 3,
87 IPSRC = 4,
88 MAC = 5,
89 SUBNET = 6,
90 GATEWAY = 12,
91 VLAN = 20,
92 CIPHER_SUITE_COUNT = 22,
93 CIPHER_SUITE_ENTRIES = 23,
94 IPV6 = 59,
95};
96
Vijay Khemkaa7231892019-10-11 11:35:05 -070097namespace network
98{
99
100constexpr auto ROOT = "/xyz/openbmc_project/network";
101constexpr auto SERVICE = "xyz.openbmc_project.Network";
102constexpr auto IPV4_TYPE = "ipv4";
103constexpr auto IPV6_TYPE = "ipv6";
104constexpr auto IPV4_PREFIX = "169.254";
105constexpr auto IPV6_PREFIX = "fe80";
106constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
107constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
Potin Lai8d1a81e2022-12-20 11:13:45 +0800108constexpr auto IPV4_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv4";
109constexpr auto IPV6_PROTOCOL = "xyz.openbmc_project.Network.IP.Protocol.IPv6";
Vijay Khemkaa7231892019-10-11 11:35:05 -0700110
Vijay Khemka63c99be2020-05-27 19:14:35 -0700111bool isLinkLocalIP(const std::string& address)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700112{
113 return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
114}
115
Patrick Williamscd315e02022-07-22 19:26:52 -0500116DbusObjectInfo getIPObject(sdbusplus::bus_t& bus, const std::string& interface,
Vijay Khemka63c99be2020-05-27 19:14:35 -0700117 const std::string& serviceRoot,
Potin Lai8d1a81e2022-12-20 11:13:45 +0800118 const std::string& protocol,
119 const std::string& ethdev)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700120{
Potin Lai8d1a81e2022-12-20 11:13:45 +0800121 auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, ethdev);
Vijay Khemkaa7231892019-10-11 11:35:05 -0700122
123 if (objectTree.empty())
124 {
125 log<level::ERR>("No Object has implemented the IP interface",
126 entry("INTERFACE=%s", interface.c_str()));
127 }
128
129 DbusObjectInfo objectInfo;
130
Vijay Khemka63c99be2020-05-27 19:14:35 -0700131 for (auto& object : objectTree)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700132 {
133 auto variant =
134 ipmi::getDbusProperty(bus, object.second.begin()->first,
Potin Lai8d1a81e2022-12-20 11:13:45 +0800135 object.first, IP_INTERFACE, "Type");
136 if (std::get<std::string>(variant) != protocol)
137 {
138 continue;
139 }
140
141 variant = ipmi::getDbusProperty(bus, object.second.begin()->first,
142 object.first, IP_INTERFACE, "Address");
Vijay Khemkaa7231892019-10-11 11:35:05 -0700143
144 objectInfo = std::make_pair(object.first, object.second.begin()->first);
145
146 // if LinkLocalIP found look for Non-LinkLocalIP
147 if (isLinkLocalIP(std::get<std::string>(variant)))
148 {
149 continue;
150 }
151 else
152 {
153 break;
154 }
155 }
156 return objectInfo;
157}
158
159} // namespace network
160
Jayashree-Df0cf6652020-11-30 11:03:30 +0530161namespace boot
162{
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530163using BootSource =
164 sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources;
165using BootMode =
166 sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes;
167using BootType =
168 sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types;
Jayashree-Df0cf6652020-11-30 11:03:30 +0530169
Jayashree-Df0cf6652020-11-30 11:03:30 +0530170using IpmiValue = uint8_t;
171
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530172std::map<IpmiValue, BootSource> sourceIpmiToDbus = {
173 {0x0f, BootSource::Default}, {0x00, BootSource::RemovableMedia},
174 {0x01, BootSource::Network}, {0x02, BootSource::Disk},
175 {0x03, BootSource::ExternalMedia}, {0x09, BootSource::Network}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530176
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530177std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x06, BootMode::Setup},
178 {0x00, BootMode::Regular}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530179
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530180std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy},
181 {0x01, BootType::EFI}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530182
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530183std::map<std::optional<BootSource>, IpmiValue> sourceDbusToIpmi = {
184 {BootSource::Default, 0x0f},
185 {BootSource::RemovableMedia, 0x00},
186 {BootSource::Network, 0x01},
187 {BootSource::Disk, 0x02},
188 {BootSource::ExternalMedia, 0x03}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530189
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530190std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = {
191 {BootMode::Setup, 0x06}, {BootMode::Regular, 0x00}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530192
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530193std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = {
194 {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530195
Jayashree-Df0cf6652020-11-30 11:03:30 +0530196static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
197static constexpr auto bootSourceIntf =
198 "xyz.openbmc_project.Control.Boot.Source";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530199static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530200static constexpr auto bootSourceProp = "BootSource";
201static constexpr auto bootModeProp = "BootMode";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530202static constexpr auto bootTypeProp = "BootType";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530203
Jayashree-Df0cf6652020-11-30 11:03:30 +0530204std::tuple<std::string, std::string> objPath(size_t id)
205{
206 std::string hostName = "host" + std::to_string(id);
207 std::string bootObjPath =
208 "/xyz/openbmc_project/control/" + hostName + "/boot";
209 return std::make_tuple(std::move(bootObjPath), std::move(hostName));
210}
211
212} // namespace boot
213
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700214//----------------------------------------------------------------------
215// Helper functions for storing oem data
216//----------------------------------------------------------------------
217
218void flushOemData()
219{
220 std::ofstream file(JSON_OEM_DATA_FILE);
221 file << oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -0700222 file.close();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700223 return;
224}
225
Vijay Khemka63c99be2020-05-27 19:14:35 -0700226std::string bytesToStr(uint8_t* byte, int len)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700227{
228 std::stringstream ss;
229 int i;
230
231 ss << std::hex;
232 for (i = 0; i < len; i++)
233 {
234 ss << std::setw(2) << std::setfill('0') << (int)byte[i];
235 }
236
237 return ss.str();
238}
239
Vijay Khemka63c99be2020-05-27 19:14:35 -0700240int strToBytes(std::string& str, uint8_t* data)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700241{
242 std::string sstr;
Willy Tue39f9392022-06-15 13:24:20 -0700243 size_t i;
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700244
245 for (i = 0; i < (str.length()) / 2; i++)
246 {
247 sstr = str.substr(i * 2, 2);
248 data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16);
249 }
250 return i;
251}
252
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530253int readDimmType(std::string& data, uint8_t param)
254{
255 nlohmann::json dimmObj;
256 /* Get dimm type names stored in json file */
257 std::ifstream file(JSON_DIMM_TYPE_FILE);
258 if (file)
259 {
260 file >> dimmObj;
261 file.close();
262 }
263 else
264 {
265 phosphor::logging::log<phosphor::logging::level::ERR>(
266 "DIMM type names file not found",
267 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
268 return -1;
269 }
270
271 std::string dimmKey = "dimm_type" + std::to_string(param);
272 auto obj = dimmObj[dimmKey]["short_name"];
273 data = obj;
274 return 0;
275}
276
Vijay Khemka63c99be2020-05-27 19:14:35 -0700277ipmi_ret_t getNetworkData(uint8_t lan_param, char* data)
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700278{
279 ipmi_ret_t rc = IPMI_CC_OK;
Patrick Williamscd315e02022-07-22 19:26:52 -0500280 sdbusplus::bus_t bus(ipmid_get_sd_bus_connection());
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700281
282 const std::string ethdevice = "eth0";
283
284 switch (static_cast<LanParam>(lan_param))
285 {
Vijay Khemkad1194022020-05-27 18:58:33 -0700286 case LanParam::IP:
287 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700288 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700289 auto ipObjectInfo = ipmi::network::getIPObject(
Potin Lai8d1a81e2022-12-20 11:13:45 +0800290 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
291 ipmi::network::IPV4_PROTOCOL, ethdevice);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700292
293 auto properties = ipmi::getAllDbusProperties(
294 bus, ipObjectInfo.second, ipObjectInfo.first,
295 ipmi::network::IP_INTERFACE);
296
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500297 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700298
299 std::strcpy(data, ipaddress.c_str());
300 }
301 break;
302
Vijay Khemkad1194022020-05-27 18:58:33 -0700303 case LanParam::IPV6:
304 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700305 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700306 auto ipObjectInfo = ipmi::network::getIPObject(
Potin Lai8d1a81e2022-12-20 11:13:45 +0800307 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT,
308 ipmi::network::IPV6_PROTOCOL, ethdevice);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700309
310 auto properties = ipmi::getAllDbusProperties(
311 bus, ipObjectInfo.second, ipObjectInfo.first,
312 ipmi::network::IP_INTERFACE);
313
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500314 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700315
316 std::strcpy(data, ipaddress.c_str());
317 }
318 break;
319
Vijay Khemkad1194022020-05-27 18:58:33 -0700320 case LanParam::MAC:
321 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700322 std::string macAddress;
323 auto macObjectInfo =
324 ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE,
325 ipmi::network::ROOT, ethdevice);
326
327 auto variant = ipmi::getDbusProperty(
328 bus, macObjectInfo.second, macObjectInfo.first,
329 ipmi::network::MAC_INTERFACE, "MACAddress");
330
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500331 macAddress = std::get<std::string>(variant);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700332
333 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
334 (data), (data + 1), (data + 2), (data + 3), (data + 4),
335 (data + 5));
336 std::strcpy(data, macAddress.c_str());
337 }
338 break;
339
340 default:
341 rc = IPMI_CC_PARM_OUT_OF_RANGE;
342 }
343 return rc;
344}
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800345
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530346bool isMultiHostPlatform()
347{
348 bool platform;
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530349 if (hostInstances == "0")
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530350 {
351 platform = false;
352 }
353 else
354 {
355 platform = true;
356 }
357 return platform;
358}
359
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800360// return code: 0 successful
Vijay Khemka63c99be2020-05-27 19:14:35 -0700361int8_t getFruData(std::string& data, std::string& name)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800362{
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530363 size_t pos;
364 static constexpr const auto depth = 0;
365 std::vector<std::string> paths;
366 std::string machinePath;
367 std::string baseBoard = "Baseboard";
368
369 bool platform = isMultiHostPlatform();
370 if (platform == true)
371 {
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +0530372 getSelectorPosition(pos);
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530373 }
374
375 sd_bus* bus = NULL;
376 int ret = sd_bus_default_system(&bus);
377 if (ret < 0)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800378 {
379 phosphor::logging::log<phosphor::logging::level::ERR>(
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530380 "Failed to connect to system bus",
381 phosphor::logging::entry("ERRNO=0x%X", -ret));
382 sd_bus_unref(bus);
383 return -1;
384 }
Patrick Williamscd315e02022-07-22 19:26:52 -0500385 sdbusplus::bus_t dbus(bus);
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530386 auto mapperCall = dbus.new_method_call("xyz.openbmc_project.ObjectMapper",
387 "/xyz/openbmc_project/object_mapper",
388 "xyz.openbmc_project.ObjectMapper",
389 "GetSubTreePaths");
390 static constexpr std::array<const char*, 1> interface = {
391 "xyz.openbmc_project.Inventory.Decorator.Asset"};
392 mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface);
393
394 try
395 {
396 auto reply = dbus.call(mapperCall);
397 reply.read(paths);
398 }
399 catch (sdbusplus::exception_t& e)
400 {
401 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800402 return -1;
403 }
404
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530405 for (const auto& path : paths)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800406 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530407 if (platform == true)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800408 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530409 if (pos == BMC_POS)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800410 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530411 machinePath = baseBoard;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800412 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530413 else
414 {
415 machinePath = "_" + std::to_string(pos);
416 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800417 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530418 else
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800419 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530420 machinePath = baseBoard;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800421 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530422
423 auto found = path.find(machinePath);
Patrick Williams123cbcc2022-06-24 06:13:59 -0500424 if (found == std::string::npos)
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530425 {
426 continue;
427 }
428
429 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
430 std::string service = getService(
431 *dbus, "xyz.openbmc_project.Inventory.Decorator.Asset", path);
432
433 auto Value = ipmi::getDbusProperty(
434 *dbus, service, path,
435 "xyz.openbmc_project.Inventory.Decorator.Asset", name);
436
437 data = std::get<std::string>(Value);
438 return 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800439 }
440 return -1;
441}
442
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530443int8_t sysConfig(std::vector<std::string>& data, size_t pos)
444{
445 nlohmann::json sysObj;
446 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(pos);
447 std::string result, typeName;
448 uint8_t res[MAX_BUF];
449
450 /* Get sysConfig data stored in json file */
451 std::ifstream file(JSON_OEM_DATA_FILE);
452 if (file)
453 {
454 file >> sysObj;
455 file.close();
456 }
457 else
458 {
459 phosphor::logging::log<phosphor::logging::level::ERR>(
460 "oemData file not found",
461 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
462 return -1;
463 }
464
465 if (sysObj.find(dimmInfo) == sysObj.end())
466 {
467 phosphor::logging::log<phosphor::logging::level::ERR>(
468 "sysconfig key not available",
469 phosphor::logging::entry("SYS_JSON_KEY=%s", dimmInfo.c_str()));
470 return -1;
471 }
472 /* Get dimm type names stored in json file */
473 nlohmann::json dimmObj;
474 std::ifstream dimmFile(JSON_DIMM_TYPE_FILE);
475 if (file)
476 {
477 dimmFile >> dimmObj;
478 dimmFile.close();
479 }
480 else
481 {
482 phosphor::logging::log<phosphor::logging::level::ERR>(
483 "DIMM type names file not found",
484 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
485 return -1;
486 }
487 std::vector<std::string> a;
488 for (auto& j : dimmObj.items())
489 {
490 std::string name = j.key();
491 a.push_back(name);
492 }
493
494 uint8_t len = a.size();
495 for (uint8_t ii = 0; ii < len; ii++)
496 {
497 std::string indKey = std::to_string(ii);
498 std::string speedSize = sysObj[dimmInfo][indKey][DIMM_SPEED];
499 strToBytes(speedSize, res);
500 auto speed = (res[1] << 8 | res[0]);
501 size_t dimmSize = ((res[3] << 8 | res[2]) / 1000);
502
503 if (dimmSize == 0)
504 {
505 std::cerr << "Dimm information not available for slot_" +
506 std::to_string(ii)
507 << std::endl;
508 continue;
509 }
510 std::string type = sysObj[dimmInfo][indKey][DIMM_TYPE];
511 std::string dualInlineMem = sysObj[dimmInfo][indKey][KEY_DIMM_TYPE];
512 strToBytes(type, res);
513 size_t dimmType = res[0];
514 if (dimmVenMap.find(dimmType) == dimmVenMap.end())
515 {
516 typeName = "unknown";
517 }
518 else
519 {
520 typeName = dimmVenMap[dimmType];
521 }
522 result = dualInlineMem + "/" + typeName + "/" + std::to_string(speed) +
523 "MHz" + "/" + std::to_string(dimmSize) + "GB";
524 data.push_back(result);
525 }
526 return 0;
527}
528
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +0530529int8_t procInfo(std::string& result, size_t pos)
530{
531 std::vector<char> data;
532 uint8_t res[MAX_BUF];
533 std::string procIndex = "00";
534 nlohmann::json proObj;
535 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(pos);
536 /* Get processor data stored in json file */
537 std::ifstream file(JSON_OEM_DATA_FILE);
538 if (file)
539 {
540 file >> proObj;
541 file.close();
542 }
543 else
544 {
545 phosphor::logging::log<phosphor::logging::level::ERR>(
546 "oemData file not found",
547 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
548 return -1;
549 }
550 if (proObj.find(procInfo) == proObj.end())
551 {
552 phosphor::logging::log<phosphor::logging::level::ERR>(
553 "processor info key not available",
554 phosphor::logging::entry("PROC_JSON_KEY=%s", procInfo.c_str()));
555 return -1;
556 }
557 std::string procName = proObj[procInfo][procIndex][KEY_PROC_NAME];
558 std::string basicInfo = proObj[procInfo][procIndex][KEY_BASIC_INFO];
559 // Processor Product Name
560 strToBytes(procName, res);
561 data.assign(reinterpret_cast<char*>(&res),
562 reinterpret_cast<char*>(&res) + sizeof(res));
563
564 std::string s(data.begin(), data.end());
565 std::regex regex(" ");
566 std::vector<std::string> productName(
567 std::sregex_token_iterator(s.begin(), s.end(), regex, -1),
568 std::sregex_token_iterator());
569
570 // Processor core and frequency
571 strToBytes(basicInfo, res);
572 uint16_t coreNum = res[0];
573 double procFrequency = (float)(res[4] << 8 | res[3]) / 1000;
574 result = "CPU:" + productName[2] + "/" + std::to_string(procFrequency) +
575 "GHz" + "/" + std::to_string(coreNum) + "c";
576 return 0;
577}
578
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800579typedef struct
580{
581 uint8_t cur_power_state;
582 uint8_t last_power_event;
583 uint8_t misc_power_state;
584 uint8_t front_panel_button_cap_status;
585} ipmi_get_chassis_status_t;
586
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800587//----------------------------------------------------------------------
588// Get Debug Frame Info
589//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700590ipmi_ret_t ipmiOemDbgGetFrameInfo(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800591 ipmi_request_t request,
592 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700593 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800594{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700595 uint8_t* req = reinterpret_cast<uint8_t*>(request);
596 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800597 uint8_t num_frames = 3;
598
599 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
600 res[SIZE_IANA_ID] = num_frames;
601 *data_len = SIZE_IANA_ID + 1;
602
603 return IPMI_CC_OK;
604}
605
606//----------------------------------------------------------------------
607// Get Debug Updated Frames
608//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700609ipmi_ret_t ipmiOemDbgGetUpdFrames(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800610 ipmi_request_t request,
611 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700612 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800613{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700614 uint8_t* req = reinterpret_cast<uint8_t*>(request);
615 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800616 uint8_t num_updates = 3;
617 *data_len = 4;
618
619 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
620 res[SIZE_IANA_ID] = num_updates;
621 *data_len = SIZE_IANA_ID + num_updates + 1;
622 res[SIZE_IANA_ID + 1] = 1; // info page update
623 res[SIZE_IANA_ID + 2] = 2; // cri sel update
624 res[SIZE_IANA_ID + 3] = 3; // cri sensor update
625
626 return IPMI_CC_OK;
627}
628
629//----------------------------------------------------------------------
630// Get Debug POST Description
631//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700632ipmi_ret_t ipmiOemDbgGetPostDesc(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800633 ipmi_request_t request,
634 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700635 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800636{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700637 uint8_t* req = reinterpret_cast<uint8_t*>(request);
638 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800639 uint8_t index = 0;
640 uint8_t next = 0;
641 uint8_t end = 0;
642 uint8_t phase = 0;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700643 uint8_t descLen = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800644 int ret;
645
646 index = req[3];
647 phase = req[4];
648
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700649 ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800650 if (ret)
651 {
652 memcpy(res, req, SIZE_IANA_ID); // IANA ID
653 *data_len = SIZE_IANA_ID;
654 return IPMI_CC_UNSPECIFIED_ERROR;
655 }
656
657 memcpy(res, req, SIZE_IANA_ID); // IANA ID
658 res[3] = index;
659 res[4] = next;
660 res[5] = phase;
661 res[6] = end;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700662 res[7] = descLen;
663 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800664
665 return IPMI_CC_OK;
666}
667
668//----------------------------------------------------------------------
669// Get Debug GPIO Description
670//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700671ipmi_ret_t ipmiOemDbgGetGpioDesc(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800672 ipmi_request_t request,
673 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700674 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800675{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700676 uint8_t* req = reinterpret_cast<uint8_t*>(request);
677 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800678
Vijay Khemka38183d62019-08-28 16:19:33 -0700679 uint8_t index = 0;
680 uint8_t next = 0;
681 uint8_t level = 0;
682 uint8_t pinDef = 0;
683 uint8_t descLen = 0;
684 int ret;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800685
Vijay Khemka38183d62019-08-28 16:19:33 -0700686 index = req[3];
687
688 ret = plat_udbg_get_gpio_desc(index, &next, &level, &pinDef, &descLen,
689 &res[8]);
690 if (ret)
691 {
692 memcpy(res, req, SIZE_IANA_ID); // IANA ID
693 *data_len = SIZE_IANA_ID;
694 return IPMI_CC_UNSPECIFIED_ERROR;
695 }
696
697 memcpy(res, req, SIZE_IANA_ID); // IANA ID
698 res[3] = index;
699 res[4] = next;
700 res[5] = level;
701 res[6] = pinDef;
702 res[7] = descLen;
703 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800704
705 return IPMI_CC_OK;
706}
707
708//----------------------------------------------------------------------
709// Get Debug Frame Data
710//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700711ipmi_ret_t ipmiOemDbgGetFrameData(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800712 ipmi_request_t request,
713 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700714 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800715{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700716 uint8_t* req = reinterpret_cast<uint8_t*>(request);
717 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800718 uint8_t frame;
719 uint8_t page;
720 uint8_t next;
721 uint8_t count;
722 int ret;
723
724 frame = req[3];
725 page = req[4];
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800726
727 ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]);
728 if (ret)
729 {
730 memcpy(res, req, SIZE_IANA_ID); // IANA ID
731 *data_len = SIZE_IANA_ID;
732 return IPMI_CC_UNSPECIFIED_ERROR;
733 }
734
735 memcpy(res, req, SIZE_IANA_ID); // IANA ID
736 res[3] = frame;
737 res[4] = page;
738 res[5] = next;
739 res[6] = count;
740 *data_len = SIZE_IANA_ID + 4 + count;
741
742 return IPMI_CC_OK;
743}
744
745//----------------------------------------------------------------------
746// Get Debug Control Panel
747//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700748ipmi_ret_t ipmiOemDbgGetCtrlPanel(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800749 ipmi_request_t request,
750 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700751 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800752{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700753 uint8_t* req = reinterpret_cast<uint8_t*>(request);
754 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800755
756 uint8_t panel;
757 uint8_t operation;
758 uint8_t item;
759 uint8_t count;
760 ipmi_ret_t ret;
761
762 panel = req[3];
763 operation = req[4];
764 item = req[5];
765
766 ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]);
767
768 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
769 *data_len = SIZE_IANA_ID + count;
770
771 return ret;
772}
773
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800774//----------------------------------------------------------------------
775// Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
776//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700777ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
778 ipmi_response_t, ipmi_data_len_t data_len,
779 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800780{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700781 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700782
783 uint8_t index = req[0];
784 uint8_t type = req[1];
785 uint16_t speed;
786 uint32_t size;
787
788 memcpy(&speed, &req[2], 2);
789 memcpy(&size, &req[4], 4);
790
791 std::stringstream ss;
792 ss << std::hex;
793 ss << std::setw(2) << std::setfill('0') << (int)index;
794
795 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index;
796 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type;
797 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed;
798 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size;
799
800 flushOemData();
801
802 *data_len = 0;
803
804 return IPMI_CC_OK;
805}
806
807//----------------------------------------------------------------------
808// Get Board ID (CMD_OEM_GET_BOARD_ID)
809//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700810ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
811 ipmi_response_t, ipmi_data_len_t data_len,
812 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700813{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700814 /* TODO: Needs to implement this after GPIO implementation */
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800815 *data_len = 0;
816
817 return IPMI_CC_OK;
818}
819
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800820/* Helper functions to set boot order */
Jayashree-Df0cf6652020-11-30 11:03:30 +0530821void setBootOrder(std::string bootObjPath, uint8_t* data,
822 std::string bootOrderKey)
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800823{
Jayashree-Df0cf6652020-11-30 11:03:30 +0530824 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
825
826 // SETTING BOOT MODE PROPERTY
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530827 uint8_t bootModeBit = data[0] & 0x06;
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530828 auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit);
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530829
Jayashree-Df0cf6652020-11-30 11:03:30 +0530830 std::string bootOption =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530831 sdbusplus::message::convert_to_string<boot::BootMode>(bootValue);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530832
833 std::string service =
834 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
835 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
836 ipmi::boot::bootModeProp, bootOption);
837
838 // SETTING BOOT SOURCE PROPERTY
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530839 auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530840 std::string bootSource =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530841 sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530842
843 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
844 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
845 ipmi::boot::bootSourceProp, bootSource);
846
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530847 // SETTING BOOT TYPE PROPERTY
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530848 uint8_t bootTypeBit = data[0] & 0x01;
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530849 auto bootTypeVal = ipmi::boot::typeIpmiToDbus.at(bootTypeBit);
850
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530851 std::string bootType =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530852 sdbusplus::message::convert_to_string<boot::BootType>(bootTypeVal);
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530853
854 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
855
856 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
857 ipmi::boot::bootTypeProp, bootType);
858
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800859 nlohmann::json bootMode;
860 uint8_t mode = data[0];
861 int i;
862
863 bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
864 bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
865 bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
866 bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530867 oemData[bootOrderKey][KEY_BOOT_MODE] = bootMode;
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800868
869 /* Initialize boot sequence array */
Jayashree-Df0cf6652020-11-30 11:03:30 +0530870 oemData[bootOrderKey][KEY_BOOT_SEQ] = {};
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800871 for (i = 1; i < SIZE_BOOT_ORDER; i++)
872 {
873 if (data[i] >= BOOT_SEQ_ARRAY_SIZE)
Jayashree-Df0cf6652020-11-30 11:03:30 +0530874 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = "NA";
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800875 else
Jayashree-Df0cf6652020-11-30 11:03:30 +0530876 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = bootSeq[data[i]];
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800877 }
878
879 flushOemData();
880}
881
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800882//----------------------------------------------------------------------
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700883// Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
884//----------------------------------------------------------------------
Jayashree-Df0cf6652020-11-30 11:03:30 +0530885ipmi::RspType<std::vector<uint8_t>>
886 ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700887{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700888
Jayashree-Df0cf6652020-11-30 11:03:30 +0530889 uint8_t bootSeq[SIZE_BOOT_ORDER];
890 size_t len = data.size();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700891
892 if (len != SIZE_BOOT_ORDER)
893 {
894 phosphor::logging::log<phosphor::logging::level::ERR>(
895 "Invalid Boot order length received");
Jayashree-Df0cf6652020-11-30 11:03:30 +0530896 return ipmi::responseReqDataLenInvalid();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700897 }
898
Jayashree-Df0cf6652020-11-30 11:03:30 +0530899 std::copy(std::begin(data), std::end(data), bootSeq);
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530900 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700901
Jayashree-Df0cf6652020-11-30 11:03:30 +0530902 if (!hostId)
903 {
904 phosphor::logging::log<phosphor::logging::level::ERR>(
905 "Invalid Host Id received");
906 return ipmi::responseInvalidCommand();
907 }
908 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
909
910 setBootOrder(bootObjPath, bootSeq, hostName);
911
912 return ipmi::responseSuccess(data);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700913}
914
915//----------------------------------------------------------------------
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800916// Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
917//----------------------------------------------------------------------
Jayashree-Df0cf6652020-11-30 11:03:30 +0530918ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
919 ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800920{
Jayashree-Df0cf6652020-11-30 11:03:30 +0530921 uint8_t bootSeq[SIZE_BOOT_ORDER];
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700922 uint8_t mode = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800923
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530924 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700925
Jayashree-Df0cf6652020-11-30 11:03:30 +0530926 if (!hostId)
927 {
928 phosphor::logging::log<phosphor::logging::level::ERR>(
929 "Invalid Host Id received");
930 return ipmi::responseInvalidCommand();
931 }
932 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
933
Jayashree-Df0cf6652020-11-30 11:03:30 +0530934 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
935
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530936 // GETTING PROPERTY OF MODE INTERFACE
937
Jayashree-Df0cf6652020-11-30 11:03:30 +0530938 std::string service =
939 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
940 Value variant =
941 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
942 ipmi::boot::bootModeProp);
943
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530944 auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>(
Jayashree-Df0cf6652020-11-30 11:03:30 +0530945 std::get<std::string>(variant));
946
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530947 uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530948
949 // GETTING PROPERTY OF SOURCE INTERFACE
950
951 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
952 variant =
953 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
954 ipmi::boot::bootSourceProp);
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530955
956 auto bootSource = sdbusplus::message::convert_from_string<boot::BootSource>(
Jayashree-Df0cf6652020-11-30 11:03:30 +0530957 std::get<std::string>(variant));
958
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530959 uint8_t bootOrder = ipmi::boot::sourceDbusToIpmi.at(bootSource);
960
961 // GETTING PROPERTY OF TYPE INTERFACE
962
963 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
964 variant =
965 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
966 ipmi::boot::bootTypeProp);
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530967
968 auto bootType = sdbusplus::message::convert_from_string<boot::BootType>(
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530969 std::get<std::string>(variant));
970
971 uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
972
973 uint8_t bootVal = bootOption | bootTypeVal;
Jayashree-Df0cf6652020-11-30 11:03:30 +0530974
975 if (oemData.find(hostName) == oemData.end())
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800976 {
977 /* Return default boot order 0100090203ff */
978 uint8_t defaultBoot[SIZE_BOOT_ORDER] = {
Willy Tue39f9392022-06-15 13:24:20 -0700979 BOOT_MODE_UEFI,
980 static_cast<uint8_t>(bootMap["USB_DEV"]),
981 static_cast<uint8_t>(bootMap["NET_IPV6"]),
982 static_cast<uint8_t>(bootMap["SATA_HDD"]),
983 static_cast<uint8_t>(bootMap["SATA_CD"]),
984 0xff};
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700985
Jayashree-Df0cf6652020-11-30 11:03:30 +0530986 memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER);
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800987 phosphor::logging::log<phosphor::logging::level::INFO>(
988 "Set default boot order");
Jayashree-Df0cf6652020-11-30 11:03:30 +0530989 setBootOrder(bootObjPath, defaultBoot, hostName);
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800990 }
991 else
992 {
Jayashree-Df0cf6652020-11-30 11:03:30 +0530993 nlohmann::json bootMode = oemData[hostName][KEY_BOOT_MODE];
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800994 if (bootMode["UEFI"])
995 mode |= BOOT_MODE_UEFI;
996 if (bootMode["CMOS_CLR"])
997 mode |= BOOT_MODE_CMOS_CLR;
998 if (bootMode["BOOT_FLAG"])
999 mode |= BOOT_MODE_BOOT_FLAG;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001000
Jayashree-Df0cf6652020-11-30 11:03:30 +05301001 bootSeq[0] = mode;
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001002
Jayashree-Df0cf6652020-11-30 11:03:30 +05301003 for (int i = 1; i < SIZE_BOOT_ORDER; i++)
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001004 {
Jayashree-Df0cf6652020-11-30 11:03:30 +05301005 std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001006 if (bootMap.find(seqStr) != bootMap.end())
Jayashree-Df0cf6652020-11-30 11:03:30 +05301007 bootSeq[i] = bootMap[seqStr];
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001008 else
Jayashree-Df0cf6652020-11-30 11:03:30 +05301009 bootSeq[i] = 0xff;
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001010 }
1011 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001012
Jayashree Dhanapal778147d2022-03-30 16:48:53 +05301013 return ipmi::responseSuccess(bootVal, bootOrder, bootSeq[2], bootSeq[3],
Jayashree-Df0cf6652020-11-30 11:03:30 +05301014 bootSeq[4], bootSeq[5]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001015}
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001016// Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
1017//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001018ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t, ipmi_cmd_t,
1019 ipmi_request_t request, ipmi_response_t,
1020 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001021{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001022 machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001023 uint8_t len = *data_len;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001024
1025 *data_len = 0;
1026
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001027 if (len < sizeof(machineConfigInfo_t))
1028 {
1029 phosphor::logging::log<phosphor::logging::level::ERR>(
1030 "Invalid machine configuration length received");
1031 return IPMI_CC_REQ_DATA_LEN_INVALID;
1032 }
1033
Vijay Khemka63c99be2020-05-27 19:14:35 -07001034 if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001035 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN";
1036 else
1037 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] =
1038 chassisType[req->chassis_type];
1039
Vijay Khemka63c99be2020-05-27 19:14:35 -07001040 if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001041 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN";
1042 else
1043 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type];
1044
1045 oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt;
1046 oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt;
1047 oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt;
1048 oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt;
1049
Vijay Khemka63c99be2020-05-27 19:14:35 -07001050 if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001051 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN";
1052 else
1053 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type];
1054
1055 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {};
1056 int i = 0;
1057 if (req->pcie_card_loc & BIT_0)
1058 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1";
1059 if (req->pcie_card_loc & BIT_1)
1060 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2";
1061 if (req->pcie_card_loc & BIT_2)
1062 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3";
1063 if (req->pcie_card_loc & BIT_3)
1064 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4";
1065
Vijay Khemka63c99be2020-05-27 19:14:35 -07001066 if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001067 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN";
1068 else
1069 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] =
1070 pcieType[req->slot1_pcie_type];
1071
Vijay Khemka63c99be2020-05-27 19:14:35 -07001072 if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001073 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN";
1074 else
1075 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] =
1076 pcieType[req->slot2_pcie_type];
1077
Vijay Khemka63c99be2020-05-27 19:14:35 -07001078 if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001079 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN";
1080 else
1081 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] =
1082 pcieType[req->slot3_pcie_type];
1083
Vijay Khemka63c99be2020-05-27 19:14:35 -07001084 if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001085 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN";
1086 else
1087 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] =
1088 pcieType[req->slot4_pcie_type];
1089
1090 oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt;
1091
1092 flushOemData();
1093
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001094 return IPMI_CC_OK;
1095}
1096
1097//----------------------------------------------------------------------
1098// Set POST start (CMD_OEM_SET_POST_START)
1099//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001100ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1101 ipmi_response_t, ipmi_data_len_t data_len,
1102 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001103{
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001104 phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
1105
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001106 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001107 *data_len = 0;
1108 return IPMI_CC_OK;
1109}
1110
1111//----------------------------------------------------------------------
1112// Set POST End (CMD_OEM_SET_POST_END)
1113//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001114ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1115 ipmi_response_t, ipmi_data_len_t data_len,
1116 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001117{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001118 struct timespec ts;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001119
1120 phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
1121
1122 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001123
1124 // Timestamp post end time.
1125 clock_gettime(CLOCK_REALTIME, &ts);
1126 oemData[KEY_TS_SLED] = ts.tv_sec;
1127 flushOemData();
1128
1129 // Sync time with system
1130 // TODO: Add code for syncing time
1131
1132 return IPMI_CC_OK;
1133}
1134
1135//----------------------------------------------------------------------
1136// Set PPIN Info (CMD_OEM_SET_PPIN_INFO)
1137//----------------------------------------------------------------------
1138// Inform BMC about PPIN data of 8 bytes for each CPU
1139//
1140// Request:
1141// Byte 1:8 – CPU0 PPIN data
1142// Optional:
1143// Byte 9:16 – CPU1 PPIN data
1144//
1145// Response:
1146// Byte 1 – Completion Code
Willy Tue39f9392022-06-15 13:24:20 -07001147ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1148 ipmi_response_t, ipmi_data_len_t data_len,
1149 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001150{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001151 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001152 std::string ppinStr;
1153 int len;
1154
1155 if (*data_len > SIZE_CPU_PPIN * 2)
1156 len = SIZE_CPU_PPIN * 2;
1157 else
1158 len = *data_len;
1159 *data_len = 0;
1160
1161 ppinStr = bytesToStr(req, len);
1162 oemData[KEY_PPIN_INFO] = ppinStr.c_str();
1163 flushOemData();
1164
1165 return IPMI_CC_OK;
1166}
1167
1168//----------------------------------------------------------------------
1169// Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER)
1170//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001171ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1172 ipmi_response_t, ipmi_data_len_t data_len,
1173 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001174{
1175 /* Do nothing, return success */
1176 *data_len = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001177 return IPMI_CC_OK;
1178}
1179
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001180// Helper function to set guid at offset in EEPROM
Willy Tue39f9392022-06-15 13:24:20 -07001181[[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001182{
1183 int fd = -1;
1184 ssize_t len;
1185 int ret = 0;
1186
1187 errno = 0;
1188
1189 // Check if file is present
1190 if (access(FRU_EEPROM, F_OK) == -1)
1191 {
1192 std::cerr << "Unable to access: " << FRU_EEPROM << std::endl;
1193 return errno;
1194 }
1195
1196 // Open the file
1197 fd = open(FRU_EEPROM, O_WRONLY);
1198 if (fd == -1)
1199 {
1200 std::cerr << "Unable to open: " << FRU_EEPROM << std::endl;
1201 return errno;
1202 }
1203
1204 // seek to the offset
1205 lseek(fd, offset, SEEK_SET);
1206
1207 // Write bytes to location
1208 len = write(fd, guid, GUID_SIZE);
1209 if (len != GUID_SIZE)
1210 {
1211 phosphor::logging::log<phosphor::logging::level::ERR>(
1212 "GUID write data to EEPROM failed");
1213 ret = errno;
1214 }
1215
1216 close(fd);
1217 return ret;
1218}
1219
1220//----------------------------------------------------------------------
1221// Set System GUID (CMD_OEM_SET_SYSTEM_GUID)
1222//----------------------------------------------------------------------
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301223#if BIC_ENABLED
Bonnie Lo3f671272022-10-12 15:46:45 +08001224ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx,
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301225 std::vector<uint8_t> reqData)
1226{
1227 std::vector<uint8_t> respData;
1228
1229 if (reqData.size() != GUID_SIZE) // 16bytes
1230 {
1231
1232 return ipmi::responseReqDataLenInvalid();
1233 }
1234
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301235 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
1236
1237 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
1238 return ipmi::responseUnspecifiedError();
1239
1240 return ipmi::responseSuccess();
1241}
1242
1243#else
Potin Laid5353ca2022-08-11 04:52:11 +00001244ipmi_ret_t ipmiOemSetSystemGuid(ipmi_netfn_t, ipmi_cmd_t,
1245 ipmi_request_t request, ipmi_response_t,
1246 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001247{
1248 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1249
1250 if (*data_len != GUID_SIZE) // 16bytes
1251 {
1252 *data_len = 0;
1253 return IPMI_CC_REQ_DATA_LEN_INVALID;
1254 }
1255
1256 *data_len = 0;
1257
1258 if (setGUID(OFFSET_SYS_GUID, req))
1259 {
1260 return IPMI_CC_UNSPECIFIED_ERROR;
1261 }
1262 return IPMI_CC_OK;
1263}
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301264#endif
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001265
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001266//----------------------------------------------------------------------
1267// Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
1268//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001269ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1270 ipmi_response_t, ipmi_data_len_t data_len,
1271 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001272{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001273 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001274 *data_len = 0;
1275 return IPMI_CC_OK;
1276}
1277
1278//----------------------------------------------------------------------
1279// Set PPR (CMD_OEM_SET_PPR)
1280//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001281ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1282 ipmi_response_t, ipmi_data_len_t data_len,
1283 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001284{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001285 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001286 uint8_t pprCnt, pprAct, pprIndex;
1287 uint8_t selParam = req[0];
1288 uint8_t len = *data_len;
1289 std::stringstream ss;
1290 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001291
1292 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001293
1294 switch (selParam)
1295 {
1296 case PPR_ACTION:
1297 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) ==
1298 oemData[KEY_PPR].end())
1299 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1300
1301 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1302 if (pprCnt == 0)
1303 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1304
1305 pprAct = req[1];
1306 /* Check if ppr is enabled or disabled */
1307 if (!(pprAct & 0x80))
1308 pprAct = 0;
1309
1310 oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct;
1311 break;
1312 case PPR_ROW_COUNT:
1313 if (req[1] > 100)
1314 return IPMI_CC_PARM_OUT_OF_RANGE;
1315
1316 oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1];
1317 break;
1318 case PPR_ROW_ADDR:
1319 pprIndex = req[1];
1320 if (pprIndex > 100)
1321 return IPMI_CC_PARM_OUT_OF_RANGE;
1322
1323 if (len < PPR_ROW_ADDR_LEN + 1)
1324 {
1325 phosphor::logging::log<phosphor::logging::level::ERR>(
1326 "Invalid PPR Row Address length received");
1327 return IPMI_CC_REQ_DATA_LEN_INVALID;
1328 }
1329
1330 ss << std::hex;
1331 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1332
1333 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1334
1335 str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN);
1336 oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str();
1337 break;
1338 case PPR_HISTORY_DATA:
1339 pprIndex = req[1];
1340 if (pprIndex > 100)
1341 return IPMI_CC_PARM_OUT_OF_RANGE;
1342
1343 if (len < PPR_HST_DATA_LEN + 1)
1344 {
1345 phosphor::logging::log<phosphor::logging::level::ERR>(
1346 "Invalid PPR history data length received");
1347 return IPMI_CC_REQ_DATA_LEN_INVALID;
1348 }
1349
1350 ss << std::hex;
1351 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1352
1353 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1354
1355 str = bytesToStr(&req[1], PPR_HST_DATA_LEN);
1356 oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str();
1357 break;
1358 default:
1359 return IPMI_CC_PARM_OUT_OF_RANGE;
1360 break;
1361 }
1362
1363 flushOemData();
1364
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001365 return IPMI_CC_OK;
1366}
1367
1368//----------------------------------------------------------------------
1369// Get PPR (CMD_OEM_GET_PPR)
1370//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001371ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1372 ipmi_response_t response, ipmi_data_len_t data_len,
1373 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001374{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001375 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1376 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001377 uint8_t pprCnt, pprIndex;
1378 uint8_t selParam = req[0];
1379 std::stringstream ss;
1380 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001381
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001382 /* Any failure will return zero length data */
1383 *data_len = 0;
1384
1385 switch (selParam)
1386 {
1387 case PPR_ACTION:
1388 res[0] = 0;
1389 *data_len = 1;
1390
1391 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1392 oemData[KEY_PPR].end())
1393 {
1394 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1395 if (pprCnt != 0)
1396 {
1397 if (oemData[KEY_PPR].find(KEY_PPR_ACTION) !=
1398 oemData[KEY_PPR].end())
1399 {
1400 res[0] = oemData[KEY_PPR][KEY_PPR_ACTION];
1401 }
1402 }
1403 }
1404 break;
1405 case PPR_ROW_COUNT:
1406 res[0] = 0;
1407 *data_len = 1;
1408 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1409 oemData[KEY_PPR].end())
1410 res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1411 break;
1412 case PPR_ROW_ADDR:
1413 pprIndex = req[1];
1414 if (pprIndex > 100)
1415 return IPMI_CC_PARM_OUT_OF_RANGE;
1416
1417 ss << std::hex;
1418 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1419
1420 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1421 return IPMI_CC_PARM_OUT_OF_RANGE;
1422
1423 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) ==
1424 oemData[KEY_PPR][ss.str()].end())
1425 return IPMI_CC_PARM_OUT_OF_RANGE;
1426
1427 str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR];
1428 *data_len = strToBytes(str, res);
1429 break;
1430 case PPR_HISTORY_DATA:
1431 pprIndex = req[1];
1432 if (pprIndex > 100)
1433 return IPMI_CC_PARM_OUT_OF_RANGE;
1434
1435 ss << std::hex;
1436 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1437
1438 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1439 return IPMI_CC_PARM_OUT_OF_RANGE;
1440
1441 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) ==
1442 oemData[KEY_PPR][ss.str()].end())
1443 return IPMI_CC_PARM_OUT_OF_RANGE;
1444
1445 str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA];
1446 *data_len = strToBytes(str, res);
1447 break;
1448 default:
1449 return IPMI_CC_PARM_OUT_OF_RANGE;
1450 break;
1451 }
1452
1453 return IPMI_CC_OK;
1454}
1455
1456/* FB OEM QC Commands */
1457
1458//----------------------------------------------------------------------
1459// Set Proc Info (CMD_OEM_Q_SET_PROC_INFO)
1460//----------------------------------------------------------------------
1461//"Request:
1462// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1463// Byte 4 – Processor Index, 0 base
1464// Byte 5 – Parameter Selector
1465// Byte 6..N – Configuration parameter data (see below for Parameters
1466// of Processor Information)
1467// Response:
1468// Byte 1 – Completion code
1469//
1470// Parameter#1: (Processor Product Name)
1471//
1472// Byte 1..48 –Product name(ASCII code)
1473// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1474//
1475// Param#2: Processor Basic Information
1476// Byte 1 – Core Number
1477// Byte 2 – Thread Number (LSB)
1478// Byte 3 – Thread Number (MSB)
1479// Byte 4 – Processor frequency in MHz (LSB)
1480// Byte 5 – Processor frequency in MHz (MSB)
1481// Byte 6..7 – Revision
1482//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301483
1484ipmi::RspType<> ipmiOemQSetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1485 uint8_t, uint8_t procIndex,
1486 uint8_t paramSel,
1487 std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001488{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001489 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001490 std::stringstream ss;
1491 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301492 uint8_t len = request.size();
1493 auto hostId = findHost(ctx->hostIdx);
1494 if (!hostId)
1495 {
1496 phosphor::logging::log<phosphor::logging::level::ERR>(
1497 "Invalid Host Id received");
1498 return ipmi::responseInvalidCommand();
1499 }
1500 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001501 /* check for requested data params */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301502 if (len < 5 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001503 {
1504 phosphor::logging::log<phosphor::logging::level::ERR>(
1505 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301506 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001507 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001508 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301509 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1510 oemData[procInfo][ss.str()][KEY_PROC_INDEX] = procIndex;
1511 str = bytesToStr(request.data(), len);
1512 oemData[procInfo][ss.str()][cpuInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001513 flushOemData();
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301514 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001515}
1516
1517//----------------------------------------------------------------------
1518// Get Proc Info (CMD_OEM_Q_GET_PROC_INFO)
1519//----------------------------------------------------------------------
1520// Request:
1521// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1522// Byte 4 – Processor Index, 0 base
1523// Byte 5 – Parameter Selector
1524// Response:
1525// Byte 1 – Completion code
1526// Byte 2..N – Configuration Parameter Data (see below for Parameters
1527// of Processor Information)
1528//
1529// Parameter#1: (Processor Product Name)
1530//
1531// Byte 1..48 –Product name(ASCII code)
1532// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1533//
1534// Param#2: Processor Basic Information
1535// Byte 1 – Core Number
1536// Byte 2 – Thread Number (LSB)
1537// Byte 3 – Thread Number (MSB)
1538// Byte 4 – Processor frequency in MHz (LSB)
1539// Byte 5 – Processor frequency in MHz (MSB)
1540// Byte 6..7 – Revision
1541//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301542
1543ipmi::RspType<std::vector<uint8_t>>
1544 ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1545 uint8_t procIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001546{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001547 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001548 std::stringstream ss;
1549 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301550 uint8_t res[MAX_BUF];
1551 auto hostId = findHost(ctx->hostIdx);
1552 if (!hostId)
1553 {
1554 phosphor::logging::log<phosphor::logging::level::ERR>(
1555 "Invalid Host Id received");
1556 return ipmi::responseInvalidCommand();
1557 }
1558 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
1559 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001560 {
1561 phosphor::logging::log<phosphor::logging::level::ERR>(
1562 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301563 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001564 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001565 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301566 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1567 if (oemData[procInfo].find(ss.str()) == oemData[procInfo].end())
1568 return ipmi::responseCommandNotAvailable();
1569 if (oemData[procInfo][ss.str()].find(cpuInfoKey[paramSel]) ==
1570 oemData[procInfo][ss.str()].end())
1571 return ipmi::responseCommandNotAvailable();
1572 str = oemData[procInfo][ss.str()][cpuInfoKey[paramSel]];
1573 int dataLen = strToBytes(str, res);
1574 std::vector<uint8_t> response(&res[0], &res[dataLen]);
1575 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001576}
1577
1578//----------------------------------------------------------------------
1579// Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO)
1580//----------------------------------------------------------------------
1581// Request:
1582// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1583// Byte 4 – DIMM Index, 0 base
1584// Byte 5 – Parameter Selector
1585// Byte 6..N – Configuration parameter data (see below for Parameters
1586// of DIMM Information)
1587// Response:
1588// Byte 1 – Completion code
1589//
1590// Param#1 (DIMM Location):
1591// Byte 1 – DIMM Present
1592// Byte 1 – DIMM Present
1593// 01h – Present
1594// FFh – Not Present
1595// Byte 2 – Node Number, 0 base
1596// Byte 3 – Channel Number , 0 base
1597// Byte 4 – DIMM Number , 0 base
1598//
1599// Param#2 (DIMM Type):
1600// Byte 1 – DIMM Type
1601// Bit [7:6]
1602// For DDR3
1603// 00 – Normal Voltage (1.5V)
1604// 01 – Ultra Low Voltage (1.25V)
1605// 10 – Low Voltage (1.35V)
1606// 11 – Reserved
1607// For DDR4
1608// 00 – Reserved
1609// 01 – Reserved
1610// 10 – Reserved
1611// 11 – Normal Voltage (1.2V)
1612// Bit [5:0]
1613// 0x00 – SDRAM
1614// 0x01 – DDR-1 RAM
1615// 0x02 – Rambus
1616// 0x03 – DDR-2 RAM
1617// 0x04 – FBDIMM
1618// 0x05 – DDR-3 RAM
1619// 0x06 – DDR-4 RAM
1620//
1621// Param#3 (DIMM Speed):
1622// Byte 1..2 – DIMM speed in MHz, LSB
1623// Byte 3..6 – DIMM size in Mbytes, LSB
1624//
1625// Param#4 (Module Part Number):
1626// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1627//
1628// Param#5 (Module Serial Number):
1629// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1630//
1631// Param#6 (Module Manufacturer ID):
1632// Byte 1 - Module Manufacturer ID, LSB
1633// Byte 2 - Module Manufacturer ID, MSB
1634//
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301635ipmi::RspType<> ipmiOemQSetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1636 uint8_t, uint8_t dimmIndex,
1637 uint8_t paramSel,
1638 std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001639{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001640 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001641 std::stringstream ss;
1642 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301643 uint8_t len = request.size();
1644 std::string dimmType;
1645 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001646 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301647 if (!hostId)
1648 {
1649 phosphor::logging::log<phosphor::logging::level::ERR>(
1650 "Invalid Host Id received");
1651 return ipmi::responseInvalidCommand();
1652 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001653
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301654 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001655
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301656 if (len < 3 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001657 {
1658 phosphor::logging::log<phosphor::logging::level::ERR>(
1659 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301660 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001661 }
1662
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001663 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301664 ss << (int)dimmIndex;
1665 oemData[dimmInfo][ss.str()][KEY_DIMM_INDEX] = dimmIndex;
1666 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1667 str = bytesToStr(request.data(), len);
1668 oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001669 flushOemData();
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301670 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001671}
1672
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001673// Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO)
1674//----------------------------------------------------------------------
1675// Request:
1676// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1677// Byte 4 – DIMM Index, 0 base
1678// Byte 5 – Parameter Selector
1679// Byte 6..N – Configuration parameter data (see below for Parameters
1680// of DIMM Information)
1681// Response:
1682// Byte 1 – Completion code
1683// Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters
1684// of DIMM Information)
1685//
1686// Param#1 (DIMM Location):
1687// Byte 1 – DIMM Present
1688// Byte 1 – DIMM Present
1689// 01h – Present
1690// FFh – Not Present
1691// Byte 2 – Node Number, 0 base
1692// Byte 3 – Channel Number , 0 base
1693// Byte 4 – DIMM Number , 0 base
1694//
1695// Param#2 (DIMM Type):
1696// Byte 1 – DIMM Type
1697// Bit [7:6]
1698// For DDR3
1699// 00 – Normal Voltage (1.5V)
1700// 01 – Ultra Low Voltage (1.25V)
1701// 10 – Low Voltage (1.35V)
1702// 11 – Reserved
1703// For DDR4
1704// 00 – Reserved
1705// 01 – Reserved
1706// 10 – Reserved
1707// 11 – Normal Voltage (1.2V)
1708// Bit [5:0]
1709// 0x00 – SDRAM
1710// 0x01 – DDR-1 RAM
1711// 0x02 – Rambus
1712// 0x03 – DDR-2 RAM
1713// 0x04 – FBDIMM
1714// 0x05 – DDR-3 RAM
1715// 0x06 – DDR-4 RAM
1716//
1717// Param#3 (DIMM Speed):
1718// Byte 1..2 – DIMM speed in MHz, LSB
1719// Byte 3..6 – DIMM size in Mbytes, LSB
1720//
1721// Param#4 (Module Part Number):
1722// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1723//
1724// Param#5 (Module Serial Number):
1725// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1726//
1727// Param#6 (Module Manufacturer ID):
1728// Byte 1 - Module Manufacturer ID, LSB
1729// Byte 2 - Module Manufacturer ID, MSB
1730//
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301731ipmi::RspType<std::vector<uint8_t>>
1732 ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1733 uint8_t dimmIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001734{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001735 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301736 uint8_t res[MAX_BUF];
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001737 std::stringstream ss;
1738 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301739 std::string dimmType;
1740 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001741 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301742 if (!hostId)
1743 {
1744 phosphor::logging::log<phosphor::logging::level::ERR>(
1745 "Invalid Host Id received");
1746 return ipmi::responseInvalidCommand();
1747 }
1748 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001749
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301750 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001751 {
1752 phosphor::logging::log<phosphor::logging::level::ERR>(
1753 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301754 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001755 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001756 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301757 ss << (int)dimmIndex;
1758 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1759 if (oemData[dimmInfo].find(ss.str()) == oemData[dimmInfo].end())
1760 return ipmi::responseCommandNotAvailable();
1761 if (oemData[dimmInfo][ss.str()].find(dimmInfoKey[paramSel]) ==
1762 oemData[dimmInfo][ss.str()].end())
1763 return ipmi::responseCommandNotAvailable();
1764 str = oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]];
1765 int data_length = strToBytes(str, res);
1766 std::vector<uint8_t> response(&res[0], &res[data_length]);
1767 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001768}
1769
1770//----------------------------------------------------------------------
1771// Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO)
1772//----------------------------------------------------------------------
1773// BIOS issue this command to provide HDD information to BMC.
1774//
1775// BIOS just can get information by standard ATA / SMART command for
1776// OB SATA controller.
1777// BIOS can get
1778// 1. Serial Number
1779// 2. Model Name
1780// 3. HDD FW Version
1781// 4. HDD Capacity
1782// 5. HDD WWN
1783//
1784// Use Get HDD info Param #5 to know the MAX HDD info index.
1785//
1786// Request:
1787// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1788// Byte 4 –
1789// [7:4] Reserved
1790// [3:0] HDD Controller Type
1791// 0x00 – BIOS
1792// 0x01 – Expander
1793// 0x02 – LSI
1794// Byte 5 – HDD Info Index, 0 base
1795// Byte 6 – Parameter Selector
1796// Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD
1797// Information)
1798//
1799// Response:
1800// Byte 1 – Completion Code
1801//
1802// Param#0 (HDD Location):
1803// Byte 1 – Controller
1804// [7:3] Device Number
1805// [2:0] Function Number
1806// For Intel C610 series (Wellsburg)
1807// D31:F2 (0xFA) – SATA control 1
1808// D31:F5 (0xFD) – SATA control 2
1809// D17:F4 (0x8C) – sSata control
1810// Byte 2 – Port Number
1811// Byte 3 – Location (0xFF: No HDD Present)
1812// BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param
1813// #1~4, #6, #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if
1814// the HDD present. BMC or other people who know the HDD location has
1815// responsibility for update Location info
1816//
1817// Param#1 (Serial Number):
1818// Bytes 1..33: HDD Serial Number
1819//
1820// Param#2 (Model Name):
1821// Byte 1..33 – HDD Model Name
1822//
1823// Param#3 (HDD FW Version):
1824// Byte 1..17 –HDD FW version
1825//
1826// Param#4 (Capacity):
1827// Byte 1..4 –HDD Block Size, LSB
1828// Byte 5..12 - HDD Block Number, LSB
1829// HDD Capacity = HDD Block size * HDD BLock number (Unit Byte)
1830//
1831// Param#5 (Max HDD Quantity):
1832// Byte 1 - Max HDD Quantity
1833// Max supported port numbers in this PCH
1834//
1835// Param#6 (HDD Type)
1836// Byte 1 – HDD Type
1837// 0h – Reserved
1838// 1h – SAS
1839// 2h – SATA
1840// 3h – PCIE SSD (NVME)
1841//
1842// Param#7 (HDD WWN)
1843// Data 1...8: HDD World Wide Name, LSB
1844//
Willy Tue39f9392022-06-15 13:24:20 -07001845ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
1846 ipmi_request_t request, ipmi_response_t,
1847 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001848{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001849 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1850 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001851 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1852 std::stringstream ss;
1853 std::string str;
1854 uint8_t len = *data_len;
1855
1856 *data_len = 0;
1857
1858 /* check for requested data params */
1859 if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam ||
1860 ctrlType > 2)
1861 {
1862 phosphor::logging::log<phosphor::logging::level::ERR>(
1863 "Invalid parameter received");
1864 return IPMI_CC_PARM_OUT_OF_RANGE;
1865 }
1866
1867 len = len - 6; // Get Actual data length
1868
1869 ss << std::hex;
1870 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1871 oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType;
1872 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] =
1873 req->hddIndex;
1874
1875 str = bytesToStr(req->data, len);
1876 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
1877 [driveInfoKey[req->paramSel]] = str.c_str();
1878 flushOemData();
1879
1880 return IPMI_CC_OK;
1881}
1882
1883//----------------------------------------------------------------------
1884// Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO)
1885//----------------------------------------------------------------------
1886// BMC needs to check HDD presented or not first. If NOT presented, return
1887// completion code 0xD5.
1888//
1889// Request:
1890// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1891// Byte 4 –
1892//[7:4] Reserved
1893//[3:0] HDD Controller Type
1894// 0x00 – BIOS
1895// 0x01 – Expander
1896// 0x02 – LSI
1897// Byte 5 – HDD Index, 0 base
1898// Byte 6 – Parameter Selector (See Above Set HDD Information)
1899// Response:
1900// Byte 1 – Completion Code
1901// 0xD5 – Not support in current status (HDD Not Present)
1902// Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD
1903// Information)
1904//
Willy Tue39f9392022-06-15 13:24:20 -07001905ipmi_ret_t ipmiOemQGetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001906 ipmi_request_t request,
1907 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -07001908 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001909{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001910 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1911 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
1912 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001913 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1914 std::stringstream ss;
1915 std::string str;
1916
1917 *data_len = 0;
1918
1919 /* check for requested data params */
1920 if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2)
1921 {
1922 phosphor::logging::log<phosphor::logging::level::ERR>(
1923 "Invalid parameter received");
1924 return IPMI_CC_PARM_OUT_OF_RANGE;
1925 }
1926
1927 if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) ==
1928 oemData[KEY_Q_DRIVE_INFO].end())
1929 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1930
1931 ss << std::hex;
1932 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1933
1934 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) ==
1935 oemData[KEY_Q_DRIVE_INFO].end())
1936 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1937
1938 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find(
1939 dimmInfoKey[req->paramSel]) ==
1940 oemData[KEY_Q_DRIVE_INFO][ss.str()].end())
1941 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1942
1943 str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
1944 [dimmInfoKey[req->paramSel]];
1945 *data_len = strToBytes(str, res);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001946
1947 return IPMI_CC_OK;
1948}
1949
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301950/* Helper function for sending DCMI commands to ME/BIC and
1951 * getting response back
1952 */
1953ipmi::RspType<std::vector<uint8_t>>
1954 sendDCMICmd([[maybe_unused]] ipmi::Context::ptr ctx,
1955 [[maybe_unused]] uint8_t cmd, std::vector<uint8_t>& cmdData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001956{
1957 std::vector<uint8_t> respData;
1958
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301959#if BIC_ENABLED
1960
1961 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
1962
1963 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, cmdData, respData))
1964 {
1965 return ipmi::responseUnspecifiedError();
1966 }
1967
1968#else
1969
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001970 /* Add group id as first byte to request for ME command */
1971 cmdData.insert(cmdData.begin(), groupDCMI);
1972
1973 if (sendMeCmd(ipmi::netFnGroup, cmd, cmdData, respData))
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301974 {
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001975 return ipmi::responseUnspecifiedError();
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301976 }
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001977
1978 /* Remove group id as first byte as it will be added by IPMID */
1979 respData.erase(respData.begin());
1980
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301981#endif
1982
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001983 return ipmi::responseSuccess(std::move(respData));
1984}
1985
1986/* DCMI Command handellers. */
1987
1988ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301989 ipmiOemDCMIGetPowerReading(ipmi::Context::ptr ctx,
1990 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001991{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301992 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerReading, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001993}
1994
1995ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301996 ipmiOemDCMIGetPowerLimit(ipmi::Context::ptr ctx,
1997 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001998{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05301999 return sendDCMICmd(ctx, ipmi::dcmi::cmdGetPowerLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002000}
2001
2002ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302003 ipmiOemDCMISetPowerLimit(ipmi::Context::ptr ctx,
2004 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002005{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302006 return sendDCMICmd(ctx, ipmi::dcmi::cmdSetPowerLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002007}
2008
2009ipmi::RspType<std::vector<uint8_t>>
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302010 ipmiOemDCMIApplyPowerLimit(ipmi::Context::ptr ctx,
2011 std::vector<uint8_t> reqData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002012{
Logananth Sundararaje4d6fe72022-08-23 20:36:31 +05302013 return sendDCMICmd(ctx, ipmi::dcmi::cmdActDeactivatePwrLimit, reqData);
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002014}
2015
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002016static void registerOEMFunctions(void)
2017{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002018 /* Get OEM data from json file */
2019 std::ifstream file(JSON_OEM_DATA_FILE);
2020 if (file)
Vijay Khemkafeaa9812019-08-27 15:08:08 -07002021 {
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002022 file >> oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -07002023 file.close();
2024 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002025
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002026 phosphor::logging::log<phosphor::logging::level::INFO>(
2027 "Registering OEM commands");
Vijay Khemka7c0aea42020-03-05 13:31:53 -08002028
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002029 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO,
2030 NULL, ipmiOemDbgGetFrameInfo,
2031 PRIVILEGE_USER); // get debug frame info
2032 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ,
2033 CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL,
2034 ipmiOemDbgGetUpdFrames,
2035 PRIVILEGE_USER); // get debug updated frames
2036 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC,
2037 NULL, ipmiOemDbgGetPostDesc,
2038 PRIVILEGE_USER); // get debug post description
2039 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC,
2040 NULL, ipmiOemDbgGetGpioDesc,
2041 PRIVILEGE_USER); // get debug gpio description
2042 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA,
2043 NULL, ipmiOemDbgGetFrameData,
2044 PRIVILEGE_USER); // get debug frame data
2045 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL,
2046 NULL, ipmiOemDbgGetCtrlPanel,
2047 PRIVILEGE_USER); // get debug control panel
2048 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL,
2049 ipmiOemSetDimmInfo,
2050 PRIVILEGE_USER); // Set Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002051 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
2052 ipmiOemGetBoardID,
2053 PRIVILEGE_USER); // Get Board ID
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002054 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL,
2055 ipmiOemSetMachineCfgInfo,
2056 PRIVILEGE_USER); // Set Machine Config Info
2057 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL,
2058 ipmiOemSetPostStart,
2059 PRIVILEGE_USER); // Set POST start
2060 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL,
2061 ipmiOemSetPostEnd,
2062 PRIVILEGE_USER); // Set POST End
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002063 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
2064 ipmiOemSetPPINInfo,
2065 PRIVILEGE_USER); // Set PPIN Info
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302066#if BIC_ENABLED
2067
2068 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2069 ipmi::cmdSetSystemGuid, ipmi::Privilege::User,
2070 ipmiOemSetSystemGuid);
2071#else
2072
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07002073 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL,
2074 ipmiOemSetSystemGuid,
2075 PRIVILEGE_USER); // Set System GUID
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302076#endif
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002077 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
2078 ipmiOemSetAdrTrigger,
2079 PRIVILEGE_USER); // Set ADR Trigger
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002080 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL,
2081 ipmiOemSetBiosFlashInfo,
2082 PRIVILEGE_USER); // Set Bios Flash Info
2083 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr,
2084 PRIVILEGE_USER); // Set PPR
2085 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr,
2086 PRIVILEGE_USER); // Get PPR
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002087 /* FB OEM QC Commands */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05302088 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2089 CMD_OEM_Q_SET_PROC_INFO, ipmi::Privilege::User,
2090 ipmiOemQSetProcInfo); // Set Proc Info
2091 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2092 CMD_OEM_Q_GET_PROC_INFO, ipmi::Privilege::User,
2093 ipmiOemQGetProcInfo); // Get Proc Info
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05302094 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2095 ipmi::cmdSetQDimmInfo, ipmi::Privilege::User,
2096 ipmiOemQSetDimmInfo); // Set Dimm Info
2097 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2098 ipmi::cmdGetQDimmInfo, ipmi::Privilege::User,
2099 ipmiOemQGetDimmInfo); // Get Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002100 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL,
2101 ipmiOemQSetDriveInfo,
2102 PRIVILEGE_USER); // Set Drive Info
2103 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL,
2104 ipmiOemQGetDriveInfo,
2105 PRIVILEGE_USER); // Get Drive Info
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002106
2107 /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */
2108 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2109 ipmi::dcmi::cmdGetPowerReading,
2110 ipmi::Privilege::User,
2111 ipmiOemDCMIGetPowerReading); // Get Power Reading
2112
2113 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2114 ipmi::dcmi::cmdGetPowerLimit,
2115 ipmi::Privilege::User,
2116 ipmiOemDCMIGetPowerLimit); // Get Power Limit
2117
2118 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2119 ipmi::dcmi::cmdSetPowerLimit,
2120 ipmi::Privilege::Operator,
2121 ipmiOemDCMISetPowerLimit); // Set Power Limit
2122
2123 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2124 ipmi::dcmi::cmdActDeactivatePwrLimit,
2125 ipmi::Privilege::Operator,
2126 ipmiOemDCMIApplyPowerLimit); // Apply Power Limit
2127
Jayashree-Df0cf6652020-11-30 11:03:30 +05302128 /* FB OEM BOOT ORDER COMMANDS */
2129 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2130 CMD_OEM_GET_BOOT_ORDER, ipmi::Privilege::User,
2131 ipmiOemGetBootOrder); // Get Boot Order
2132
2133 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2134 CMD_OEM_SET_BOOT_ORDER, ipmi::Privilege::User,
2135 ipmiOemSetBootOrder); // Set Boot Order
2136
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002137 return;
2138}
2139
2140} // namespace ipmi