blob: f0c61a9b6cddf6d22f2338659eae49a8fb96e28b [file] [log] [blame]
Patrick Venture4d49ae62018-09-17 11:35:32 -07001/*
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"
21#include "eth.hpp"
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080022#include "pcie_i2c.hpp"
Patrick Venture4d49ae62018-09-17 11:35:32 -070023#include "psu.hpp"
24
25#include <host-ipmid/ipmid-api.h>
26
27#include <cstdint>
Patrick Venture28557a12018-09-28 08:56:05 -070028#include <cstdio>
Patrick Venture4d49ae62018-09-17 11:35:32 -070029#include <host-ipmid/iana.hpp>
30#include <host-ipmid/oemrouter.hpp>
Patrick Venture4d49ae62018-09-17 11:35:32 -070031
32namespace oem
33{
34namespace google
35{
36constexpr int sysCmd = 50;
37} // namespace google
38} // namespace oem
39
40namespace google
41{
42namespace ipmi
43{
44
45static ipmi_ret_t HandleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
46 uint8_t* replyCmdBuf, size_t* dataLen)
47{
48 // Verify it's at least as long as it needs to be for a subcommand.
49 if ((*dataLen) < 1)
50 {
Patrick Venturece07ee02018-09-19 18:09:32 -070051 std::fprintf(stderr, "*dataLen too small: %u\n",
52 static_cast<uint32_t>(*dataLen));
Patrick Venturefff98612018-11-12 09:05:54 -080053 return IPMI_CC_REQ_DATA_LEN_INVALID;
Patrick Venture4d49ae62018-09-17 11:35:32 -070054 }
55
56 switch (reqBuf[0])
57 {
58 case SysCableCheck:
59 return CableCheck(reqBuf, replyCmdBuf, dataLen);
60 case SysCpldVersion:
61 return CpldVersion(reqBuf, replyCmdBuf, dataLen);
62 case SysGetEthDevice:
63 return GetEthDevice(reqBuf, replyCmdBuf, dataLen);
64 case SysPsuHardReset:
65 return PsuHardReset(reqBuf, replyCmdBuf, dataLen);
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080066 case SysPcieSlotCount:
67 return PcieSlotCount(reqBuf, replyCmdBuf, dataLen);
68 case SysPcieSlotI2cBusMapping:
69 return PcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen);
Patrick Venture4d49ae62018-09-17 11:35:32 -070070 default:
Patrick Venturece07ee02018-09-19 18:09:32 -070071 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
Patrick Venture4d49ae62018-09-17 11:35:32 -070072 return IPMI_CC_INVALID;
73 }
74}
75
Patrick Venture96b088a2018-11-13 15:02:33 -080076void setupGoogleOemSysCommands() __attribute__((constructor));
Patrick Venture4d49ae62018-09-17 11:35:32 -070077
Patrick Venture96b088a2018-11-13 15:02:33 -080078void setupGoogleOemSysCommands()
Patrick Venture4d49ae62018-09-17 11:35:32 -070079{
80 oem::Router* oemRouter = oem::mutableRouter();
81
Patrick Venturece07ee02018-09-19 18:09:32 -070082 std::fprintf(stderr,
83 "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
84 oem::googOemNumber, oem::google::sysCmd);
Patrick Venture4d49ae62018-09-17 11:35:32 -070085
86 oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
87 HandleSysCommand);
88}
89
90} // namespace ipmi
91} // namespace google