Skip to content

Commit

Permalink
mlxsw: core_hwmon: Extend hwmon interface with critical and emergency…
Browse files Browse the repository at this point in the history
… alarms

Add new attributes to hwmon object for exposing critical and emergency
alarms.

In case that current temperature is higher than emergency threshold,
EMERGENCY alarm will be reported in sensors utility:

$ sensors
...
front panel 025:  +55.0°C  (crit = +35.0°C, emerg = +40.0°C) ALARM(EMERGENCY)

In case that current temperature is higher than critical threshold,
CRIT alarm will be reported in sensors utility:

$ sensors
...
front panel 025:  +54.0°C  (crit = +35.0°C, emerg = +80.0°C) ALARM(CRIT)

Signed-off-by: Amit Cohen <[email protected]>
Reviewed-by: Petr Machata <[email protected]>
Acked-by: Vadim Pasternak <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
amitcohen1 authored and davem330 committed Sep 3, 2020
1 parent 02bed4e commit 91df5d3
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define MLXSW_HWMON_GEARBOXES_MAX_COUNT 32

#define MLXSW_HWMON_ATTR_PER_SENSOR 3
#define MLXSW_HWMON_ATTR_PER_MODULE 5
#define MLXSW_HWMON_ATTR_PER_MODULE 7
#define MLXSW_HWMON_ATTR_PER_GEARBOX 4

#define MLXSW_HWMON_ATTR_COUNT (MLXSW_HWMON_SENSORS_MAX_COUNT * MLXSW_HWMON_ATTR_PER_SENSOR + \
Expand Down Expand Up @@ -388,6 +388,53 @@ mlxsw_hwmon_gbox_temp_label_show(struct device *dev,
return sprintf(buf, "gearbox %03u\n", index);
}

static ssize_t mlxsw_hwmon_temp_critical_alarm_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int err, temp, emergency_temp, critic_temp;

err = mlxsw_hwmon_module_temp_get(dev, attr, &temp);
if (err)
return err;

if (temp <= 0)
return sprintf(buf, "%d\n", false);

err = mlxsw_hwmon_module_temp_emergency_get(dev, attr, &emergency_temp);
if (err)
return err;

if (temp >= emergency_temp)
return sprintf(buf, "%d\n", false);

err = mlxsw_hwmon_module_temp_critical_get(dev, attr, &critic_temp);
if (err)
return err;

return sprintf(buf, "%d\n", temp >= critic_temp);
}

static ssize_t mlxsw_hwmon_temp_emergency_alarm_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int err, temp, emergency_temp;

err = mlxsw_hwmon_module_temp_get(dev, attr, &temp);
if (err)
return err;

if (temp <= 0)
return sprintf(buf, "%d\n", false);

err = mlxsw_hwmon_module_temp_emergency_get(dev, attr, &emergency_temp);
if (err)
return err;

return sprintf(buf, "%d\n", temp >= emergency_temp);
}

enum mlxsw_hwmon_attr_type {
MLXSW_HWMON_ATTR_TYPE_TEMP,
MLXSW_HWMON_ATTR_TYPE_TEMP_MAX,
Expand All @@ -401,6 +448,8 @@ enum mlxsw_hwmon_attr_type {
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL,
MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL,
MLXSW_HWMON_ATTR_TYPE_TEMP_CRIT_ALARM,
MLXSW_HWMON_ATTR_TYPE_TEMP_EMERGENCY_ALARM,
};

static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
Expand Down Expand Up @@ -491,6 +540,20 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
"temp%u_label", num + 1);
break;
case MLXSW_HWMON_ATTR_TYPE_TEMP_CRIT_ALARM:
mlxsw_hwmon_attr->dev_attr.show =
mlxsw_hwmon_temp_critical_alarm_show;
mlxsw_hwmon_attr->dev_attr.attr.mode = 0444;
snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
"temp%u_crit_alarm", num + 1);
break;
case MLXSW_HWMON_ATTR_TYPE_TEMP_EMERGENCY_ALARM:
mlxsw_hwmon_attr->dev_attr.show =
mlxsw_hwmon_temp_emergency_alarm_show;
mlxsw_hwmon_attr->dev_attr.attr.mode = 0444;
snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
"temp%u_emergency_alarm", num + 1);
break;
default:
WARN_ON(1);
}
Expand Down Expand Up @@ -613,6 +676,12 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL,
i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_CRIT_ALARM,
i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_EMERGENCY_ALARM,
i, i);
}

return 0;
Expand Down

0 comments on commit 91df5d3

Please sign in to comment.