mlxsw: core: Extend hwmon interface with fan fault attribute
authorVadim Pasternak <vadimp@mellanox.com>
Wed, 13 Feb 2019 11:28:53 +0000 (11:28 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 14 Feb 2019 06:33:02 +0000 (22:33 -0800)
Add new fan hwmon attribute for exposing fan faults (fault indication is
read from Fan Out of Range Event Register).

Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c

index e04e8162aa140d42990bfde521cde7ebf0e9d2af..40e13093b62d3646a254c96a4b08f2e6ad84ce2e 100644 (file)
@@ -121,6 +121,27 @@ static ssize_t mlxsw_hwmon_fan_rpm_show(struct device *dev,
        return sprintf(buf, "%u\n", mlxsw_reg_mfsm_rpm_get(mfsm_pl));
 }
 
+static ssize_t mlxsw_hwmon_fan_fault_show(struct device *dev,
+                                         struct device_attribute *attr,
+                                         char *buf)
+{
+       struct mlxsw_hwmon_attr *mlwsw_hwmon_attr =
+                       container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
+       struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
+       char fore_pl[MLXSW_REG_FORE_LEN];
+       bool fault;
+       int err;
+
+       err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(fore), fore_pl);
+       if (err) {
+               dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query fan\n");
+               return err;
+       }
+       mlxsw_reg_fore_unpack(fore_pl, mlwsw_hwmon_attr->type_index, &fault);
+
+       return sprintf(buf, "%u\n", fault);
+}
+
 static ssize_t mlxsw_hwmon_pwm_show(struct device *dev,
                                    struct device_attribute *attr,
                                    char *buf)
@@ -172,6 +193,7 @@ enum mlxsw_hwmon_attr_type {
        MLXSW_HWMON_ATTR_TYPE_TEMP_MAX,
        MLXSW_HWMON_ATTR_TYPE_TEMP_RST,
        MLXSW_HWMON_ATTR_TYPE_FAN_RPM,
+       MLXSW_HWMON_ATTR_TYPE_FAN_FAULT,
        MLXSW_HWMON_ATTR_TYPE_PWM,
 };
 
@@ -209,6 +231,12 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
                snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
                         "fan%u_input", num + 1);
                break;
+       case MLXSW_HWMON_ATTR_TYPE_FAN_FAULT:
+               mlxsw_hwmon_attr->dev_attr.show = mlxsw_hwmon_fan_fault_show;
+               mlxsw_hwmon_attr->dev_attr.attr.mode = 0444;
+               snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
+                        "fan%u_fault", num + 1);
+               break;
        case MLXSW_HWMON_ATTR_TYPE_PWM:
                mlxsw_hwmon_attr->dev_attr.show = mlxsw_hwmon_pwm_show;
                mlxsw_hwmon_attr->dev_attr.store = mlxsw_hwmon_pwm_store;
@@ -280,10 +308,14 @@ static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon *mlxsw_hwmon)
        mlxsw_reg_mfcr_unpack(mfcr_pl, &freq, &tacho_active, &pwm_active);
        num = 0;
        for (type_index = 0; type_index < MLXSW_MFCR_TACHOS_MAX; type_index++) {
-               if (tacho_active & BIT(type_index))
+               if (tacho_active & BIT(type_index)) {
                        mlxsw_hwmon_attr_add(mlxsw_hwmon,
                                             MLXSW_HWMON_ATTR_TYPE_FAN_RPM,
+                                            type_index, num);
+                       mlxsw_hwmon_attr_add(mlxsw_hwmon,
+                                            MLXSW_HWMON_ATTR_TYPE_FAN_FAULT,
                                             type_index, num++);
+               }
        }
        num = 0;
        for (type_index = 0; type_index < MLXSW_MFCR_PWMS_MAX; type_index++) {