targets.hpp (505523772e7b1ba789d6522397f9932629b96e83) targets.hpp (043d32306e00484afc446a44789b61869ea14f84)
1#pragma once
2
1#pragma once
2
3#include "env.hpp"
4#include "fan_pwm.hpp"
5#include "fan_speed.hpp"
6#include "hwmonio.hpp"
7
3#include <experimental/filesystem>
4#include <memory>
5#include <phosphor-logging/elog-errors.hpp>
6#include <phosphor-logging/log.hpp>
7#include <xyz/openbmc_project/Sensor/Device/error.hpp>
8#include <experimental/filesystem>
9#include <memory>
10#include <phosphor-logging/elog-errors.hpp>
11#include <phosphor-logging/log.hpp>
12#include <xyz/openbmc_project/Sensor/Device/error.hpp>
8#include "env.hpp"
9#include "fan_speed.hpp"
10#include "fan_pwm.hpp"
11#include "hwmonio.hpp"
12
13enum class targetType
14{
15 DEFAULT,
16 RPM,
17 PWM
18};
19

--- 39 unchanged lines hidden (view full) ---

59 * @param[in] info - The sdbusplus server connection and interfaces
60 *
61 * @return A shared pointer to the target interface object
62 * Will be empty if no interface was created
63 */
64template <typename T>
65std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
66 const hwmonio::HwmonIO& ioAccess,
13
14enum class targetType
15{
16 DEFAULT,
17 RPM,
18 PWM
19};
20

--- 39 unchanged lines hidden (view full) ---

60 * @param[in] info - The sdbusplus server connection and interfaces
61 *
62 * @return A shared pointer to the target interface object
63 * Will be empty if no interface was created
64 */
65template <typename T>
66std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor,
67 const hwmonio::HwmonIO& ioAccess,
67 const std::string& devPath,
68 ObjectInfo& info)
68 const std::string& devPath, ObjectInfo& info)
69{
70 std::shared_ptr<T> target;
71 namespace fs = std::experimental::filesystem;
72 static constexpr bool deferSignals = true;
73
74 auto& bus = *std::get<sdbusplus::bus::bus*>(info);
75 auto& obj = std::get<Object>(info);
76 auto& objPath = std::get<std::string>(info);

--- 16 unchanged lines hidden (view full) ---

93 auto id = env::getEnv("PWM_TARGET", sensor);
94 if (!id.empty())
95 {
96 targetId = id;
97 }
98 entry = empty;
99 }
100
69{
70 std::shared_ptr<T> target;
71 namespace fs = std::experimental::filesystem;
72 static constexpr bool deferSignals = true;
73
74 auto& bus = *std::get<sdbusplus::bus::bus*>(info);
75 auto& obj = std::get<Object>(info);
76 auto& objPath = std::get<std::string>(info);

--- 16 unchanged lines hidden (view full) ---

93 auto id = env::getEnv("PWM_TARGET", sensor);
94 if (!id.empty())
95 {
96 targetId = id;
97 }
98 entry = empty;
99 }
100
101 sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(),
102 targetName,
103 targetId,
104 entry);
101 sysfsFullPath =
102 sysfs::make_sysfs_path(ioAccess.path(), targetName, targetId, entry);
105 if (fs::exists(sysfsFullPath))
106 {
107 auto useTarget = true;
108 auto tmEnv = env::getEnv("TARGET_MODE");
109 if (!tmEnv.empty())
110 {
111 std::string mode{tmEnv};
112 std::transform(mode.begin(), mode.end(), mode.begin(), toupper);

--- 10 unchanged lines hidden (view full) ---

123 if (type != InterfaceType::FAN_PWM)
124 {
125 useTarget = false;
126 }
127 }
128 else
129 {
130 using namespace phosphor::logging;
103 if (fs::exists(sysfsFullPath))
104 {
105 auto useTarget = true;
106 auto tmEnv = env::getEnv("TARGET_MODE");
107 if (!tmEnv.empty())
108 {
109 std::string mode{tmEnv};
110 std::transform(mode.begin(), mode.end(), mode.begin(), toupper);

--- 10 unchanged lines hidden (view full) ---

121 if (type != InterfaceType::FAN_PWM)
122 {
123 useTarget = false;
124 }
125 }
126 else
127 {
128 using namespace phosphor::logging;
131 log<level::ERR>("Invalid TARGET_MODE env var found",
132 phosphor::logging::entry(
133 "TARGET_MODE=%s", tmEnv.c_str()),
134 phosphor::logging::entry(
135 "DEVPATH=%s", devPath.c_str()));
129 log<level::ERR>(
130 "Invalid TARGET_MODE env var found",
131 phosphor::logging::entry("TARGET_MODE=%s", tmEnv.c_str()),
132 phosphor::logging::entry("DEVPATH=%s", devPath.c_str()));
136 }
137 }
138
139 if (useTarget)
140 {
141 uint32_t targetSpeed = 0;
142
143 try
144 {
133 }
134 }
135
136 if (useTarget)
137 {
138 uint32_t targetSpeed = 0;
139
140 try
141 {
145 targetSpeed = ioAccess.read(
146 targetName,
147 targetId,
148 entry,
149 hwmonio::retries,
150 hwmonio::delay);
142 targetSpeed = ioAccess.read(targetName, targetId, entry,
143 hwmonio::retries, hwmonio::delay);
151 }
152 catch (const std::system_error& e)
153 {
154 using namespace phosphor::logging;
144 }
145 catch (const std::system_error& e)
146 {
147 using namespace phosphor::logging;
155 using namespace sdbusplus::xyz::openbmc_project::
156 Sensor::Device::Error;
157 using metadata = xyz::openbmc_project::Sensor::
158 Device::ReadFailure;
148 using namespace sdbusplus::xyz::openbmc_project::Sensor::
149 Device::Error;
150 using metadata =
151 xyz::openbmc_project::Sensor::Device::ReadFailure;
159
160 report<ReadFailure>(
152
153 report<ReadFailure>(
161 metadata::CALLOUT_ERRNO(e.code().value()),
162 metadata::CALLOUT_DEVICE_PATH(devPath.c_str()));
154 metadata::CALLOUT_ERRNO(e.code().value()),
155 metadata::CALLOUT_DEVICE_PATH(devPath.c_str()));
163
156
164 log<level::INFO>("Logging failing sysfs file",
165 phosphor::logging::entry(
166 "FILE=%s", sysfsFullPath.c_str()));
157 log<level::INFO>(
158 "Logging failing sysfs file",
159 phosphor::logging::entry("FILE=%s", sysfsFullPath.c_str()));
167 }
168
169 // ioAccess.path() is a path like: /sys/class/hwmon/hwmon1
170 target = std::make_shared<T>(
160 }
161
162 // ioAccess.path() is a path like: /sys/class/hwmon/hwmon1
163 target = std::make_shared<T>(
171 std::move(std::make_unique<hwmonio::HwmonIO>(
172 ioAccess.path())),
173 devPath,
174 targetId,
175 bus,
176 objPath.c_str(),
177 deferSignals,
178 targetSpeed);
164 std::move(std::make_unique<hwmonio::HwmonIO>(ioAccess.path())),
165 devPath, targetId, bus, objPath.c_str(), deferSignals,
166 targetSpeed);
179 obj[type] = target;
180 }
181 }
182
183 return target;
184}
167 obj[type] = target;
168 }
169 }
170
171 return target;
172}