blob: 50bfb0286f3f48d3b049d8e00318180fb781dcc5 [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>
Gaurav Gandhid455bfd2024-01-29 22:32:27 -080018#include <ipmid/message.hpp>
Patrick Williams444b5ea2023-05-19 13:56:42 -050019
20#include <cstdint>
Patrick Ventureab650002019-03-16 09:08:47 -070021#include <map>
Willy Tuff3cd8e2021-09-14 22:49:55 -070022#include <span>
Patrick Venturef085d912019-03-15 08:50:00 -070023#include <string>
Steve Foreman4f0d1de2021-09-20 14:06:32 -070024#include <string_view>
Patrick Venturef085d912019-03-15 08:50:00 -070025#include <tuple>
Patrick Venture49f23ad2019-03-16 11:59:55 -070026#include <vector>
Patrick Venturef085d912019-03-15 08:50:00 -070027
28namespace google
29{
30namespace ipmi
31{
32
Willy Tuff3cd8e2021-09-14 22:49:55 -070033using Resp = ::ipmi::RspType<std::uint8_t, std::vector<uint8_t>>;
34
Patrick Venturebb90d4f2019-03-15 13:42:06 -070035using VersionTuple =
36 std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>;
37
Patrick Venturef085d912019-03-15 08:50:00 -070038class HandlerInterface
39{
40 public:
41 virtual ~HandlerInterface() = default;
42
43 /**
Nikhil Namjoshi5e70dc82022-09-16 00:36:07 +000044 * Return the operation mode of BMC
45 *
46 * @return the BMC operation mode
47 */
48 virtual uint8_t getBmcMode() = 0;
49
50 /**
Patrick Venturef085d912019-03-15 08:50:00 -070051 * Return ethernet details (hard-coded).
52 *
53 * @return tuple of ethernet details (channel, if name).
54 */
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070055 virtual std::tuple<std::uint8_t, std::string>
56 getEthDetails(std::string intf) const = 0;
Patrick Ventured2037c62019-03-15 10:29:47 -070057
58 /**
59 * Return the value of rx_packets, given a if_name.
60 *
61 * @param[in] name, the interface name.
62 * @return the number of packets received.
63 * @throw IpmiException on failure.
64 */
65 virtual std::int64_t getRxPackets(const std::string& name) const = 0;
Patrick Venturebb90d4f2019-03-15 13:42:06 -070066
67 /**
68 * Return the values from a cpld version file.
69 *
70 * @param[in] id - the cpld id number.
71 * @return the quad of numbers as a tuple (maj,min,pt,subpt)
72 * @throw IpmiException on failure.
73 */
74 virtual VersionTuple getCpldVersion(unsigned int id) const = 0;
Patrick Ventureaa374122019-03-15 15:09:10 -070075
76 /**
77 * Set the PSU Reset delay.
78 *
79 * @param[in] delay - delay in seconds.
80 * @throw IpmiException on failure.
81 */
82 virtual void psuResetDelay(std::uint32_t delay) const = 0;
Patrick Venture07f85152019-03-15 21:36:56 -070083
84 /**
Shounak Mitraac4a16f2021-02-02 11:11:44 -080085 * Arm for PSU reset on host shutdown.
86 *
87 * @throw IpmiException on failure.
88 */
89 virtual void psuResetOnShutdown() const = 0;
90
91 /**
Patrick Venture07f85152019-03-15 21:36:56 -070092 * Return the entity name.
93 * On the first call to this method it'll build the list of entities.
94 * @todo Consider moving the list building to construction time (and ignore
95 * failures).
96 *
97 * @param[in] id - the entity id value
98 * @param[in] instance - the entity instance
99 * @return the entity's name
100 * @throw IpmiException on failure.
101 */
102 virtual std::string getEntityName(std::uint8_t id,
103 std::uint8_t instance) = 0;
Patrick Venture49f23ad2019-03-16 11:59:55 -0700104
105 /**
Willy Tu3b1b4272021-03-02 17:58:10 -0800106 * Return the flash size of bmc chip.
107 *
108 * @return the flash size of bmc chip
109 * @throw IpmiException on failure.
110 */
111 virtual uint32_t getFlashSize() = 0;
112
113 /**
William A. Kennington III29f35bc2020-11-03 23:30:31 -0800114 * Return the name of the machine, parsed from release information.
115 *
116 * @return the machine name
117 * @throw IpmiException on failure.
118 */
119 virtual std::string getMachineName() = 0;
120
121 /**
Patrick Venture49f23ad2019-03-16 11:59:55 -0700122 * Populate the i2c-pcie mapping vector.
123 */
124 virtual void buildI2cPcieMapping() = 0;
125
126 /**
127 * Return the size of the i2c-pcie mapping vector.
128 *
129 * @return the size of the vector holding the i2c-pcie mapping tuples.
130 */
131 virtual size_t getI2cPcieMappingSize() const = 0;
132
133 /**
134 * Return a copy of the entry in the vector.
135 *
136 * @param[in] entry - the index into the vector.
137 * @return the tuple at that index.
138 */
139 virtual std::tuple<std::uint32_t, std::string>
140 getI2cEntry(unsigned int entry) const = 0;
linyuny8cfa4c42021-06-16 13:53:08 -0700141
142 /**
143 * Set the Host Power Off delay.
144 *
145 * @param[in] delay - delay in seconds.
146 * @throw IpmiException on failure.
147 */
148 virtual void hostPowerOffDelay(std::uint32_t delay) const = 0;
Steve Foreman4f0d1de2021-09-20 14:06:32 -0700149
150 /**
151 * Return the number of devices from the CustomAccel service.
152 *
153 * @return the number of devices.
154 * @throw IpmiException on failure.
155 */
156 virtual uint32_t accelOobDeviceCount() const = 0;
157
158 /**
159 * Return the name of a single device from the CustomAccel service.
160 *
161 * Valid indexes start at 0 and go up to (but don't include) the number of
162 * devices. The number of devices can be queried with accelOobDeviceCount.
163 *
164 * @param[in] index - the index of the device, starting at 0.
165 * @return the name of the device.
166 * @throw IpmiException on failure.
167 */
168 virtual std::string accelOobDeviceName(size_t index) const = 0;
169
170 /**
171 * Read from a single CustomAccel service device.
172 *
173 * Valid device names can be queried with accelOobDeviceName.
174 * If num_bytes < 8, all unused MSBs are padded with 0s.
175 *
176 * @param[in] name - the name of the device (from DeviceName).
177 * @param[in] address - the address to read from.
178 * @param[in] num_bytes - the size of the read, in bytes.
179 * @return the data read, with 0s padding any unused MSBs.
180 * @throw IpmiException on failure.
181 */
182 virtual uint64_t accelOobRead(std::string_view name, uint64_t address,
183 uint8_t num_bytes) const = 0;
184
185 /**
186 * Write to a single CustomAccel service device.
187 *
188 * Valid device names can be queried with accelOobDeviceName.
189 * If num_bytes < 8, all unused MSBs are ignored.
190 *
191 * @param[in] name - the name of the device (from DeviceName).
192 * @param[in] address - the address to read from.
193 * @param[in] num_bytes - the size of the read, in bytes.
194 * @param[in] data - the data to write.
195 * @throw IpmiException on failure.
196 */
197 virtual void accelOobWrite(std::string_view name, uint64_t address,
198 uint8_t num_bytes, uint64_t data) const = 0;
Willy Tu6c71b0f2021-10-10 13:34:41 -0700199
200 /**
Willy Tu7e71a432022-07-07 14:43:27 -0700201 * Parse the I2C tree to get the highest level of bifurcation in target bus.
Willy Tu6c71b0f2021-10-10 13:34:41 -0700202 *
203 * @param[in] index - PCIe Slot Index
204 * @return list of lanes taken by each device.
205 */
206 virtual std::vector<uint8_t> pcieBifurcation(uint8_t index) = 0;
John Wediga92d0e62023-06-29 10:43:47 -0700207
208 /**
209 * Prepare for OS boot.
210 *
211 * If in bare metal mode, the BMC will disable IPMI, to protect against an
212 * untrusted OS.
213 */
214 virtual void linuxBootDone() const = 0;
Gaurav Gandhid455bfd2024-01-29 22:32:27 -0800215
216 /**
217 * Update the VR settings for the given settings_id
218 *
219 * @param[in] chip_id - Accel Device#
220 * @param[in] settings_id - ID of the setting to update
221 * @param[in] value - Value of the setting
222 */
223 virtual void accelSetVrSettings(::ipmi::Context::ptr ctx, uint8_t chip_id,
224 uint8_t settings_id,
225 uint16_t value) const = 0;
226
227 /**
228 * Read current VR settings value for the given settings_id
229 *
230 * @param[in] chip_id - Accel Device#
231 * @param[in] settings_id - ID of the setting to read
232 */
233 virtual uint16_t accelGetVrSettings(::ipmi::Context::ptr ctx,
234 uint8_t chip_id,
235 uint8_t settings_id) const = 0;
Brandon Kim559cb012024-05-03 09:12:07 +0000236
237 /**
238 * Get the BM instance property from /run/<propertyType>
239 *
240 * @param[in] propertyType - BM instance property type
241 * @return - string of the requested BM instance property
242 */
243 virtual std::string getBMInstanceProperty(uint8_t propertyType) const = 0;
Patrick Venturef085d912019-03-15 08:50:00 -0700244};
245
Patrick Venturef085d912019-03-15 08:50:00 -0700246} // namespace ipmi
247} // namespace google