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

mlxsw: thermal: Provide optimization for QSFP modules number detection

Use new field "num_of_modules" of MGPIR register for "thermal" 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.
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 ea30a92a
...@@ -112,6 +112,7 @@ struct mlxsw_thermal { ...@@ -112,6 +112,7 @@ struct mlxsw_thermal {
struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS];
enum thermal_device_mode mode; enum thermal_device_mode mode;
struct mlxsw_thermal_module *tz_module_arr; struct mlxsw_thermal_module *tz_module_arr;
u8 tz_module_num;
struct mlxsw_thermal_module *tz_gearbox_arr; struct mlxsw_thermal_module *tz_gearbox_arr;
u8 tz_gearbox_num; u8 tz_gearbox_num;
unsigned int tz_highest_score; unsigned int tz_highest_score;
...@@ -775,23 +776,10 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev) ...@@ -775,23 +776,10 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
static int static int
mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core, mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core,
struct mlxsw_thermal *thermal, u8 local_port) struct mlxsw_thermal *thermal, u8 module)
{ {
struct mlxsw_thermal_module *module_tz; struct mlxsw_thermal_module *module_tz;
char pmlp_pl[MLXSW_REG_PMLP_LEN];
u8 width, module;
int err;
mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
err = mlxsw_reg_query(core, MLXSW_REG(pmlp), pmlp_pl);
if (err)
return err;
width = mlxsw_reg_pmlp_width_get(pmlp_pl);
if (!width)
return 0;
module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0);
module_tz = &thermal->tz_module_arr[module]; module_tz = &thermal->tz_module_arr[module];
/* Skip if parent is already set (case of port split). */ /* Skip if parent is already set (case of port split). */
if (module_tz->parent) if (module_tz->parent)
...@@ -819,26 +807,34 @@ static int ...@@ -819,26 +807,34 @@ static int
mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core, mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
struct mlxsw_thermal *thermal) struct mlxsw_thermal *thermal)
{ {
unsigned int module_count = mlxsw_core_max_ports(core);
struct mlxsw_thermal_module *module_tz; struct mlxsw_thermal_module *module_tz;
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
int i, err; int i, err;
if (!mlxsw_core_res_query_enabled(core)) if (!mlxsw_core_res_query_enabled(core))
return 0; return 0;
thermal->tz_module_arr = kcalloc(module_count, mlxsw_reg_mgpir_pack(mgpir_pl);
err = mlxsw_reg_query(core, MLXSW_REG(mgpir), mgpir_pl);
if (err)
return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL,
&thermal->tz_module_num);
thermal->tz_module_arr = kcalloc(thermal->tz_module_num,
sizeof(*thermal->tz_module_arr), sizeof(*thermal->tz_module_arr),
GFP_KERNEL); GFP_KERNEL);
if (!thermal->tz_module_arr) if (!thermal->tz_module_arr)
return -ENOMEM; return -ENOMEM;
for (i = 1; i < module_count; i++) { for (i = 0; i < thermal->tz_module_num; i++) {
err = mlxsw_thermal_module_init(dev, core, thermal, i); err = mlxsw_thermal_module_init(dev, core, thermal, i);
if (err) if (err)
goto err_unreg_tz_module_arr; goto err_unreg_tz_module_arr;
} }
for (i = 0; i < module_count - 1; i++) { for (i = 0; i < thermal->tz_module_num; i++) {
module_tz = &thermal->tz_module_arr[i]; module_tz = &thermal->tz_module_arr[i];
if (!module_tz->parent) if (!module_tz->parent)
continue; continue;
...@@ -850,7 +846,7 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core, ...@@ -850,7 +846,7 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
return 0; return 0;
err_unreg_tz_module_arr: err_unreg_tz_module_arr:
for (i = module_count - 1; i >= 0; i--) for (i = thermal->tz_module_num - 1; i >= 0; i--)
mlxsw_thermal_module_fini(&thermal->tz_module_arr[i]); mlxsw_thermal_module_fini(&thermal->tz_module_arr[i]);
kfree(thermal->tz_module_arr); kfree(thermal->tz_module_arr);
return err; return err;
...@@ -859,13 +855,12 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core, ...@@ -859,13 +855,12 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
static void static void
mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal) mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal)
{ {
unsigned int module_count = mlxsw_core_max_ports(thermal->core);
int i; int i;
if (!mlxsw_core_res_query_enabled(thermal->core)) if (!mlxsw_core_res_query_enabled(thermal->core))
return; return;
for (i = module_count - 1; i >= 0; i--) for (i = thermal->tz_module_num - 1; i >= 0; i--)
mlxsw_thermal_module_fini(&thermal->tz_module_arr[i]); mlxsw_thermal_module_fini(&thermal->tz_module_arr[i]);
kfree(thermal->tz_module_arr); kfree(thermal->tz_module_arr);
} }
......
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