diff options
author | Christine Gharzuzi <cgharzuzi@habana.ai> | 2020-04-16 16:43:26 +0300 |
---|---|---|
committer | Oded Gabbay <oded.gabbay@gmail.com> | 2020-05-19 14:48:41 +0300 |
commit | 8e708af2846fd1183ce2e5690e46155ee1342d25 (patch) | |
tree | d826cce20d017725508e651ec25b370364224909 /drivers/misc/habanalabs | |
parent | 79c823c57e69d9e584a5ee4ee6406eb3854393ae (diff) | |
download | linux-8e708af2846fd1183ce2e5690e46155ee1342d25.tar.xz |
habanalabs: support hwmon_reset_history attribute
Support hwmon_temp_reset_histroy, hwmon_in_reset_history and
hwmon_curr_reset attribute which resets the historical highest value.
Signed-off-by: Christine Gharzuzi <cgharzuzi@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')
-rw-r--r-- | drivers/misc/habanalabs/habanalabs.h | 4 | ||||
-rw-r--r-- | drivers/misc/habanalabs/hwmon.c | 75 | ||||
-rw-r--r-- | drivers/misc/habanalabs/include/armcp_if.h | 21 |
3 files changed, 97 insertions, 3 deletions
diff --git a/drivers/misc/habanalabs/habanalabs.h b/drivers/misc/habanalabs/habanalabs.h index a8ee241b2fce..0d3d3c59ae2b 100644 --- a/drivers/misc/habanalabs/habanalabs.h +++ b/drivers/misc/habanalabs/habanalabs.h @@ -1676,6 +1676,10 @@ void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, long value); u64 hl_get_max_power(struct hl_device *hdev); void hl_set_max_power(struct hl_device *hdev, u64 value); +int hl_set_voltage(struct hl_device *hdev, + int sensor_index, u32 attr, long value); +int hl_set_current(struct hl_device *hdev, + int sensor_index, u32 attr, long value); #ifdef CONFIG_DEBUG_FS diff --git a/drivers/misc/habanalabs/hwmon.c b/drivers/misc/habanalabs/hwmon.c index a21a26e07c3b..8c6cd77e6af6 100644 --- a/drivers/misc/habanalabs/hwmon.c +++ b/drivers/misc/habanalabs/hwmon.c @@ -200,6 +200,7 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type, case hwmon_temp: switch (attr) { case hwmon_temp_offset: + case hwmon_temp_reset_history: break; default: return -EINVAL; @@ -216,6 +217,24 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type, } hl_set_pwm_info(hdev, channel, attr, val); break; + case hwmon_in: + switch (attr) { + case hwmon_in_reset_history: + break; + default: + return -EINVAL; + } + hl_set_voltage(hdev, channel, attr, val); + break; + case hwmon_curr: + switch (attr) { + case hwmon_curr_reset_history: + break; + default: + return -EINVAL; + } + hl_set_current(hdev, channel, attr, val); + break; default: return -EINVAL; } @@ -237,6 +256,8 @@ static umode_t hl_is_visible(const void *data, enum hwmon_sensor_types type, return 0444; case hwmon_temp_offset: return 0644; + case hwmon_temp_reset_history: + return 0200; } break; case hwmon_in: @@ -246,6 +267,8 @@ static umode_t hl_is_visible(const void *data, enum hwmon_sensor_types type, case hwmon_in_max: case hwmon_in_highest: return 0444; + case hwmon_in_reset_history: + return 0200; } break; case hwmon_curr: @@ -255,6 +278,8 @@ static umode_t hl_is_visible(const void *data, enum hwmon_sensor_types type, case hwmon_curr_max: case hwmon_curr_highest: return 0444; + case hwmon_curr_reset_history: + return 0200; } break; case hwmon_fan: @@ -462,6 +487,56 @@ void hl_set_pwm_info(struct hl_device *hdev, int sensor_index, u32 attr, sensor_index, rc); } +int hl_set_voltage(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_VOLTAGE_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 voltage of sensor %d, error %d\n", + sensor_index, rc); + + return rc; +} + +int hl_set_current(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_CURRENT_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 current of sensor %d, error %d\n", + sensor_index, rc); + + return rc; +} + int hl_hwmon_init(struct hl_device *hdev) { struct device *dev = hdev->pdev ? &hdev->pdev->dev : hdev->dev; diff --git a/drivers/misc/habanalabs/include/armcp_if.h b/drivers/misc/habanalabs/include/armcp_if.h index bdd0a4c3a9cf..9e3bc21f20a0 100644 --- a/drivers/misc/habanalabs/include/armcp_if.h +++ b/drivers/misc/habanalabs/include/armcp_if.h @@ -193,6 +193,16 @@ enum pq_init_status { * Set the value of the offset property of a specified thermal sensor. * The packet's arguments specify the desired sensor and the field to * set. + * + * ARMCP_PACKET_VOLTAGE_SET - + * Trigger the reset_history property of a specified voltage sensor. + * The packet's arguments specify the desired sensor and the field to + * set. + * + * ARMCP_PACKET_CURRENT_SET - + * Trigger the reset_history property of a specified current sensor. + * The packet's arguments specify the desired sensor and the field to + * set. */ enum armcp_packet_id { @@ -220,6 +230,8 @@ enum armcp_packet_id { ARMCP_PACKET_EEPROM_DATA_GET, /* sysfs */ ARMCP_RESERVED, ARMCP_PACKET_TEMPERATURE_SET, /* sysfs */ + ARMCP_PACKET_VOLTAGE_SET, /* sysfs */ + ARMCP_PACKET_CURRENT_SET, /* sysfs */ }; #define ARMCP_PACKET_FENCE_VAL 0xFE8CE7A5 @@ -288,21 +300,24 @@ enum armcp_temp_type { armcp_temp_crit, armcp_temp_crit_hyst, armcp_temp_offset = 19, - armcp_temp_highest = 22 + armcp_temp_highest = 22, + armcp_temp_reset_history = 23 }; enum armcp_in_attributes { armcp_in_input, armcp_in_min, armcp_in_max, - armcp_in_highest = 7 + armcp_in_highest = 7, + armcp_in_reset_history }; enum armcp_curr_attributes { armcp_curr_input, armcp_curr_min, armcp_curr_max, - armcp_curr_highest = 7 + armcp_curr_highest = 7, + armcp_curr_reset_history }; enum armcp_fan_attributes { |