Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 1 | // Copyright 2022 Google LLC |
Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 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. |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include "ipmi.hpp" |
| 16 | |
Brandon Kim | 93a4c0a | 2024-08-17 00:36:55 +0000 | [diff] [blame] | 17 | #include "bios_setting.hpp" |
Brandon Kim | 559cb01 | 2024-05-03 09:12:07 +0000 | [diff] [blame] | 18 | #include "bm_instance.hpp" |
Nikhil Namjoshi | 5e70dc8 | 2022-09-16 00:36:07 +0000 | [diff] [blame] | 19 | #include "bmc_mode.hpp" |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 20 | #include "cable.hpp" |
Patrick Venture | 0e9aae5 | 2020-08-13 13:07:09 -0700 | [diff] [blame] | 21 | #include "commands.hpp" |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 22 | #include "cpld.hpp" |
| 23 | #include "entity_name.hpp" |
| 24 | #include "eth.hpp" |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 25 | #include "flash_size.hpp" |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 26 | #include "google_accel_oob.hpp" |
Patrick Venture | 6d50744 | 2020-08-13 13:41:55 -0700 | [diff] [blame] | 27 | #include "handler.hpp" |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 28 | #include "host_power_off.hpp" |
John Wedig | a92d0e6 | 2023-06-29 10:43:47 -0700 | [diff] [blame] | 29 | #include "linux_boot_done.hpp" |
William A. Kennington III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 30 | #include "machine_name.hpp" |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 31 | #include "pcie_bifurcation.hpp" |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 32 | #include "pcie_i2c.hpp" |
| 33 | #include "psu.hpp" |
| 34 | |
| 35 | #include <ipmid/api.h> |
| 36 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 37 | #include <ipmid/api-types.hpp> |
| 38 | #include <ipmid/message.hpp> |
Michael Shen | 8d61853 | 2023-10-25 09:14:07 +0000 | [diff] [blame] | 39 | #include <stdplus/print.hpp> |
Patrick Williams | 444b5ea | 2023-05-19 13:56:42 -0500 | [diff] [blame] | 40 | |
| 41 | #include <cstdint> |
| 42 | #include <cstdio> |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 43 | #include <optional> |
Willy Tu | b4e3704 | 2021-10-12 17:12:30 -0700 | [diff] [blame] | 44 | #include <span> |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 45 | |
| 46 | namespace google |
| 47 | { |
| 48 | namespace ipmi |
| 49 | { |
| 50 | |
Gaurav Gandhi | d455bfd | 2024-01-29 22:32:27 -0800 | [diff] [blame] | 51 | Resp handleSysCommand(HandlerInterface* handler, ::ipmi::Context::ptr ctx, |
Willy Tu | b4e3704 | 2021-10-12 17:12:30 -0700 | [diff] [blame] | 52 | uint8_t cmd, std::span<const uint8_t> data) |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 53 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 54 | switch (cmd) |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 55 | { |
Nikhil Namjoshi | 5e70dc8 | 2022-09-16 00:36:07 +0000 | [diff] [blame] | 56 | case SysGetBmcMode: |
| 57 | return getBmcMode(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 58 | case SysCableCheck: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 59 | return cableCheck(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 60 | case SysCpldVersion: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 61 | return cpldVersion(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 62 | case SysGetEthDevice: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 63 | return getEthDevice(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 64 | case SysPsuHardReset: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 65 | return psuHardReset(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 66 | case SysPcieSlotCount: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 67 | return pcieSlotCount(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 68 | case SysPcieSlotI2cBusMapping: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 69 | return pcieSlotI2cBusMapping(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 70 | case SysEntityName: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 71 | return getEntityName(data, handler); |
William A. Kennington III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 72 | case SysMachineName: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 73 | return getMachineName(data, handler); |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 74 | case SysPsuHardResetOnShutdown: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 75 | return psuHardResetOnShutdown(data, handler); |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 76 | case SysGetFlashSize: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 77 | return getFlashSize(data, handler); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 78 | case SysHostPowerOff: |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 79 | return hostPowerOff(data, handler); |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 80 | case SysAccelOobDeviceCount: |
| 81 | return accelOobDeviceCount(data, handler); |
| 82 | case SysAccelOobDeviceName: |
| 83 | return accelOobDeviceName(data, handler); |
| 84 | case SysAccelOobRead: |
| 85 | return accelOobRead(data, handler); |
| 86 | case SysAccelOobWrite: |
| 87 | return accelOobWrite(data, handler); |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 88 | case SysPCIeSlotBifurcation: |
| 89 | return pcieBifurcation(data, handler); |
John Wedig | a92d0e6 | 2023-06-29 10:43:47 -0700 | [diff] [blame] | 90 | case SysLinuxBootDone: |
| 91 | return linuxBootDone(data, handler); |
Gaurav Gandhi | d455bfd | 2024-01-29 22:32:27 -0800 | [diff] [blame] | 92 | case SysGetAccelVrSettings: |
| 93 | return accelGetVrSettings(ctx, data, handler); |
| 94 | case SysSetAccelVrSettings: |
| 95 | return accelSetVrSettings(ctx, data, handler); |
Brandon Kim | 559cb01 | 2024-05-03 09:12:07 +0000 | [diff] [blame] | 96 | case SysGetBMInstanceProperty: |
| 97 | return getBMInstanceProperty(data, handler); |
Brandon Kim | 93a4c0a | 2024-08-17 00:36:55 +0000 | [diff] [blame] | 98 | case SysReadBiosSetting: |
| 99 | return readBiosSetting(data, handler); |
Brandon Kim | e892969 | 2024-08-19 22:00:36 +0000 | [diff] [blame] | 100 | case SysWriteBiosSetting: |
| 101 | return writeBiosSetting(data, handler); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 102 | default: |
Michael Shen | 8d61853 | 2023-10-25 09:14:07 +0000 | [diff] [blame] | 103 | stdplus::print(stderr, "Invalid subcommand: {:#x}\n", cmd); |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 104 | return ::ipmi::responseInvalidCommand(); |
Patrick Venture | eff1f2e | 2020-08-05 08:27:36 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | } // namespace ipmi |
| 109 | } // namespace google |