xref: /openbmc/google-ipmi-sys/handler.hpp (revision 5e70dc8c)
1 // Copyright 2022 Google LLC
2 //
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 
15 #pragma once
16 
17 #include <cstdint>
18 #include <ipmid/api-types.hpp>
19 #include <map>
20 #include <span>
21 #include <string>
22 #include <string_view>
23 #include <tuple>
24 #include <vector>
25 
26 namespace google
27 {
28 namespace ipmi
29 {
30 
31 using Resp = ::ipmi::RspType<std::uint8_t, std::vector<uint8_t>>;
32 
33 using VersionTuple =
34     std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>;
35 
36 class HandlerInterface
37 {
38   public:
39     virtual ~HandlerInterface() = default;
40 
41     /**
42      * Return the operation mode of BMC
43      *
44      * @return the BMC operation mode
45      */
46     virtual uint8_t getBmcMode() = 0;
47 
48     /**
49      * Return ethernet details (hard-coded).
50      *
51      * @return tuple of ethernet details (channel, if name).
52      */
53     virtual std::tuple<std::uint8_t, std::string>
54         getEthDetails(std::string intf) const = 0;
55 
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;
64 
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;
73 
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;
81 
82     /**
83      * Arm for PSU reset on host shutdown.
84      *
85      * @throw IpmiException on failure.
86      */
87     virtual void psuResetOnShutdown() const = 0;
88 
89     /**
90      * 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;
102 
103     /**
104      * 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     /**
112      * 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     /**
120      * 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;
139 
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;
147 
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;
197 
198     /**
199      * Parse the I2C tree to get the highest level of bifurcation in target bus.
200      *
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;
205 };
206 
207 } // namespace ipmi
208 } // namespace google
209