Hao Zhou | 15d4d21 | 2023-07-11 20:18:04 +0000 | [diff] [blame] | 1 | // Copyright 2023 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 | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 15 | #pragma once |
| 16 | |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 17 | #include "bifurcation.hpp" |
Hao Zhou | 15d4d21 | 2023-07-11 20:18:04 +0000 | [diff] [blame] | 18 | #include "file_system_wrapper_impl.hpp" |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 19 | #include "handler.hpp" |
| 20 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 21 | #include <nlohmann/json.hpp> |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 22 | #include <sdbusplus/bus.hpp> |
Patrick Williams | 444b5ea | 2023-05-19 13:56:42 -0500 | [diff] [blame] | 23 | |
| 24 | #include <cstdint> |
| 25 | #include <map> |
Hao Zhou | 15d4d21 | 2023-07-11 20:18:04 +0000 | [diff] [blame] | 26 | #include <memory> |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 27 | #include <string> |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 28 | #include <string_view> |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 29 | #include <tuple> |
| 30 | #include <vector> |
| 31 | |
| 32 | namespace google |
| 33 | { |
| 34 | namespace ipmi |
| 35 | { |
| 36 | |
William A. Kennington III | 96ad906 | 2020-11-24 21:47:20 -0800 | [diff] [blame] | 37 | constexpr char defaultConfigFile[] = |
| 38 | "/usr/share/ipmi-entity-association/entity_association_map.json"; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 39 | |
| 40 | class Handler : public HandlerInterface |
| 41 | { |
| 42 | public: |
| 43 | explicit Handler(const std::string& entityConfigPath = defaultConfigFile) : |
Hao Zhou | 15d4d21 | 2023-07-11 20:18:04 +0000 | [diff] [blame] | 44 | fsPtr(std::make_unique<FileSystemWrapper>()), |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 45 | _configFile(entityConfigPath), |
Patrick Williams | 8c0094e | 2024-08-16 15:22:37 -0400 | [diff] [blame] | 46 | bifurcationHelper(BifurcationStatic::createBifurcation()) {}; |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 47 | Handler(std::reference_wrapper<BifurcationInterface> bifurcationHelper, |
| 48 | const std::string& entityConfigPath = defaultConfigFile) : |
Hao Zhou | 15d4d21 | 2023-07-11 20:18:04 +0000 | [diff] [blame] | 49 | fsPtr(std::make_unique<FileSystemWrapper>()), |
Patrick Williams | 8c0094e | 2024-08-16 15:22:37 -0400 | [diff] [blame] | 50 | _configFile(entityConfigPath), bifurcationHelper(bifurcationHelper) {}; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 51 | ~Handler() = default; |
| 52 | |
Nikhil Namjoshi | 5e70dc8 | 2022-09-16 00:36:07 +0000 | [diff] [blame] | 53 | uint8_t getBmcMode() override; |
William A. Kennington III | b69209b | 2021-07-13 13:22:24 -0700 | [diff] [blame] | 54 | std::tuple<std::uint8_t, std::string> |
| 55 | getEthDetails(std::string intf) const override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 56 | std::int64_t getRxPackets(const std::string& name) const override; |
| 57 | VersionTuple getCpldVersion(unsigned int id) const override; |
| 58 | void psuResetDelay(std::uint32_t delay) const override; |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 59 | void psuResetOnShutdown() const override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 60 | std::string getEntityName(std::uint8_t id, std::uint8_t instance) override; |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 61 | uint32_t getFlashSize() override; |
William A. Kennington III | 29f35bc | 2020-11-03 23:30:31 -0800 | [diff] [blame] | 62 | std::string getMachineName() override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 63 | void buildI2cPcieMapping() override; |
| 64 | size_t getI2cPcieMappingSize() const override; |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 65 | void hostPowerOffDelay(std::uint32_t delay) const override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 66 | std::tuple<std::uint32_t, std::string> |
| 67 | getI2cEntry(unsigned int entry) const override; |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 68 | std::vector<uint8_t> pcieBifurcation(uint8_t) override; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 69 | |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 70 | uint32_t accelOobDeviceCount() const override; |
| 71 | std::string accelOobDeviceName(size_t index) const override; |
| 72 | uint64_t accelOobRead(std::string_view name, uint64_t address, |
| 73 | uint8_t num_bytes) const override; |
| 74 | void accelOobWrite(std::string_view name, uint64_t address, |
| 75 | uint8_t num_bytes, uint64_t data) const override; |
John Wedig | a92d0e6 | 2023-06-29 10:43:47 -0700 | [diff] [blame] | 76 | void linuxBootDone() const override; |
Gaurav Gandhi | d455bfd | 2024-01-29 22:32:27 -0800 | [diff] [blame] | 77 | void accelSetVrSettings(::ipmi::Context::ptr ctx, uint8_t chip_id, |
| 78 | uint8_t settings_id, uint16_t value) const override; |
| 79 | uint16_t accelGetVrSettings(::ipmi::Context::ptr ctx, uint8_t chip_id, |
| 80 | uint8_t settings_id) const override; |
Brandon Kim | 559cb01 | 2024-05-03 09:12:07 +0000 | [diff] [blame] | 81 | std::string getBMInstanceProperty(uint8_t propertyType) const override; |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 82 | |
| 83 | protected: |
| 84 | // Exposed for dependency injection |
Patrick Williams | 6537122 | 2023-05-19 02:31:40 -0500 | [diff] [blame] | 85 | virtual sdbusplus::bus_t getDbus() const; |
Hao Zhou | 15d4d21 | 2023-07-11 20:18:04 +0000 | [diff] [blame] | 86 | virtual const std::unique_ptr<FileSystemInterface>& getFs() const; |
Steve Foreman | 4f0d1de | 2021-09-20 14:06:32 -0700 | [diff] [blame] | 87 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 88 | private: |
Hao Zhou | 15d4d21 | 2023-07-11 20:18:04 +0000 | [diff] [blame] | 89 | std::unique_ptr<FileSystemInterface> fsPtr; |
| 90 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 91 | std::string _configFile; |
| 92 | |
| 93 | bool _entityConfigParsed = false; |
| 94 | |
| 95 | const std::map<uint8_t, std::string> _entityIdToName{ |
| 96 | {0x03, "cpu"}, |
| 97 | {0x04, "storage_device"}, |
| 98 | {0x06, "system_management_module"}, |
| 99 | {0x07, "system_board"}, |
| 100 | {0x08, "memory_module"}, |
| 101 | {0x0B, "add_in_card"}, |
| 102 | {0x0E, "power_system_board"}, |
| 103 | {0x10, "system_internal_expansion_board"}, |
| 104 | {0x11, "other_system_board"}, |
| 105 | {0x17, "system_chassis"}, |
| 106 | {0x1D, "fan"}, |
| 107 | {0x1E, "cooling_unit"}, |
| 108 | {0x20, "memory_device"}}; |
| 109 | |
Gaurav Gandhi | d455bfd | 2024-01-29 22:32:27 -0800 | [diff] [blame] | 110 | const std::unordered_map<uint8_t, std::string> _vrSettingsMap{ |
Gaurav Gandhi | 9846023 | 2024-03-03 20:10:54 -0800 | [diff] [blame] | 111 | {0, "idle_mode_"}, {1, "power_brake_"}, {2, "loadline_"}}; |
Gaurav Gandhi | d455bfd | 2024-01-29 22:32:27 -0800 | [diff] [blame] | 112 | |
Brandon Kim | 559cb01 | 2024-05-03 09:12:07 +0000 | [diff] [blame] | 113 | const std::unordered_map<uint8_t, std::string> bmInstanceTypeStringMap = { |
| 114 | {0x00, "asset-tag"}, {0x01, "board-serial-number"}, |
| 115 | {0x02, "family"}, {0x03, "product-name"}, |
| 116 | {0x04, "sku"}, {0x05, "system-serial-number"}, |
| 117 | {0x06, "uuid"}}; |
| 118 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 119 | nlohmann::json _entityConfig{}; |
| 120 | |
| 121 | std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map; |
Willy Tu | 6c71b0f | 2021-10-10 13:34:41 -0700 | [diff] [blame] | 122 | |
| 123 | std::reference_wrapper<BifurcationInterface> bifurcationHelper; |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Patrick Venture | a3f9c2d | 2020-05-29 14:36:25 -0700 | [diff] [blame] | 126 | /** |
| 127 | * Given a type, entity instance, and a configuration, return the name. |
| 128 | * |
| 129 | * @param[in] type - the entity type |
| 130 | * @param[in] instance - the entity instance |
| 131 | * @param[in] config - the json object holding the entity mapping |
| 132 | * @return the name of the entity from the map |
| 133 | */ |
| 134 | std::string readNameFromConfig(const std::string& type, uint8_t instance, |
| 135 | const nlohmann::json& config); |
| 136 | |
Patrick Venture | c87de55 | 2020-05-20 20:25:39 -0700 | [diff] [blame] | 137 | } // namespace ipmi |
| 138 | } // namespace google |