| 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> | 
| Patrick Williams | 444b5ea | 2023-05-19 13:56:42 -0500 | [diff] [blame] | 18 |  | 
|  | 19 | #include <cstdint> | 
| Patrick Venture | ab65000 | 2019-03-16 09:08:47 -0700 | [diff] [blame] | 20 | #include <map> | 
| Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 21 | #include <span> | 
| Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 22 | #include <string> | 
| Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 23 | #include <string_view> | 
| Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 24 | #include <tuple> | 
| Patrick Venture | 49f23ad | 2019-03-16 11:59:55 -0700 | [diff] [blame] | 25 | #include <vector> | 
| Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | namespace google | 
|  | 28 | { | 
|  | 29 | namespace ipmi | 
|  | 30 | { | 
|  | 31 |  | 
| Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 32 | using Resp = ::ipmi::RspType<std::uint8_t, std::vector<uint8_t>>; | 
|  | 33 |  | 
| Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 34 | using VersionTuple = | 
|  | 35 | std::tuple<std::uint8_t, std::uint8_t, std::uint8_t, std::uint8_t>; | 
|  | 36 |  | 
| Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 37 | class HandlerInterface | 
|  | 38 | { | 
|  | 39 | public: | 
|  | 40 | virtual ~HandlerInterface() = default; | 
|  | 41 |  | 
|  | 42 | /** | 
| Nikhil Namjoshi | 5e70dc8 | 2022-09-16 00:36:07 +0000 | [diff] [blame] | 43 | * Return the operation mode of BMC | 
|  | 44 | * | 
|  | 45 | * @return the BMC operation mode | 
|  | 46 | */ | 
|  | 47 | virtual uint8_t getBmcMode() = 0; | 
|  | 48 |  | 
|  | 49 | /** | 
| Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 50 | * Return ethernet details (hard-coded). | 
|  | 51 | * | 
|  | 52 | * @return tuple of ethernet details (channel, if name). | 
|  | 53 | */ | 
| William A. Kennington III | b69209b | 2021-07-13 13:22:24 -0700 | [diff] [blame] | 54 | virtual std::tuple<std::uint8_t, std::string> | 
|  | 55 | getEthDetails(std::string intf) const = 0; | 
| Patrick Venture | d2037c6 | 2019-03-15 10:29:47 -0700 | [diff] [blame] | 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; | 
| Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 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; | 
| Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 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; | 
| Patrick Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | /** | 
| Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 84 | * Arm for PSU reset on host shutdown. | 
|  | 85 | * | 
|  | 86 | * @throw IpmiException on failure. | 
|  | 87 | */ | 
|  | 88 | virtual void psuResetOnShutdown() const = 0; | 
|  | 89 |  | 
|  | 90 | /** | 
| Patrick Venture | 07f8515 | 2019-03-15 21:36:56 -0700 | [diff] [blame] | 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; | 
| Patrick Venture | 49f23ad | 2019-03-16 11:59:55 -0700 | [diff] [blame] | 103 |  | 
|  | 104 | /** | 
| Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 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 | /** | 
| William A. Kennington III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 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 | /** | 
| Patrick Venture | 49f23ad | 2019-03-16 11:59:55 -0700 | [diff] [blame] | 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; | 
| linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 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; | 
| Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 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; | 
| Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 198 |  | 
|  | 199 | /** | 
| Willy Tu | 7e71a43 | 2022-07-07 14:43:27 -0700 | [diff] [blame] | 200 | * 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] | 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; | 
| Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 206 | }; | 
|  | 207 |  | 
| Patrick Venture | f085d91 | 2019-03-15 08:50:00 -0700 | [diff] [blame] | 208 | } // namespace ipmi | 
|  | 209 | } // namespace google |