Skip to content

Commit f85b882

Browse files
committed
Merge branch 'mlxsw-transceiver-trip-points'
Petr Machata says: ==================== mlxsw: Use static trip points for transceiver modules Ido Schimmel writes: See patch #1 for motivation and implementation details. Patches #2-#3 are simple cleanups as a result of the changes in the first patch. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents dd2d660 + cc19439 commit f85b882

1 file changed

Lines changed: 36 additions & 129 deletions

File tree

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

Lines changed: 36 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#define MLXSW_THERMAL_ASIC_TEMP_NORM 75000 /* 75C */
2020
#define MLXSW_THERMAL_ASIC_TEMP_HIGH 85000 /* 85C */
2121
#define MLXSW_THERMAL_ASIC_TEMP_HOT 105000 /* 105C */
22+
#define MLXSW_THERMAL_MODULE_TEMP_NORM 55000 /* 55C */
23+
#define MLXSW_THERMAL_MODULE_TEMP_HIGH 65000 /* 65C */
24+
#define MLXSW_THERMAL_MODULE_TEMP_HOT 80000 /* 80C */
2225
#define MLXSW_THERMAL_HYSTERESIS_TEMP 5000 /* 5C */
2326
#define MLXSW_THERMAL_MODULE_TEMP_SHIFT (MLXSW_THERMAL_HYSTERESIS_TEMP * 2)
2427
#define MLXSW_THERMAL_MAX_STATE 10
@@ -30,12 +33,6 @@ static char * const mlxsw_thermal_external_allowed_cdev[] = {
3033
"mlxreg_fan",
3134
};
3235

33-
enum mlxsw_thermal_trips {
34-
MLXSW_THERMAL_TEMP_TRIP_NORM,
35-
MLXSW_THERMAL_TEMP_TRIP_HIGH,
36-
MLXSW_THERMAL_TEMP_TRIP_HOT,
37-
};
38-
3936
struct mlxsw_cooling_states {
4037
int min_state;
4138
int max_state;
@@ -59,6 +56,24 @@ static const struct thermal_trip default_thermal_trips[] = {
5956
},
6057
};
6158

59+
static const struct thermal_trip default_thermal_module_trips[] = {
60+
{ /* In range - 0-40% PWM */
61+
.type = THERMAL_TRIP_ACTIVE,
62+
.temperature = MLXSW_THERMAL_MODULE_TEMP_NORM,
63+
.hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP,
64+
},
65+
{
66+
/* In range - 40-100% PWM */
67+
.type = THERMAL_TRIP_ACTIVE,
68+
.temperature = MLXSW_THERMAL_MODULE_TEMP_HIGH,
69+
.hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP,
70+
},
71+
{ /* Warning */
72+
.type = THERMAL_TRIP_HOT,
73+
.temperature = MLXSW_THERMAL_MODULE_TEMP_HOT,
74+
},
75+
};
76+
6277
static const struct mlxsw_cooling_states default_cooling_states[] = {
6378
{
6479
.min_state = 0,
@@ -140,63 +155,6 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal,
140155
return -ENODEV;
141156
}
142157

143-
static void
144-
mlxsw_thermal_module_trips_reset(struct mlxsw_thermal_module *tz)
145-
{
146-
tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temperature = 0;
147-
tz->trips[MLXSW_THERMAL_TEMP_TRIP_HIGH].temperature = 0;
148-
tz->trips[MLXSW_THERMAL_TEMP_TRIP_HOT].temperature = 0;
149-
}
150-
151-
static int
152-
mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
153-
struct mlxsw_thermal_module *tz,
154-
int crit_temp, int emerg_temp)
155-
{
156-
int err;
157-
158-
/* Do not try to query temperature thresholds directly from the module's
159-
* EEPROM if we got valid thresholds from MTMP.
160-
*/
161-
if (!emerg_temp || !crit_temp) {
162-
err = mlxsw_env_module_temp_thresholds_get(core, tz->slot_index,
163-
tz->module,
164-
SFP_TEMP_HIGH_WARN,
165-
&crit_temp);
166-
if (err)
167-
return err;
168-
169-
err = mlxsw_env_module_temp_thresholds_get(core, tz->slot_index,
170-
tz->module,
171-
SFP_TEMP_HIGH_ALARM,
172-
&emerg_temp);
173-
if (err)
174-
return err;
175-
}
176-
177-
if (crit_temp > emerg_temp) {
178-
dev_warn(dev, "%s : Critical threshold %d is above emergency threshold %d\n",
179-
tz->tzdev->type, crit_temp, emerg_temp);
180-
return 0;
181-
}
182-
183-
/* According to the system thermal requirements, the thermal zones are
184-
* defined with three trip points. The critical and emergency
185-
* temperature thresholds, provided by QSFP module are set as "active"
186-
* and "hot" trip points, "normal" trip point is derived from "active"
187-
* by subtracting double hysteresis value.
188-
*/
189-
if (crit_temp >= MLXSW_THERMAL_MODULE_TEMP_SHIFT)
190-
tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temperature = crit_temp -
191-
MLXSW_THERMAL_MODULE_TEMP_SHIFT;
192-
else
193-
tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temperature = crit_temp;
194-
tz->trips[MLXSW_THERMAL_TEMP_TRIP_HIGH].temperature = crit_temp;
195-
tz->trips[MLXSW_THERMAL_TEMP_TRIP_HOT].temperature = emerg_temp;
196-
197-
return 0;
198-
}
199-
200158
static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
201159
struct thermal_cooling_device *cdev)
202160
{
@@ -325,59 +283,22 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
325283
return err;
326284
}
327285

