Skip to content

Commit e57977b

Browse files
odmykodavem330
authored andcommitted
mlxsw: thermal: Add function for reading module temperature and thresholds
Provide new function mlxsw_thermal_module_temp_and_thresholds_get() for reading temperature and temperature thresholds by a single operation. The motivation is to reduce the number of transactions with the device which is important when operating over a slow bus such as I2C. Currently, the sole caller of the function is only using it to read the module's temperature. The next patch will also use it to query the module's temperature thresholds. Signed-off-by: Mykola Kostenok <[email protected]> Acked-by: Vadim Pasternak <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent befc204 commit e57977b

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -420,29 +420,49 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
420420
return err;
421421
}
422422

423+
static void
424+
mlxsw_thermal_module_temp_and_thresholds_get(struct mlxsw_core *core,
425+
u16 sensor_index, int *p_temp,
426+
int *p_crit_temp,
427+
int *p_emerg_temp)
428+
{
429+
char mtmp_pl[MLXSW_REG_MTMP_LEN];
430+
int err;
431+
432+
/* Read module temperature and thresholds. */
433+
mlxsw_reg_mtmp_pack(mtmp_pl, sensor_index, false, false);
434+
err = mlxsw_reg_query(core, MLXSW_REG(mtmp), mtmp_pl);
435+
if (err) {
436+
/* Set temperature and thresholds to zero to avoid passing
437+
* uninitialized data back to the caller.
438+
*/
439+
*p_temp = 0;
440+
*p_crit_temp = 0;
441+
*p_emerg_temp = 0;
442+
443+
return;
444+
}
445+
mlxsw_reg_mtmp_unpack(mtmp_pl, p_temp, NULL, p_crit_temp, p_emerg_temp,
446+
NULL);
447+
}
448+
423449
static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
424450
int *p_temp)
425451
{
426452
struct mlxsw_thermal_module *tz = tzdev->devdata;
427453
struct mlxsw_thermal *thermal = tz->parent;
428-
struct device *dev = thermal->bus_info->dev;
429-
char mtmp_pl[MLXSW_REG_MTMP_LEN];
454+
struct device *dev;
455+
u16 sensor_index;
430456
int temp;
431457
int err;
432458

433-
/* Read module temperature. */
434-
mlxsw_reg_mtmp_pack(mtmp_pl, MLXSW_REG_MTMP_MODULE_INDEX_MIN +
435-
tz->module, false, false);
436-
err = mlxsw_reg_query(thermal->core, MLXSW_REG(mtmp), mtmp_pl);
437-
if (err) {
438-
/* Do not return error - in case of broken module's sensor
439-
* it will cause error message flooding.
440-
*/
441-
temp = 0;
442-
*p_temp = (int) temp;
443-
return 0;
444-
}
445-
mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL, NULL, NULL);
459+
dev = thermal->bus_info->dev;
460+
sensor_index = MLXSW_REG_MTMP_MODULE_INDEX_MIN + tz->module;
461+
462+
/* Read module temperature and thresholds. */
463+
mlxsw_thermal_module_temp_and_thresholds_get(thermal->core,
464+
sensor_index, &temp, NULL,
465+
NULL);
446466
*p_temp = temp;
447467

448468
if (!temp)

0 commit comments

Comments
 (0)