blob: 3b0a3725dc33b8e01f3d76dc1e68b615f03eb86c [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
Willy Tuff3cd8e2021-09-14 22:49:55 -070017#include <ipmid/api-types.hpp>
Patrick Williams444b5ea2023-05-19 13:56:42 -050018
19#include <cstdint>
Patrick Ventureab650002019-03-16 09:08:47 -070020#include <map>
Willy Tuff3cd8e2021-09-14 22:49:55 -070021#include <span>
Patrick Venturef085d912019-03-15 08:50:00 -070022#include <string>
Steve Foreman4f0d1de2021-09-20 14:06:32 -070023#include <string_view>
Patrick Venturef085d912019-03-15 08:50:00 -070024#include <tuple>
Patrick Venture49f23ad2019-03-16 11:59:55 -070025#include <vector>
Patrick Venturef085d912019-03-15 08:50:00 -070026
27namespace google
28{
29namespace ipmi
30{
31
Willy Tuff3cd8e2021-09-14 22:49:55 -070032using Resp = ::ipmi::RspType<std::uint8_t, std::vector<uint8_t>>;
33
Patrick Venturebb90d4f2019-03-15 13:42:06 -070034using VersionTuple =
35 std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>;
36
Patrick Venturef085d912019-03-15 08:50:00 -070037class HandlerInterface
38{
39 public:
40 virtual ~HandlerInterface() = default;
41
42 /**
Nikhil Namjoshi5e70dc82022-09-16 00:36:07 +000043 * Return the operation mode of BMC
44 *
45 * @return the BMC operation mode
46 */
47 virtual uint8_t getBmcMode() = 0;
48
49 /**
Patrick Venturef085d912019-03-15 08:50:00 -070050 * Return ethernet details (hard-coded).
51 *
52 * @return tuple of ethernet details (channel, if name).
53 */
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070054 virtual std::tuple<std::uint8_t, std::string>
55 getEthDetails(std::string intf) const = 0;
Patrick Ventured2037c62019-03-15 10:29:47 -070056
57 /**
58 * Return the value of rx_packets, given a if_name.
59 *
60 * @param[in] name, the interface name.
61 * @return the number of packets received.
62 * @throw IpmiException on failure.
63 */
64 virtual std::int64_t getRxPackets(const std::string& name) const = 0;
Patrick Venturebb90d4f2019-03-15 13:42:06 -070065
66 /**
67 * Return the values from a cpld version file.
68 *
69 * @param[in] id - the cpld id number.
70 * @return the quad of numbers as a tuple (maj,min,pt,subpt)
71 * @throw IpmiException on failure.
72 */
73 virtual VersionTuple getCpldVersion(unsigned int id) const = 0;
Patrick Ventureaa374122019-03-15 15:09:10 -070074
75 /**
76 * Set the PSU Reset delay.
77 *
78 * @param[in] delay - delay in seconds.
79 * @throw IpmiException on failure.
80 */
81 virtual void psuResetDelay(std::uint32_t delay) const = 0;
Patrick Venture07f85152019-03-15 21:36:56 -070082
83 /**
Shounak Mitraac4a16f2021-02-02 11:11:44 -080084 * Arm for PSU reset on host shutdown.
85 *
86 * @throw IpmiException on failure.
87 */
88 virtual void psuResetOnShutdown() const = 0;
89
90 /**
Patrick Venture07f85152019-03-15 21:36:56 -070091 * Return the entity name.
92 * On the first call to this method it'll build the list of entities.
93 * @todo Consider moving the list building to construction time (and ignore
94 * failures).
95 *
96 * @param[in] id - the entity id value
97 * @param[in] instance - the entity instance
98 * @return the entity's name
99 * @throw IpmiException on failure.
100 */
101 virtual std::string getEntityName(std::uint8_t id,
102 std::uint8_t instance) = 0;
Patrick Venture49f23ad2019-03-16 11:59:55 -0700103
104 /**
Willy Tu3b1b4272021-03-02 17:58:10 -0800105 * Return the flash size of bmc chip.
106 *
107 * @return the flash size of bmc chip
108 * @throw IpmiException on failure.
109 */
110 virtual uint32_t getFlashSize() = 0;
111
112 /**
William A. Kennington III29f35bc2020-11-03 23:30:31 -0800113 * Return the name of the machine, parsed from release information.
114 *
115 * @return the machine name
116 * @throw IpmiException on failure.
117 */
118 virtual std::string getMachineName() = 0;
119
120 /**
Patrick Venture49f23ad2019-03-16 11:59:55 -0700121 * Populate the i2c-pcie mapping vector.
122 */
123 virtual void buildI2cPcieMapping() = 0;
124
125 /**
126 * Return the size of the i2c-pcie mapping vector.
127 *
128 * @return the size of the vector holding the i2c-pcie mapping tuples.
129 */
130 virtual size_t getI2cPcieMappingSize() const = 0;
131
132 /**
133 * Return a copy of the entry in the vector.
134 *
135 * @param[in] entry - the index into the vector.
136 * @return the tuple at that index.
137 */
138 virtual std::tuple<std::uint32_t, std::string>
139 getI2cEntry(unsigned int entry) const = 0;
linyuny8cfa4c42021-06-16 13:53:08 -0700140
141 /**
142 * Set the Host Power Off delay.
143 *
144 * @param[in] delay - delay in seconds.
145 * @throw IpmiException on failure.
146 */
147 virtual void hostPowerOffDelay(std::uint32_t delay) const = 0;
Steve Foreman4f0d1de2021-09-20 14:06:32 -0700148
149 /**
150 * Return the number of devices from the CustomAccel service.
151 *
152 * @return the number of devices.
153 * @throw IpmiException on failure.
154 */
155 virtual uint32_t accelOobDeviceCount() const = 0;
156
157 /**
158 * Return the name of a single device from the CustomAccel service.
159 *
160 * Valid indexes start at 0 and go up to (but don't include) the number of
161 * devices. The number of devices can be queried with accelOobDeviceCount.
162 *
163 * @param[in] index - the index of the device, starting at 0.
164 * @return the name of the device.
165 * @throw IpmiException on failure.
166 */
167 virtual std::string accelOobDeviceName(size_t index) const = 0;
168
169 /**
170 * Read from a single CustomAccel service device.
171 *
172 * Valid device names can be queried with accelOobDeviceName.
173 * If num_bytes < 8, all unused MSBs are padded with 0s.
174 *
175 * @param[in] name - the name of the device (from DeviceName).
176 * @param[in] address - the address to read from.
177 * @param[in] num_bytes - the size of the read, in bytes.
178 * @return the data read, with 0s padding any unused MSBs.
179 * @throw IpmiException on failure.
180 */
181 virtual uint64_t accelOobRead(std::string_view name, uint64_t address,
182 uint8_t num_bytes) const = 0;
183
184 /**
185 * Write to a single CustomAccel service device.
186 *
187 * Valid device names can be queried with accelOobDeviceName.
188 * If num_bytes < 8, all unused MSBs are ignored.
189 *
190 * @param[in] name - the name of the device (from DeviceName).
191 * @param[in] address - the address to read from.
192 * @param[in] num_bytes - the size of the read, in bytes.
193 * @param[in] data - the data to write.
194 * @throw IpmiException on failure.
195 */
196 virtual void accelOobWrite(std::string_view name, uint64_t address,
197 uint8_t num_bytes, uint64_t data) const = 0;
Willy Tu6c71b0f2021-10-10 13:34:41 -0700198
199 /**
Willy Tu7e71a432022-07-07 14:43:27 -0700200 * Parse the I2C tree to get the highest level of bifurcation in target bus.
Willy Tu6c71b0f2021-10-10 13:34:41 -0700201 *
202 * @param[in] index - PCIe Slot Index
203 * @return list of lanes taken by each device.
204 */
205 virtual std::vector<uint8_t> pcieBifurcation(uint8_t index) = 0;
Patrick Venturef085d912019-03-15 08:50:00 -0700206};
207
Patrick Venturef085d912019-03-15 08:50:00 -0700208} // namespace ipmi
209} // namespace google