blob: fce8c54dade12258d51f520292e002b61fe42ee4 [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"
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080021#include "entity_name.hpp"
Patrick Venture4d49ae62018-09-17 11:35:32 -070022#include "eth.hpp"
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080023#include "pcie_i2c.hpp"
Patrick Venture4d49ae62018-09-17 11:35:32 -070024#include "psu.hpp"
25
William A. Kennington III2c9e1622019-02-07 15:45:19 -080026#include <ipmid/api.h>
Patrick Venture4d49ae62018-09-17 11:35:32 -070027
28#include <cstdint>
Patrick Venture28557a12018-09-28 08:56:05 -070029#include <cstdio>
William A. Kennington III2c9e1622019-02-07 15:45:19 -080030#include <ipmid/iana.hpp>
31#include <ipmid/oemrouter.hpp>
Patrick Venture4d49ae62018-09-17 11:35:32 -070032
33namespace oem
34{
35namespace google
36{
37constexpr int sysCmd = 50;
38} // namespace google
39} // namespace oem
40
41namespace google
42{
43namespace ipmi
44{
45
46static ipmi_ret_t HandleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
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 Venturece07ee02018-09-19 18:09:32 -070052 std::fprintf(stderr, "*dataLen too small: %u\n",
53 static_cast<uint32_t>(*dataLen));
Patrick Venturefff98612018-11-12 09:05:54 -080054 return IPMI_CC_REQ_DATA_LEN_INVALID;
Patrick Venture4d49ae62018-09-17 11:35:32 -070055 }
56
57 switch (reqBuf[0])
58 {
59 case SysCableCheck:
60 return CableCheck(reqBuf, replyCmdBuf, dataLen);
61 case SysCpldVersion:
62 return CpldVersion(reqBuf, replyCmdBuf, dataLen);
63 case SysGetEthDevice:
64 return GetEthDevice(reqBuf, replyCmdBuf, dataLen);
65 case SysPsuHardReset:
66 return PsuHardReset(reqBuf, replyCmdBuf, dataLen);
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080067 case SysPcieSlotCount:
68 return PcieSlotCount(reqBuf, replyCmdBuf, dataLen);
69 case SysPcieSlotI2cBusMapping:
70 return PcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen);
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080071 case SysEntityName:
72 return GetEntityName(reqBuf, replyCmdBuf, dataLen);
Patrick Venture4d49ae62018-09-17 11:35:32 -070073 default:
Patrick Venturece07ee02018-09-19 18:09:32 -070074 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
Patrick Venture4d49ae62018-09-17 11:35:32 -070075 return IPMI_CC_INVALID;
76 }
77}
78
Patrick Venture96b088a2018-11-13 15:02:33 -080079void setupGoogleOemSysCommands() __attribute__((constructor));
Patrick Venture4d49ae62018-09-17 11:35:32 -070080
Patrick Venture96b088a2018-11-13 15:02:33 -080081void setupGoogleOemSysCommands()
Patrick Venture4d49ae62018-09-17 11:35:32 -070082{
83 oem::Router* oemRouter = oem::mutableRouter();
84
Patrick Venturece07ee02018-09-19 18:09:32 -070085 std::fprintf(stderr,
86 "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
87 oem::googOemNumber, oem::google::sysCmd);
Patrick Venture4d49ae62018-09-17 11:35:32 -070088
89 oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
90 HandleSysCommand);
91}
92
93} // namespace ipmi
94} // namespace google