blob: 9ac3bb775da1e8aadb75db4156274d8fcb1a8544 [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 /**
Nikhil Namjoshi5e70dc82022-09-16 00:36:07 +000042 * Return the operation mode of BMC
43 *
44 * @return the BMC operation mode
45 */
46 virtual uint8_t getBmcMode() = 0;
47
48 /**
Patrick Venturef085d912019-03-15 08:50:00 -070049 * Return ethernet details (hard-coded).
50 *
51 * @return tuple of ethernet details (channel, if name).
52 */
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070053 virtual std::tuple<std::uint8_t, std::string>
54 getEthDetails(std::string intf) const = 0;
Patrick Ventured2037c62019-03-15 10:29:47 -070055
56 /**
57 * Return the value of rx_packets, given a if_name.
58 *
59 * @param[in] name, the interface name.
60 * @return the number of packets received.
61 * @throw IpmiException on failure.
62 */
63 virtual std::int64_t getRxPackets(const std::string& name) const = 0;
Patrick Venturebb90d4f2019-03-15 13:42:06 -070064
65 /**
66 * Return the values from a cpld version file.
67 *
68 * @param[in] id - the cpld id number.
69 * @return the quad of numbers as a tuple (maj,min,pt,subpt)
70 * @throw IpmiException on failure.
71 */
72 virtual VersionTuple getCpldVersion(unsigned int id) const = 0;
Patrick Ventureaa374122019-03-15 15:09:10 -070073
74 /**
75 * Set the PSU Reset delay.
76 *
77 * @param[in] delay - delay in seconds.
78 * @throw IpmiException on failure.
79 */
80 virtual void psuResetDelay(std::uint32_t delay) const = 0;
Patrick Venture07f85152019-03-15 21:36:56 -070081
82 /**
Shounak Mitraac4a16f2021-02-02 11:11:44 -080083 * Arm for PSU reset on host shutdown.
84 *
85 * @throw IpmiException on failure.
86 */
87 virtual void psuResetOnShutdown() const = 0;
88
89 /**
Patrick Venture07f85152019-03-15 21:36:56 -070090 * Return the entity name.
91 * On the first call to this method it'll build the list of entities.
92 * @todo Consider moving the list building to construction time (and ignore
93 * failures).
94 *
95 * @param[in] id - the entity id value
96 * @param[in] instance - the entity instance
97 * @return the entity's name
98 * @throw IpmiException on failure.
99 */
100 virtual std::string getEntityName(std::uint8_t id,
101 std::uint8_t instance) = 0;
Patrick Venture49f23ad2019-03-16 11:59:55 -0700102
103 /**
Willy Tu3b1b4272021-03-02 17:58:10 -0800104 * Return the flash size of bmc chip.
105 *
106 * @return the flash size of bmc chip
107 * @throw IpmiException on failure.
108 */
109 virtual uint32_t getFlashSize() = 0;
110
111 /**
William A. Kennington III29f35bc2020-11-03 23:30:31 -0800112 * Return the name of the machine, parsed from release information.
113 *
114 * @return the machine name
115 * @throw IpmiException on failure.
116 */
117 virtual std::string getMachineName() = 0;
118
119 /**
Patrick Venture49f23ad2019-03-16 11:59:55 -0700120 * Populate the i2c-pcie mapping vector.
121 */
122 virtual void buildI2cPcieMapping() = 0;
123
124 /**
125 * Return the size of the i2c-pcie mapping vector.
126 *
127 * @return the size of the vector holding the i2c-pcie mapping tuples.
128 */
129 virtual size_t getI2cPcieMappingSize() const = 0;
130
131 /**
132 * Return a copy of the entry in the vector.
133 *
134 * @param[in] entry - the index into the vector.
135 * @return the tuple at that index.
136 */
137 virtual std::tuple<std::uint32_t, std::string>
138 getI2cEntry(unsigned int entry) const = 0;
linyuny8cfa4c42021-06-16 13:53:08 -0700139
140 /**
141 * Set the Host Power Off delay.
142 *
143 * @param[in] delay - delay in seconds.
144 * @throw IpmiException on failure.
145 */
146 virtual void hostPowerOffDelay(std::uint32_t delay) const = 0;
Steve Foreman4f0d1de2021-09-20 14:06:32 -0700147
148 /**
149 * Return the number of devices from the CustomAccel service.
150 *
151 * @return the number of devices.
152 * @throw IpmiException on failure.
153 */
154 virtual uint32_t accelOobDeviceCount() const = 0;
155
156 /**
157 * Return the name of a single device from the CustomAccel service.
158 *
159 * Valid indexes start at 0 and go up to (but don't include) the number of
160 * devices. The number of devices can be queried with accelOobDeviceCount.
161 *
162 * @param[in] index - the index of the device, starting at 0.
163 * @return the name of the device.
164 * @throw IpmiException on failure.
165 */
166 virtual std::string accelOobDeviceName(size_t index) const = 0;
167
168 /**
169 * Read from a single CustomAccel service device.
170 *
171 * Valid device names can be queried with accelOobDeviceName.
172 * If num_bytes < 8, all unused MSBs are padded with 0s.
173 *
174 * @param[in] name - the name of the device (from DeviceName).
175 * @param[in] address - the address to read from.
176 * @param[in] num_bytes - the size of the read, in bytes.
177 * @return the data read, with 0s padding any unused MSBs.
178 * @throw IpmiException on failure.
179 */
180 virtual uint64_t accelOobRead(std::string_view name, uint64_t address,
181 uint8_t num_bytes) const = 0;
182
183 /**
184 * Write to a single CustomAccel service device.
185 *
186 * Valid device names can be queried with accelOobDeviceName.
187 * If num_bytes < 8, all unused MSBs are ignored.
188 *
189 * @param[in] name - the name of the device (from DeviceName).
190 * @param[in] address - the address to read from.
191 * @param[in] num_bytes - the size of the read, in bytes.
192 * @param[in] data - the data to write.
193 * @throw IpmiException on failure.
194 */
195 virtual void accelOobWrite(std::string_view name, uint64_t address,
196 uint8_t num_bytes, uint64_t data) const = 0;
Willy Tu6c71b0f2021-10-10 13:34:41 -0700197
198 /**
Willy Tu7e71a432022-07-07 14:43:27 -0700199 * Parse the I2C tree to get the highest level of bifurcation in target bus.
Willy Tu6c71b0f2021-10-10 13:34:41 -0700200 *
201 * @param[in] index - PCIe Slot Index
202 * @return list of lanes taken by each device.
203 */
204 virtual std::vector<uint8_t> pcieBifurcation(uint8_t index) = 0;
Patrick Venturef085d912019-03-15 08:50:00 -0700205};
206
Patrick Venturef085d912019-03-15 08:50:00 -0700207} // namespace ipmi
208} // namespace google