Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 1 | // Copyright 2022 Google LLC |
Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 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 | |
Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 15 | #pragma once |
| 16 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 17 | #include <ipmid/api-types.hpp> |
Gaurav Gandhi | d455bfd | 2024-01-29 22:32:27 -0800 | [diff] [blame] | 18 | #include <ipmid/message.hpp> |
Patrick Williams | 444b5ea | 2023-05-19 13:56:42 -0500 | [diff] [blame] | 19 | |
| 20 | #include <cstdint> |
Patrick Venture | ab65000 | 2019-03-16 09:08:47 -0700 | [diff] [blame] | 21 | #include <map> |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 22 | #include <span> |
Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 23 | #include <string> |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 24 | #include <string_view> |
Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 25 | #include <tuple> |
Patrick Venture | 49f23ad | 2019-03-16 11:59:55 -0700 | [diff] [blame] | 26 | #include <vector> |
Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 27 | |
| 28 | namespace google |
| 29 | { |
| 30 | namespace ipmi |
| 31 | { |
| 32 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 33 | using Resp = ::ipmi::RspType<std::uint8_t, std::vector<uint8_t>>; |
| 34 | |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 35 | using VersionTuple = |
| 36 | std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>; |
| 37 | |
Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 38 | class HandlerInterface |
| 39 | { |
| 40 | public: |
| 41 | virtual ~HandlerInterface() = default; |
| 42 | |
| 43 | /** |
Nikhil Namjoshi | 5e70dc8 | 2022-09-16 00:36:07 +0000 | [diff] [blame] | 44 | * Return the operation mode of BMC |
| 45 | * |
| 46 | * @return the BMC operation mode |
| 47 | */ |
| 48 | virtual uint8_t getBmcMode() = 0; |
| 49 | |
| 50 | /** |
Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 51 | * Return ethernet details (hard-coded). |
| 52 | * |
| 53 | * @return tuple of ethernet details (channel, if name). |
| 54 | */ |
William A. Kennington III | b69209b | 2021-07-13 13:22:24 -0700 | [diff] [blame] | 55 | virtual std::tuple<std::uint8_t, std::string> |
| 56 | getEthDetails(std::string intf) const = 0; |
Patrick Venture | d2037c6 | 2019-03-15 10:29:47 -0700 | [diff] [blame] | 57 | |
| 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 Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 66 | |
| 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 Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 75 | |
| 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 Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 85 | * Arm for PSU reset on host shutdown. |
| 86 | * |
| 87 | * @throw IpmiException on failure. |
| 88 | */ |
| 89 | virtual void psuResetOnShutdown() const = 0; |
| 90 | |
| 91 | /** |
Patrick Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 92 | * 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 Venture | 49f23ad | 2019-03-16 11:59:55 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 106 | * 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 III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 114 | * 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 Venture | 49f23ad | 2019-03-16 11:59:55 -0700 | [diff] [blame] | 122 | * 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; |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 141 | |
| 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 Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 149 | |
| 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 Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 199 | |
| 200 | /** |
Willy Tu | 7e71a43 | 2022-07-07 14:43:27 -0700 | [diff] [blame] | 201 | * Parse the I2C tree to get the highest level of bifurcation in target bus. |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 202 | * |
| 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 Wedig | a92d0e6 | 2023-06-29 10:43:47 -0700 | [diff] [blame] | 207 | |
| 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 Gandhi | d455bfd | 2024-01-29 22:32:27 -0800 | [diff] [blame] | 215 | |
| 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 Kim | 559cb01 | 2024-05-03 09:12:07 +0000 | [diff] [blame] | 236 | |
| 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 Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 246 | } // namespace ipmi |
| 247 | } // namespace google |