blob: b628c7b93add98d94db5a1816ce3267ce27fa840 [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"
19#include <ipmid/api.h>
20
Vijay Khemka1d4a0692019-04-09 15:20:28 -070021#include <nlohmann/json.hpp>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080022#include <array>
23#include <commandutils.hpp>
24#include <cstring>
25#include <iostream>
Vijay Khemka1d4a0692019-04-09 15:20:28 -070026#include <iomanip>
27#include <sstream>
28#include <fstream>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080029#include <oemcommands.hpp>
Vijay Khemka1b6fae32019-03-25 17:43:01 -070030#include <ipmid/utils.hpp>
Vijay Khemkae7d23d02019-03-08 13:13:40 -080031#include <phosphor-logging/log.hpp>
32#include <sdbusplus/bus.hpp>
33#include <string>
34#include <vector>
35
36#define SIZE_IANA_ID 3
37
38namespace ipmi
39{
Vijay Khemkaa7231892019-10-11 11:35:05 -070040
41using namespace phosphor::logging;
42
Vijay Khemkae7d23d02019-03-08 13:13:40 -080043static void registerOEMFunctions() __attribute__((constructor));
44sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection()); // from ipmid/api.h
45static constexpr size_t maxFRUStringLength = 0x3F;
46
Vijay Khemkacc0d6d92019-08-27 14:51:17 -070047int plat_udbg_get_post_desc(uint8_t, uint8_t *, uint8_t, uint8_t *, uint8_t *,
48 uint8_t *);
Vijay Khemkae7d23d02019-03-08 13:13:40 -080049ipmi_ret_t plat_udbg_get_frame_data(uint8_t, uint8_t, uint8_t *, uint8_t *,
50 uint8_t *);
51ipmi_ret_t plat_udbg_control_panel(uint8_t, uint8_t, uint8_t, uint8_t *,
52 uint8_t *);
Vijay Khemka1b6fae32019-03-25 17:43:01 -070053namespace variant_ns = sdbusplus::message::variant_ns;
Vijay Khemkafeaa9812019-08-27 15:08:08 -070054nlohmann::json oemData __attribute__((init_priority(101)));
Vijay Khemka1b6fae32019-03-25 17:43:01 -070055
56enum class LanParam : uint8_t
57{
58 INPROGRESS = 0,
59 AUTHSUPPORT = 1,
60 AUTHENABLES = 2,
61 IP = 3,
62 IPSRC = 4,
63 MAC = 5,
64 SUBNET = 6,
65 GATEWAY = 12,
66 VLAN = 20,
67 CIPHER_SUITE_COUNT = 22,
68 CIPHER_SUITE_ENTRIES = 23,
69 IPV6 = 59,
70};
71
Vijay Khemkaa7231892019-10-11 11:35:05 -070072namespace network
73{
74
75constexpr auto ROOT = "/xyz/openbmc_project/network";
76constexpr auto SERVICE = "xyz.openbmc_project.Network";
77constexpr auto IPV4_TYPE = "ipv4";
78constexpr auto IPV6_TYPE = "ipv6";
79constexpr auto IPV4_PREFIX = "169.254";
80constexpr auto IPV6_PREFIX = "fe80";
81constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
82constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
83
84bool isLinkLocalIP(const std::string &address)
85{
86 return address.find(IPV4_PREFIX) == 0 || address.find(IPV6_PREFIX) == 0;
87}
88
89DbusObjectInfo getIPObject(sdbusplus::bus::bus &bus,
90 const std::string &interface,
91 const std::string &serviceRoot,
92 const std::string &match)
93{
94 auto objectTree = getAllDbusObjects(bus, serviceRoot, interface, match);
95
96 if (objectTree.empty())
97 {
98 log<level::ERR>("No Object has implemented the IP interface",
99 entry("INTERFACE=%s", interface.c_str()));
100 }
101
102 DbusObjectInfo objectInfo;
103
104 for (auto &object : objectTree)
105 {
106 auto variant =
107 ipmi::getDbusProperty(bus, object.second.begin()->first,
108 object.first, IP_INTERFACE, "Address");
109
110 objectInfo = std::make_pair(object.first, object.second.begin()->first);
111
112 // if LinkLocalIP found look for Non-LinkLocalIP
113 if (isLinkLocalIP(std::get<std::string>(variant)))
114 {
115 continue;
116 }
117 else
118 {
119 break;
120 }
121 }
122 return objectInfo;
123}
124
125} // namespace network
126
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700127//----------------------------------------------------------------------
128// Helper functions for storing oem data
129//----------------------------------------------------------------------
130
131void flushOemData()
132{
133 std::ofstream file(JSON_OEM_DATA_FILE);
134 file << oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -0700135 file.close();
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700136 return;
137}
138
139std::string bytesToStr(uint8_t *byte, int len)
140{
141 std::stringstream ss;
142 int i;
143
144 ss << std::hex;
145 for (i = 0; i < len; i++)
146 {
147 ss << std::setw(2) << std::setfill('0') << (int)byte[i];
148 }
149
150 return ss.str();
151}
152
153int strToBytes(std::string &str, uint8_t *data)
154{
155 std::string sstr;
156 int i;
157
158 for (i = 0; i < (str.length()) / 2; i++)
159 {
160 sstr = str.substr(i * 2, 2);
161 data[i] = (uint8_t)std::strtol(sstr.c_str(), NULL, 16);
162 }
163 return i;
164}
165
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700166ipmi_ret_t getNetworkData(uint8_t lan_param, char *data)
167{
168 ipmi_ret_t rc = IPMI_CC_OK;
169 sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
170
171 const std::string ethdevice = "eth0";
172
173 switch (static_cast<LanParam>(lan_param))
174 {
175 case LanParam::IP:
176 {
Vijay Khemkaa7231892019-10-11 11:35:05 -0700177 auto ethIP = ethdevice + "/" + ipmi::network::IPV4_TYPE;
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700178 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700179 auto ipObjectInfo = ipmi::network::getIPObject(
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700180 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT, ethIP);
181
182 auto properties = ipmi::getAllDbusProperties(
183 bus, ipObjectInfo.second, ipObjectInfo.first,
184 ipmi::network::IP_INTERFACE);
185
186 ipaddress = variant_ns::get<std::string>(properties["Address"]);
187
188 std::strcpy(data, ipaddress.c_str());
189 }
190 break;
191
192 case LanParam::IPV6:
193 {
Vijay Khemkaa7231892019-10-11 11:35:05 -0700194 auto ethIP = ethdevice + "/" + ipmi::network::IPV6_TYPE;
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700195 std::string ipaddress;
Vijay Khemkaa7231892019-10-11 11:35:05 -0700196 auto ipObjectInfo = ipmi::network::getIPObject(
Vijay Khemka1b6fae32019-03-25 17:43:01 -0700197 bus, ipmi::network::IP_INTERFACE, ipmi::network::ROOT, ethIP);
198
199 auto properties = ipmi::getAllDbusProperties(
200 bus, ipObjectInfo.second, ipObjectInfo.first,
201 ipmi::network::IP_INTERFACE);
202
203 ipaddress = variant_ns::get<std::string>(properties["Address"]);
204
205 std::strcpy(data, ipaddress.c_str());
206 }
207 break;
208
209 case LanParam::MAC:
210 {
211 std::string macAddress;
212 auto macObjectInfo =
213 ipmi::getDbusObject(bus, ipmi::network::MAC_INTERFACE,
214 ipmi::network::ROOT, ethdevice);
215
216 auto variant = ipmi::getDbusProperty(
217 bus, macObjectInfo.second, macObjectInfo.first,
218 ipmi::network::MAC_INTERFACE, "MACAddress");
219
220 macAddress = variant_ns::get<std::string>(variant);
221
222 sscanf(macAddress.c_str(), ipmi::network::MAC_ADDRESS_FORMAT,
223 (data), (data + 1), (data + 2), (data + 3), (data + 4),
224 (data + 5));
225 std::strcpy(data, macAddress.c_str());
226 }
227 break;
228
229 default:
230 rc = IPMI_CC_PARM_OUT_OF_RANGE;
231 }
232 return rc;
233}
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800234
235// return code: 0 successful
236int8_t getFruData(std::string &data, std::string &name)
237{
238 std::string objpath = "/xyz/openbmc_project/FruDevice";
239 std::string intf = "xyz.openbmc_project.FruDeviceManager";
240 std::string service = getService(dbus, intf, objpath);
241 ObjectValueTree valueTree = getManagedObjects(dbus, service, "/");
242 if (valueTree.empty())
243 {
244 phosphor::logging::log<phosphor::logging::level::ERR>(
245 "No object implements interface",
246 phosphor::logging::entry("INTF=%s", intf.c_str()));
247 return -1;
248 }
249
250 for (const auto &item : valueTree)
251 {
252 auto interface = item.second.find("xyz.openbmc_project.FruDevice");
253 if (interface == item.second.end())
254 {
255 continue;
256 }
257
258 auto property = interface->second.find(name.c_str());
259 if (property == interface->second.end())
260 {
261 continue;
262 }
263
264 try
265 {
266 Value variant = property->second;
267 std::string &result =
268 sdbusplus::message::variant_ns::get<std::string>(variant);
269 if (result.size() > maxFRUStringLength)
270 {
271 phosphor::logging::log<phosphor::logging::level::ERR>(
272 "FRU serial number exceed maximum length");
273 return -1;
274 }
275 data = result;
276 return 0;
277 }
278 catch (sdbusplus::message::variant_ns::bad_variant_access &e)
279 {
280 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
281 return -1;
282 }
283 }
284 return -1;
285}
286
287typedef struct
288{
289 uint8_t cur_power_state;
290 uint8_t last_power_event;
291 uint8_t misc_power_state;
292 uint8_t front_panel_button_cap_status;
293} ipmi_get_chassis_status_t;
294
295// Todo: Needs to update this as per power policy when integrated
296//----------------------------------------------------------------------
297// Get Chassis Status commands
298//----------------------------------------------------------------------
299ipmi_ret_t ipmiGetChassisStatus(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
300 ipmi_request_t request,
301 ipmi_response_t response,
302 ipmi_data_len_t data_len,
303 ipmi_context_t context)
304{
305 ipmi_get_chassis_status_t chassis_status;
306 uint8_t s = 2;
307
308 *data_len = 4;
309
310 // Current Power State
311 // [7] reserved
312 // [6..5] power restore policy
313 // 00b = chassis stays powered off after AC/mains returns
314 // 01b = after AC returns, power is restored to the state that was
315 // in effect when AC/mains was lost.
316 // 10b = chassis always powers up after AC/mains returns
317 // 11b = unknow
318 // Set to 00b, by observing the hardware behavior.
319 // Do we need to define a dbus property to identify the restore
320 // policy?
321
322 // [4] power control fault
323 // 1b = controller attempted to turn system power on or off, but
324 // system did not enter desired state.
325 // Set to 0b, since We don't support it..
326
327 // [3] power fault
328 // 1b = fault detected in main power subsystem.
329 // set to 0b. for we don't support it.
330
331 // [2] 1b = interlock (chassis is presently shut down because a chassis
332 // panel interlock switch is active). (IPMI 1.5)
333 // set to 0b, for we don't support it.
334
335 // [1] power overload
336 // 1b = system shutdown because of power overload condition.
337 // set to 0b, for we don't support it.
338
339 // [0] power is on
340 // 1b = system power is on
341 // 0b = system power is off(soft-off S4/S5, or mechanical off)
342
343 chassis_status.cur_power_state = ((s & 0x3) << 5) | (1 & 0x1);
344
345 // Last Power Event
346 // [7..5] – reserved
347 // [4] – 1b = last ‘Power is on’ state was entered via IPMI command
348 // [3] – 1b = last power down caused by power fault
349 // [2] – 1b = last power down caused by a power interlock being activated
350 // [1] – 1b = last power down caused by a Power overload
351 // [0] – 1b = AC failed
352 // set to 0x0, for we don't support these fields.
353
354 chassis_status.last_power_event = 0;
355
356 // Misc. Chassis State
357 // [7] – reserved
358 // [6] – 1b = Chassis Identify command and state info supported (Optional)
359 // 0b = Chassis Identify command support unspecified via this command.
360 // (The Get Command Support command , if implemented, would still
361 // indicate support for the Chassis Identify command)
362 // [5..4] – Chassis Identify State. Mandatory when bit[6] =1b, reserved
363 // (return
364 // as 00b) otherwise. Returns the present chassis identify state.
365 // Refer to the Chassis Identify command for more info.
366 // 00b = chassis identify state = Off
367 // 01b = chassis identify state = Temporary(timed) On
368 // 10b = chassis identify state = Indefinite On
369 // 11b = reserved
370 // [3] – 1b = Cooling/fan fault detected
371 // [2] – 1b = Drive Fault
372 // [1] – 1b = Front Panel Lockout active (power off and reset via chassis
373 // push-buttons disabled.)
374 // [0] – 1b = Chassis Intrusion active
375 // set to 0, for we don't support them.
376 chassis_status.misc_power_state = 0x40;
377
378 // Front Panel Button Capabilities and disable/enable status(Optional)
379 // set to 0, for we don't support them.
380 chassis_status.front_panel_button_cap_status = 0;
381
382 // Pack the actual response
383 std::memcpy(response, &chassis_status, *data_len);
384
385 return IPMI_CC_OK;
386}
387
388//----------------------------------------------------------------------
389// Get Debug Frame Info
390//----------------------------------------------------------------------
391ipmi_ret_t ipmiOemDbgGetFrameInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
392 ipmi_request_t request,
393 ipmi_response_t response,
394 ipmi_data_len_t data_len,
395 ipmi_context_t context)
396{
397 uint8_t *req = reinterpret_cast<uint8_t *>(request);
398 uint8_t *res = reinterpret_cast<uint8_t *>(response);
399 uint8_t num_frames = 3;
400
401 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
402 res[SIZE_IANA_ID] = num_frames;
403 *data_len = SIZE_IANA_ID + 1;
404
405 return IPMI_CC_OK;
406}
407
408//----------------------------------------------------------------------
409// Get Debug Updated Frames
410//----------------------------------------------------------------------
411ipmi_ret_t ipmiOemDbgGetUpdFrames(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
412 ipmi_request_t request,
413 ipmi_response_t response,
414 ipmi_data_len_t data_len,
415 ipmi_context_t context)
416{
417 uint8_t *req = reinterpret_cast<uint8_t *>(request);
418 uint8_t *res = reinterpret_cast<uint8_t *>(response);
419 uint8_t num_updates = 3;
420 *data_len = 4;
421
422 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
423 res[SIZE_IANA_ID] = num_updates;
424 *data_len = SIZE_IANA_ID + num_updates + 1;
425 res[SIZE_IANA_ID + 1] = 1; // info page update
426 res[SIZE_IANA_ID + 2] = 2; // cri sel update
427 res[SIZE_IANA_ID + 3] = 3; // cri sensor update
428
429 return IPMI_CC_OK;
430}
431
432//----------------------------------------------------------------------
433// Get Debug POST Description
434//----------------------------------------------------------------------
435ipmi_ret_t ipmiOemDbgGetPostDesc(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
436 ipmi_request_t request,
437 ipmi_response_t response,
438 ipmi_data_len_t data_len,
439 ipmi_context_t context)
440{
441 uint8_t *req = reinterpret_cast<uint8_t *>(request);
442 uint8_t *res = reinterpret_cast<uint8_t *>(response);
443 uint8_t index = 0;
444 uint8_t next = 0;
445 uint8_t end = 0;
446 uint8_t phase = 0;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700447 uint8_t descLen = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800448 int ret;
449
450 index = req[3];
451 phase = req[4];
452
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700453 ret = plat_udbg_get_post_desc(index, &next, phase, &end, &descLen, &res[8]);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800454 if (ret)
455 {
456 memcpy(res, req, SIZE_IANA_ID); // IANA ID
457 *data_len = SIZE_IANA_ID;
458 return IPMI_CC_UNSPECIFIED_ERROR;
459 }
460
461 memcpy(res, req, SIZE_IANA_ID); // IANA ID
462 res[3] = index;
463 res[4] = next;
464 res[5] = phase;
465 res[6] = end;
Vijay Khemkacc0d6d92019-08-27 14:51:17 -0700466 res[7] = descLen;
467 *data_len = SIZE_IANA_ID + 5 + descLen;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800468
469 return IPMI_CC_OK;
470}
471
472//----------------------------------------------------------------------
473// Get Debug GPIO Description
474//----------------------------------------------------------------------
475ipmi_ret_t ipmiOemDbgGetGpioDesc(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
476 ipmi_request_t request,
477 ipmi_response_t response,
478 ipmi_data_len_t data_len,
479 ipmi_context_t context)
480{
481 uint8_t *req = reinterpret_cast<uint8_t *>(request);
482 uint8_t *res = reinterpret_cast<uint8_t *>(response);
483
484 phosphor::logging::log<phosphor::logging::level::INFO>(
485 "Get GPIO Description Event");
486
487 std::memcpy(res, req, SIZE_IANA_ID + 1); // IANA ID
488 *data_len = SIZE_IANA_ID + 1;
489
490 return IPMI_CC_OK;
491}
492
493//----------------------------------------------------------------------
494// Get Debug Frame Data
495//----------------------------------------------------------------------
496ipmi_ret_t ipmiOemDbgGetFrameData(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
497 ipmi_request_t request,
498 ipmi_response_t response,
499 ipmi_data_len_t data_len,
500 ipmi_context_t context)
501{
502 uint8_t *req = reinterpret_cast<uint8_t *>(request);
503 uint8_t *res = reinterpret_cast<uint8_t *>(response);
504 uint8_t frame;
505 uint8_t page;
506 uint8_t next;
507 uint8_t count;
508 int ret;
509
510 frame = req[3];
511 page = req[4];
512 int fr = frame;
513 int pg = page;
514
515 ret = plat_udbg_get_frame_data(frame, page, &next, &count, &res[7]);
516 if (ret)
517 {
518 memcpy(res, req, SIZE_IANA_ID); // IANA ID
519 *data_len = SIZE_IANA_ID;
520 return IPMI_CC_UNSPECIFIED_ERROR;
521 }
522
523 memcpy(res, req, SIZE_IANA_ID); // IANA ID
524 res[3] = frame;
525 res[4] = page;
526 res[5] = next;
527 res[6] = count;
528 *data_len = SIZE_IANA_ID + 4 + count;
529
530 return IPMI_CC_OK;
531}
532
533//----------------------------------------------------------------------
534// Get Debug Control Panel
535//----------------------------------------------------------------------
536ipmi_ret_t ipmiOemDbgGetCtrlPanel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
537 ipmi_request_t request,
538 ipmi_response_t response,
539 ipmi_data_len_t data_len,
540 ipmi_context_t context)
541{
542 uint8_t *req = reinterpret_cast<uint8_t *>(request);
543 uint8_t *res = reinterpret_cast<uint8_t *>(response);
544
545 uint8_t panel;
546 uint8_t operation;
547 uint8_t item;
548 uint8_t count;
549 ipmi_ret_t ret;
550
551 panel = req[3];
552 operation = req[4];
553 item = req[5];
554
555 ret = plat_udbg_control_panel(panel, operation, item, &count, &res[3]);
556
557 std::memcpy(res, req, SIZE_IANA_ID); // IANA ID
558 *data_len = SIZE_IANA_ID + count;
559
560 return ret;
561}
562
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800563//----------------------------------------------------------------------
564// Set Dimm Info (CMD_OEM_SET_DIMM_INFO)
565//----------------------------------------------------------------------
566ipmi_ret_t ipmiOemSetDimmInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
567 ipmi_request_t request, ipmi_response_t response,
568 ipmi_data_len_t data_len, ipmi_context_t context)
569{
570 uint8_t *req = reinterpret_cast<uint8_t *>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700571
572 uint8_t index = req[0];
573 uint8_t type = req[1];
574 uint16_t speed;
575 uint32_t size;
576
577 memcpy(&speed, &req[2], 2);
578 memcpy(&size, &req[4], 4);
579
580 std::stringstream ss;
581 ss << std::hex;
582 ss << std::setw(2) << std::setfill('0') << (int)index;
583
584 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_INDEX] = index;
585 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_TYPE] = type;
586 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SPEED] = speed;
587 oemData[KEY_SYS_CONFIG][ss.str()][KEY_DIMM_SIZE] = size;
588
589 flushOemData();
590
591 *data_len = 0;
592
593 return IPMI_CC_OK;
594}
595
596//----------------------------------------------------------------------
597// Get Board ID (CMD_OEM_GET_BOARD_ID)
598//----------------------------------------------------------------------
599ipmi_ret_t ipmiOemGetBoardID(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
600 ipmi_request_t request, ipmi_response_t response,
601 ipmi_data_len_t data_len, ipmi_context_t context)
602{
603 uint8_t *req = reinterpret_cast<uint8_t *>(request);
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800604 uint8_t *res = reinterpret_cast<uint8_t *>(response);
605
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700606 /* TODO: Needs to implement this after GPIO implementation */
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800607 *data_len = 0;
608
609 return IPMI_CC_OK;
610}
611
612//----------------------------------------------------------------------
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700613// Set Boot Order (CMD_OEM_SET_BOOT_ORDER)
614//----------------------------------------------------------------------
615ipmi_ret_t ipmiOemSetBootOrder(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
616 ipmi_request_t request, ipmi_response_t response,
617 ipmi_data_len_t data_len, ipmi_context_t context)
618{
619 uint8_t *req = reinterpret_cast<uint8_t *>(request);
620 uint8_t len = *data_len;
621 uint8_t mode = req[0];
622 nlohmann::json bootMode;
623 int i;
624
625 *data_len = 0;
626
627 if (len != SIZE_BOOT_ORDER)
628 {
629 phosphor::logging::log<phosphor::logging::level::ERR>(
630 "Invalid Boot order length received");
631 return IPMI_CC_REQ_DATA_LEN_INVALID;
632 }
633
634 bootMode["UEFI"] = (mode & BOOT_MODE_UEFI ? true : false);
635 bootMode["CMOS_CLR"] = (mode & BOOT_MODE_CMOS_CLR ? true : false);
636 bootMode["FORCE_BOOT"] = (mode & BOOT_MODE_FORCE_BOOT ? true : false);
637 bootMode["BOOT_FLAG"] = (mode & BOOT_MODE_BOOT_FLAG ? true : false);
638
639 oemData[KEY_BOOT_ORDER][KEY_BOOT_MODE] = bootMode;
640
641 /* Initialize boot sequence array */
642 oemData[KEY_BOOT_ORDER][KEY_BOOT_SEQ] = {};
643 for (i = 1; i < SIZE_BOOT_ORDER; i++)
644 oemData[KEY_BOOT_ORDER][KEY_BOOT_SEQ][i - 1] = bootSeq[req[i]];
645
646 flushOemData();
647
648 return IPMI_CC_OK;
649}
650
651//----------------------------------------------------------------------
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800652// Get Boot Order (CMD_OEM_GET_BOOT_ORDER)
653//----------------------------------------------------------------------
654ipmi_ret_t ipmiOemGetBootOrder(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
655 ipmi_request_t request, ipmi_response_t response,
656 ipmi_data_len_t data_len, ipmi_context_t context)
657{
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800658 uint8_t *res = reinterpret_cast<uint8_t *>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700659 nlohmann::json bootMode = oemData[KEY_BOOT_ORDER][KEY_BOOT_MODE];
660 uint8_t mode = 0;
661 int i;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800662
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700663 *data_len = SIZE_BOOT_ORDER;
664
665 if (bootMode["UEFI"])
666 mode |= BOOT_MODE_UEFI;
667 if (bootMode["CMOS_CLR"])
668 mode |= BOOT_MODE_CMOS_CLR;
669 if (bootMode["BOOT_FLAG"])
670 mode |= BOOT_MODE_BOOT_FLAG;
671
672 res[0] = mode;
673
674 for (i = 1; i < SIZE_BOOT_ORDER; i++)
675 res[i] = bootMap[oemData[KEY_BOOT_ORDER][KEY_BOOT_SEQ][i - 1]];
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800676
677 return IPMI_CC_OK;
678}
679
680//----------------------------------------------------------------------
681// Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)
682//----------------------------------------------------------------------
683ipmi_ret_t ipmiOemSetMachineCfgInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
684 ipmi_request_t request,
685 ipmi_response_t response,
686 ipmi_data_len_t data_len,
687 ipmi_context_t context)
688{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700689 machineConfigInfo_t *req = reinterpret_cast<machineConfigInfo_t *>(request);
690 uint8_t len = *data_len;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800691
692 *data_len = 0;
693
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700694 if (len < sizeof(machineConfigInfo_t))
695 {
696 phosphor::logging::log<phosphor::logging::level::ERR>(
697 "Invalid machine configuration length received");
698 return IPMI_CC_REQ_DATA_LEN_INVALID;
699 }
700
701 if (req->chassis_type >= sizeof(chassisType) / sizeof(uint8_t *))
702 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] = "UNKNOWN";
703 else
704 oemData[KEY_MC_CONFIG][KEY_MC_CHAS_TYPE] =
705 chassisType[req->chassis_type];
706
707 if (req->mb_type >= sizeof(mbType) / sizeof(uint8_t *))
708 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = "UNKNOWN";
709 else
710 oemData[KEY_MC_CONFIG][KEY_MC_MB_TYPE] = mbType[req->mb_type];
711
712 oemData[KEY_MC_CONFIG][KEY_MC_PROC_CNT] = req->proc_cnt;
713 oemData[KEY_MC_CONFIG][KEY_MC_MEM_CNT] = req->mem_cnt;
714 oemData[KEY_MC_CONFIG][KEY_MC_HDD35_CNT] = req->hdd35_cnt;
715 oemData[KEY_MC_CONFIG][KEY_MC_HDD25_CNT] = req->hdd25_cnt;
716
717 if (req->riser_type >= sizeof(riserType) / sizeof(uint8_t *))
718 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = "UNKNOWN";
719 else
720 oemData[KEY_MC_CONFIG][KEY_MC_RSR_TYPE] = riserType[req->riser_type];
721
722 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC] = {};
723 int i = 0;
724 if (req->pcie_card_loc & BIT_0)
725 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT1";
726 if (req->pcie_card_loc & BIT_1)
727 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT2";
728 if (req->pcie_card_loc & BIT_2)
729 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT3";
730 if (req->pcie_card_loc & BIT_3)
731 oemData[KEY_MC_CONFIG][KEY_MC_PCIE_LOC][i++] = "SLOT4";
732
733 if (req->slot1_pcie_type >= sizeof(pcieType) / sizeof(uint8_t *))
734 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] = "UNKNOWN";
735 else
736 oemData[KEY_MC_CONFIG][KEY_MC_SLOT1_TYPE] =
737 pcieType[req->slot1_pcie_type];
738
739 if (req->slot2_pcie_type >= sizeof(pcieType) / sizeof(uint8_t *))
740 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] = "UNKNOWN";
741 else
742 oemData[KEY_MC_CONFIG][KEY_MC_SLOT2_TYPE] =
743 pcieType[req->slot2_pcie_type];
744
745 if (req->slot3_pcie_type >= sizeof(pcieType) / sizeof(uint8_t *))
746 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] = "UNKNOWN";
747 else
748 oemData[KEY_MC_CONFIG][KEY_MC_SLOT3_TYPE] =
749 pcieType[req->slot3_pcie_type];
750
751 if (req->slot4_pcie_type >= sizeof(pcieType) / sizeof(uint8_t *))
752 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] = "UNKNOWN";
753 else
754 oemData[KEY_MC_CONFIG][KEY_MC_SLOT4_TYPE] =
755 pcieType[req->slot4_pcie_type];
756
757 oemData[KEY_MC_CONFIG][KEY_MC_AEP_CNT] = req->aep_mem_cnt;
758
759 flushOemData();
760
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800761 return IPMI_CC_OK;
762}
763
764//----------------------------------------------------------------------
765// Set POST start (CMD_OEM_SET_POST_START)
766//----------------------------------------------------------------------
767ipmi_ret_t ipmiOemSetPostStart(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
768 ipmi_request_t request, ipmi_response_t response,
769 ipmi_data_len_t data_len, ipmi_context_t context)
770{
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800771 phosphor::logging::log<phosphor::logging::level::INFO>("POST Start Event");
772
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700773 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800774 *data_len = 0;
775 return IPMI_CC_OK;
776}
777
778//----------------------------------------------------------------------
779// Set POST End (CMD_OEM_SET_POST_END)
780//----------------------------------------------------------------------
781ipmi_ret_t ipmiOemSetPostEnd(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
782 ipmi_request_t request, ipmi_response_t response,
783 ipmi_data_len_t data_len, ipmi_context_t context)
784{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700785 struct timespec ts;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800786
787 phosphor::logging::log<phosphor::logging::level::INFO>("POST End Event");
788
789 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700790
791 // Timestamp post end time.
792 clock_gettime(CLOCK_REALTIME, &ts);
793 oemData[KEY_TS_SLED] = ts.tv_sec;
794 flushOemData();
795
796 // Sync time with system
797 // TODO: Add code for syncing time
798
799 return IPMI_CC_OK;
800}
801
802//----------------------------------------------------------------------
803// Set PPIN Info (CMD_OEM_SET_PPIN_INFO)
804//----------------------------------------------------------------------
805// Inform BMC about PPIN data of 8 bytes for each CPU
806//
807// Request:
808// Byte 1:8 – CPU0 PPIN data
809// Optional:
810// Byte 9:16 – CPU1 PPIN data
811//
812// Response:
813// Byte 1 – Completion Code
814ipmi_ret_t ipmiOemSetPPINInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
815 ipmi_request_t request, ipmi_response_t response,
816 ipmi_data_len_t data_len, ipmi_context_t context)
817{
818 uint8_t *req = reinterpret_cast<uint8_t *>(request);
819 std::string ppinStr;
820 int len;
821
822 if (*data_len > SIZE_CPU_PPIN * 2)
823 len = SIZE_CPU_PPIN * 2;
824 else
825 len = *data_len;
826 *data_len = 0;
827
828 ppinStr = bytesToStr(req, len);
829 oemData[KEY_PPIN_INFO] = ppinStr.c_str();
830 flushOemData();
831
832 return IPMI_CC_OK;
833}
834
835//----------------------------------------------------------------------
836// Set ADR Trigger (CMD_OEM_SET_ADR_TRIGGER)
837//----------------------------------------------------------------------
838ipmi_ret_t ipmiOemSetAdrTrigger(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
839 ipmi_request_t request,
840 ipmi_response_t response,
841 ipmi_data_len_t data_len,
842 ipmi_context_t context)
843{
844 /* Do nothing, return success */
845 *data_len = 0;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800846 return IPMI_CC_OK;
847}
848
849//----------------------------------------------------------------------
850// Set Bios Flash Info (CMD_OEM_SET_BIOS_FLASH_INFO)
851//----------------------------------------------------------------------
852ipmi_ret_t ipmiOemSetBiosFlashInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
853 ipmi_request_t request,
854 ipmi_response_t response,
855 ipmi_data_len_t data_len,
856 ipmi_context_t context)
857{
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700858 /* Do nothing, return success */
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800859 *data_len = 0;
860 return IPMI_CC_OK;
861}
862
863//----------------------------------------------------------------------
864// Set PPR (CMD_OEM_SET_PPR)
865//----------------------------------------------------------------------
866ipmi_ret_t ipmiOemSetPpr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
867 ipmi_request_t request, ipmi_response_t response,
868 ipmi_data_len_t data_len, ipmi_context_t context)
869{
870 uint8_t *req = reinterpret_cast<uint8_t *>(request);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700871 uint8_t pprCnt, pprAct, pprIndex;
872 uint8_t selParam = req[0];
873 uint8_t len = *data_len;
874 std::stringstream ss;
875 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800876
877 *data_len = 0;
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700878
879 switch (selParam)
880 {
881 case PPR_ACTION:
882 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) ==
883 oemData[KEY_PPR].end())
884 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
885
886 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
887 if (pprCnt == 0)
888 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
889
890 pprAct = req[1];
891 /* Check if ppr is enabled or disabled */
892 if (!(pprAct & 0x80))
893 pprAct = 0;
894
895 oemData[KEY_PPR][KEY_PPR_ACTION] = pprAct;
896 break;
897 case PPR_ROW_COUNT:
898 if (req[1] > 100)
899 return IPMI_CC_PARM_OUT_OF_RANGE;
900
901 oemData[KEY_PPR][KEY_PPR_ROW_COUNT] = req[1];
902 break;
903 case PPR_ROW_ADDR:
904 pprIndex = req[1];
905 if (pprIndex > 100)
906 return IPMI_CC_PARM_OUT_OF_RANGE;
907
908 if (len < PPR_ROW_ADDR_LEN + 1)
909 {
910 phosphor::logging::log<phosphor::logging::level::ERR>(
911 "Invalid PPR Row Address length received");
912 return IPMI_CC_REQ_DATA_LEN_INVALID;
913 }
914
915 ss << std::hex;
916 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
917
918 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
919
920 str = bytesToStr(&req[1], PPR_ROW_ADDR_LEN);
921 oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR] = str.c_str();
922 break;
923 case PPR_HISTORY_DATA:
924 pprIndex = req[1];
925 if (pprIndex > 100)
926 return IPMI_CC_PARM_OUT_OF_RANGE;
927
928 if (len < PPR_HST_DATA_LEN + 1)
929 {
930 phosphor::logging::log<phosphor::logging::level::ERR>(
931 "Invalid PPR history data length received");
932 return IPMI_CC_REQ_DATA_LEN_INVALID;
933 }
934
935 ss << std::hex;
936 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
937
938 oemData[KEY_PPR][ss.str()][KEY_PPR_INDEX] = pprIndex;
939
940 str = bytesToStr(&req[1], PPR_HST_DATA_LEN);
941 oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA] = str.c_str();
942 break;
943 default:
944 return IPMI_CC_PARM_OUT_OF_RANGE;
945 break;
946 }
947
948 flushOemData();
949
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800950 return IPMI_CC_OK;
951}
952
953//----------------------------------------------------------------------
954// Get PPR (CMD_OEM_GET_PPR)
955//----------------------------------------------------------------------
956ipmi_ret_t ipmiOemGetPpr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
957 ipmi_request_t request, ipmi_response_t response,
958 ipmi_data_len_t data_len, ipmi_context_t context)
959{
960 uint8_t *req = reinterpret_cast<uint8_t *>(request);
961 uint8_t *res = reinterpret_cast<uint8_t *>(response);
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700962 uint8_t pprCnt, pprIndex;
963 uint8_t selParam = req[0];
964 std::stringstream ss;
965 std::string str;
Vijay Khemkae7d23d02019-03-08 13:13:40 -0800966
Vijay Khemka1d4a0692019-04-09 15:20:28 -0700967 /* Any failure will return zero length data */
968 *data_len = 0;
969
970 switch (selParam)
971 {
972 case PPR_ACTION:
973 res[0] = 0;
974 *data_len = 1;
975
976 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
977 oemData[KEY_PPR].end())
978 {
979 pprCnt = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
980 if (pprCnt != 0)
981 {
982 if (oemData[KEY_PPR].find(KEY_PPR_ACTION) !=
983 oemData[KEY_PPR].end())
984 {
985 res[0] = oemData[KEY_PPR][KEY_PPR_ACTION];
986 }
987 }
988 }
989 break;
990 case PPR_ROW_COUNT:
991 res[0] = 0;
992 *data_len = 1;
993 if (oemData[KEY_PPR].find(KEY_PPR_ROW_COUNT) !=
994 oemData[KEY_PPR].end())
995 res[0] = oemData[KEY_PPR][KEY_PPR_ROW_COUNT];
996 break;
997 case PPR_ROW_ADDR:
998 pprIndex = req[1];
999 if (pprIndex > 100)
1000 return IPMI_CC_PARM_OUT_OF_RANGE;
1001
1002 ss << std::hex;
1003 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1004
1005 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1006 return IPMI_CC_PARM_OUT_OF_RANGE;
1007
1008 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_ROW_ADDR) ==
1009 oemData[KEY_PPR][ss.str()].end())
1010 return IPMI_CC_PARM_OUT_OF_RANGE;
1011
1012 str = oemData[KEY_PPR][ss.str()][KEY_PPR_ROW_ADDR];
1013 *data_len = strToBytes(str, res);
1014 break;
1015 case PPR_HISTORY_DATA:
1016 pprIndex = req[1];
1017 if (pprIndex > 100)
1018 return IPMI_CC_PARM_OUT_OF_RANGE;
1019
1020 ss << std::hex;
1021 ss << std::setw(2) << std::setfill('0') << (int)pprIndex;
1022
1023 if (oemData[KEY_PPR].find(ss.str()) == oemData[KEY_PPR].end())
1024 return IPMI_CC_PARM_OUT_OF_RANGE;
1025
1026 if (oemData[KEY_PPR][ss.str()].find(KEY_PPR_HST_DATA) ==
1027 oemData[KEY_PPR][ss.str()].end())
1028 return IPMI_CC_PARM_OUT_OF_RANGE;
1029
1030 str = oemData[KEY_PPR][ss.str()][KEY_PPR_HST_DATA];
1031 *data_len = strToBytes(str, res);
1032 break;
1033 default:
1034 return IPMI_CC_PARM_OUT_OF_RANGE;
1035 break;
1036 }
1037
1038 return IPMI_CC_OK;
1039}
1040
1041/* FB OEM QC Commands */
1042
1043//----------------------------------------------------------------------
1044// Set Proc Info (CMD_OEM_Q_SET_PROC_INFO)
1045//----------------------------------------------------------------------
1046//"Request:
1047// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1048// Byte 4 – Processor Index, 0 base
1049// Byte 5 – Parameter Selector
1050// Byte 6..N – Configuration parameter data (see below for Parameters
1051// of Processor Information)
1052// Response:
1053// Byte 1 – Completion code
1054//
1055// Parameter#1: (Processor Product Name)
1056//
1057// Byte 1..48 –Product name(ASCII code)
1058// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1059//
1060// Param#2: Processor Basic Information
1061// Byte 1 – Core Number
1062// Byte 2 – Thread Number (LSB)
1063// Byte 3 – Thread Number (MSB)
1064// Byte 4 – Processor frequency in MHz (LSB)
1065// Byte 5 – Processor frequency in MHz (MSB)
1066// Byte 6..7 – Revision
1067//
1068ipmi_ret_t ipmiOemQSetProcInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1069 ipmi_request_t request, ipmi_response_t response,
1070 ipmi_data_len_t data_len, ipmi_context_t context)
1071{
1072 qProcInfo_t *req = reinterpret_cast<qProcInfo_t *>(request);
1073 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t *);
1074 std::stringstream ss;
1075 std::string str;
1076 uint8_t len = *data_len;
1077
1078 *data_len = 0;
1079
1080 /* check for requested data params */
1081 if (len < 5 || req->paramSel < 1 || req->paramSel >= numParam)
1082 {
1083 phosphor::logging::log<phosphor::logging::level::ERR>(
1084 "Invalid parameter received");
1085 return IPMI_CC_PARM_OUT_OF_RANGE;
1086 }
1087
1088 len = len - 5; // Get Actual data length
1089
1090 ss << std::hex;
1091 ss << std::setw(2) << std::setfill('0') << (int)req->procIndex;
1092 oemData[KEY_Q_PROC_INFO][ss.str()][KEY_PROC_INDEX] = req->procIndex;
1093
1094 str = bytesToStr(req->data, len);
1095 oemData[KEY_Q_PROC_INFO][ss.str()][cpuInfoKey[req->paramSel]] = str.c_str();
1096 flushOemData();
1097
1098 return IPMI_CC_OK;
1099}
1100
1101//----------------------------------------------------------------------
1102// Get Proc Info (CMD_OEM_Q_GET_PROC_INFO)
1103//----------------------------------------------------------------------
1104// Request:
1105// Byte 1:3 – Manufacturer ID – XXYYZZ h, LSB first
1106// Byte 4 – Processor Index, 0 base
1107// Byte 5 – Parameter Selector
1108// Response:
1109// Byte 1 – Completion code
1110// Byte 2..N – Configuration Parameter Data (see below for Parameters
1111// of Processor Information)
1112//
1113// Parameter#1: (Processor Product Name)
1114//
1115// Byte 1..48 –Product name(ASCII code)
1116// Ex. Intel(R) Xeon(R) CPU E5-2685 v3 @ 2.60GHz
1117//
1118// Param#2: Processor Basic Information
1119// Byte 1 – Core Number
1120// Byte 2 – Thread Number (LSB)
1121// Byte 3 – Thread Number (MSB)
1122// Byte 4 – Processor frequency in MHz (LSB)
1123// Byte 5 – Processor frequency in MHz (MSB)
1124// Byte 6..7 – Revision
1125//
1126ipmi_ret_t ipmiOemQGetProcInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1127 ipmi_request_t request, ipmi_response_t response,
1128 ipmi_data_len_t data_len, ipmi_context_t context)
1129{
1130 qProcInfo_t *req = reinterpret_cast<qProcInfo_t *>(request);
1131 uint8_t numParam = sizeof(cpuInfoKey) / sizeof(uint8_t *);
1132 uint8_t *res = reinterpret_cast<uint8_t *>(response);
1133 std::stringstream ss;
1134 std::string str;
1135
1136 *data_len = 0;
1137
1138 /* check for requested data params */
1139 if (req->paramSel < 1 || req->paramSel >= numParam)
1140 {
1141 phosphor::logging::log<phosphor::logging::level::ERR>(
1142 "Invalid parameter received");
1143 return IPMI_CC_PARM_OUT_OF_RANGE;
1144 }
1145
1146 ss << std::hex;
1147 ss << std::setw(2) << std::setfill('0') << (int)req->procIndex;
1148
1149 if (oemData[KEY_Q_PROC_INFO].find(ss.str()) ==
1150 oemData[KEY_Q_PROC_INFO].end())
1151 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1152
1153 if (oemData[KEY_Q_PROC_INFO][ss.str()].find(cpuInfoKey[req->paramSel]) ==
1154 oemData[KEY_Q_PROC_INFO][ss.str()].end())
1155 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1156
1157 str = oemData[KEY_Q_PROC_INFO][ss.str()][cpuInfoKey[req->paramSel]];
1158 *data_len = strToBytes(str, res);
1159
1160 return IPMI_CC_OK;
1161}
1162
1163//----------------------------------------------------------------------
1164// Set Dimm Info (CMD_OEM_Q_SET_DIMM_INFO)
1165//----------------------------------------------------------------------
1166// Request:
1167// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1168// Byte 4 – DIMM Index, 0 base
1169// Byte 5 – Parameter Selector
1170// Byte 6..N – Configuration parameter data (see below for Parameters
1171// of DIMM Information)
1172// Response:
1173// Byte 1 – Completion code
1174//
1175// Param#1 (DIMM Location):
1176// Byte 1 – DIMM Present
1177// Byte 1 – DIMM Present
1178// 01h – Present
1179// FFh – Not Present
1180// Byte 2 – Node Number, 0 base
1181// Byte 3 – Channel Number , 0 base
1182// Byte 4 – DIMM Number , 0 base
1183//
1184// Param#2 (DIMM Type):
1185// Byte 1 – DIMM Type
1186// Bit [7:6]
1187// For DDR3
1188// 00 – Normal Voltage (1.5V)
1189// 01 – Ultra Low Voltage (1.25V)
1190// 10 – Low Voltage (1.35V)
1191// 11 – Reserved
1192// For DDR4
1193// 00 – Reserved
1194// 01 – Reserved
1195// 10 – Reserved
1196// 11 – Normal Voltage (1.2V)
1197// Bit [5:0]
1198// 0x00 – SDRAM
1199// 0x01 – DDR-1 RAM
1200// 0x02 – Rambus
1201// 0x03 – DDR-2 RAM
1202// 0x04 – FBDIMM
1203// 0x05 – DDR-3 RAM
1204// 0x06 – DDR-4 RAM
1205//
1206// Param#3 (DIMM Speed):
1207// Byte 1..2 – DIMM speed in MHz, LSB
1208// Byte 3..6 – DIMM size in Mbytes, LSB
1209//
1210// Param#4 (Module Part Number):
1211// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1212//
1213// Param#5 (Module Serial Number):
1214// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1215//
1216// Param#6 (Module Manufacturer ID):
1217// Byte 1 - Module Manufacturer ID, LSB
1218// Byte 2 - Module Manufacturer ID, MSB
1219//
1220ipmi_ret_t ipmiOemQSetDimmInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1221 ipmi_request_t request, ipmi_response_t response,
1222 ipmi_data_len_t data_len, ipmi_context_t context)
1223{
1224 qDimmInfo_t *req = reinterpret_cast<qDimmInfo_t *>(request);
1225 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t *);
1226 std::stringstream ss;
1227 std::string str;
1228 uint8_t len = *data_len;
1229
1230 *data_len = 0;
1231
1232 /* check for requested data params */
1233 if (len < 5 || req->paramSel < 1 || req->paramSel >= numParam)
1234 {
1235 phosphor::logging::log<phosphor::logging::level::ERR>(
1236 "Invalid parameter received");
1237 return IPMI_CC_PARM_OUT_OF_RANGE;
1238 }
1239
1240 len = len - 5; // Get Actual data length
1241
1242 ss << std::hex;
1243 ss << std::setw(2) << std::setfill('0') << (int)req->dimmIndex;
1244 oemData[KEY_Q_DIMM_INFO][ss.str()][KEY_DIMM_INDEX] = req->dimmIndex;
1245
1246 str = bytesToStr(req->data, len);
1247 oemData[KEY_Q_DIMM_INFO][ss.str()][dimmInfoKey[req->paramSel]] =
1248 str.c_str();
1249 flushOemData();
1250
1251 return IPMI_CC_OK;
1252}
1253
1254//----------------------------------------------------------------------
1255// Get Dimm Info (CMD_OEM_Q_GET_DIMM_INFO)
1256//----------------------------------------------------------------------
1257// Request:
1258// Byte 1:3 – Manufacturer ID – XXYYZZh, LSB first
1259// Byte 4 – DIMM Index, 0 base
1260// Byte 5 – Parameter Selector
1261// Byte 6..N – Configuration parameter data (see below for Parameters
1262// of DIMM Information)
1263// Response:
1264// Byte 1 – Completion code
1265// Byte 2..N – Configuration Parameter Data (see Table_1213h Parameters
1266// of DIMM Information)
1267//
1268// Param#1 (DIMM Location):
1269// Byte 1 – DIMM Present
1270// Byte 1 – DIMM Present
1271// 01h – Present
1272// FFh – Not Present
1273// Byte 2 – Node Number, 0 base
1274// Byte 3 – Channel Number , 0 base
1275// Byte 4 – DIMM Number , 0 base
1276//
1277// Param#2 (DIMM Type):
1278// Byte 1 – DIMM Type
1279// Bit [7:6]
1280// For DDR3
1281// 00 – Normal Voltage (1.5V)
1282// 01 – Ultra Low Voltage (1.25V)
1283// 10 – Low Voltage (1.35V)
1284// 11 – Reserved
1285// For DDR4
1286// 00 – Reserved
1287// 01 – Reserved
1288// 10 – Reserved
1289// 11 – Normal Voltage (1.2V)
1290// Bit [5:0]
1291// 0x00 – SDRAM
1292// 0x01 – DDR-1 RAM
1293// 0x02 – Rambus
1294// 0x03 – DDR-2 RAM
1295// 0x04 – FBDIMM
1296// 0x05 – DDR-3 RAM
1297// 0x06 – DDR-4 RAM
1298//
1299// Param#3 (DIMM Speed):
1300// Byte 1..2 – DIMM speed in MHz, LSB
1301// Byte 3..6 – DIMM size in Mbytes, LSB
1302//
1303// Param#4 (Module Part Number):
1304// Byte 1..20 –Module Part Number (JEDEC Standard No. 21-C)
1305//
1306// Param#5 (Module Serial Number):
1307// Byte 1..4 –Module Serial Number (JEDEC Standard No. 21-C)
1308//
1309// Param#6 (Module Manufacturer ID):
1310// Byte 1 - Module Manufacturer ID, LSB
1311// Byte 2 - Module Manufacturer ID, MSB
1312//
1313ipmi_ret_t ipmiOemQGetDimmInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1314 ipmi_request_t request, ipmi_response_t response,
1315 ipmi_data_len_t data_len, ipmi_context_t context)
1316{
1317 qDimmInfo_t *req = reinterpret_cast<qDimmInfo_t *>(request);
1318 uint8_t numParam = sizeof(dimmInfoKey) / sizeof(uint8_t *);
1319 uint8_t *res = reinterpret_cast<uint8_t *>(response);
1320 std::stringstream ss;
1321 std::string str;
1322
1323 *data_len = 0;
1324
1325 /* check for requested data params */
1326 if (req->paramSel < 1 || req->paramSel >= numParam)
1327 {
1328 phosphor::logging::log<phosphor::logging::level::ERR>(
1329 "Invalid parameter received");
1330 return IPMI_CC_PARM_OUT_OF_RANGE;
1331 }
1332
1333 ss << std::hex;
1334 ss << std::setw(2) << std::setfill('0') << (int)req->dimmIndex;
1335
1336 if (oemData[KEY_Q_DIMM_INFO].find(ss.str()) ==
1337 oemData[KEY_Q_DIMM_INFO].end())
1338 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1339
1340 if (oemData[KEY_Q_DIMM_INFO][ss.str()].find(dimmInfoKey[req->paramSel]) ==
1341 oemData[KEY_Q_DIMM_INFO][ss.str()].end())
1342 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1343
1344 str = oemData[KEY_Q_DIMM_INFO][ss.str()][dimmInfoKey[req->paramSel]];
1345 *data_len = strToBytes(str, res);
1346
1347 return IPMI_CC_OK;
1348}
1349
1350//----------------------------------------------------------------------
1351// Set Drive Info (CMD_OEM_Q_SET_DRIVE_INFO)
1352//----------------------------------------------------------------------
1353// BIOS issue this command to provide HDD information to BMC.
1354//
1355// BIOS just can get information by standard ATA / SMART command for
1356// OB SATA controller.
1357// BIOS can get
1358// 1. Serial Number
1359// 2. Model Name
1360// 3. HDD FW Version
1361// 4. HDD Capacity
1362// 5. HDD WWN
1363//
1364// Use Get HDD info Param #5 to know the MAX HDD info index.
1365//
1366// Request:
1367// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1368// Byte 4 –
1369// [7:4] Reserved
1370// [3:0] HDD Controller Type
1371// 0x00 – BIOS
1372// 0x01 – Expander
1373// 0x02 – LSI
1374// Byte 5 – HDD Info Index, 0 base
1375// Byte 6 – Parameter Selector
1376// Byte 7..N – Configuration parameter data (see Table_1415h Parameters of HDD
1377// Information)
1378//
1379// Response:
1380// Byte 1 – Completion Code
1381//
1382// Param#0 (HDD Location):
1383// Byte 1 – Controller
1384// [7:3] Device Number
1385// [2:0] Function Number
1386// For Intel C610 series (Wellsburg)
1387// D31:F2 (0xFA) – SATA control 1
1388// D31:F5 (0xFD) – SATA control 2
1389// D17:F4 (0x8C) – sSata control
1390// Byte 2 – Port Number
1391// Byte 3 – Location (0xFF: No HDD Present)
1392// BIOS default set Byte 3 to 0xFF, if No HDD Present. And then skip send param
1393// #1~4, #6, #7 to BMC (still send param #5) BIOS default set Byte 3 to 0, if
1394// the HDD present. BMC or other people who know the HDD location has
1395// responsibility for update Location info
1396//
1397// Param#1 (Serial Number):
1398// Bytes 1..33: HDD Serial Number
1399//
1400// Param#2 (Model Name):
1401// Byte 1..33 – HDD Model Name
1402//
1403// Param#3 (HDD FW Version):
1404// Byte 1..17 –HDD FW version
1405//
1406// Param#4 (Capacity):
1407// Byte 1..4 –HDD Block Size, LSB
1408// Byte 5..12 - HDD Block Number, LSB
1409// HDD Capacity = HDD Block size * HDD BLock number (Unit Byte)
1410//
1411// Param#5 (Max HDD Quantity):
1412// Byte 1 - Max HDD Quantity
1413// Max supported port numbers in this PCH
1414//
1415// Param#6 (HDD Type)
1416// Byte 1 – HDD Type
1417// 0h – Reserved
1418// 1h – SAS
1419// 2h – SATA
1420// 3h – PCIE SSD (NVME)
1421//
1422// Param#7 (HDD WWN)
1423// Data 1...8: HDD World Wide Name, LSB
1424//
1425ipmi_ret_t ipmiOemQSetDriveInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1426 ipmi_request_t request,
1427 ipmi_response_t response,
1428 ipmi_data_len_t data_len,
1429 ipmi_context_t context)
1430{
1431 qDriveInfo_t *req = reinterpret_cast<qDriveInfo_t *>(request);
1432 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t *);
1433 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1434 std::stringstream ss;
1435 std::string str;
1436 uint8_t len = *data_len;
1437
1438 *data_len = 0;
1439
1440 /* check for requested data params */
1441 if (len < 6 || req->paramSel < 1 || req->paramSel >= numParam ||
1442 ctrlType > 2)
1443 {
1444 phosphor::logging::log<phosphor::logging::level::ERR>(
1445 "Invalid parameter received");
1446 return IPMI_CC_PARM_OUT_OF_RANGE;
1447 }
1448
1449 len = len - 6; // Get Actual data length
1450
1451 ss << std::hex;
1452 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1453 oemData[KEY_Q_DRIVE_INFO][KEY_HDD_CTRL_TYPE] = req->hddCtrlType;
1454 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()][KEY_HDD_INDEX] =
1455 req->hddIndex;
1456
1457 str = bytesToStr(req->data, len);
1458 oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
1459 [driveInfoKey[req->paramSel]] = str.c_str();
1460 flushOemData();
1461
1462 return IPMI_CC_OK;
1463}
1464
1465//----------------------------------------------------------------------
1466// Get Drive Info (CMD_OEM_Q_GET_DRIVE_INFO)
1467//----------------------------------------------------------------------
1468// BMC needs to check HDD presented or not first. If NOT presented, return
1469// completion code 0xD5.
1470//
1471// Request:
1472// Byte 1:3 – Quanta Manufacturer ID – 001C4Ch, LSB first
1473// Byte 4 –
1474//[7:4] Reserved
1475//[3:0] HDD Controller Type
1476// 0x00 – BIOS
1477// 0x01 – Expander
1478// 0x02 – LSI
1479// Byte 5 – HDD Index, 0 base
1480// Byte 6 – Parameter Selector (See Above Set HDD Information)
1481// Response:
1482// Byte 1 – Completion Code
1483// 0xD5 – Not support in current status (HDD Not Present)
1484// Byte 2..N – Configuration parameter data (see Table_1415h Parameters of HDD
1485// Information)
1486//
1487ipmi_ret_t ipmiOemQGetDriveInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1488 ipmi_request_t request,
1489 ipmi_response_t response,
1490 ipmi_data_len_t data_len,
1491 ipmi_context_t context)
1492{
1493 qDriveInfo_t *req = reinterpret_cast<qDriveInfo_t *>(request);
1494 uint8_t numParam = sizeof(driveInfoKey) / sizeof(uint8_t *);
1495 uint8_t *res = reinterpret_cast<uint8_t *>(response);
1496 uint8_t ctrlType = req->hddCtrlType & 0x0f;
1497 std::stringstream ss;
1498 std::string str;
1499
1500 *data_len = 0;
1501
1502 /* check for requested data params */
1503 if (req->paramSel < 1 || req->paramSel >= numParam || ctrlType > 2)
1504 {
1505 phosphor::logging::log<phosphor::logging::level::ERR>(
1506 "Invalid parameter received");
1507 return IPMI_CC_PARM_OUT_OF_RANGE;
1508 }
1509
1510 if (oemData[KEY_Q_DRIVE_INFO].find(ctrlTypeKey[ctrlType]) ==
1511 oemData[KEY_Q_DRIVE_INFO].end())
1512 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1513
1514 ss << std::hex;
1515 ss << std::setw(2) << std::setfill('0') << (int)req->hddIndex;
1516
1517 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]].find(ss.str()) ==
1518 oemData[KEY_Q_DRIVE_INFO].end())
1519 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1520
1521 if (oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()].find(
1522 dimmInfoKey[req->paramSel]) ==
1523 oemData[KEY_Q_DRIVE_INFO][ss.str()].end())
1524 return CC_PARAM_NOT_SUPP_IN_CURR_STATE;
1525
1526 str = oemData[KEY_Q_DRIVE_INFO][ctrlTypeKey[ctrlType]][ss.str()]
1527 [dimmInfoKey[req->paramSel]];
1528 *data_len = strToBytes(str, res);
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001529
1530 return IPMI_CC_OK;
1531}
1532
1533static void registerOEMFunctions(void)
1534{
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001535 /* Get OEM data from json file */
1536 std::ifstream file(JSON_OEM_DATA_FILE);
1537 if (file)
Vijay Khemkafeaa9812019-08-27 15:08:08 -07001538 {
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001539 file >> oemData;
Vijay Khemkafeaa9812019-08-27 15:08:08 -07001540 file.close();
1541 }
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001542
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001543 phosphor::logging::log<phosphor::logging::level::INFO>(
1544 "Registering OEM commands");
1545 ipmiPrintAndRegister(NETFUN_CHASSIS, 1, NULL, ipmiGetChassisStatus,
1546 PRIVILEGE_USER); // get chassis status
1547 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_INFO,
1548 NULL, ipmiOemDbgGetFrameInfo,
1549 PRIVILEGE_USER); // get debug frame info
1550 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ,
1551 CMD_OEM_USB_DBG_GET_UPDATED_FRAMES, NULL,
1552 ipmiOemDbgGetUpdFrames,
1553 PRIVILEGE_USER); // get debug updated frames
1554 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_POST_DESC,
1555 NULL, ipmiOemDbgGetPostDesc,
1556 PRIVILEGE_USER); // get debug post description
1557 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_GPIO_DESC,
1558 NULL, ipmiOemDbgGetGpioDesc,
1559 PRIVILEGE_USER); // get debug gpio description
1560 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_GET_FRAME_DATA,
1561 NULL, ipmiOemDbgGetFrameData,
1562 PRIVILEGE_USER); // get debug frame data
1563 ipmiPrintAndRegister(NETFN_OEM_USB_DBG_REQ, CMD_OEM_USB_DBG_CTRL_PANEL,
1564 NULL, ipmiOemDbgGetCtrlPanel,
1565 PRIVILEGE_USER); // get debug control panel
1566 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_DIMM_INFO, NULL,
1567 ipmiOemSetDimmInfo,
1568 PRIVILEGE_USER); // Set Dimm Info
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001569 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOARD_ID, NULL,
1570 ipmiOemGetBoardID,
1571 PRIVILEGE_USER); // Get Board ID
1572 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BOOT_ORDER, NULL,
1573 ipmiOemSetBootOrder,
1574 PRIVILEGE_USER); // Set Boot Order
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001575 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_BOOT_ORDER, NULL,
1576 ipmiOemGetBootOrder,
1577 PRIVILEGE_USER); // Get Boot Order
1578 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_MACHINE_CONFIG_INFO, NULL,
1579 ipmiOemSetMachineCfgInfo,
1580 PRIVILEGE_USER); // Set Machine Config Info
1581 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_START, NULL,
1582 ipmiOemSetPostStart,
1583 PRIVILEGE_USER); // Set POST start
1584 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_POST_END, NULL,
1585 ipmiOemSetPostEnd,
1586 PRIVILEGE_USER); // Set POST End
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001587 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPIN_INFO, NULL,
1588 ipmiOemSetPPINInfo,
1589 PRIVILEGE_USER); // Set PPIN Info
1590 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_ADR_TRIGGER, NULL,
1591 ipmiOemSetAdrTrigger,
1592 PRIVILEGE_USER); // Set ADR Trigger
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001593 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_BIOS_FLASH_INFO, NULL,
1594 ipmiOemSetBiosFlashInfo,
1595 PRIVILEGE_USER); // Set Bios Flash Info
1596 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_SET_PPR, NULL, ipmiOemSetPpr,
1597 PRIVILEGE_USER); // Set PPR
1598 ipmiPrintAndRegister(NETFUN_NONE, CMD_OEM_GET_PPR, NULL, ipmiOemGetPpr,
1599 PRIVILEGE_USER); // Get PPR
Vijay Khemka1d4a0692019-04-09 15:20:28 -07001600 /* FB OEM QC Commands */
1601 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_PROC_INFO, NULL,
1602 ipmiOemQSetProcInfo,
1603 PRIVILEGE_USER); // Set Proc Info
1604 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_PROC_INFO, NULL,
1605 ipmiOemQGetProcInfo,
1606 PRIVILEGE_USER); // Get Proc Info
1607 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DIMM_INFO, NULL,
1608 ipmiOemQSetDimmInfo,
1609 PRIVILEGE_USER); // Set Dimm Info
1610 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DIMM_INFO, NULL,
1611 ipmiOemQGetDimmInfo,
1612 PRIVILEGE_USER); // Get Dimm Info
1613 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_SET_DRIVE_INFO, NULL,
1614 ipmiOemQSetDriveInfo,
1615 PRIVILEGE_USER); // Set Drive Info
1616 ipmiPrintAndRegister(NETFUN_FB_OEM_QC, CMD_OEM_Q_GET_DRIVE_INFO, NULL,
1617 ipmiOemQGetDriveInfo,
1618 PRIVILEGE_USER); // Get Drive Info
Vijay Khemkae7d23d02019-03-08 13:13:40 -08001619 return;
1620}
1621
1622} // namespace ipmi