blob: 8c36c525ecfa48bf48b2317dc57ebab43c1f8fc4 [file] [log] [blame]
Steve Foreman4f0d1de2021-09-20 14:06:32 -07001// Copyright 2022 Google LLC
Willy Tua2056e92021-10-10 13:36:16 -07002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Patrick Venturef085d912019-03-15 08:50:00 -070015#pragma once
16
17#include <cstdint>
Willy Tuff3cd8e2021-09-14 22:49:55 -070018#include <ipmid/api-types.hpp>
Patrick Ventureab650002019-03-16 09:08:47 -070019#include <map>
Willy Tuff3cd8e2021-09-14 22:49:55 -070020#include <span>
Patrick Venturef085d912019-03-15 08:50:00 -070021#include <string>
Steve Foreman4f0d1de2021-09-20 14:06:32 -070022#include <string_view>
Patrick Venturef085d912019-03-15 08:50:00 -070023#include <tuple>
Patrick Venture49f23ad2019-03-16 11:59:55 -070024#include <vector>
Patrick Venturef085d912019-03-15 08:50:00 -070025
26namespace google
27{
28namespace ipmi
29{
30
Willy Tuff3cd8e2021-09-14 22:49:55 -070031using Resp = ::ipmi::RspType<std::uint8_t, std::vector<uint8_t>>;
32
Patrick Venturebb90d4f2019-03-15 13:42:06 -070033using VersionTuple =
34 std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>;
35
Patrick Venturef085d912019-03-15 08:50:00 -070036class HandlerInterface
37{
38 public:
39 virtual ~HandlerInterface() = default;
40
41 /**
42 * Return ethernet details (hard-coded).
43 *
44 * @return tuple of ethernet details (channel, if name).
45 */
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070046 virtual std::tuple<std::uint8_t, std::string>
47 getEthDetails(std::string intf) const = 0;
Patrick Ventured2037c62019-03-15 10:29:47 -070048
49 /**
50 * Return the value of rx_packets, given a if_name.
51 *
52 * @param[in] name, the interface name.
53 * @return the number of packets received.
54 * @throw IpmiException on failure.
55 */
56 virtual std::int64_t getRxPackets(const std::string& name) const = 0;
Patrick Venturebb90d4f2019-03-15 13:42:06 -070057
58 /**
59 * Return the values from a cpld version file.
60 *
61 * @param[in] id - the cpld id number.
62 * @return the quad of numbers as a tuple (maj,min,pt,subpt)
63 * @throw IpmiException on failure.
64 */
65 virtual VersionTuple getCpldVersion(unsigned int id) const = 0;
Patrick Ventureaa374122019-03-15 15:09:10 -070066
67 /**
68 * Set the PSU Reset delay.
69 *
70 * @param[in] delay - delay in seconds.
71 * @throw IpmiException on failure.
72 */
73 virtual void psuResetDelay(std::uint32_t delay) const = 0;
Patrick Venture07f85152019-03-15 21:36:56 -070074
75 /**
Shounak Mitraac4a16f2021-02-02 11:11:44 -080076 * Arm for PSU reset on host shutdown.
77 *
78 * @throw IpmiException on failure.
79 */
80 virtual void psuResetOnShutdown() const = 0;
81
82 /**
Patrick Venture07f85152019-03-15 21:36:56 -070083 * Return the entity name.
84 * On the first call to this method it'll build the list of entities.
85 * @todo Consider moving the list building to construction time (and ignore
86 * failures).
87 *
88 * @param[in] id - the entity id value
89 * @param[in] instance - the entity instance
90 * @return the entity's name
91 * @throw IpmiException on failure.
92 */
93 virtual std::string getEntityName(std::uint8_t id,
94 std::uint8_t instance) = 0;
Patrick Venture49f23ad2019-03-16 11:59:55 -070095
96 /**
Willy Tu3b1b4272021-03-02 17:58:10 -080097 * Return the flash size of bmc chip.
98 *
99 * @return the flash size of bmc chip
100 * @throw IpmiException on failure.
101 */
102 virtual uint32_t getFlashSize() = 0;
103
104 /**
William A. Kennington III29f35bc2020-11-03 23:30:31 -0800105 * Return the name of the machine, parsed from release information.
106 *
107 * @return the machine name
108 * @throw IpmiException on failure.
109 */
110 virtual std::string getMachineName() = 0;
111
112 /**
Patrick Venture49f23ad2019-03-16 11:59:55 -0700113 * Populate the i2c-pcie mapping vector.
114 */
115 virtual void buildI2cPcieMapping() = 0;
116
117 /**
118 * Return the size of the i2c-pcie mapping vector.
119 *
120 * @return the size of the vector holding the i2c-pcie mapping tuples.
121 */
122 virtual size_t getI2cPcieMappingSize() const = 0;
123
124 /**
125 * Return a copy of the entry in the vector.
126 *
127 * @param[in] entry - the index into the vector.
128 * @return the tuple at that index.
129 */
130 virtual std::tuple<std::uint32_t, std::string>
131 getI2cEntry(unsigned int entry) const = 0;
linyuny8cfa4c42021-06-16 13:53:08 -0700132
133 /**
134 * Set the Host Power Off delay.
135 *
136 * @param[in] delay - delay in seconds.
137 * @throw IpmiException on failure.
138 */
139 virtual void hostPowerOffDelay(std::uint32_t delay) const = 0;
Steve Foreman4f0d1de2021-09-20 14:06:32 -0700140
141 /**
142 * Return the number of devices from the CustomAccel service.
143 *
144 * @return the number of devices.
145 * @throw IpmiException on failure.
146 */
147 virtual uint32_t accelOobDeviceCount() const = 0;
148
149 /**
150 * Return the name of a single device from the CustomAccel service.
151 *
152 * Valid indexes start at 0 and go up to (but don't include) the number of
153 * devices. The number of devices can be queried with accelOobDeviceCount.
154 *
155 * @param[in] index - the index of the device, starting at 0.
156 * @return the name of the device.
157 * @throw IpmiException on failure.
158 */
159 virtual std::string accelOobDeviceName(size_t index) const = 0;
160
161 /**
162 * Read from a single CustomAccel service device.
163 *
164 * Valid device names can be queried with accelOobDeviceName.
165 * If num_bytes < 8, all unused MSBs are padded with 0s.
166 *
167 * @param[in] name - the name of the device (from DeviceName).
168 * @param[in] address - the address to read from.
169 * @param[in] num_bytes - the size of the read, in bytes.
170 * @return the data read, with 0s padding any unused MSBs.
171 * @throw IpmiException on failure.
172 */
173 virtual uint64_t accelOobRead(std::string_view name, uint64_t address,
174 uint8_t num_bytes) const = 0;
175
176 /**
177 * Write to a single CustomAccel service device.
178 *
179 * Valid device names can be queried with accelOobDeviceName.
180 * If num_bytes < 8, all unused MSBs are ignored.
181 *
182 * @param[in] name - the name of the device (from DeviceName).
183 * @param[in] address - the address to read from.
184 * @param[in] num_bytes - the size of the read, in bytes.
185 * @param[in] data - the data to write.
186 * @throw IpmiException on failure.
187 */
188 virtual void accelOobWrite(std::string_view name, uint64_t address,
189 uint8_t num_bytes, uint64_t data) const = 0;
Patrick Venturef085d912019-03-15 08:50:00 -0700190};
191
Patrick Venturef085d912019-03-15 08:50:00 -0700192} // namespace ipmi
193} // namespace google