mlxsw: hwmon: Provide optimization for QSFP modules number detection

Use new field "num_of_modules" of MGPIR register for "hwmon" interface
in order to get the number of modules supported by system directly from
the system configuration, instead of getting it from port to module
mapping info.

Reading this info through MGPIR register is faster and does not depend
on possible dynamic re-configuration of ports.
In case of port dynamic re-configuration some modules can logically
"disappear" as a result of port split and un-spilt operations, which
can cause missing of some modules, in case this info is taken from port
to module mapping info.

Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Vadim Pasternak 2019-10-06 09:34:49 +03:00 committed by David S. Miller
parent 5cfa030a1c
commit ea30a92a46
1 changed files with 29 additions and 35 deletions

View File

@ -41,7 +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; u8 module_sensor_max;
}; };
static ssize_t mlxsw_hwmon_temp_show(struct device *dev, static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
@ -56,7 +56,7 @@ static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
int err; int err;
index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index,
mlxsw_hwmon->module_sensor_count); mlxsw_hwmon->module_sensor_max);
mlxsw_reg_mtmp_pack(mtmp_pl, index, false, false); 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) {
@ -79,7 +79,7 @@ static ssize_t mlxsw_hwmon_temp_max_show(struct device *dev,
int err; int err;
index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index,
mlxsw_hwmon->module_sensor_count); mlxsw_hwmon->module_sensor_max);
mlxsw_reg_mtmp_pack(mtmp_pl, index, false, false); 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) {
@ -109,7 +109,7 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
return -EINVAL; return -EINVAL;
index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlwsw_hwmon_attr->type_index,
mlxsw_hwmon->module_sensor_count); mlxsw_hwmon->module_sensor_max);
mlxsw_reg_mtmp_pack(mtmp_pl, index, true, true); 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) {
@ -336,7 +336,7 @@ mlxsw_hwmon_gbox_temp_label_show(struct device *dev,
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
int index = mlwsw_hwmon_attr->type_index - int index = mlwsw_hwmon_attr->type_index -
mlxsw_hwmon->module_sensor_count + 1; mlxsw_hwmon->module_sensor_max + 1;
return sprintf(buf, "gearbox %03u\n", index); return sprintf(buf, "gearbox %03u\n", index);
} }
@ -528,51 +528,45 @@ static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon *mlxsw_hwmon)
static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon) static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
{ {
unsigned int module_count = mlxsw_core_max_ports(mlxsw_hwmon->core); char mgpir_pl[MLXSW_REG_MGPIR_LEN];
char pmlp_pl[MLXSW_REG_PMLP_LEN] = {0}; u8 module_sensor_max;
int i, index; int i, err;
u8 width;
int err;
if (!mlxsw_core_res_query_enabled(mlxsw_hwmon->core)) if (!mlxsw_core_res_query_enabled(mlxsw_hwmon->core))
return 0; return 0;
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, NULL, NULL, NULL,
&module_sensor_max);
/* Add extra attributes for module temperature. Sensor index is /* Add extra attributes for module temperature. Sensor index is
* assigned to sensor_count value, while all indexed before * assigned to sensor_count value, while all indexed before
* sensor_count are already utilized by the sensors connected through * sensor_count are already utilized by the sensors connected through
* mtmp register by mlxsw_hwmon_temp_init(). * mtmp register by mlxsw_hwmon_temp_init().
*/ */
index = mlxsw_hwmon->sensor_count; mlxsw_hwmon->module_sensor_max = mlxsw_hwmon->sensor_count +
for (i = 1; i < module_count; i++) { module_sensor_max;
mlxsw_reg_pmlp_pack(pmlp_pl, i); for (i = mlxsw_hwmon->sensor_count;
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(pmlp), i < mlxsw_hwmon->module_sensor_max; i++) {
pmlp_pl);
if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to read module index %d\n",
i);
return err;
}
width = mlxsw_reg_pmlp_width_get(pmlp_pl);
if (!width)
continue;
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE, index, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE, i, i);
index);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_FAULT, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_FAULT,
index, index); i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT, i,
index, index); i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG,
index, index); i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL,
index, index); i, i);
index++;
} }
mlxsw_hwmon->module_sensor_count = index;
return 0; return 0;
} }
@ -594,10 +588,10 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon)
if (!gbox_num) if (!gbox_num)
return 0; return 0;
index = mlxsw_hwmon->module_sensor_count; index = mlxsw_hwmon->module_sensor_max;
max_index = mlxsw_hwmon->module_sensor_count + gbox_num; max_index = mlxsw_hwmon->module_sensor_max + gbox_num;
while (index < max_index) { while (index < max_index) {
sensor_index = index % mlxsw_hwmon->module_sensor_count + sensor_index = index % mlxsw_hwmon->module_sensor_max +
MLXSW_REG_MTMP_GBOX_INDEX_MIN; MLXSW_REG_MTMP_GBOX_INDEX_MIN;
mlxsw_reg_mtmp_pack(mtmp_pl, sensor_index, true, true); mlxsw_reg_mtmp_pack(mtmp_pl, sensor_index, true, true);
err = mlxsw_reg_write(mlxsw_hwmon->core, err = mlxsw_reg_write(mlxsw_hwmon->core,