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 ethernet details (hard-coded). 43 * 44 * @return tuple of ethernet details (channel, if name). 45 */ 46 virtual std::tuple<std::uint8_t, std::string> 47 getEthDetails(std::string intf) const = 0; 48 49 /** 50 * Return the value of rx_packets, given a if_name. 51 * 52 * @param[in] name, the interface name. 53 * @return the number of packets received. 54 * @throw IpmiException on failure. 55 */ 56 virtual std::int64_t getRxPackets(const std::string& name) const = 0; 57 58 /** 59 * Return the values from a cpld version file. 60 * 61 * @param[in] id - the cpld id number. 62 * @return the quad of numbers as a tuple (maj,min,pt,subpt) 63 * @throw IpmiException on failure. 64 */ 65 virtual VersionTuple getCpldVersion(unsigned int id) const = 0; 66 67 /** 68 * Set the PSU Reset delay. 69 * 70 * @param[in] delay - delay in seconds. 71 * @throw IpmiException on failure. 72 */ 73 virtual void psuResetDelay(std::uint32_t delay) const = 0; 74 75 /** 76 * Arm for PSU reset on host shutdown. 77 * 78 * @throw IpmiException on failure. 79 */ 80 virtual void psuResetOnShutdown() const = 0; 81 82 /** 83 * Return the entity name. 84 * On the first call to this method it'll build the list of entities. 85 * @todo Consider moving the list building to construction time (and ignore 86 * failures). 87 * 88 * @param[in] id - the entity id value 89 * @param[in] instance - the entity instance 90 * @return the entity's name 91 * @throw IpmiException on failure. 92 */ 93 virtual std::string getEntityName(std::uint8_t id, 94 std::uint8_t instance) = 0; 95 96 /** 97 * Return the flash size of bmc chip. 98 * 99 * @return the flash size of bmc chip 100 * @throw IpmiException on failure. 101 */ 102 virtual uint32_t getFlashSize() = 0; 103 104 /** 105 * Return the name of the machine, parsed from release information. 106 * 107 * @return the machine name 108 * @throw IpmiException on failure. 109 */ 110 virtual std::string getMachineName() = 0; 111 112 /** 113 * Populate the i2c-pcie mapping vector. 114 */ 115 virtual void buildI2cPcieMapping() = 0; 116 117 /** 118 * Return the size of the i2c-pcie mapping vector. 119 * 120 * @return the size of the vector holding the i2c-pcie mapping tuples. 121 */ 122 virtual size_t getI2cPcieMappingSize() const = 0; 123 124 /** 125 * Return a copy of the entry in the vector. 126 * 127 * @param[in] entry - the index into the vector. 128 * @return the tuple at that index. 129 */ 130 virtual std::tuple<std::uint32_t, std::string> 131 getI2cEntry(unsigned int entry) const = 0; 132 133 /** 134 * Set the Host Power Off delay. 135 * 136 * @param[in] delay - delay in seconds. 137 * @throw IpmiException on failure. 138 */ 139 virtual void hostPowerOffDelay(std::uint32_t delay) const = 0; 140 141 /** 142 * Return the number of devices from the CustomAccel service. 143 * 144 * @return the number of devices. 145 * @throw IpmiException on failure. 146 */ 147 virtual uint32_t accelOobDeviceCount() const = 0; 148 149 /** 150 * Return the name of a single device from the CustomAccel service. 151 * 152 * Valid indexes start at 0 and go up to (but don't include) the number of 153 * devices. The number of devices can be queried with accelOobDeviceCount. 154 * 155 * @param[in] index - the index of the device, starting at 0. 156 * @return the name of the device. 157 * @throw IpmiException on failure. 158 */ 159 virtual std::string accelOobDeviceName(size_t index) const = 0; 160 161 /** 162 * Read from a single CustomAccel service device. 163 * 164 * Valid device names can be queried with accelOobDeviceName. 165 * If num_bytes < 8, all unused MSBs are padded with 0s. 166 * 167 * @param[in] name - the name of the device (from DeviceName). 168 * @param[in] address - the address to read from. 169 * @param[in] num_bytes - the size of the read, in bytes. 170 * @return the data read, with 0s padding any unused MSBs. 171 * @throw IpmiException on failure. 172 */ 173 virtual uint64_t accelOobRead(std::string_view name, uint64_t address, 174 uint8_t num_bytes) const = 0; 175 176 /** 177 * Write to a single CustomAccel service device. 178 * 179 * Valid device names can be queried with accelOobDeviceName. 180 * If num_bytes < 8, all unused MSBs are ignored. 181 * 182 * @param[in] name - the name of the device (from DeviceName). 183 * @param[in] address - the address to read from. 184 * @param[in] num_bytes - the size of the read, in bytes. 185 * @param[in] data - the data to write. 186 * @throw IpmiException on failure. 187 */ 188 virtual void accelOobWrite(std::string_view name, uint64_t address, 189 uint8_t num_bytes, uint64_t data) const = 0; 190 191 /** 192 * Prase the I2C tree to get the highest level of bifurcation in target bus. 193 * 194 * @param[in] index - PCIe Slot Index 195 * @return list of lanes taken by each device. 196 */ 197 virtual std::vector<uint8_t> pcieBifurcation(uint8_t index) = 0; 198 }; 199 200 } // namespace ipmi 201 } // namespace google 202