blob: 372cc04a8ce58c2483235bb4d5fdbad986f6dc74 [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
Patrick Venture45fad1b2019-03-18 16:52:14 -070046static ipmi_ret_t handleSysCommand(ipmi_cmd_t cmd, const uint8_t* reqBuf,
Patrick Venture4d49ae62018-09-17 11:35:32 -070047 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:
Patrick Venture45fad1b2019-03-18 16:52:14 -070060 return cableCheck(reqBuf, replyCmdBuf, dataLen);
Patrick Venture4d49ae62018-09-17 11:35:32 -070061 case SysCpldVersion:
Patrick Venture45fad1b2019-03-18 16:52:14 -070062 return cpldVersion(reqBuf, replyCmdBuf, dataLen);
Patrick Venture4d49ae62018-09-17 11:35:32 -070063 case SysGetEthDevice:
Patrick Venture45fad1b2019-03-18 16:52:14 -070064 return getEthDevice(reqBuf, replyCmdBuf, dataLen);
Patrick Venture4d49ae62018-09-17 11:35:32 -070065 case SysPsuHardReset:
Patrick Venture45fad1b2019-03-18 16:52:14 -070066 return psuHardReset(reqBuf, replyCmdBuf, dataLen);
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080067 case SysPcieSlotCount:
Patrick Venture45fad1b2019-03-18 16:52:14 -070068 return pcieSlotCount(reqBuf, replyCmdBuf, dataLen);
Jaghathiswari Rankappagounder Natarajan2d4836d2018-11-29 14:16:39 -080069 case SysPcieSlotI2cBusMapping:
Patrick Venture45fad1b2019-03-18 16:52:14 -070070 return pcieSlotI2cBusMapping(reqBuf, replyCmdBuf, dataLen);
Jaghathiswari Rankappagounder Natarajanfd0f1cf2019-01-18 15:31:07 -080071 case SysEntityName:
Patrick Venture45fad1b2019-03-18 16:52:14 -070072 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,
Patrick Venture45fad1b2019-03-18 16:52:14 -070090 handleSysCommand);
Patrick Venture4d49ae62018-09-17 11:35:32 -070091}
92
93} // namespace ipmi
94} // namespace google