xref: /openbmc/google-ipmi-sys/ipmi.cpp (revision 559cb011)
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 "bm_instance.hpp"
18 #include "bmc_mode.hpp"
19 #include "cable.hpp"
20 #include "commands.hpp"
21 #include "cpld.hpp"
22 #include "entity_name.hpp"
23 #include "eth.hpp"
24 #include "flash_size.hpp"
25 #include "google_accel_oob.hpp"
26 #include "handler.hpp"
27 #include "host_power_off.hpp"
28 #include "linux_boot_done.hpp"
29 #include "machine_name.hpp"
30 #include "pcie_bifurcation.hpp"
31 #include "pcie_i2c.hpp"
32 #include "psu.hpp"
33 
34 #include <ipmid/api.h>
35 
36 #include <ipmid/api-types.hpp>
37 #include <ipmid/message.hpp>
38 #include <stdplus/print.hpp>
39 
40 #include <cstdint>
41 #include <cstdio>
42 #include <optional>
43 #include <span>
44 
45 namespace google
46 {
47 namespace ipmi
48 {
49 
50 Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr ctx,
51                       uint8_t cmd, std::span<const uint8_t> data)
52 {
53     switch (cmd)
54     {
55         case SysGetBmcMode:
56             return getBmcMode(data, handler);
57         case SysCableCheck:
58             return cableCheck(data, handler);
59         case SysCpldVersion:
60             return cpldVersion(data, handler);
61         case SysGetEthDevice:
62             return getEthDevice(data, handler);
63         case SysPsuHardReset:
64             return psuHardReset(data, handler);
65         case SysPcieSlotCount:
66             return pcieSlotCount(data, handler);
67         case SysPcieSlotI2cBusMapping:
68             return pcieSlotI2cBusMapping(data, handler);
69         case SysEntityName:
70             return getEntityName(data, handler);
71         case SysMachineName:
72             return getMachineName(data, handler);
73         case SysPsuHardResetOnShutdown:
74             return psuHardResetOnShutdown(data, handler);
75         case SysGetFlashSize:
76             return getFlashSize(data, handler);
77         case SysHostPowerOff:
78             return hostPowerOff(data, handler);
79         case SysAccelOobDeviceCount:
80             return accelOobDeviceCount(data, handler);
81         case SysAccelOobDeviceName:
82             return accelOobDeviceName(data, handler);
83         case SysAccelOobRead:
84             return accelOobRead(data, handler);
85         case SysAccelOobWrite:
86             return accelOobWrite(data, handler);
87         case SysPCIeSlotBifurcation:
88             return pcieBifurcation(data, handler);
89         case SysLinuxBootDone:
90             return linuxBootDone(data, handler);
91         case SysGetAccelVrSettings:
92             return accelGetVrSettings(ctx, data, handler);
93         case SysSetAccelVrSettings:
94             return accelSetVrSettings(ctx, data, handler);
95         case SysGetBMInstanceProperty:
96             return getBMInstanceProperty(data, handler);
97         default:
98             stdplus::print(stderr, "Invalid subcommand: {:#x}\n", cmd);
99             return ::ipmi::responseInvalidCommand();
100     }
101 }
102 
103 } // namespace ipmi
104 } // namespace google
105