328-
static void
329-
mlxsw_thermal_module_temp_and_thresholds_get(struct mlxsw_core *core,
330-
u8 slot_index, u16 sensor_index,
331-
int *p_temp, int *p_crit_temp,
332-
int *p_emerg_temp)
333-
{
334-
char mtmp_pl[MLXSW_REG_MTMP_LEN];
335-
int err;
336-
337-
/* Read module temperature and thresholds. */
338-
mlxsw_reg_mtmp_pack(mtmp_pl, slot_index, sensor_index,
339-
false, false);
340-
err = mlxsw_reg_query(core, MLXSW_REG(mtmp), mtmp_pl);
341-
if (err) {
342-
/* Set temperature and thresholds to zero to avoid passing
343-
* uninitialized data back to the caller.
344-
*/
345-
*p_temp = 0;
346-
*p_crit_temp = 0;
347-
*p_emerg_temp = 0;
348-
349-
return;
350-
}
351-
mlxsw_reg_mtmp_unpack(mtmp_pl, p_temp, NULL, p_crit_temp, p_emerg_temp,
352-
NULL);
353-
}
354-
355286
static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
356287
int *p_temp)
357288
{
358289
struct mlxsw_thermal_module *tz = tzdev->devdata;
359290
struct mlxsw_thermal *thermal = tz->parent;
360-
int temp, crit_temp, emerg_temp;
361-
struct device *dev;
291+
char mtmp_pl[MLXSW_REG_MTMP_LEN];
362292
u16 sensor_index;
293+
int err;
363294

364-
dev = thermal->bus_info->dev;
365295
sensor_index = MLXSW_REG_MTMP_MODULE_INDEX_MIN + tz->module;
366-
367-
/* Read module temperature and thresholds. */
368-
mlxsw_thermal_module_temp_and_thresholds_get(thermal->core,
369-
tz->slot_index,
370-
sensor_index, &temp,
371-
&crit_temp, &emerg_temp);
372-
*p_temp = temp;
373-
374-
if (!temp)
375-
return 0;
376-
377-
/* Update trip points. */
378-
mlxsw_thermal_module_trips_update(dev, thermal->core, tz,
379-
crit_temp, emerg_temp);
380-
296+
mlxsw_reg_mtmp_pack(mtmp_pl, tz->slot_index, sensor_index,
297+
false, false);
298+
err = mlxsw_reg_query(thermal->core, MLXSW_REG(mtmp), mtmp_pl);
299+
if (err)
300+
return err;
301+
mlxsw_reg_mtmp_unpack(mtmp_pl, p_temp, NULL, NULL, NULL, NULL);
381302
return 0;
382303
}
383304

@@ -521,36 +442,26 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
521442
thermal_zone_device_unregister(tzdev);
522443
}
523444

524-
static int
445+
static void
525446
mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core,
526447
struct mlxsw_thermal *thermal,
527448
struct mlxsw_thermal_area *area, u8 module)
528449
{
529450
struct mlxsw_thermal_module *module_tz;
530-
int dummy_temp, crit_temp, emerg_temp;
531-
u16 sensor_index;
532451

533-
sensor_index = MLXSW_REG_MTMP_MODULE_INDEX_MIN + module;
534452
module_tz = &area->tz_module_arr[module];
535453
/* Skip if parent is already set (case of port split). */
536454
if (module_tz->parent)
537-
return 0;
455+
return;
538456
module_tz->module = module;
539457
module_tz->slot_index = area->slot_index;
540458
module_tz->parent = thermal;
541-
memcpy(module_tz->trips, default_thermal_trips,
459+
BUILD_BUG_ON(ARRAY_SIZE(default_thermal_module_trips) !=
460+
MLXSW_THERMAL_NUM_TRIPS);
461+
memcpy(module_tz->trips, default_thermal_module_trips,
542462
sizeof(thermal->trips));
543463
memcpy(module_tz->cooling_states, default_cooling_states,
544464
sizeof(thermal->cooling_states));
545-
/* Initialize all trip point. */
546-
mlxsw_thermal_module_trips_reset(module_tz);
547-
/* Read module temperature and thresholds. */
548-
mlxsw_thermal_module_temp_and_thresholds_get(core, area->slot_index,
549-
sensor_index, &dummy_temp,
550-
&crit_temp, &emerg_temp);
551-
/* Update trip point according to the module data. */
552-
return mlxsw_thermal_module_trips_update(dev, core, module_tz,
553-
crit_temp, emerg_temp);
554465
}
555466

556467
static void mlxsw_thermal_module_fini(struct mlxsw_thermal_module *module_tz)
@@ -589,11 +500,8 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
589500
if (!area->tz_module_arr)
590501
return -ENOMEM;
591502

592-
for (i = 0; i < area->tz_module_num; i++) {
593-
err = mlxsw_thermal_module_init(dev, core, thermal, area, i);
594-
if (err)
595-
goto err_thermal_module_init;
596-
}
503+
for (i = 0; i < area->tz_module_num; i++)
504+
mlxsw_thermal_module_init(dev, core, thermal, area, i);
597505

598506
for (i = 0; i < area->tz_module_num; i++) {
599507
module_tz = &area->tz_module_arr[i];
@@ -607,7 +515,6 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
607515
return 0;
608516

609517
err_thermal_module_tz_init:
610-
err_thermal_module_init:
611518
for (i = area->tz_module_num - 1; i >= 0; i--)
612519
mlxsw_thermal_module_fini(&area->tz_module_arr[i]);
613520
kfree(area->tz_module_arr);

0 commit comments

Comments
 (0)