blob: 577f513e30d4059663086e210f5999461766e38e [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 Pasupathi98aabdb2022-04-06 17:18:51 +053051size_t getSelectorPosition();
Vijay Khemkae7d23d02019-03-08 13:13:40 -080052static void registerOEMFunctions() __attribute__((constructor));
53sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
54static 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";
108
Vijay Khemka63c99be2020-05-27 19:14:35 -0700109bool isLinkLocalIP(const std::string& address)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700110{
111 return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
112}
113
Vijay Khemka63c99be2020-05-27 19:14:35 -0700114DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus,
115 const std::string& interface,
116 const std::string& serviceRoot,
117 const std::string& match)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700118{
119 auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, match);
120
121 if (objectTree.empty())
122 {
123 log<level::ERR>("No Object has implemented the IP interface",
124 entry("INTERFACE=%s", interface.c_str()));
125 }
126
127 DbusObjectInfo objectInfo;
128
Vijay Khemka63c99be2020-05-27 19:14:35 -0700129 for (auto& object : objectTree)
Vijay Khemkaa7231892019-10-11 11:35:05 -0700130 {
131 auto variant =
132 ipmi::getDbusProperty(bus, object.second.begin()->first,
133 object.first, IP_INTERFACE, "Address");
134
135 objectInfo = std::make_pair(object.first, object.second.begin()->first);
136
137 // if LinkLocalIP found look for Non-LinkLocalIP
138 if (isLinkLocalIP(std::get<std::string>(variant)))
139 {
140 continue;
141 }
142 else
143 {
144 break;
145 }
146 }
147 return objectInfo;
148}
149
150} // namespace network
151
Jayashree-Df0cf6652020-11-30 11:03:30 +0530152namespace boot
153{
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530154using BootSource =
155 sdbusplus::xyz::openbmc_project::Control::Boot::server::Source::Sources;
156using BootMode =
157 sdbusplus::xyz::openbmc_project::Control::Boot::server::Mode::Modes;
158using BootType =
159 sdbusplus::xyz::openbmc_project::Control::Boot::server::Type::Types;
Jayashree-Df0cf6652020-11-30 11:03:30 +0530160
Jayashree-Df0cf6652020-11-30 11:03:30 +0530161using IpmiValue = uint8_t;
162
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530163std::map<IpmiValue, BootSource> sourceIpmiToDbus = {
164 {0x0f, BootSource::Default}, {0x00, BootSource::RemovableMedia},
165 {0x01, BootSource::Network}, {0x02, BootSource::Disk},
166 {0x03, BootSource::ExternalMedia}, {0x09, BootSource::Network}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530167
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530168std::map<IpmiValue, BootMode> modeIpmiToDbus = {{0x06, BootMode::Setup},
169 {0x00, BootMode::Regular}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530170
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530171std::map<IpmiValue, BootType> typeIpmiToDbus = {{0x00, BootType::Legacy},
172 {0x01, BootType::EFI}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530173
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530174std::map<std::optional<BootSource>, IpmiValue> sourceDbusToIpmi = {
175 {BootSource::Default, 0x0f},
176 {BootSource::RemovableMedia, 0x00},
177 {BootSource::Network, 0x01},
178 {BootSource::Disk, 0x02},
179 {BootSource::ExternalMedia, 0x03}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530180
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530181std::map<std::optional<BootMode>, IpmiValue> modeDbusToIpmi = {
182 {BootMode::Setup, 0x06}, {BootMode::Regular, 0x00}};
Jayashree-Df0cf6652020-11-30 11:03:30 +0530183
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530184std::map<std::optional<BootType>, IpmiValue> typeDbusToIpmi = {
185 {BootType::Legacy, 0x00}, {BootType::EFI, 0x01}};
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530186
Jayashree-Df0cf6652020-11-30 11:03:30 +0530187static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
188static constexpr auto bootSourceIntf =
189 "xyz.openbmc_project.Control.Boot.Source";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530190static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530191static constexpr auto bootSourceProp = "BootSource";
192static constexpr auto bootModeProp = "BootMode";
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530193static constexpr auto bootTypeProp = "BootType";
Jayashree-Df0cf6652020-11-30 11:03:30 +0530194
Jayashree-Df0cf6652020-11-30 11:03:30 +0530195std::tuple<std::string, std::string> objPath(size_t id)
196{
197 std::string hostName = "host" + std::to_string(id);
198 std::string bootObjPath =
199 "/xyz/openbmc_project/control/" + hostName + "/boot";
200 return std::make_tuple(std::move(bootObjPath), std::move(hostName));
201}
202
203} // namespace boot
204
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700205//----------------------------------------------------------------------
206// Helper functions for storing oem data
207//----------------------------------------------------------------------
208
209void flushOemData()
210{
211 std::ofstream file(JSON_OEM_DATA_FILE);
212 file << oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -0700213 file.close();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700214 return;
215}
216
Vijay Khemka63c99be2020-05-27 19:14:35 -0700217std::string bytesToStr(uint8_t* byte, int len)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700218{
219 std::stringstream ss;
220 int i;
221
222 ss << std::hex;
223 for (i = 0; i < len; i++)
224 {
225 ss << std::setw(2) << std::setfill('0') << (int)byte[i];
226 }
227
228 return ss.str();
229}
230
Vijay Khemka63c99be2020-05-27 19:14:35 -0700231int strToBytes(std::string& str, uint8_t* data)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700232{
233 std::string sstr;
Willy Tue39f9392022-06-15 13:24:20 -0700234 size_t i;
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700235
236 for (i = 0; i < (str.length()) / 2; i++)
237 {
238 sstr = str.substr(i * 2, 2);
239 data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16);
240 }
241 return i;
242}
243
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530244int readDimmType(std::string& data, uint8_t param)
245{
246 nlohmann::json dimmObj;
247 /* Get dimm type names stored in json file */
248 std::ifstream file(JSON_DIMM_TYPE_FILE);
249 if (file)
250 {
251 file >> dimmObj;
252 file.close();
253 }
254 else
255 {
256 phosphor::logging::log<phosphor::logging::level::ERR>(
257 "DIMM type names file not found",
258 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
259 return -1;
260 }
261
262 std::string dimmKey = "dimm_type" + std::to_string(param);
263 auto obj = dimmObj[dimmKey]["short_name"];
264 data = obj;
265 return 0;
266}
267
Vijay Khemka63c99be2020-05-27 19:14:35 -0700268ipmi_ret_t getNetworkData(uint8_t lan_param, char* data)
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700269{
270 ipmi_ret_t rc = IPMI_CC_OK;
271 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
272
273 const std::string ethdevice = "eth0";
274
275 switch (static_cast<LanParam>(lan_param))
276 {
Vijay Khemkad1194022020-05-27 18:58:33 -0700277 case LanParam::IP:
278 {
Vijay Khemkaa7231892019-10-11 11:35:05 -0700279 auto ethIP = ethdevice + "/" + ipmi::network::IPV4_TYPE;
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700280 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700281 auto ipObjectInfo = ipmi::network::getIPObject(
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700282 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT, ethIP);
283
284 auto properties = ipmi::getAllDbusProperties(
285 bus, ipObjectInfo.second, ipObjectInfo.first,
286 ipmi::network::IP_INTERFACE);
287
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500288 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700289
290 std::strcpy(data, ipaddress.c_str());
291 }
292 break;
293
Vijay Khemkad1194022020-05-27 18:58:33 -0700294 case LanParam::IPV6:
295 {
Vijay Khemkaa7231892019-10-11 11:35:05 -0700296 auto ethIP = ethdevice + "/" + ipmi::network::IPV6_TYPE;
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700297 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700298 auto ipObjectInfo = ipmi::network::getIPObject(
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700299 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT, ethIP);
300
301 auto properties = ipmi::getAllDbusProperties(
302 bus, ipObjectInfo.second, ipObjectInfo.first,
303 ipmi::network::IP_INTERFACE);
304
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500305 ipaddress = std::get<std::string>(properties["Address"]);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700306
307 std::strcpy(data, ipaddress.c_str());
308 }
309 break;
310
Vijay Khemkad1194022020-05-27 18:58:33 -0700311 case LanParam::MAC:
312 {
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700313 std::string macAddress;
314 auto macObjectInfo =
315 ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE,
316 ipmi::network::ROOT, ethdevice);
317
318 auto variant = ipmi::getDbusProperty(
319 bus, macObjectInfo.second, macObjectInfo.first,
320 ipmi::network::MAC_INTERFACE, "MACAddress");
321
Patrick Williamsef0efbc2020-05-13 11:26:51 -0500322 macAddress = std::get<std::string>(variant);
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700323
324 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
325 (data), (data + 1), (data + 2), (data + 3), (data + 4),
326 (data + 5));
327 std::strcpy(data, macAddress.c_str());
328 }
329 break;
330
331 default:
332 rc = IPMI_CC_PARM_OUT_OF_RANGE;
333 }
334 return rc;
335}
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800336
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530337bool isMultiHostPlatform()
338{
339 bool platform;
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530340 if (hostInstances == "0")
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +0530341 {
342 platform = false;
343 }
344 else
345 {
346 platform = true;
347 }
348 return platform;
349}
350
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800351// return code: 0 successful
Vijay Khemka63c99be2020-05-27 19:14:35 -0700352int8_t getFruData(std::string& data, std::string& name)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800353{
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530354 size_t pos;
355 static constexpr const auto depth = 0;
356 std::vector<std::string> paths;
357 std::string machinePath;
358 std::string baseBoard = "Baseboard";
359
360 bool platform = isMultiHostPlatform();
361 if (platform == true)
362 {
363 pos = getSelectorPosition();
364 }
365
366 sd_bus* bus = NULL;
367 int ret = sd_bus_default_system(&bus);
368 if (ret < 0)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800369 {
370 phosphor::logging::log<phosphor::logging::level::ERR>(
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530371 "Failed to connect to system bus",
372 phosphor::logging::entry("ERRNO=0x%X", -ret));
373 sd_bus_unref(bus);
374 return -1;
375 }
376 sdbusplus::bus::bus dbus(bus);
377 auto mapperCall = dbus.new_method_call("xyz.openbmc_project.ObjectMapper",
378 "/xyz/openbmc_project/object_mapper",
379 "xyz.openbmc_project.ObjectMapper",
380 "GetSubTreePaths");
381 static constexpr std::array<const char*, 1> interface = {
382 "xyz.openbmc_project.Inventory.Decorator.Asset"};
383 mapperCall.append("/xyz/openbmc_project/inventory/", depth, interface);
384
385 try
386 {
387 auto reply = dbus.call(mapperCall);
388 reply.read(paths);
389 }
390 catch (sdbusplus::exception_t& e)
391 {
392 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800393 return -1;
394 }
395
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530396 for (const auto& path : paths)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800397 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530398 if (platform == true)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800399 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530400 if (pos == BMC_POS)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800401 {
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530402 machinePath = baseBoard;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800403 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530404 else
405 {
406 machinePath = "_" + std::to_string(pos);
407 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800408 }
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530409 else
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
414 auto found = path.find(machinePath);
Patrick Williams123cbcc2022-06-24 06:13:59 -0500415 if (found == std::string::npos)
Karthikeyan Pasupathi98aabdb2022-04-06 17:18:51 +0530416 {
417 continue;
418 }
419
420 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
421 std::string service = getService(
422 *dbus, "xyz.openbmc_project.Inventory.Decorator.Asset", path);
423
424 auto Value = ipmi::getDbusProperty(
425 *dbus, service, path,
426 "xyz.openbmc_project.Inventory.Decorator.Asset", name);
427
428 data = std::get<std::string>(Value);
429 return 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800430 }
431 return -1;
432}
433
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +0530434int8_t sysConfig(std::vector<std::string>& data, size_t pos)
435{
436 nlohmann::json sysObj;
437 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(pos);
438 std::string result, typeName;
439 uint8_t res[MAX_BUF];
440
441 /* Get sysConfig data stored in json file */
442 std::ifstream file(JSON_OEM_DATA_FILE);
443 if (file)
444 {
445 file >> sysObj;
446 file.close();
447 }
448 else
449 {
450 phosphor::logging::log<phosphor::logging::level::ERR>(
451 "oemData file not found",
452 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
453 return -1;
454 }
455
456 if (sysObj.find(dimmInfo) == sysObj.end())
457 {
458 phosphor::logging::log<phosphor::logging::level::ERR>(
459 "sysconfig key not available",
460 phosphor::logging::entry("SYS_JSON_KEY=%s", dimmInfo.c_str()));
461 return -1;
462 }
463 /* Get dimm type names stored in json file */
464 nlohmann::json dimmObj;
465 std::ifstream dimmFile(JSON_DIMM_TYPE_FILE);
466 if (file)
467 {
468 dimmFile >> dimmObj;
469 dimmFile.close();
470 }
471 else
472 {
473 phosphor::logging::log<phosphor::logging::level::ERR>(
474 "DIMM type names file not found",
475 phosphor::logging::entry("DIMM_TYPE_FILE=%s", JSON_DIMM_TYPE_FILE));
476 return -1;
477 }
478 std::vector<std::string> a;
479 for (auto& j : dimmObj.items())
480 {
481 std::string name = j.key();
482 a.push_back(name);
483 }
484
485 uint8_t len = a.size();
486 for (uint8_t ii = 0; ii < len; ii++)
487 {
488 std::string indKey = std::to_string(ii);
489 std::string speedSize = sysObj[dimmInfo][indKey][DIMM_SPEED];
490 strToBytes(speedSize, res);
491 auto speed = (res[1] << 8 | res[0]);
492 size_t dimmSize = ((res[3] << 8 | res[2]) / 1000);
493
494 if (dimmSize == 0)
495 {
496 std::cerr << "Dimm information not available for slot_" +
497 std::to_string(ii)
498 << std::endl;
499 continue;
500 }
501 std::string type = sysObj[dimmInfo][indKey][DIMM_TYPE];
502 std::string dualInlineMem = sysObj[dimmInfo][indKey][KEY_DIMM_TYPE];
503 strToBytes(type, res);
504 size_t dimmType = res[0];
505 if (dimmVenMap.find(dimmType) == dimmVenMap.end())
506 {
507 typeName = "unknown";
508 }
509 else
510 {
511 typeName = dimmVenMap[dimmType];
512 }
513 result = dualInlineMem + "/" + typeName + "/" + std::to_string(speed) +
514 "MHz" + "/" + std::to_string(dimmSize) + "GB";
515 data.push_back(result);
516 }
517 return 0;
518}
519
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +0530520int8_t procInfo(std::string& result, size_t pos)
521{
522 std::vector<char> data;
523 uint8_t res[MAX_BUF];
524 std::string procIndex = "00";
525 nlohmann::json proObj;
526 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(pos);
527 /* Get processor data stored in json file */
528 std::ifstream file(JSON_OEM_DATA_FILE);
529 if (file)
530 {
531 file >> proObj;
532 file.close();
533 }
534 else
535 {
536 phosphor::logging::log<phosphor::logging::level::ERR>(
537 "oemData file not found",
538 phosphor::logging::entry("OEM_DATA_FILE=%s", JSON_OEM_DATA_FILE));
539 return -1;
540 }
541 if (proObj.find(procInfo) == proObj.end())
542 {
543 phosphor::logging::log<phosphor::logging::level::ERR>(
544 "processor info key not available",
545 phosphor::logging::entry("PROC_JSON_KEY=%s", procInfo.c_str()));
546 return -1;
547 }
548 std::string procName = proObj[procInfo][procIndex][KEY_PROC_NAME];
549 std::string basicInfo = proObj[procInfo][procIndex][KEY_BASIC_INFO];
550 // Processor Product Name
551 strToBytes(procName, res);
552 data.assign(reinterpret_cast<char*>(&res),
553 reinterpret_cast<char*>(&res) + sizeof(res));
554
555 std::string s(data.begin(), data.end());
556 std::regex regex(" ");
557 std::vector<std::string> productName(
558 std::sregex_token_iterator(s.begin(), s.end(), regex, -1),
559 std::sregex_token_iterator());
560
561 // Processor core and frequency
562 strToBytes(basicInfo, res);
563 uint16_t coreNum = res[0];
564 double procFrequency = (float)(res[4] << 8 | res[3]) / 1000;
565 result = "CPU:" + productName[2] + "/" + std::to_string(procFrequency) +
566 "GHz" + "/" + std::to_string(coreNum) + "c";
567 return 0;
568}
569
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800570typedef struct
571{
572 uint8_t cur_power_state;
573 uint8_t last_power_event;
574 uint8_t misc_power_state;
575 uint8_t front_panel_button_cap_status;
576} ipmi_get_chassis_status_t;
577
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800578//----------------------------------------------------------------------
579// Get Debug Frame Info
580//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700581ipmi_ret_t ipmiOemDbgGetFrameInfo(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800582 ipmi_request_t request,
583 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700584 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800585{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700586 uint8_t* req = reinterpret_cast<uint8_t*>(request);
587 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800588 uint8_t num_frames = 3;
589
590 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
591 res[SIZE_IANA_ID] = num_frames;
592 *data_len = SIZE_IANA_ID + 1;
593
594 return IPMI_CC_OK;
595}
596
597//----------------------------------------------------------------------
598// Get Debug Updated Frames
599//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700600ipmi_ret_t ipmiOemDbgGetUpdFrames(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800601 ipmi_request_t request,
602 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700603 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800604{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700605 uint8_t* req = reinterpret_cast<uint8_t*>(request);
606 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800607 uint8_t num_updates = 3;
608 *data_len = 4;
609
610 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
611 res[SIZE_IANA_ID] = num_updates;
612 *data_len = SIZE_IANA_ID + num_updates + 1;
613 res[SIZE_IANA_ID + 1] = 1; // info page update
614 res[SIZE_IANA_ID + 2] = 2; // cri sel update
615 res[SIZE_IANA_ID + 3] = 3; // cri sensor update
616
617 return IPMI_CC_OK;
618}
619
620//----------------------------------------------------------------------
621// Get Debug POST Description
622//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700623ipmi_ret_t ipmiOemDbgGetPostDesc(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800624 ipmi_request_t request,
625 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700626 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800627{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700628 uint8_t* req = reinterpret_cast<uint8_t*>(request);
629 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800630 uint8_t index = 0;
631 uint8_t next = 0;
632 uint8_t end = 0;
633 uint8_t phase = 0;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700634 uint8_t descLen = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800635 int ret;
636
637 index = req[3];
638 phase = req[4];
639
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700640 ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800641 if (ret)
642 {
643 memcpy(res, req, SIZE_IANA_ID); // IANA ID
644 *data_len = SIZE_IANA_ID;
645 return IPMI_CC_UNSPECIFIED_ERROR;
646 }
647
648 memcpy(res, req, SIZE_IANA_ID); // IANA ID
649 res[3] = index;
650 res[4] = next;
651 res[5] = phase;
652 res[6] = end;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700653 res[7] = descLen;
654 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800655
656 return IPMI_CC_OK;
657}
658
659//----------------------------------------------------------------------
660// Get Debug GPIO Description
661//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700662ipmi_ret_t ipmiOemDbgGetGpioDesc(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800663 ipmi_request_t request,
664 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700665 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800666{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700667 uint8_t* req = reinterpret_cast<uint8_t*>(request);
668 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800669
Vijay Khemka38183d62019-08-28 16:19:33 -0700670 uint8_t index = 0;
671 uint8_t next = 0;
672 uint8_t level = 0;
673 uint8_t pinDef = 0;
674 uint8_t descLen = 0;
675 int ret;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800676
Vijay Khemka38183d62019-08-28 16:19:33 -0700677 index = req[3];
678
679 ret = plat_udbg_get_gpio_desc(index, &next, &level, &pinDef, &descLen,
680 &res[8]);
681 if (ret)
682 {
683 memcpy(res, req, SIZE_IANA_ID); // IANA ID
684 *data_len = SIZE_IANA_ID;
685 return IPMI_CC_UNSPECIFIED_ERROR;
686 }
687
688 memcpy(res, req, SIZE_IANA_ID); // IANA ID
689 res[3] = index;
690 res[4] = next;
691 res[5] = level;
692 res[6] = pinDef;
693 res[7] = descLen;
694 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800695
696 return IPMI_CC_OK;
697}
698
699//----------------------------------------------------------------------
700// Get Debug Frame Data
701//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700702ipmi_ret_t ipmiOemDbgGetFrameData(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800703 ipmi_request_t request,
704 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700705 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800706{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700707 uint8_t* req = reinterpret_cast<uint8_t*>(request);
708 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800709 uint8_t frame;
710 uint8_t page;
711 uint8_t next;
712 uint8_t count;
713 int ret;
714
715 frame = req[3];
716 page = req[4];
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800717
718 ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]);
719 if (ret)
720 {
721 memcpy(res, req, SIZE_IANA_ID); // IANA ID
722 *data_len = SIZE_IANA_ID;
723 return IPMI_CC_UNSPECIFIED_ERROR;
724 }
725
726 memcpy(res, req, SIZE_IANA_ID); // IANA ID
727 res[3] = frame;
728 res[4] = page;
729 res[5] = next;
730 res[6] = count;
731 *data_len = SIZE_IANA_ID + 4 + count;
732
733 return IPMI_CC_OK;
734}
735
736//----------------------------------------------------------------------
737// Get Debug Control Panel
738//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700739ipmi_ret_t ipmiOemDbgGetCtrlPanel(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800740 ipmi_request_t request,
741 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -0700742 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800743{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700744 uint8_t* req = reinterpret_cast<uint8_t*>(request);
745 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800746
747 uint8_t panel;
748 uint8_t operation;
749 uint8_t item;
750 uint8_t count;
751 ipmi_ret_t ret;
752
753 panel = req[3];
754 operation = req[4];
755 item = req[5];
756
757 ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]);
758
759 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
760 *data_len = SIZE_IANA_ID + count;
761
762 return ret;
763}
764
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800765//----------------------------------------------------------------------
766// Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
767//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700768ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
769 ipmi_response_t, ipmi_data_len_t data_len,
770 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800771{
Vijay Khemka63c99be2020-05-27 19:14:35 -0700772 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700773
774 uint8_t index = req[0];
775 uint8_t type = req[1];
776 uint16_t speed;
777 uint32_t size;
778
779 memcpy(&speed, &req[2], 2);
780 memcpy(&size, &req[4], 4);
781
782 std::stringstream ss;
783 ss << std::hex;
784 ss << std::setw(2) << std::setfill('0') << (int)index;
785
786 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index;
787 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type;
788 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed;
789 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size;
790
791 flushOemData();
792
793 *data_len = 0;
794
795 return IPMI_CC_OK;
796}
797
798//----------------------------------------------------------------------
799// Get Board ID (CMD_OEM_GET_BOARD_ID)
800//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -0700801ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
802 ipmi_response_t, ipmi_data_len_t data_len,
803 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700804{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700805 /* TODO: Needs to implement this after GPIO implementation */
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800806 *data_len = 0;
807
808 return IPMI_CC_OK;
809}
810
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800811/* Helper functions to set boot order */
Jayashree-Df0cf6652020-11-30 11:03:30 +0530812void setBootOrder(std::string bootObjPath, uint8_t* data,
813 std::string bootOrderKey)
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800814{
Jayashree-Df0cf6652020-11-30 11:03:30 +0530815 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
816
817 // SETTING BOOT MODE PROPERTY
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530818 uint8_t bootModeBit = data[0] & 0x06;
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530819 auto bootValue = ipmi::boot::modeIpmiToDbus.at(bootModeBit);
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530820
Jayashree-Df0cf6652020-11-30 11:03:30 +0530821 std::string bootOption =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530822 sdbusplus::message::convert_to_string<boot::BootMode>(bootValue);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530823
824 std::string service =
825 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
826 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
827 ipmi::boot::bootModeProp, bootOption);
828
829 // SETTING BOOT SOURCE PROPERTY
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530830 auto bootOrder = ipmi::boot::sourceIpmiToDbus.at(data[1]);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530831 std::string bootSource =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530832 sdbusplus::message::convert_to_string<boot::BootSource>(bootOrder);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530833
834 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
835 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
836 ipmi::boot::bootSourceProp, bootSource);
837
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530838 // SETTING BOOT TYPE PROPERTY
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530839 uint8_t bootTypeBit = data[0] & 0x01;
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530840 auto bootTypeVal = ipmi::boot::typeIpmiToDbus.at(bootTypeBit);
841
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530842 std::string bootType =
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530843 sdbusplus::message::convert_to_string<boot::BootType>(bootTypeVal);
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530844
845 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
846
847 setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
848 ipmi::boot::bootTypeProp, bootType);
849
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800850 nlohmann::json bootMode;
851 uint8_t mode = data[0];
852 int i;
853
854 bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
855 bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
856 bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
857 bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530858 oemData[bootOrderKey][KEY_BOOT_MODE] = bootMode;
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800859
860 /* Initialize boot sequence array */
Jayashree-Df0cf6652020-11-30 11:03:30 +0530861 oemData[bootOrderKey][KEY_BOOT_SEQ] = {};
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800862 for (i = 1; i < SIZE_BOOT_ORDER; i++)
863 {
864 if (data[i] >= BOOT_SEQ_ARRAY_SIZE)
Jayashree-Df0cf6652020-11-30 11:03:30 +0530865 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = "NA";
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800866 else
Jayashree-Df0cf6652020-11-30 11:03:30 +0530867 oemData[bootOrderKey][KEY_BOOT_SEQ][i - 1] = bootSeq[data[i]];
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800868 }
869
870 flushOemData();
871}
872
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800873//----------------------------------------------------------------------
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700874// Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
875//----------------------------------------------------------------------
Jayashree-Df0cf6652020-11-30 11:03:30 +0530876ipmi::RspType<std::vector<uint8_t>>
877 ipmiOemSetBootOrder(ipmi::Context::ptr ctx, std::vector<uint8_t> data)
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700878{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700879
Jayashree-Df0cf6652020-11-30 11:03:30 +0530880 uint8_t bootSeq[SIZE_BOOT_ORDER];
881 size_t len = data.size();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700882
883 if (len != SIZE_BOOT_ORDER)
884 {
885 phosphor::logging::log<phosphor::logging::level::ERR>(
886 "Invalid Boot order length received");
Jayashree-Df0cf6652020-11-30 11:03:30 +0530887 return ipmi::responseReqDataLenInvalid();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700888 }
889
Jayashree-Df0cf6652020-11-30 11:03:30 +0530890 std::copy(std::begin(data), std::end(data), bootSeq);
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530891 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700892
Jayashree-Df0cf6652020-11-30 11:03:30 +0530893 if (!hostId)
894 {
895 phosphor::logging::log<phosphor::logging::level::ERR>(
896 "Invalid Host Id received");
897 return ipmi::responseInvalidCommand();
898 }
899 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
900
901 setBootOrder(bootObjPath, bootSeq, hostName);
902
903 return ipmi::responseSuccess(data);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700904}
905
906//----------------------------------------------------------------------
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800907// Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
908//----------------------------------------------------------------------
Jayashree-Df0cf6652020-11-30 11:03:30 +0530909ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
910 ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800911{
Jayashree-Df0cf6652020-11-30 11:03:30 +0530912 uint8_t bootSeq[SIZE_BOOT_ORDER];
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700913 uint8_t mode = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800914
Jayashree Dhanapal4ec80562022-06-28 15:41:47 +0530915 std::optional<size_t> hostId = findHost(ctx->hostIdx);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700916
Jayashree-Df0cf6652020-11-30 11:03:30 +0530917 if (!hostId)
918 {
919 phosphor::logging::log<phosphor::logging::level::ERR>(
920 "Invalid Host Id received");
921 return ipmi::responseInvalidCommand();
922 }
923 auto [bootObjPath, hostName] = ipmi::boot::objPath(*hostId);
924
Jayashree-Df0cf6652020-11-30 11:03:30 +0530925 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
926
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530927 // GETTING PROPERTY OF MODE INTERFACE
928
Jayashree-Df0cf6652020-11-30 11:03:30 +0530929 std::string service =
930 getService(*dbus, ipmi::boot::bootModeIntf, bootObjPath);
931 Value variant =
932 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootModeIntf,
933 ipmi::boot::bootModeProp);
934
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530935 auto bootMode = sdbusplus::message::convert_from_string<boot::BootMode>(
Jayashree-Df0cf6652020-11-30 11:03:30 +0530936 std::get<std::string>(variant));
937
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530938 uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
Jayashree-Df0cf6652020-11-30 11:03:30 +0530939
940 // GETTING PROPERTY OF SOURCE INTERFACE
941
942 service = getService(*dbus, ipmi::boot::bootSourceIntf, bootObjPath);
943 variant =
944 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
945 ipmi::boot::bootSourceProp);
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530946
947 auto bootSource = sdbusplus::message::convert_from_string<boot::BootSource>(
Jayashree-Df0cf6652020-11-30 11:03:30 +0530948 std::get<std::string>(variant));
949
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530950 uint8_t bootOrder = ipmi::boot::sourceDbusToIpmi.at(bootSource);
951
952 // GETTING PROPERTY OF TYPE INTERFACE
953
954 service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
955 variant =
956 getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
957 ipmi::boot::bootTypeProp);
Jayashree Dhanapal77ee4892022-04-08 16:53:51 +0530958
959 auto bootType = sdbusplus::message::convert_from_string<boot::BootType>(
Jayashree Dhanapal778147d2022-03-30 16:48:53 +0530960 std::get<std::string>(variant));
961
962 uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
963
964 uint8_t bootVal = bootOption | bootTypeVal;
Jayashree-Df0cf6652020-11-30 11:03:30 +0530965
966 if (oemData.find(hostName) == oemData.end())
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800967 {
968 /* Return default boot order 0100090203ff */
969 uint8_t defaultBoot[SIZE_BOOT_ORDER] = {
Willy Tue39f9392022-06-15 13:24:20 -0700970 BOOT_MODE_UEFI,
971 static_cast<uint8_t>(bootMap["USB_DEV"]),
972 static_cast<uint8_t>(bootMap["NET_IPV6"]),
973 static_cast<uint8_t>(bootMap["SATA_HDD"]),
974 static_cast<uint8_t>(bootMap["SATA_CD"]),
975 0xff};
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700976
Jayashree-Df0cf6652020-11-30 11:03:30 +0530977 memcpy(bootSeq, defaultBoot, SIZE_BOOT_ORDER);
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800978 phosphor::logging::log<phosphor::logging::level::INFO>(
979 "Set default boot order");
Jayashree-Df0cf6652020-11-30 11:03:30 +0530980 setBootOrder(bootObjPath, defaultBoot, hostName);
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800981 }
982 else
983 {
Jayashree-Df0cf6652020-11-30 11:03:30 +0530984 nlohmann::json bootMode = oemData[hostName][KEY_BOOT_MODE];
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800985 if (bootMode["UEFI"])
986 mode |= BOOT_MODE_UEFI;
987 if (bootMode["CMOS_CLR"])
988 mode |= BOOT_MODE_CMOS_CLR;
989 if (bootMode["BOOT_FLAG"])
990 mode |= BOOT_MODE_BOOT_FLAG;
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700991
Jayashree-Df0cf6652020-11-30 11:03:30 +0530992 bootSeq[0] = mode;
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800993
Jayashree-Df0cf6652020-11-30 11:03:30 +0530994 for (int i = 1; i < SIZE_BOOT_ORDER; i++)
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800995 {
Jayashree-Df0cf6652020-11-30 11:03:30 +0530996 std::string seqStr = oemData[hostName][KEY_BOOT_SEQ][i - 1];
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800997 if (bootMap.find(seqStr) != bootMap.end())
Jayashree-Df0cf6652020-11-30 11:03:30 +0530998 bootSeq[i] = bootMap[seqStr];
Vijay Khemka877d5dd2019-12-16 14:46:21 -0800999 else
Jayashree-Df0cf6652020-11-30 11:03:30 +05301000 bootSeq[i] = 0xff;
Vijay Khemka877d5dd2019-12-16 14:46:21 -08001001 }
1002 }
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001003
Jayashree Dhanapal778147d2022-03-30 16:48:53 +05301004 return ipmi::responseSuccess(bootVal, bootOrder, bootSeq[2], bootSeq[3],
Jayashree-Df0cf6652020-11-30 11:03:30 +05301005 bootSeq[4], bootSeq[5]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001006}
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001007// Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
1008//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001009ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t, ipmi_cmd_t,
1010 ipmi_request_t request, ipmi_response_t,
1011 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001012{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001013 machineConfigInfo_t* req = reinterpret_cast<machineConfigInfo_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001014 uint8_t len = *data_len;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001015
1016 *data_len = 0;
1017
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001018 if (len < sizeof(machineConfigInfo_t))
1019 {
1020 phosphor::logging::log<phosphor::logging::level::ERR>(
1021 "Invalid machine configuration length received");
1022 return IPMI_CC_REQ_DATA_LEN_INVALID;
1023 }
1024
Vijay Khemka63c99be2020-05-27 19:14:35 -07001025 if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001026 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN";
1027 else
1028 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] =
1029 chassisType[req->chassis_type];
1030
Vijay Khemka63c99be2020-05-27 19:14:35 -07001031 if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001032 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN";
1033 else
1034 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type];
1035
1036 oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt;
1037 oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt;
1038 oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt;
1039 oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt;
1040
Vijay Khemka63c99be2020-05-27 19:14:35 -07001041 if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001042 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN";
1043 else
1044 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type];
1045
1046 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {};
1047 int i = 0;
1048 if (req->pcie_card_loc & BIT_0)
1049 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1";
1050 if (req->pcie_card_loc & BIT_1)
1051 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2";
1052 if (req->pcie_card_loc & BIT_2)
1053 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3";
1054 if (req->pcie_card_loc & BIT_3)
1055 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4";
1056
Vijay Khemka63c99be2020-05-27 19:14:35 -07001057 if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001058 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN";
1059 else
1060 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] =
1061 pcieType[req->slot1_pcie_type];
1062
Vijay Khemka63c99be2020-05-27 19:14:35 -07001063 if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001064 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN";
1065 else
1066 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] =
1067 pcieType[req->slot2_pcie_type];
1068
Vijay Khemka63c99be2020-05-27 19:14:35 -07001069 if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001070 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN";
1071 else
1072 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] =
1073 pcieType[req->slot3_pcie_type];
1074
Vijay Khemka63c99be2020-05-27 19:14:35 -07001075 if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t*))
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001076 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN";
1077 else
1078 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] =
1079 pcieType[req->slot4_pcie_type];
1080
1081 oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt;
1082
1083 flushOemData();
1084
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001085 return IPMI_CC_OK;
1086}
1087
1088//----------------------------------------------------------------------
1089// Set POST start (CMD_OEM_SET_POST_START)
1090//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001091ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1092 ipmi_response_t, ipmi_data_len_t data_len,
1093 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001094{
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001095 phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
1096
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001097 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001098 *data_len = 0;
1099 return IPMI_CC_OK;
1100}
1101
1102//----------------------------------------------------------------------
1103// Set POST End (CMD_OEM_SET_POST_END)
1104//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001105ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1106 ipmi_response_t, ipmi_data_len_t data_len,
1107 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001108{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001109 struct timespec ts;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001110
1111 phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
1112
1113 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001114
1115 // Timestamp post end time.
1116 clock_gettime(CLOCK_REALTIME, &ts);
1117 oemData[KEY_TS_SLED] = ts.tv_sec;
1118 flushOemData();
1119
1120 // Sync time with system
1121 // TODO: Add code for syncing time
1122
1123 return IPMI_CC_OK;
1124}
1125
1126//----------------------------------------------------------------------
1127// Set PPIN Info (CMD_OEM_SET_PPIN_INFO)
1128//----------------------------------------------------------------------
1129// Inform BMC about PPIN data of 8 bytes for each CPU
1130//
1131// Request:
1132// Byte 1:8 – CPU0 PPIN data
1133// Optional:
1134// Byte 9:16 – CPU1 PPIN data
1135//
1136// Response:
1137// Byte 1 – Completion Code
Willy Tue39f9392022-06-15 13:24:20 -07001138ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1139 ipmi_response_t, ipmi_data_len_t data_len,
1140 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001141{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001142 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001143 std::string ppinStr;
1144 int len;
1145
1146 if (*data_len > SIZE_CPU_PPIN * 2)
1147 len = SIZE_CPU_PPIN * 2;
1148 else
1149 len = *data_len;
1150 *data_len = 0;
1151
1152 ppinStr = bytesToStr(req, len);
1153 oemData[KEY_PPIN_INFO] = ppinStr.c_str();
1154 flushOemData();
1155
1156 return IPMI_CC_OK;
1157}
1158
1159//----------------------------------------------------------------------
1160// Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER)
1161//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001162ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1163 ipmi_response_t, ipmi_data_len_t data_len,
1164 ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001165{
1166 /* Do nothing, return success */
1167 *data_len = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001168 return IPMI_CC_OK;
1169}
1170
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001171// Helper function to set guid at offset in EEPROM
Willy Tue39f9392022-06-15 13:24:20 -07001172[[maybe_unused]] static int setGUID(off_t offset, uint8_t* guid)
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001173{
1174 int fd = -1;
1175 ssize_t len;
1176 int ret = 0;
1177
1178 errno = 0;
1179
1180 // Check if file is present
1181 if (access(FRU_EEPROM, F_OK) == -1)
1182 {
1183 std::cerr << "Unable to access: " << FRU_EEPROM << std::endl;
1184 return errno;
1185 }
1186
1187 // Open the file
1188 fd = open(FRU_EEPROM, O_WRONLY);
1189 if (fd == -1)
1190 {
1191 std::cerr << "Unable to open: " << FRU_EEPROM << std::endl;
1192 return errno;
1193 }
1194
1195 // seek to the offset
1196 lseek(fd, offset, SEEK_SET);
1197
1198 // Write bytes to location
1199 len = write(fd, guid, GUID_SIZE);
1200 if (len != GUID_SIZE)
1201 {
1202 phosphor::logging::log<phosphor::logging::level::ERR>(
1203 "GUID write data to EEPROM failed");
1204 ret = errno;
1205 }
1206
1207 close(fd);
1208 return ret;
1209}
1210
1211//----------------------------------------------------------------------
1212// Set System GUID (CMD_OEM_SET_SYSTEM_GUID)
1213//----------------------------------------------------------------------
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301214#if BIC_ENABLED
Willy Tue39f9392022-06-15 13:24:20 -07001215ipmi::RspType<> ipmiOemSetSystemGuid(ipmi::Context::ptr ctx, uint8_t,
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301216 std::vector<uint8_t> reqData)
1217{
1218 std::vector<uint8_t> respData;
1219
1220 if (reqData.size() != GUID_SIZE) // 16bytes
1221 {
1222
1223 return ipmi::responseReqDataLenInvalid();
1224 }
1225
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301226 uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
1227
1228 if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
1229 return ipmi::responseUnspecifiedError();
1230
1231 return ipmi::responseSuccess();
1232}
1233
1234#else
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001235ipmi_ret_t ipmiOemSetSystemGuid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1236 ipmi_request_t request,
1237 ipmi_response_t response,
1238 ipmi_data_len_t data_len,
1239 ipmi_context_t context)
1240{
1241 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1242
1243 if (*data_len != GUID_SIZE) // 16bytes
1244 {
1245 *data_len = 0;
1246 return IPMI_CC_REQ_DATA_LEN_INVALID;
1247 }
1248
1249 *data_len = 0;
1250
1251 if (setGUID(OFFSET_SYS_GUID, req))
1252 {
1253 return IPMI_CC_UNSPECIFIED_ERROR;
1254 }
1255 return IPMI_CC_OK;
1256}
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05301257#endif
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07001258
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001259//----------------------------------------------------------------------
1260// Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
1261//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001262ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
1263 ipmi_response_t, ipmi_data_len_t data_len,
1264 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001265{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001266 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001267 *data_len = 0;
1268 return IPMI_CC_OK;
1269}
1270
1271//----------------------------------------------------------------------
1272// Set PPR (CMD_OEM_SET_PPR)
1273//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001274ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1275 ipmi_response_t, ipmi_data_len_t data_len,
1276 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001277{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001278 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001279 uint8_t pprCnt, pprAct, pprIndex;
1280 uint8_t selParam = req[0];
1281 uint8_t len = *data_len;
1282 std::stringstream ss;
1283 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001284
1285 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001286
1287 switch (selParam)
1288 {
1289 case PPR_ACTION:
1290 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) ==
1291 oemData[KEY_PPR].end())
1292 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1293
1294 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1295 if (pprCnt == 0)
1296 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1297
1298 pprAct = req[1];
1299 /* Check if ppr is enabled or disabled */
1300 if (!(pprAct & 0x80))
1301 pprAct = 0;
1302
1303 oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct;
1304 break;
1305 case PPR_ROW_COUNT:
1306 if (req[1] > 100)
1307 return IPMI_CC_PARM_OUT_OF_RANGE;
1308
1309 oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1];
1310 break;
1311 case PPR_ROW_ADDR:
1312 pprIndex = req[1];
1313 if (pprIndex > 100)
1314 return IPMI_CC_PARM_OUT_OF_RANGE;
1315
1316 if (len < PPR_ROW_ADDR_LEN + 1)
1317 {
1318 phosphor::logging::log<phosphor::logging::level::ERR>(
1319 "Invalid PPR Row Address length received");
1320 return IPMI_CC_REQ_DATA_LEN_INVALID;
1321 }
1322
1323 ss << std::hex;
1324 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1325
1326 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1327
1328 str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN);
1329 oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str();
1330 break;
1331 case PPR_HISTORY_DATA:
1332 pprIndex = req[1];
1333 if (pprIndex > 100)
1334 return IPMI_CC_PARM_OUT_OF_RANGE;
1335
1336 if (len < PPR_HST_DATA_LEN + 1)
1337 {
1338 phosphor::logging::log<phosphor::logging::level::ERR>(
1339 "Invalid PPR history data length received");
1340 return IPMI_CC_REQ_DATA_LEN_INVALID;
1341 }
1342
1343 ss << std::hex;
1344 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1345
1346 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
1347
1348 str = bytesToStr(&req[1], PPR_HST_DATA_LEN);
1349 oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str();
1350 break;
1351 default:
1352 return IPMI_CC_PARM_OUT_OF_RANGE;
1353 break;
1354 }
1355
1356 flushOemData();
1357
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001358 return IPMI_CC_OK;
1359}
1360
1361//----------------------------------------------------------------------
1362// Get PPR (CMD_OEM_GET_PPR)
1363//----------------------------------------------------------------------
Willy Tue39f9392022-06-15 13:24:20 -07001364ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t request,
1365 ipmi_response_t response, ipmi_data_len_t data_len,
1366 ipmi_context_t)
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001367{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001368 uint8_t* req = reinterpret_cast<uint8_t*>(request);
1369 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001370 uint8_t pprCnt, pprIndex;
1371 uint8_t selParam = req[0];
1372 std::stringstream ss;
1373 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001374
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001375 /* Any failure will return zero length data */
1376 *data_len = 0;
1377
1378 switch (selParam)
1379 {
1380 case PPR_ACTION:
1381 res[0] = 0;
1382 *data_len = 1;
1383
1384 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1385 oemData[KEY_PPR].end())
1386 {
1387 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1388 if (pprCnt != 0)
1389 {
1390 if (oemData[KEY_PPR].find(KEY_PPR_ACTION) !=
1391 oemData[KEY_PPR].end())
1392 {
1393 res[0] = oemData[KEY_PPR][KEY_PPR_ACTION];
1394 }
1395 }
1396 }
1397 break;
1398 case PPR_ROW_COUNT:
1399 res[0] = 0;
1400 *data_len = 1;
1401 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
1402 oemData[KEY_PPR].end())
1403 res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
1404 break;
1405 case PPR_ROW_ADDR:
1406 pprIndex = req[1];
1407 if (pprIndex > 100)
1408 return IPMI_CC_PARM_OUT_OF_RANGE;
1409
1410 ss << std::hex;
1411 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1412
1413 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1414 return IPMI_CC_PARM_OUT_OF_RANGE;
1415
1416 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) ==
1417 oemData[KEY_PPR][ss.str()].end())
1418 return IPMI_CC_PARM_OUT_OF_RANGE;
1419
1420 str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR];
1421 *data_len = strToBytes(str, res);
1422 break;
1423 case PPR_HISTORY_DATA:
1424 pprIndex = req[1];
1425 if (pprIndex > 100)
1426 return IPMI_CC_PARM_OUT_OF_RANGE;
1427
1428 ss << std::hex;
1429 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1430
1431 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1432 return IPMI_CC_PARM_OUT_OF_RANGE;
1433
1434 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) ==
1435 oemData[KEY_PPR][ss.str()].end())
1436 return IPMI_CC_PARM_OUT_OF_RANGE;
1437
1438 str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA];
1439 *data_len = strToBytes(str, res);
1440 break;
1441 default:
1442 return IPMI_CC_PARM_OUT_OF_RANGE;
1443 break;
1444 }
1445
1446 return IPMI_CC_OK;
1447}
1448
1449/* FB OEM QC Commands */
1450
1451//----------------------------------------------------------------------
1452// Set Proc Info (CMD_OEM_Q_SET_PROC_INFO)
1453//----------------------------------------------------------------------
1454//"Request:
1455// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1456// Byte 4 – Processor Index, 0 base
1457// Byte 5 – Parameter Selector
1458// Byte 6..N – Configuration parameter data (see below for Parameters
1459// of Processor Information)
1460// Response:
1461// Byte 1 – Completion code
1462//
1463// Parameter#1: (Processor Product Name)
1464//
1465// Byte 1..48 –Product name(ASCII code)
1466// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1467//
1468// Param#2: Processor Basic Information
1469// Byte 1 – Core Number
1470// Byte 2 – Thread Number (LSB)
1471// Byte 3 – Thread Number (MSB)
1472// Byte 4 – Processor frequency in MHz (LSB)
1473// Byte 5 – Processor frequency in MHz (MSB)
1474// Byte 6..7 – Revision
1475//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301476
1477ipmi::RspType<> ipmiOemQSetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1478 uint8_t, uint8_t procIndex,
1479 uint8_t paramSel,
1480 std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001481{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001482 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001483 std::stringstream ss;
1484 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301485 uint8_t len = request.size();
1486 auto hostId = findHost(ctx->hostIdx);
1487 if (!hostId)
1488 {
1489 phosphor::logging::log<phosphor::logging::level::ERR>(
1490 "Invalid Host Id received");
1491 return ipmi::responseInvalidCommand();
1492 }
1493 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001494 /* check for requested data params */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301495 if (len < 5 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001496 {
1497 phosphor::logging::log<phosphor::logging::level::ERR>(
1498 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301499 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001500 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001501 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301502 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1503 oemData[procInfo][ss.str()][KEY_PROC_INDEX] = procIndex;
1504 str = bytesToStr(request.data(), len);
1505 oemData[procInfo][ss.str()][cpuInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001506 flushOemData();
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301507 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001508}
1509
1510//----------------------------------------------------------------------
1511// Get Proc Info (CMD_OEM_Q_GET_PROC_INFO)
1512//----------------------------------------------------------------------
1513// Request:
1514// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1515// Byte 4 – Processor Index, 0 base
1516// Byte 5 – Parameter Selector
1517// Response:
1518// Byte 1 – Completion code
1519// Byte 2..N – Configuration Parameter Data (see below for Parameters
1520// of Processor Information)
1521//
1522// Parameter#1: (Processor Product Name)
1523//
1524// Byte 1..48 –Product name(ASCII code)
1525// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1526//
1527// Param#2: Processor Basic Information
1528// Byte 1 – Core Number
1529// Byte 2 – Thread Number (LSB)
1530// Byte 3 – Thread Number (MSB)
1531// Byte 4 – Processor frequency in MHz (LSB)
1532// Byte 5 – Processor frequency in MHz (MSB)
1533// Byte 6..7 – Revision
1534//
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301535
1536ipmi::RspType<std::vector<uint8_t>>
1537 ipmiOemQGetProcInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1538 uint8_t procIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001539{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001540 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001541 std::stringstream ss;
1542 std::string str;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301543 uint8_t res[MAX_BUF];
1544 auto hostId = findHost(ctx->hostIdx);
1545 if (!hostId)
1546 {
1547 phosphor::logging::log<phosphor::logging::level::ERR>(
1548 "Invalid Host Id received");
1549 return ipmi::responseInvalidCommand();
1550 }
1551 std::string procInfo = KEY_Q_PROC_INFO + std::to_string(*hostId);
1552 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001553 {
1554 phosphor::logging::log<phosphor::logging::level::ERR>(
1555 "Invalid parameter received");
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301556 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001557 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001558 ss << std::hex;
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05301559 ss << std::setw(2) << std::setfill('0') << (int)procIndex;
1560 if (oemData[procInfo].find(ss.str()) == oemData[procInfo].end())
1561 return ipmi::responseCommandNotAvailable();
1562 if (oemData[procInfo][ss.str()].find(cpuInfoKey[paramSel]) ==
1563 oemData[procInfo][ss.str()].end())
1564 return ipmi::responseCommandNotAvailable();
1565 str = oemData[procInfo][ss.str()][cpuInfoKey[paramSel]];
1566 int dataLen = strToBytes(str, res);
1567 std::vector<uint8_t> response(&res[0], &res[dataLen]);
1568 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001569}
1570
1571//----------------------------------------------------------------------
1572// Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO)
1573//----------------------------------------------------------------------
1574// Request:
1575// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1576// Byte 4 – DIMM Index, 0 base
1577// Byte 5 – Parameter Selector
1578// Byte 6..N – Configuration parameter data (see below for Parameters
1579// of DIMM Information)
1580// Response:
1581// Byte 1 – Completion code
1582//
1583// Param#1 (DIMM Location):
1584// Byte 1 – DIMM Present
1585// Byte 1 – DIMM Present
1586// 01h – Present
1587// FFh – Not Present
1588// Byte 2 – Node Number, 0 base
1589// Byte 3 – Channel Number , 0 base
1590// Byte 4 – DIMM Number , 0 base
1591//
1592// Param#2 (DIMM Type):
1593// Byte 1 – DIMM Type
1594// Bit [7:6]
1595// For DDR3
1596// 00 – Normal Voltage (1.5V)
1597// 01 – Ultra Low Voltage (1.25V)
1598// 10 – Low Voltage (1.35V)
1599// 11 – Reserved
1600// For DDR4
1601// 00 – Reserved
1602// 01 – Reserved
1603// 10 – Reserved
1604// 11 – Normal Voltage (1.2V)
1605// Bit [5:0]
1606// 0x00 – SDRAM
1607// 0x01 – DDR-1 RAM
1608// 0x02 – Rambus
1609// 0x03 – DDR-2 RAM
1610// 0x04 – FBDIMM
1611// 0x05 – DDR-3 RAM
1612// 0x06 – DDR-4 RAM
1613//
1614// Param#3 (DIMM Speed):
1615// Byte 1..2 – DIMM speed in MHz, LSB
1616// Byte 3..6 – DIMM size in Mbytes, LSB
1617//
1618// Param#4 (Module Part Number):
1619// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1620//
1621// Param#5 (Module Serial Number):
1622// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1623//
1624// Param#6 (Module Manufacturer ID):
1625// Byte 1 - Module Manufacturer ID, LSB
1626// Byte 2 - Module Manufacturer ID, MSB
1627//
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301628ipmi::RspType<> ipmiOemQSetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t,
1629 uint8_t, uint8_t dimmIndex,
1630 uint8_t paramSel,
1631 std::vector<uint8_t> request)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001632{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001633 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001634 std::stringstream ss;
1635 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301636 uint8_t len = request.size();
1637 std::string dimmType;
1638 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001639 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301640 if (!hostId)
1641 {
1642 phosphor::logging::log<phosphor::logging::level::ERR>(
1643 "Invalid Host Id received");
1644 return ipmi::responseInvalidCommand();
1645 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001646
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301647 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001648
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301649 if (len < 3 || paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001650 {
1651 phosphor::logging::log<phosphor::logging::level::ERR>(
1652 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301653 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001654 }
1655
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001656 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301657 ss << (int)dimmIndex;
1658 oemData[dimmInfo][ss.str()][KEY_DIMM_INDEX] = dimmIndex;
1659 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1660 str = bytesToStr(request.data(), len);
1661 oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]] = str.c_str();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001662 flushOemData();
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301663 return ipmi::responseSuccess();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001664}
1665
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001666// Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO)
1667//----------------------------------------------------------------------
1668// Request:
1669// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1670// Byte 4 – DIMM Index, 0 base
1671// Byte 5 – Parameter Selector
1672// Byte 6..N – Configuration parameter data (see below for Parameters
1673// of DIMM Information)
1674// Response:
1675// Byte 1 – Completion code
1676// Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters
1677// of DIMM Information)
1678//
1679// Param#1 (DIMM Location):
1680// Byte 1 – DIMM Present
1681// Byte 1 – DIMM Present
1682// 01h – Present
1683// FFh – Not Present
1684// Byte 2 – Node Number, 0 base
1685// Byte 3 – Channel Number , 0 base
1686// Byte 4 – DIMM Number , 0 base
1687//
1688// Param#2 (DIMM Type):
1689// Byte 1 – DIMM Type
1690// Bit [7:6]
1691// For DDR3
1692// 00 – Normal Voltage (1.5V)
1693// 01 – Ultra Low Voltage (1.25V)
1694// 10 – Low Voltage (1.35V)
1695// 11 – Reserved
1696// For DDR4
1697// 00 – Reserved
1698// 01 – Reserved
1699// 10 – Reserved
1700// 11 – Normal Voltage (1.2V)
1701// Bit [5:0]
1702// 0x00 – SDRAM
1703// 0x01 – DDR-1 RAM
1704// 0x02 – Rambus
1705// 0x03 – DDR-2 RAM
1706// 0x04 – FBDIMM
1707// 0x05 – DDR-3 RAM
1708// 0x06 – DDR-4 RAM
1709//
1710// Param#3 (DIMM Speed):
1711// Byte 1..2 – DIMM speed in MHz, LSB
1712// Byte 3..6 – DIMM size in Mbytes, LSB
1713//
1714// Param#4 (Module Part Number):
1715// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1716//
1717// Param#5 (Module Serial Number):
1718// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1719//
1720// Param#6 (Module Manufacturer ID):
1721// Byte 1 - Module Manufacturer ID, LSB
1722// Byte 2 - Module Manufacturer ID, MSB
1723//
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301724ipmi::RspType<std::vector<uint8_t>>
1725 ipmiOemQGetDimmInfo(ipmi::Context::ptr ctx, uint8_t, uint8_t, uint8_t,
1726 uint8_t dimmIndex, uint8_t paramSel)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001727{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001728 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t*);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301729 uint8_t res[MAX_BUF];
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001730 std::stringstream ss;
1731 std::string str;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301732 std::string dimmType;
1733 readDimmType(dimmType, dimmIndex);
Patrick Williams6d9e9a72022-07-18 10:30:50 -05001734 auto hostId = findHost(ctx->hostIdx);
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301735 if (!hostId)
1736 {
1737 phosphor::logging::log<phosphor::logging::level::ERR>(
1738 "Invalid Host Id received");
1739 return ipmi::responseInvalidCommand();
1740 }
1741 std::string dimmInfo = KEY_Q_DIMM_INFO + std::to_string(*hostId);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001742
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301743 if (paramSel < 1 || paramSel >= numParam)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001744 {
1745 phosphor::logging::log<phosphor::logging::level::ERR>(
1746 "Invalid parameter received");
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301747 return ipmi::responseParmOutOfRange();
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001748 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001749 ss << std::hex;
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05301750 ss << (int)dimmIndex;
1751 oemData[dimmInfo][ss.str()][KEY_DIMM_TYPE] = dimmType;
1752 if (oemData[dimmInfo].find(ss.str()) == oemData[dimmInfo].end())
1753 return ipmi::responseCommandNotAvailable();
1754 if (oemData[dimmInfo][ss.str()].find(dimmInfoKey[paramSel]) ==
1755 oemData[dimmInfo][ss.str()].end())
1756 return ipmi::responseCommandNotAvailable();
1757 str = oemData[dimmInfo][ss.str()][dimmInfoKey[paramSel]];
1758 int data_length = strToBytes(str, res);
1759 std::vector<uint8_t> response(&res[0], &res[data_length]);
1760 return ipmi::responseSuccess(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001761}
1762
1763//----------------------------------------------------------------------
1764// Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO)
1765//----------------------------------------------------------------------
1766// BIOS issue this command to provide HDD information to BMC.
1767//
1768// BIOS just can get information by standard ATA / SMART command for
1769// OB SATA controller.
1770// BIOS can get
1771// 1. Serial Number
1772// 2. Model Name
1773// 3. HDD FW Version
1774// 4. HDD Capacity
1775// 5. HDD WWN
1776//
1777// Use Get HDD info Param #5 to know the MAX HDD info index.
1778//
1779// Request:
1780// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1781// Byte 4 –
1782// [7:4] Reserved
1783// [3:0] HDD Controller Type
1784// 0x00 – BIOS
1785// 0x01 – Expander
1786// 0x02 – LSI
1787// Byte 5 – HDD Info Index, 0 base
1788// Byte 6 – Parameter Selector
1789// Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD
1790// Information)
1791//
1792// Response:
1793// Byte 1 – Completion Code
1794//
1795// Param#0 (HDD Location):
1796// Byte 1 – Controller
1797// [7:3] Device Number
1798// [2:0] Function Number
1799// For Intel C610 series (Wellsburg)
1800// D31:F2 (0xFA) – SATA control 1
1801// D31:F5 (0xFD) – SATA control 2
1802// D17:F4 (0x8C) – sSata control
1803// Byte 2 – Port Number
1804// Byte 3 – Location (0xFF: No HDD Present)
1805// BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param
1806// #1~4, #6, #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if
1807// the HDD present. BMC or other people who know the HDD location has
1808// responsibility for update Location info
1809//
1810// Param#1 (Serial Number):
1811// Bytes 1..33: HDD Serial Number
1812//
1813// Param#2 (Model Name):
1814// Byte 1..33 – HDD Model Name
1815//
1816// Param#3 (HDD FW Version):
1817// Byte 1..17 –HDD FW version
1818//
1819// Param#4 (Capacity):
1820// Byte 1..4 –HDD Block Size, LSB
1821// Byte 5..12 - HDD Block Number, LSB
1822// HDD Capacity = HDD Block size * HDD BLock number (Unit Byte)
1823//
1824// Param#5 (Max HDD Quantity):
1825// Byte 1 - Max HDD Quantity
1826// Max supported port numbers in this PCH
1827//
1828// Param#6 (HDD Type)
1829// Byte 1 – HDD Type
1830// 0h – Reserved
1831// 1h – SAS
1832// 2h – SATA
1833// 3h – PCIE SSD (NVME)
1834//
1835// Param#7 (HDD WWN)
1836// Data 1...8: HDD World Wide Name, LSB
1837//
Willy Tue39f9392022-06-15 13:24:20 -07001838ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
1839 ipmi_request_t request, ipmi_response_t,
1840 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001841{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001842 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1843 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001844 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1845 std::stringstream ss;
1846 std::string str;
1847 uint8_t len = *data_len;
1848
1849 *data_len = 0;
1850
1851 /* check for requested data params */
1852 if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam ||
1853 ctrlType > 2)
1854 {
1855 phosphor::logging::log<phosphor::logging::level::ERR>(
1856 "Invalid parameter received");
1857 return IPMI_CC_PARM_OUT_OF_RANGE;
1858 }
1859
1860 len = len - 6; // Get Actual data length
1861
1862 ss << std::hex;
1863 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1864 oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType;
1865 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] =
1866 req->hddIndex;
1867
1868 str = bytesToStr(req->data, len);
1869 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
1870 [driveInfoKey[req->paramSel]] = str.c_str();
1871 flushOemData();
1872
1873 return IPMI_CC_OK;
1874}
1875
1876//----------------------------------------------------------------------
1877// Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO)
1878//----------------------------------------------------------------------
1879// BMC needs to check HDD presented or not first. If NOT presented, return
1880// completion code 0xD5.
1881//
1882// Request:
1883// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1884// Byte 4 –
1885//[7:4] Reserved
1886//[3:0] HDD Controller Type
1887// 0x00 – BIOS
1888// 0x01 – Expander
1889// 0x02 – LSI
1890// Byte 5 – HDD Index, 0 base
1891// Byte 6 – Parameter Selector (See Above Set HDD Information)
1892// Response:
1893// Byte 1 – Completion Code
1894// 0xD5 – Not support in current status (HDD Not Present)
1895// Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD
1896// Information)
1897//
Willy Tue39f9392022-06-15 13:24:20 -07001898ipmi_ret_t ipmiOemQGetDriveInfo(ipmi_netfn_t, ipmi_cmd_t,
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001899 ipmi_request_t request,
1900 ipmi_response_t response,
Willy Tue39f9392022-06-15 13:24:20 -07001901 ipmi_data_len_t data_len, ipmi_context_t)
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001902{
Vijay Khemka63c99be2020-05-27 19:14:35 -07001903 qDriveInfo_t* req = reinterpret_cast<qDriveInfo_t*>(request);
1904 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t*);
1905 uint8_t* res = reinterpret_cast<uint8_t*>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001906 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1907 std::stringstream ss;
1908 std::string str;
1909
1910 *data_len = 0;
1911
1912 /* check for requested data params */
1913 if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2)
1914 {
1915 phosphor::logging::log<phosphor::logging::level::ERR>(
1916 "Invalid parameter received");
1917 return IPMI_CC_PARM_OUT_OF_RANGE;
1918 }
1919
1920 if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) ==
1921 oemData[KEY_Q_DRIVE_INFO].end())
1922 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1923
1924 ss << std::hex;
1925 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1926
1927 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) ==
1928 oemData[KEY_Q_DRIVE_INFO].end())
1929 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1930
1931 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find(
1932 dimmInfoKey[req->paramSel]) ==
1933 oemData[KEY_Q_DRIVE_INFO][ss.str()].end())
1934 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1935
1936 str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
1937 [dimmInfoKey[req->paramSel]];
1938 *data_len = strToBytes(str, res);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001939
1940 return IPMI_CC_OK;
1941}
1942
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001943/* Helper function for sending DCMI commands to ME and getting response back */
1944ipmi::RspType<std::vector<uint8_t>> sendDCMICmd(uint8_t cmd,
Vijay Khemka63c99be2020-05-27 19:14:35 -07001945 std::vector<uint8_t>& cmdData)
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07001946{
1947 std::vector<uint8_t> respData;
1948
1949 /* Add group id as first byte to request for ME command */
1950 cmdData.insert(cmdData.begin(), groupDCMI);
1951
1952 if (sendMeCmd(ipmi::netFnGroup, cmd, cmdData, respData))
1953 return ipmi::responseUnspecifiedError();
1954
1955 /* Remove group id as first byte as it will be added by IPMID */
1956 respData.erase(respData.begin());
1957
1958 return ipmi::responseSuccess(std::move(respData));
1959}
1960
1961/* DCMI Command handellers. */
1962
1963ipmi::RspType<std::vector<uint8_t>>
1964 ipmiOemDCMIGetPowerReading(std::vector<uint8_t> reqData)
1965{
1966 return sendDCMICmd(ipmi::dcmi::cmdGetPowerReading, reqData);
1967}
1968
1969ipmi::RspType<std::vector<uint8_t>>
1970 ipmiOemDCMIGetPowerLimit(std::vector<uint8_t> reqData)
1971{
1972 return sendDCMICmd(ipmi::dcmi::cmdGetPowerLimit, reqData);
1973}
1974
1975ipmi::RspType<std::vector<uint8_t>>
1976 ipmiOemDCMISetPowerLimit(std::vector<uint8_t> reqData)
1977{
1978 return sendDCMICmd(ipmi::dcmi::cmdSetPowerLimit, reqData);
1979}
1980
1981ipmi::RspType<std::vector<uint8_t>>
1982 ipmiOemDCMIApplyPowerLimit(std::vector<uint8_t> reqData)
1983{
1984 return sendDCMICmd(ipmi::dcmi::cmdActDeactivatePwrLimit, reqData);
1985}
1986
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001987static void registerOEMFunctions(void)
1988{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001989 /* Get OEM data from json file */
1990 std::ifstream file(JSON_OEM_DATA_FILE);
1991 if (file)
Vijay Khemkafeaa9812019-08-27 15:08:08 -07001992 {
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001993 file >> oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -07001994 file.close();
1995 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001996
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001997 phosphor::logging::log<phosphor::logging::level::INFO>(
1998 "Registering OEM commands");
Vijay Khemka7c0aea42020-03-05 13:31:53 -08001999
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002000 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO,
2001 NULL, ipmiOemDbgGetFrameInfo,
2002 PRIVILEGE_USER); // get debug frame info
2003 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ,
2004 CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL,
2005 ipmiOemDbgGetUpdFrames,
2006 PRIVILEGE_USER); // get debug updated frames
2007 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC,
2008 NULL, ipmiOemDbgGetPostDesc,
2009 PRIVILEGE_USER); // get debug post description
2010 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC,
2011 NULL, ipmiOemDbgGetGpioDesc,
2012 PRIVILEGE_USER); // get debug gpio description
2013 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA,
2014 NULL, ipmiOemDbgGetFrameData,
2015 PRIVILEGE_USER); // get debug frame data
2016 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL,
2017 NULL, ipmiOemDbgGetCtrlPanel,
2018 PRIVILEGE_USER); // get debug control panel
2019 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL,
2020 ipmiOemSetDimmInfo,
2021 PRIVILEGE_USER); // Set Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002022 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
2023 ipmiOemGetBoardID,
2024 PRIVILEGE_USER); // Get Board ID
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002025 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL,
2026 ipmiOemSetMachineCfgInfo,
2027 PRIVILEGE_USER); // Set Machine Config Info
2028 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL,
2029 ipmiOemSetPostStart,
2030 PRIVILEGE_USER); // Set POST start
2031 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL,
2032 ipmiOemSetPostEnd,
2033 PRIVILEGE_USER); // Set POST End
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002034 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
2035 ipmiOemSetPPINInfo,
2036 PRIVILEGE_USER); // Set PPIN Info
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302037#if BIC_ENABLED
2038
2039 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2040 ipmi::cmdSetSystemGuid, ipmi::Privilege::User,
2041 ipmiOemSetSystemGuid);
2042#else
2043
Vijay Khemkaf2246ce2020-05-27 14:26:35 -07002044 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_SYSTEM_GUID, NULL,
2045 ipmiOemSetSystemGuid,
2046 PRIVILEGE_USER); // Set System GUID
Manikandan Elumalai5f8e3432020-12-02 03:46:55 +05302047#endif
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002048 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
2049 ipmiOemSetAdrTrigger,
2050 PRIVILEGE_USER); // Set ADR Trigger
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002051 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL,
2052 ipmiOemSetBiosFlashInfo,
2053 PRIVILEGE_USER); // Set Bios Flash Info
2054 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr,
2055 PRIVILEGE_USER); // Set PPR
2056 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr,
2057 PRIVILEGE_USER); // Get PPR
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002058 /* FB OEM QC Commands */
Karthikeyan Pasupathid532fec2022-07-14 14:43:42 +05302059 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2060 CMD_OEM_Q_SET_PROC_INFO, ipmi::Privilege::User,
2061 ipmiOemQSetProcInfo); // Set Proc Info
2062 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2063 CMD_OEM_Q_GET_PROC_INFO, ipmi::Privilege::User,
2064 ipmiOemQGetProcInfo); // Get Proc Info
Karthikeyan Pasupathi10ff3d82022-04-06 16:27:25 +05302065 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2066 ipmi::cmdSetQDimmInfo, ipmi::Privilege::User,
2067 ipmiOemQSetDimmInfo); // Set Dimm Info
2068 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFour,
2069 ipmi::cmdGetQDimmInfo, ipmi::Privilege::User,
2070 ipmiOemQGetDimmInfo); // Get Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07002071 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL,
2072 ipmiOemQSetDriveInfo,
2073 PRIVILEGE_USER); // Set Drive Info
2074 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL,
2075 ipmiOemQGetDriveInfo,
2076 PRIVILEGE_USER); // Get Drive Info
Vijay Khemkadd14c0f2020-03-18 14:48:13 -07002077
2078 /* FB OEM DCMI Commands as per DCMI spec 1.5 Section 6 */
2079 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2080 ipmi::dcmi::cmdGetPowerReading,
2081 ipmi::Privilege::User,
2082 ipmiOemDCMIGetPowerReading); // Get Power Reading
2083
2084 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2085 ipmi::dcmi::cmdGetPowerLimit,
2086 ipmi::Privilege::User,
2087 ipmiOemDCMIGetPowerLimit); // Get Power Limit
2088
2089 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2090 ipmi::dcmi::cmdSetPowerLimit,
2091 ipmi::Privilege::Operator,
2092 ipmiOemDCMISetPowerLimit); // Set Power Limit
2093
2094 ipmi::registerGroupHandler(ipmi::prioOpenBmcBase, groupDCMI,
2095 ipmi::dcmi::cmdActDeactivatePwrLimit,
2096 ipmi::Privilege::Operator,
2097 ipmiOemDCMIApplyPowerLimit); // Apply Power Limit
2098
Jayashree-Df0cf6652020-11-30 11:03:30 +05302099 /* FB OEM BOOT ORDER COMMANDS */
2100 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2101 CMD_OEM_GET_BOOT_ORDER, ipmi::Privilege::User,
2102 ipmiOemGetBootOrder); // Get Boot Order
2103
2104 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2105 CMD_OEM_SET_BOOT_ORDER, ipmi::Privilege::User,
2106 ipmiOemSetBootOrder); // Set Boot Order
2107
Vijay Khemkae7d23d02019-03-08 13:13:40 -08002108 return;
2109}
2110
2111} // namespace ipmi