Lines Matching +full:int +full:- +full:threshold

1 // SPDX-License-Identifier: GPL-2.0
19 static int nvme_get_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under, in nvme_get_temp_thresh()
22 unsigned int threshold = sensor << NVME_TEMP_THRESH_SELECT_SHIFT; in nvme_get_temp_thresh() local
24 int ret; in nvme_get_temp_thresh()
27 threshold |= NVME_TEMP_THRESH_TYPE_UNDER; in nvme_get_temp_thresh()
29 ret = nvme_get_features(ctrl, NVME_FEAT_TEMP_THRESH, threshold, NULL, 0, in nvme_get_temp_thresh()
32 return -EIO; in nvme_get_temp_thresh()
40 static int nvme_set_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under, in nvme_set_temp_thresh()
43 unsigned int threshold = sensor << NVME_TEMP_THRESH_SELECT_SHIFT; in nvme_set_temp_thresh() local
44 int ret; in nvme_set_temp_thresh()
47 threshold |= clamp_val(temp, 0, NVME_TEMP_THRESH_MASK); in nvme_set_temp_thresh()
50 threshold |= NVME_TEMP_THRESH_TYPE_UNDER; in nvme_set_temp_thresh()
52 ret = nvme_set_features(ctrl, NVME_FEAT_TEMP_THRESH, threshold, NULL, 0, in nvme_set_temp_thresh()
55 return -EIO; in nvme_set_temp_thresh()
60 static int nvme_hwmon_get_smart_log(struct nvme_hwmon_data *data) in nvme_hwmon_get_smart_log()
62 return nvme_get_log(data->ctrl, NVME_NSID_ALL, NVME_LOG_SMART, 0, in nvme_hwmon_get_smart_log()
63 NVME_CSI_NVM, data->log, sizeof(*data->log), 0); in nvme_hwmon_get_smart_log()
66 static int nvme_hwmon_read(struct device *dev, enum hwmon_sensor_types type, in nvme_hwmon_read()
67 u32 attr, int channel, long *val) in nvme_hwmon_read()
70 struct nvme_smart_log *log = data->log; in nvme_hwmon_read()
71 int temp; in nvme_hwmon_read()
72 int err; in nvme_hwmon_read()
80 return nvme_get_temp_thresh(data->ctrl, channel, false, val); in nvme_hwmon_read()
82 return nvme_get_temp_thresh(data->ctrl, channel, true, val); in nvme_hwmon_read()
84 *val = kelvin_to_millicelsius(data->ctrl->cctemp); in nvme_hwmon_read()
90 mutex_lock(&data->read_lock); in nvme_hwmon_read()
98 temp = get_unaligned_le16(log->temperature); in nvme_hwmon_read()
100 temp = le16_to_cpu(log->temp_sensor[channel - 1]); in nvme_hwmon_read()
104 *val = !!(log->critical_warning & NVME_SMART_CRIT_TEMPERATURE); in nvme_hwmon_read()
107 err = -EOPNOTSUPP; in nvme_hwmon_read()
111 mutex_unlock(&data->read_lock); in nvme_hwmon_read()
115 static int nvme_hwmon_write(struct device *dev, enum hwmon_sensor_types type, in nvme_hwmon_write()
116 u32 attr, int channel, long val) in nvme_hwmon_write()
122 return nvme_set_temp_thresh(data->ctrl, channel, false, val); in nvme_hwmon_write()
124 return nvme_set_temp_thresh(data->ctrl, channel, true, val); in nvme_hwmon_write()
129 return -EOPNOTSUPP; in nvme_hwmon_write()
144 static int nvme_hwmon_read_string(struct device *dev, in nvme_hwmon_read_string()
146 int channel, const char **str) in nvme_hwmon_read_string()
154 u32 attr, int channel) in nvme_hwmon_is_visible()
160 if (!channel && data->ctrl->cctemp) in nvme_hwmon_is_visible()
165 if ((!channel && data->ctrl->wctemp) || in nvme_hwmon_is_visible()
166 (channel && data->log->temp_sensor[channel - 1] && in nvme_hwmon_is_visible()
167 !(data->ctrl->quirks & in nvme_hwmon_is_visible()
169 if (data->ctrl->quirks & in nvme_hwmon_is_visible()
181 if (!channel || data->log->temp_sensor[channel - 1]) in nvme_hwmon_is_visible()
226 int nvme_hwmon_init(struct nvme_ctrl *ctrl) in nvme_hwmon_init()
228 struct device *dev = ctrl->device; in nvme_hwmon_init()
231 int err; in nvme_hwmon_init()
235 return -ENOMEM; in nvme_hwmon_init()
237 data->log = kzalloc(sizeof(*data->log), GFP_KERNEL); in nvme_hwmon_init()
238 if (!data->log) { in nvme_hwmon_init()
239 err = -ENOMEM; in nvme_hwmon_init()
243 data->ctrl = ctrl; in nvme_hwmon_init()
244 mutex_init(&data->read_lock); in nvme_hwmon_init()
260 ctrl->hwmon_device = hwmon; in nvme_hwmon_init()
264 kfree(data->log); in nvme_hwmon_init()
272 if (ctrl->hwmon_device) { in nvme_hwmon_exit()
274 dev_get_drvdata(ctrl->hwmon_device); in nvme_hwmon_exit()
276 hwmon_device_unregister(ctrl->hwmon_device); in nvme_hwmon_exit()
277 ctrl->hwmon_device = NULL; in nvme_hwmon_exit()
278 kfree(data->log); in nvme_hwmon_exit()