Commit 2e265a8b authored by Vadim Pasternak's avatar Vadim Pasternak Committed by David S. Miller

mlxsw: core: Extend hwmon interface with inter-connect temperature attributes

Add new attributes to hwmon object for exposing inter-connects temperature
input, highest, reset_history temperatures and label. Temperatures are read
from Management Temperature Register.
The number of inter-connect devices is read from Management General
Peripheral Information Register.
Signed-off-by: default avatarVadim Pasternak <vadimp@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7e9561ed
...@@ -23,6 +23,14 @@ struct mlxsw_hwmon_attr { ...@@ -23,6 +23,14 @@ struct mlxsw_hwmon_attr {
char name[32]; char name[32];
}; };
static int mlxsw_hwmon_get_attr_index(int index, int count)
{
if (index >= count)
return index % count + MLXSW_REG_MTMP_GBOX_INDEX_MIN;
return index;
}
struct mlxsw_hwmon { struct mlxsw_hwmon {
struct mlxsw_core *core; struct mlxsw_core *core;
const struct mlxsw_bus_info *bus_info; const struct mlxsw_bus_info *bus_info;
...@@ -33,6 +41,7 @@ struct mlxsw_hwmon { ...@@ -33,6 +41,7 @@ struct mlxsw_hwmon {
struct mlxsw_hwmon_attr hwmon_attrs[MLXSW_HWMON_ATTR_COUNT]; struct mlxsw_hwmon_attr hwmon_attrs[MLXSW_HWMON_ATTR_COUNT];
unsigned int attrs_count; unsigned int attrs_count;
u8 sensor_count; u8 sensor_count;
u8 module_sensor_count;
}; };
static ssize_t mlxsw_hwmon_temp_show(struct device *dev, static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
...@@ -44,10 +53,12 @@ static ssize_t mlxsw_hwmon_temp_show(struct device *dev, ...@@ -44,10 +53,12 @@ static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
unsigned int temp; unsigned int temp;
int index;
int err; int err;
mlxsw_reg_mtmp_pack(mtmp_pl, mlwsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index,
false, false); mlxsw_hwmon->module_sensor_count);
mlxsw_reg_mtmp_pack(mtmp_pl, index, false, false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) { if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n"); dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n");
...@@ -66,10 +77,12 @@ static ssize_t mlxsw_hwmon_temp_max_show(struct device *dev, ...@@ -66,10 +77,12 @@ static ssize_t mlxsw_hwmon_temp_max_show(struct device *dev,
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
unsigned int temp_max; unsigned int temp_max;
int index;
int err; int err;
mlxsw_reg_mtmp_pack(mtmp_pl, mlwsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index,
false, false); mlxsw_hwmon->module_sensor_count);
mlxsw_reg_mtmp_pack(mtmp_pl, index, false, false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) { if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n"); dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n");
...@@ -88,6 +101,7 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev, ...@@ -88,6 +101,7 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
unsigned long val; unsigned long val;
int index;
int err; int err;
err = kstrtoul(buf, 10, &val); err = kstrtoul(buf, 10, &val);
...@@ -96,7 +110,9 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev, ...@@ -96,7 +110,9 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
if (val != 1) if (val != 1)
return -EINVAL; return -EINVAL;
mlxsw_reg_mtmp_pack(mtmp_pl, mlwsw_hwmon_attr->type_index, true, true); index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index,
mlxsw_hwmon->module_sensor_count);
mlxsw_reg_mtmp_pack(mtmp_pl, index, true, true);
err = mlxsw_reg_write(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_write(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) { if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to reset temp sensor history\n"); dev_err(mlxsw_hwmon->bus_info->dev, "Failed to reset temp sensor history\n");
...@@ -333,6 +349,20 @@ mlxsw_hwmon_module_temp_label_show(struct device *dev, ...@@ -333,6 +349,20 @@ mlxsw_hwmon_module_temp_label_show(struct device *dev,
mlwsw_hwmon_attr->type_index); mlwsw_hwmon_attr->type_index);
} }
static ssize_t
mlxsw_hwmon_gbox_temp_label_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;
int index = mlwsw_hwmon_attr->type_index -
mlxsw_hwmon->module_sensor_count + 1;
return sprintf(buf, "gearbox %03u\n", index);
}
enum mlxsw_hwmon_attr_type { enum mlxsw_hwmon_attr_type {
MLXSW_HWMON_ATTR_TYPE_TEMP, MLXSW_HWMON_ATTR_TYPE_TEMP,
MLXSW_HWMON_ATTR_TYPE_TEMP_MAX, MLXSW_HWMON_ATTR_TYPE_TEMP_MAX,
...@@ -345,6 +375,7 @@ enum mlxsw_hwmon_attr_type { ...@@ -345,6 +375,7 @@ enum mlxsw_hwmon_attr_type {
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL,
MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL,
}; };
static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon, static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
...@@ -428,6 +459,13 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon, ...@@ -428,6 +459,13 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name), snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
"temp%u_label", num + 1); "temp%u_label", num + 1);
break; break;
case MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL:
mlxsw_hwmon_attr->dev_attr.show =
mlxsw_hwmon_gbox_temp_label_show;
mlxsw_hwmon_attr->dev_attr.attr.mode = 0444;
snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
"temp%u_label", num + 1);
break;
default: default:
WARN_ON(1); WARN_ON(1);
} }
...@@ -556,6 +594,54 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -556,6 +594,54 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
index, index); index, index);
index++; index++;
} }
mlxsw_hwmon->module_sensor_count = index;
return 0;
}
static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon)
{
int index, max_index, sensor_index;
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
char mtmp_pl[MLXSW_REG_MTMP_LEN];
u8 gbox_num;
int err;
mlxsw_reg_mgpir_pack(mgpir_pl);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mgpir), mgpir_pl);
if (err)
return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, &gbox_num, NULL, NULL);
if (!gbox_num)
return 0;
index = mlxsw_hwmon->module_sensor_count;
max_index = mlxsw_hwmon->module_sensor_count + gbox_num;
while (index < max_index) {
sensor_index = index % mlxsw_hwmon->module_sensor_count +
MLXSW_REG_MTMP_GBOX_INDEX_MIN;
mlxsw_reg_mtmp_pack(mtmp_pl, sensor_index, true, true);
err = mlxsw_reg_write(mlxsw_hwmon->core,
MLXSW_REG(mtmp), mtmp_pl);
if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to setup temp sensor number %d\n",
sensor_index);
return err;
}
mlxsw_hwmon_attr_add(mlxsw_hwmon, MLXSW_HWMON_ATTR_TYPE_TEMP,
index, index);
mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_MAX, index,
index);
mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_RST, index,
index);
mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL,
index, index);
index++;
}
return 0; return 0;
} }
...@@ -586,6 +672,10 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, ...@@ -586,6 +672,10 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
if (err) if (err)
goto err_temp_module_init; goto err_temp_module_init;
err = mlxsw_hwmon_gearbox_init(mlxsw_hwmon);
if (err)
goto err_temp_gearbox_init;
mlxsw_hwmon->groups[0] = &mlxsw_hwmon->group; mlxsw_hwmon->groups[0] = &mlxsw_hwmon->group;
mlxsw_hwmon->group.attrs = mlxsw_hwmon->attrs; mlxsw_hwmon->group.attrs = mlxsw_hwmon->attrs;
...@@ -602,6 +692,7 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, ...@@ -602,6 +692,7 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
return 0; return 0;
err_hwmon_register: err_hwmon_register:
err_temp_gearbox_init:
err_temp_module_init: err_temp_module_init:
err_fans_init: err_fans_init:
err_temp_init: err_temp_init:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment