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 <ipmid/api-types.hpp> 18 19 #include <cstdint> 20 #include <map> 21 #include <span> 22 #include <string> 23 #include <string_view> 24 #include <tuple> 25 #include <vector> 26 27 namespace google 28 { 29 namespace ipmi 30 { 31 32 using Resp = ::ipmi::RspType<std::uint8_t, std::vector<uint8_t>>; 33 34 using VersionTuple = 35 std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>; 36 37 class HandlerInterface 38 { 39 public: 40 virtual ~HandlerInterface() = default; 41 42 /** 43 * Return the operation mode of BMC 44 * 45 * @return the BMC operation mode 46 */ 47 virtual uint8_t getBmcMode() = 0; 48 49 /** 50 * Return ethernet details (hard-coded). 51 * 52 * @return tuple of ethernet details (channel, if name). 53 */ 54 virtual std::tuple<std::uint8_t, std::string> 55 getEthDetails(std::string intf) const = 0; 56 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; 65 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; 74 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; 82 83 /** 84 * Arm for PSU reset on host shutdown. 85 * 86 * @throw IpmiException on failure. 87 */ 88 virtual void psuResetOnShutdown() const = 0; 89 90 /** 91 * 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; 103 104 /** 105 * 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 /** 113 * 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 /** 121 * 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; 140 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; 148 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; 198 199 /** 200 * Parse the I2C tree to get the highest level of bifurcation in target bus. 201 * 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; 206 207 /** 208 * Prepare for OS boot. 209 * 210 * If in bare metal mode, the BMC will disable IPMI, to protect against an 211 * untrusted OS. 212 */ 213 virtual void linuxBootDone() const = 0; 214 }; 215 216 } // namespace ipmi 217 } // namespace google 218