blob: b1f48bc0b8e6f7891e80ba90aa500447e3897986 [file] [log] [blame]
Hao Zhou15d4d212023-07-11 20:18:04 +00001// Copyright 2023 Google LLC
Willy Tua2056e92021-10-10 13:36:16 -07002//
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 Venturec87de552020-05-20 20:25:39 -070015#pragma once
16
Willy Tu6c71b0f2021-10-10 13:34:41 -070017#include "bifurcation.hpp"
Hao Zhou15d4d212023-07-11 20:18:04 +000018#include "file_system_wrapper_impl.hpp"
Patrick Venturec87de552020-05-20 20:25:39 -070019#include "handler.hpp"
20
Patrick Venturec87de552020-05-20 20:25:39 -070021#include <nlohmann/json.hpp>
Steve Foreman4f0d1de2021-09-20 14:06:32 -070022#include <sdbusplus/bus.hpp>
Patrick Williams444b5ea2023-05-19 13:56:42 -050023
24#include <cstdint>
25#include <map>
Hao Zhou15d4d212023-07-11 20:18:04 +000026#include <memory>
Patrick Venturec87de552020-05-20 20:25:39 -070027#include <string>
Steve Foreman4f0d1de2021-09-20 14:06:32 -070028#include <string_view>
Patrick Venturec87de552020-05-20 20:25:39 -070029#include <tuple>
30#include <vector>
31
32namespace google
33{
34namespace ipmi
35{
36
William A. Kennington III96ad9062020-11-24 21:47:20 -080037constexpr char defaultConfigFile[] =
38 "/usr/share/ipmi-entity-association/entity_association_map.json";
Patrick Venturec87de552020-05-20 20:25:39 -070039
40class Handler : public HandlerInterface
41{
42 public:
43 explicit Handler(const std::string& entityConfigPath = defaultConfigFile) :
Hao Zhou15d4d212023-07-11 20:18:04 +000044 fsPtr(std::make_unique<FileSystemWrapper>()),
Willy Tu6c71b0f2021-10-10 13:34:41 -070045 _configFile(entityConfigPath),
46 bifurcationHelper(BifurcationStatic::createBifurcation()){};
47 Handler(std::reference_wrapper<BifurcationInterface> bifurcationHelper,
48 const std::string& entityConfigPath = defaultConfigFile) :
Hao Zhou15d4d212023-07-11 20:18:04 +000049 fsPtr(std::make_unique<FileSystemWrapper>()),
50 _configFile(entityConfigPath), bifurcationHelper(bifurcationHelper){};
Patrick Venturec87de552020-05-20 20:25:39 -070051 ~Handler() = default;
52
Nikhil Namjoshi5e70dc82022-09-16 00:36:07 +000053 uint8_t getBmcMode() override;
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070054 std::tuple<std::uint8_t, std::string>
55 getEthDetails(std::string intf) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070056 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 Mitraac4a16f2021-02-02 11:11:44 -080059 void psuResetOnShutdown() const override;
Patrick Venturec87de552020-05-20 20:25:39 -070060 std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
Willy Tu3b1b4272021-03-02 17:58:10 -080061 uint32_t getFlashSize() override;
William A. Kennington III29f35bc2020-11-03 23:30:31 -080062 std::string getMachineName() override;
Patrick Venturec87de552020-05-20 20:25:39 -070063 void buildI2cPcieMapping() override;
64 size_t getI2cPcieMappingSize() const override;
linyuny8cfa4c42021-06-16 13:53:08 -070065 void hostPowerOffDelay(std::uint32_t delay) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070066 std::tuple<std::uint32_t, std::string>
67 getI2cEntry(unsigned int entry) const override;
Willy Tu6c71b0f2021-10-10 13:34:41 -070068 std::vector<uint8_t> pcieBifurcation(uint8_t) override;
Patrick Venturec87de552020-05-20 20:25:39 -070069
Steve Foreman4f0d1de2021-09-20 14:06:32 -070070 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 Wediga92d0e62023-06-29 10:43:47 -070076 void linuxBootDone() const override;
Gaurav Gandhid455bfd2024-01-29 22:32:27 -080077 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;
Steve Foreman4f0d1de2021-09-20 14:06:32 -070081
82 protected:
83 // Exposed for dependency injection
Patrick Williams65371222023-05-19 02:31:40 -050084 virtual sdbusplus::bus_t getDbus() const;
Hao Zhou15d4d212023-07-11 20:18:04 +000085 virtual const std::unique_ptr<FileSystemInterface>& getFs() const;
Steve Foreman4f0d1de2021-09-20 14:06:32 -070086
Patrick Venturec87de552020-05-20 20:25:39 -070087 private:
Hao Zhou15d4d212023-07-11 20:18:04 +000088 std::unique_ptr<FileSystemInterface> fsPtr;
89
Patrick Venturec87de552020-05-20 20:25:39 -070090 std::string _configFile;
91
92 bool _entityConfigParsed = false;
93
94 const std::map<uint8_t, std::string> _entityIdToName{
95 {0x03, "cpu"},
96 {0x04, "storage_device"},
97 {0x06, "system_management_module"},
98 {0x07, "system_board"},
99 {0x08, "memory_module"},
100 {0x0B, "add_in_card"},
101 {0x0E, "power_system_board"},
102 {0x10, "system_internal_expansion_board"},
103 {0x11, "other_system_board"},
104 {0x17, "system_chassis"},
105 {0x1D, "fan"},
106 {0x1E, "cooling_unit"},
107 {0x20, "memory_device"}};
108
Gaurav Gandhid455bfd2024-01-29 22:32:27 -0800109 const std::unordered_map<uint8_t, std::string> _vrSettingsMap{
Gaurav Gandhi98460232024-03-03 20:10:54 -0800110 {0, "idle_mode_"}, {1, "power_brake_"}, {2, "loadline_"}};
Gaurav Gandhid455bfd2024-01-29 22:32:27 -0800111
Patrick Venturec87de552020-05-20 20:25:39 -0700112 nlohmann::json _entityConfig{};
113
114 std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map;
Willy Tu6c71b0f2021-10-10 13:34:41 -0700115
116 std::reference_wrapper<BifurcationInterface> bifurcationHelper;
Patrick Venturec87de552020-05-20 20:25:39 -0700117};
118
Patrick Venturea3f9c2d2020-05-29 14:36:25 -0700119/**
120 * Given a type, entity instance, and a configuration, return the name.
121 *
122 * @param[in] type - the entity type
123 * @param[in] instance - the entity instance
124 * @param[in] config - the json object holding the entity mapping
125 * @return the name of the entity from the map
126 */
127std::string readNameFromConfig(const std::string& type, uint8_t instance,
128 const nlohmann::json& config);
129
Patrick Venturec87de552020-05-20 20:25:39 -0700130} // namespace ipmi
131} // namespace google