Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "main.hpp" |
| 18 | |
| 19 | #include "cable.hpp" |
| 20 | #include "cpld.hpp" |
Jaghathiswari Rankappagounder Natarajan | fd0f1cf | 2019-01-18 15:31:07 -0800 | [diff] [blame] | 21 | #include "entity_name.hpp" |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 22 | #include "eth.hpp" |
Jaghathiswari Rankappagounder Natarajan | 2d4836d | 2018-11-29 14:16:39 -0800 | [diff] [blame] | 23 | #include "pcie_i2c.hpp" |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 24 | #include "psu.hpp" |
| 25 | |
William A. Kennington III | 2c9e162 | 2019-02-07 15:45:19 -0800 | [diff] [blame] | 26 | #include <ipmid/api.h> |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 27 | |
| 28 | #include <cstdint> |
Patrick Venture | 28557a1 | 2018-09-28 08:56:05 -0700 | [diff] [blame] | 29 | #include <cstdio> |
William A. Kennington III | 2c9e162 | 2019-02-07 15:45:19 -0800 | [diff] [blame] | 30 | #include <ipmid/iana.hpp> |
| 31 | #include <ipmid/oemrouter.hpp> |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 32 | |
| 33 | namespace oem |
| 34 | { |
| 35 | namespace google |
| 36 | { |
| 37 | constexpr int sysCmd = 50; |
| 38 | } // namespace google |
| 39 | } // namespace oem |
| 40 | |
| 41 | namespace google |
| 42 | { |
| 43 | namespace ipmi |
| 44 | { |
| 45 | |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 46 | static ipmi_ret_t handleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf, |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 47 | uint8_t* replyCmdBuf, size_t* dataLen) |
| 48 | { |
| 49 | // Verify it's at least as long as it needs to be for a subcommand. |
| 50 | if ((*dataLen) < 1) |
| 51 | { |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 52 | std::fprintf(stderr, "*dataLen too small: %u\n", |
| 53 | static_cast<uint32_t>(*dataLen)); |
Patrick Venture | fff9861 | 2018-11-12 09:05:54 -0800 | [diff] [blame] | 54 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | switch (reqBuf[0]) |
| 58 | { |
| 59 | case SysCableCheck: |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 60 | return cableCheck(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 61 | case SysCpldVersion: |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 62 | return cpldVersion(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 63 | case SysGetEthDevice: |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 64 | return getEthDevice(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 65 | case SysPsuHardReset: |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 66 | return psuHardReset(reqBuf, replyCmdBuf, dataLen); |
Jaghathiswari Rankappagounder Natarajan | 2d4836d | 2018-11-29 14:16:39 -0800 | [diff] [blame] | 67 | case SysPcieSlotCount: |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 68 | return pcieSlotCount(reqBuf, replyCmdBuf, dataLen); |
Jaghathiswari Rankappagounder Natarajan | 2d4836d | 2018-11-29 14:16:39 -0800 | [diff] [blame] | 69 | case SysPcieSlotI2cBusMapping: |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 70 | return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen); |
Jaghathiswari Rankappagounder Natarajan | fd0f1cf | 2019-01-18 15:31:07 -0800 | [diff] [blame] | 71 | case SysEntityName: |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 72 | return getEntityName(reqBuf, replyCmdBuf, dataLen); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 73 | default: |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 74 | std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 75 | return IPMI_CC_INVALID; |
| 76 | } |
| 77 | } |
| 78 | |
Patrick Venture | 96b088a | 2018-11-13 15:02:33 -0800 | [diff] [blame] | 79 | void setupGoogleOemSysCommands() __attribute__((constructor)); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 80 | |
Patrick Venture | 96b088a | 2018-11-13 15:02:33 -0800 | [diff] [blame] | 81 | void setupGoogleOemSysCommands() |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 82 | { |
| 83 | oem::Router* oemRouter = oem::mutableRouter(); |
| 84 | |
Patrick Venture | ce07ee0 | 2018-09-19 18:09:32 -0700 | [diff] [blame] | 85 | std::fprintf(stderr, |
| 86 | "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n", |
| 87 | oem::googOemNumber, oem::google::sysCmd); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 88 | |
| 89 | oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd, |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 90 | handleSysCommand); |
Patrick Venture | 4d49ae6 | 2018-09-17 11:35:32 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } // namespace ipmi |
| 94 | } // namespace google |