]> git.baikalelectronics.ru Git - kernel.git/commitdiff
habanalabs: support hwmon_reset_history attribute
authorChristine Gharzuzi <cgharzuzi@habana.ai>
Thu, 16 Apr 2020 13:43:26 +0000 (16:43 +0300)
committerOded Gabbay <oded.gabbay@gmail.com>
Tue, 19 May 2020 11:48:41 +0000 (14:48 +0300)
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>
drivers/misc/habanalabs/habanalabs.h
drivers/misc/habanalabs/hwmon.c
drivers/misc/habanalabs/include/armcp_if.h

index a8ee241b2fcedecba463e8c01e959e687ad3b98f..0d3d3c59ae2b034b84023d54aa952c90f429cca7 100644 (file)
@@ -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
 
index a21a26e07c3b6904c4fdaa349635247b26cf7c01..8c6cd77e6af6bd3b6ada7cd114867d9d528191a7 100644 (file)
@@ -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;
index bdd0a4c3a9cf3d236574e3572f0ed725a783a6e7..9e3bc21f20a0538bf9f819735d79b1ad66525678 100644 (file)
@@ -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 {