Skip to content

Commit 2c6a33c

Browse files
mellanoxbmcdavem330
authored andcommitted
mlxsw: core: Extend hwmon interface with fan fault attribute
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 <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2ee1165 commit 2c6a33c

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ static ssize_t mlxsw_hwmon_fan_rpm_show(struct device *dev,
121121
return sprintf(buf, "%u\n", mlxsw_reg_mfsm_rpm_get(mfsm_pl));
122122
}
123123

124+
static ssize_t mlxsw_hwmon_fan_fault_show(struct device *dev,
125+
struct device_attribute *attr,
126+
char *buf)
127+
{
128+
struct mlxsw_hwmon_attr *mlwsw_hwmon_attr =
129+
container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
130+
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
131+
char fore_pl[MLXSW_REG_FORE_LEN];
132+
bool fault;
133+
int err;
134+
135+
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(fore), fore_pl);
136+
if (err) {
137+
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query fan\n");
138+
return err;
139+
}
140+
mlxsw_reg_fore_unpack(fore_pl, mlwsw_hwmon_attr->type_index, &fault);
141+
142+
return sprintf(buf, "%u\n", fault);
143+
}
144+
124145
static ssize_t mlxsw_hwmon_pwm_show(struct device *dev,
125146
struct device_attribute *attr,
126147
char *buf)
@@ -172,6 +193,7 @@ enum mlxsw_hwmon_attr_type {
172193
MLXSW_HWMON_ATTR_TYPE_TEMP_MAX,
173194
MLXSW_HWMON_ATTR_TYPE_TEMP_RST,
174195
MLXSW_HWMON_ATTR_TYPE_FAN_RPM,
196+
MLXSW_HWMON_ATTR_TYPE_FAN_FAULT,
175197
MLXSW_HWMON_ATTR_TYPE_PWM,
176198
};
177199

@@ -209,6 +231,12 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
209231
snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
210232
"fan%u_input", num + 1);
211233
break;
234+
case MLXSW_HWMON_ATTR_TYPE_FAN_FAULT:
235+
mlxsw_hwmon_attr->dev_attr.show = mlxsw_hwmon_fan_fault_show;
236+
mlxsw_hwmon_attr->dev_attr.attr.mode = 0444;
237+
snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
238+
"fan%u_fault", num + 1);
239+
break;
212240
case MLXSW_HWMON_ATTR_TYPE_PWM:
213241
mlxsw_hwmon_attr->dev_attr.show = mlxsw_hwmon_pwm_show;
214242
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)
280308
mlxsw_reg_mfcr_unpack(mfcr_pl, &freq, &tacho_active, &pwm_active);
281309
num = 0;
282310
for (type_index = 0; type_index < MLXSW_MFCR_TACHOS_MAX; type_index++) {
283-
if (tacho_active & BIT(type_index))
311+
if (tacho_active & BIT(type_index)) {
284312
mlxsw_hwmon_attr_add(mlxsw_hwmon,
285313
MLXSW_HWMON_ATTR_TYPE_FAN_RPM,
314+
type_index, num);
315+
mlxsw_hwmon_attr_add(mlxsw_hwmon,
316+
MLXSW_HWMON_ATTR_TYPE_FAN_FAULT,
286317
type_index, num++);
318+
}
287319
}
288320
num = 0;
289321
for (type_index = 0; type_index < MLXSW_MFCR_PWMS_MAX; type_index++) {

0 commit comments

Comments
 (0)