xref: /openbmc/google-ipmi-sys/ipmi.cpp (revision d455bfd6)
1 // Copyright 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "ipmi.hpp"
16 
17 #include "bmc_mode.hpp"
18 #include "cable.hpp"
19 #include "commands.hpp"
20 #include "cpld.hpp"
21 #include "entity_name.hpp"
22 #include "eth.hpp"
23 #include "flash_size.hpp"
24 #include "google_accel_oob.hpp"
25 #include "handler.hpp"
26 #include "host_power_off.hpp"
27 #include "linux_boot_done.hpp"
28 #include "machine_name.hpp"
29 #include "pcie_bifurcation.hpp"
30 #include "pcie_i2c.hpp"
31 #include "psu.hpp"
32 
33 #include <ipmid/api.h>
34 
35 #include <ipmid/api-types.hpp>
36 #include <ipmid/message.hpp>
37 #include <stdplus/print.hpp>
38 
39 #include <cstdint>
40 #include <cstdio>
41 #include <optional>
42 #include <span>
43 
44 namespace google
45 {
46 namespace ipmi
47 {
48 
49 Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr ctx,
50                       uint8_t cmd, std::span<const uint8_t> data)
51 {
52     switch (cmd)
53     {
54         case SysGetBmcMode:
55             return getBmcMode(data, handler);
56         case SysCableCheck:
57             return cableCheck(data, handler);
58         case SysCpldVersion:
59             return cpldVersion(data, handler);
60         case SysGetEthDevice:
61             return getEthDevice(data, handler);
62         case SysPsuHardReset:
63             return psuHardReset(data, handler);
64         case SysPcieSlotCount:
65             return pcieSlotCount(data, handler);
66         case SysPcieSlotI2cBusMapping:
67             return pcieSlotI2cBusMapping(data, handler);
68         case SysEntityName:
69             return getEntityName(data, handler);
70         case SysMachineName:
71             return getMachineName(data, handler);
72         case SysPsuHardResetOnShutdown:
73             return psuHardResetOnShutdown(data, handler);
74         case SysGetFlashSize:
75             return getFlashSize(data, handler);
76         case SysHostPowerOff:
77             return hostPowerOff(data, handler);
78         case SysAccelOobDeviceCount:
79             return accelOobDeviceCount(data, handler);
80         case SysAccelOobDeviceName:
81             return accelOobDeviceName(data, handler);
82         case SysAccelOobRead:
83             return accelOobRead(data, handler);
84         case SysAccelOobWrite:
85             return accelOobWrite(data, handler);
86         case SysPCIeSlotBifurcation:
87             return pcieBifurcation(data, handler);
88         case SysLinuxBootDone:
89             return linuxBootDone(data, handler);
90         case SysGetAccelVrSettings:
91             return accelGetVrSettings(ctx, data, handler);
92         case SysSetAccelVrSettings:
93             return accelSetVrSettings(ctx, data, handler);
94         default:
95             stdplus::print(stderr, "Invalid subcommand: {:#x}\n", cmd);
96             return ::ipmi::responseInvalidCommand();
97     }
98 }
99 
100 } // namespace ipmi
101 } // namespace google
102