diff options
author | Moti Haimovski <mhaimovski@habana.ai> | 2020-01-21 15:02:06 +0200 |
---|---|---|
committer | Oded Gabbay <oded.gabbay@gmail.com> | 2020-03-24 10:54:16 +0200 |
commit | 5557b138dc11a1b93fec69c7d8760d38fc56e580 (patch) | |
tree | 418465218faaa599e058dc2bb41e3c81327bf573 /drivers/misc/habanalabs/hwmon.c | |
parent | e5509d52793c7535cca1df28dba893d2b2e8ce02 (diff) |
habanalabs: support temperature offset via sysfs
This commit adds support for offsetting the temperatures reading
by a specified value as defined in
https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
using the standard sysfs defined for hwmon.
This is required by system administrators to inject errors to test
their monitoring applications in data centers.
Signed-off-by: Moti Haimovski <mhaimovski@habana.ai>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Diffstat (limited to 'drivers/misc/habanalabs/hwmon.c')
-rw-r--r-- | drivers/misc/habanalabs/hwmon.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/misc/habanalabs/hwmon.c b/drivers/misc/habanalabs/hwmon.c index 7be4bace9b4f..70088fdb0a5b 100644 --- a/drivers/misc/habanalabs/hwmon.c +++ b/drivers/misc/habanalabs/hwmon.c @@ -125,6 +125,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type, case hwmon_temp_crit: case hwmon_temp_max_hyst: case hwmon_temp_crit_hyst: + case hwmon_temp_offset: break; default: return -EINVAL; @@ -192,6 +193,15 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type, return -ENODEV; switch (type) { + case hwmon_temp: + switch (attr) { + case hwmon_temp_offset: + break; + default: + return -EINVAL; + } + hl_set_temperature(hdev, channel, attr, val); + break; case hwmon_pwm: switch (attr) { case hwmon_pwm_input: @@ -220,6 +230,8 @@ static umode_t hl_is_visible(const void *data, enum hwmon_sensor_types type, case hwmon_temp_crit: case hwmon_temp_crit_hyst: return 0444; + case hwmon_temp_offset: + return 0644; } break; case hwmon_in: @@ -291,6 +303,31 @@ long hl_get_temperature(struct hl_device *hdev, int sensor_index, u32 attr) return result; } +int hl_set_temperature(struct hl_device *hdev, + int sensor_index, u32 attr, long value) +{ + struct armcp_packet pkt; + int rc; + + memset(&pkt, 0, sizeof(pkt)); + + pkt.ctl = cpu_to_le32(ARMCP_PACKET_TEMPERATURE_SET << + ARMCP_PKT_CTL_OPCODE_SHIFT); + pkt.sensor_index = __cpu_to_le16(sensor_index); + pkt.type = __cpu_to_le16(attr); + pkt.value = __cpu_to_le64(value); + + rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), + SENSORS_PKT_TIMEOUT, NULL); + + if (rc) + dev_err(hdev->dev, + "Failed to set temperature of sensor %d, error %d\n", + sensor_index, rc); + + return rc; +} + long hl_get_voltage(struct hl_device *hdev, int sensor_index, u32 attr) { struct armcp_packet pkt; |