blob: 4a3f5dc375c5f64ce84e09fcd683e090469d5bb7 [file] [log] [blame]
Steve Foreman4f0d1de2021-09-20 14:06:32 -07001// Copyright 2022 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"
Patrick Venturec87de552020-05-20 20:25:39 -070018#include "handler.hpp"
19
20#include <cstdint>
21#include <map>
22#include <nlohmann/json.hpp>
Steve Foreman4f0d1de2021-09-20 14:06:32 -070023#include <sdbusplus/bus.hpp>
Patrick Venturec87de552020-05-20 20:25:39 -070024#include <string>
Steve Foreman4f0d1de2021-09-20 14:06:32 -070025#include <string_view>
Patrick Venturec87de552020-05-20 20:25:39 -070026#include <tuple>
27#include <vector>
28
29namespace google
30{
31namespace ipmi
32{
33
William A. Kennington III96ad9062020-11-24 21:47:20 -080034constexpr char defaultConfigFile[] =
35 "/usr/share/ipmi-entity-association/entity_association_map.json";
Patrick Venturec87de552020-05-20 20:25:39 -070036
37class Handler : public HandlerInterface
38{
39 public:
40 explicit Handler(const std::string& entityConfigPath = defaultConfigFile) :
Willy Tu6c71b0f2021-10-10 13:34:41 -070041 _configFile(entityConfigPath),
42 bifurcationHelper(BifurcationStatic::createBifurcation()){};
43 Handler(std::reference_wrapper<BifurcationInterface> bifurcationHelper,
44 const std::string& entityConfigPath = defaultConfigFile) :
45 _configFile(entityConfigPath),
46 bifurcationHelper(bifurcationHelper){};
Patrick Venturec87de552020-05-20 20:25:39 -070047 ~Handler() = default;
48
William A. Kennington IIIb69209b2021-07-13 13:22:24 -070049 std::tuple<std::uint8_t, std::string>
50 getEthDetails(std::string intf) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070051 std::int64_t getRxPackets(const std::string& name) const override;
52 VersionTuple getCpldVersion(unsigned int id) const override;
53 void psuResetDelay(std::uint32_t delay) const override;
Shounak Mitraac4a16f2021-02-02 11:11:44 -080054 void psuResetOnShutdown() const override;
Patrick Venturec87de552020-05-20 20:25:39 -070055 std::string getEntityName(std::uint8_t id, std::uint8_t instance) override;
Willy Tu3b1b4272021-03-02 17:58:10 -080056 uint32_t getFlashSize() override;
William A. Kennington III29f35bc2020-11-03 23:30:31 -080057 std::string getMachineName() override;
Patrick Venturec87de552020-05-20 20:25:39 -070058 void buildI2cPcieMapping() override;
59 size_t getI2cPcieMappingSize() const override;
linyuny8cfa4c42021-06-16 13:53:08 -070060 void hostPowerOffDelay(std::uint32_t delay) const override;
Patrick Venturec87de552020-05-20 20:25:39 -070061 std::tuple<std::uint32_t, std::string>
62 getI2cEntry(unsigned int entry) const override;
Willy Tu6c71b0f2021-10-10 13:34:41 -070063 std::vector<uint8_t> pcieBifurcation(uint8_t) override;
Patrick Venturec87de552020-05-20 20:25:39 -070064
Steve Foreman4f0d1de2021-09-20 14:06:32 -070065 uint32_t accelOobDeviceCount() const override;
66 std::string accelOobDeviceName(size_t index) const override;
67 uint64_t accelOobRead(std::string_view name, uint64_t address,
68 uint8_t num_bytes) const override;
69 void accelOobWrite(std::string_view name, uint64_t address,
70 uint8_t num_bytes, uint64_t data) const override;
71
72 protected:
73 // Exposed for dependency injection
74 virtual sdbusplus::bus::bus accelOobGetDbus() const;
75
Patrick Venturec87de552020-05-20 20:25:39 -070076 private:
77 std::string _configFile;
78
79 bool _entityConfigParsed = false;
80
81 const std::map<uint8_t, std::string> _entityIdToName{
82 {0x03, "cpu"},
83 {0x04, "storage_device"},
84 {0x06, "system_management_module"},
85 {0x07, "system_board"},
86 {0x08, "memory_module"},
87 {0x0B, "add_in_card"},
88 {0x0E, "power_system_board"},
89 {0x10, "system_internal_expansion_board"},
90 {0x11, "other_system_board"},
91 {0x17, "system_chassis"},
92 {0x1D, "fan"},
93 {0x1E, "cooling_unit"},
94 {0x20, "memory_device"}};
95
96 nlohmann::json _entityConfig{};
97
98 std::vector<std::tuple<uint32_t, std::string>> _pcie_i2c_map;
Willy Tu6c71b0f2021-10-10 13:34:41 -070099
100 std::reference_wrapper<BifurcationInterface> bifurcationHelper;
Patrick Venturec87de552020-05-20 20:25:39 -0700101};
102
Patrick Venturea3f9c2d2020-05-29 14:36:25 -0700103/**
104 * Given a type, entity instance, and a configuration, return the name.
105 *
106 * @param[in] type - the entity type
107 * @param[in] instance - the entity instance
108 * @param[in] config - the json object holding the entity mapping
109 * @return the name of the entity from the map
110 */
111std::string readNameFromConfig(const std::string& type, uint8_t instance,
112 const nlohmann::json& config);
113
Patrick Venturec87de552020-05-20 20:25:39 -0700114} // namespace ipmi
115} // namespace google