Skip to content

Commit 36844c8

Browse files
mellanoxbmcdavem330
authored andcommitted
mlxsw: core: Add validation of hardware device types for MGPIR register
When reading the number of gearboxes from the hardware, the driver does not validate the returned 'device type' field. The driver can therefore wrongly assume that the queried devices are gearboxes. On Spectrum-3 systems that support different types of devices, this can prevent the driver from loading, as it will try to query the temperature sensors from devices which it assumes are gearboxes and in fact are not. For example: [ 218.129230] mlxsw_minimal 2-0048: Reg cmd access status failed (status=7(bad parameter)) [ 218.138282] mlxsw_minimal 2-0048: Reg cmd access failed (reg_id=900a(mtmp),type=write) [ 218.147131] mlxsw_minimal 2-0048: Failed to setup temp sensor number 256 [ 218.534480] mlxsw_minimal 2-0048: Fail to register core bus [ 218.540714] mlxsw_minimal: probe of 2-0048 failed with error -5 Fix this by validating the 'device type' field. Fixes: 2e265a8 ("mlxsw: core: Extend hwmon interface with inter-connect temperature attributes") Fixes: f14f4e6 ("mlxsw: core: Extend thermal core with per inter-connect device thermal zones") 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>
1 parent 490f054 commit 36844c8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
573573

574574
static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon)
575575
{
576+
enum mlxsw_reg_mgpir_device_type device_type;
576577
int index, max_index, sensor_index;
577578
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
578579
char mtmp_pl[MLXSW_REG_MTMP_LEN];
@@ -584,8 +585,9 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon)
584585
if (err)
585586
return err;
586587

587-
mlxsw_reg_mgpir_unpack(mgpir_pl, &gbox_num, NULL, NULL, NULL);
588-
if (!gbox_num)
588+
mlxsw_reg_mgpir_unpack(mgpir_pl, &gbox_num, &device_type, NULL, NULL);
589+
if (device_type != MLXSW_REG_MGPIR_DEVICE_TYPE_GEARBOX_DIE ||
590+
!gbox_num)
589591
return 0;
590592

591593
index = mlxsw_hwmon->module_sensor_max;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,10 @@ static int
895895
mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
896896
struct mlxsw_thermal *thermal)
897897
{
898+
enum mlxsw_reg_mgpir_device_type device_type;
898899
struct mlxsw_thermal_module *gearbox_tz;
899900
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
901+
u8 gbox_num;
900902
int i;
901903
int err;
902904

@@ -908,11 +910,13 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
908910
if (err)
909911
return err;
910912

911-
mlxsw_reg_mgpir_unpack(mgpir_pl, &thermal->tz_gearbox_num, NULL, NULL,
913+
mlxsw_reg_mgpir_unpack(mgpir_pl, &gbox_num, &device_type, NULL,
912914
NULL);
913-
if (!thermal->tz_gearbox_num)
915+
if (device_type != MLXSW_REG_MGPIR_DEVICE_TYPE_GEARBOX_DIE ||
916+
!gbox_num)
914917
return 0;
915918

919+
thermal->tz_gearbox_num = gbox_num;
916920
thermal->tz_gearbox_arr = kcalloc(thermal->tz_gearbox_num,
917921
sizeof(*thermal->tz_gearbox_arr),
918922
GFP_KERNEL);

0 commit comments

Comments
 (0)