blob: f1cb516e9554faa9052e49c4318bed37319db94b [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"
Patrick Venturec87de552020-05-20 20:25:39 -070023#include "handler_impl.hpp"
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080024#include "pcie_i2c.hpp"
Patrick Venture4d49ae62018-09-17 11:35:32 -070025#include "psu.hpp"
26
William A. Kennington III2c9e1622019-02-07 15:45:19 -080027#include <ipmid/api.h>
Patrick Venture4d49ae62018-09-17 11:35:32 -070028
29#include <cstdint>
Patrick Venture28557a12018-09-28 08:56:05 -070030#include <cstdio>
William A. Kennington III2c9e1622019-02-07 15:45:19 -080031#include <ipmid/iana.hpp>
32#include <ipmid/oemrouter.hpp>
Patrick Venture4d49ae62018-09-17 11:35:32 -070033
34namespace oem
35{
36namespace google
37{
38constexpr int sysCmd = 50;
39} // namespace google
40} // namespace oem
41
42namespace google
43{
44namespace ipmi
45{
46
Patrick Venturec87de552020-05-20 20:25:39 -070047Handler handlerImpl;
48
Patrick Venture45fad1b2019-03-18 16:52:14 -070049static ipmi_ret_t handleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
Patrick Venture4d49ae62018-09-17 11:35:32 -070050 uint8_t* replyCmdBuf, size_t* dataLen)
51{
52 // Verify it's at least as long as it needs to be for a subcommand.
53 if ((*dataLen) < 1)
54 {
Patrick Venturece07ee02018-09-19 18:09:32 -070055 std::fprintf(stderr, "*dataLen too small: %u\n",
56 static_cast<uint32_t>(*dataLen));
Patrick Venturefff98612018-11-12 09:05:54 -080057 return IPMI_CC_REQ_DATA_LEN_INVALID;
Patrick Venture4d49ae62018-09-17 11:35:32 -070058 }
59
60 switch (reqBuf[0])
61 {
62 case SysCableCheck:
Patrick Venturec87de552020-05-20 20:25:39 -070063 return cableCheck(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
Patrick Venture4d49ae62018-09-17 11:35:32 -070064 case SysCpldVersion:
Patrick Venturec87de552020-05-20 20:25:39 -070065 return cpldVersion(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
Patrick Venture4d49ae62018-09-17 11:35:32 -070066 case SysGetEthDevice:
Patrick Venturec87de552020-05-20 20:25:39 -070067 return getEthDevice(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
Patrick Venture4d49ae62018-09-17 11:35:32 -070068 case SysPsuHardReset:
Patrick Venturec87de552020-05-20 20:25:39 -070069 return psuHardReset(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080070 case SysPcieSlotCount:
Patrick Venturec87de552020-05-20 20:25:39 -070071 return pcieSlotCount(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080072 case SysPcieSlotI2cBusMapping:
Patrick Venturec87de552020-05-20 20:25:39 -070073 return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen,
74 &handlerImpl);
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080075 case SysEntityName:
Patrick Venturec87de552020-05-20 20:25:39 -070076 return getEntityName(reqBuf, replyCmdBuf, dataLen, &handlerImpl);
Patrick Venture4d49ae62018-09-17 11:35:32 -070077 default:
Patrick Venturece07ee02018-09-19 18:09:32 -070078 std::fprintf(stderr, "Invalid subcommand: 0x%x\n", reqBuf[0]);
Patrick Venture4d49ae62018-09-17 11:35:32 -070079 return IPMI_CC_INVALID;
80 }
81}
82
Patrick Venture96b088a2018-11-13 15:02:33 -080083void setupGoogleOemSysCommands() __attribute__((constructor));
Patrick Venture4d49ae62018-09-17 11:35:32 -070084
Patrick Venture96b088a2018-11-13 15:02:33 -080085void setupGoogleOemSysCommands()
Patrick Venture4d49ae62018-09-17 11:35:32 -070086{
87 oem::Router* oemRouter = oem::mutableRouter();
88
Patrick Venturece07ee02018-09-19 18:09:32 -070089 std::fprintf(stderr,
90 "Registering OEM:[%#08X], Cmd:[%#04X] for Sys Commands\n",
91 oem::googOemNumber, oem::google::sysCmd);
Patrick Venture4d49ae62018-09-17 11:35:32 -070092
93 oemRouter->registerHandler(oem::googOemNumber, oem::google::sysCmd,
Patrick Venture45fad1b2019-03-18 16:52:14 -070094 handleSysCommand);
Patrick Venture4d49ae62018-09-17 11:35:32 -070095}
96
97} // namespace ipmi
98} // namespace google