Skip to content

Commit 99a03b3

Browse files
vadimp-nvidiadavem330
authored andcommitted
mlxsw: core_hwmon: Add interfaces for line card initialization and de-initialization
Add callback functions for line card 'hwmon' initialization and de-initialization. Each line card is associated with the relevant 'hwmon' device, which may contain thermal attributes for the cages and gearboxes found on this line card. The line card 'hwmon' initialization / de-initialization APIs are to be called when line card is set to active / inactive state by got_active() / got_inactive() callbacks from line card state machine. For example cage temperature for module #9 located at line card #7 will be exposed by utility 'sensors' like: linecard#07 front panel 009: +32.0C (crit = +70.0C, emerg = +80.0C) And temperature for gearbox #3 located at line card #5 will be exposed like: linecard#05 gearbox 003: +41.0C (highest = +41.0C) Signed-off-by: Vadim Pasternak <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f11a323 commit 99a03b3

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define MLXSW_HWMON_ATTR_PER_SENSOR 3
2020
#define MLXSW_HWMON_ATTR_PER_MODULE 7
2121
#define MLXSW_HWMON_ATTR_PER_GEARBOX 4
22+
#define MLXSW_HWMON_DEV_NAME_LEN_MAX 16
2223

2324
#define MLXSW_HWMON_ATTR_COUNT (MLXSW_HWMON_SENSORS_MAX_COUNT * MLXSW_HWMON_ATTR_PER_SENSOR + \
2425
MLXSW_HWMON_MODULES_MAX_COUNT * MLXSW_HWMON_ATTR_PER_MODULE + \
@@ -41,6 +42,7 @@ static int mlxsw_hwmon_get_attr_index(int index, int count)
4142
}
4243

4344
struct mlxsw_hwmon_dev {
45+
char name[MLXSW_HWMON_DEV_NAME_LEN_MAX];
4446
struct mlxsw_hwmon *hwmon;
4547
struct device *hwmon_dev;
4648
struct attribute_group group;
@@ -51,6 +53,7 @@ struct mlxsw_hwmon_dev {
5153
u8 sensor_count;
5254
u8 module_sensor_max;
5355
u8 slot_index;
56+
bool active;
5457
};
5558

5659
struct mlxsw_hwmon {
@@ -780,6 +783,75 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon_dev *mlxsw_hwmon_dev)
780783
return 0;
781784
}
782785

786+
static void
787+
mlxsw_hwmon_got_active(struct mlxsw_core *mlxsw_core, u8 slot_index,
788+
void *priv)
789+
{
790+
struct mlxsw_hwmon *hwmon = priv;
791+
struct mlxsw_hwmon_dev *linecard;
792+
struct device *dev;
793+
int err;
794+
795+
dev = hwmon->bus_info->dev;
796+
linecard = &hwmon->line_cards[slot_index];
797+
if (linecard->active)
798+
return;
799+
/* For the main board, module sensor indexes start from 1, sensor index
800+
* 0 is used for the ASIC. Use the same numbering for line cards.
801+
*/
802+
linecard->sensor_count = 1;
803+
linecard->slot_index = slot_index;
804+
linecard->hwmon = hwmon;
805+
err = mlxsw_hwmon_module_init(linecard);
806+
if (err) {
807+
dev_err(dev, "Failed to configure hwmon objects for line card modules in slot %d\n",
808+
slot_index);
809+
return;
810+
}
811+
812+
err = mlxsw_hwmon_gearbox_init(linecard);
813+
if (err) {
814+
dev_err(dev, "Failed to configure hwmon objects for line card gearboxes in slot %d\n",
815+
slot_index);
816+
return;
817+
}
818+
819+
linecard->groups[0] = &linecard->group;
820+
linecard->group.attrs = linecard->attrs;
821+
sprintf(linecard->name, "%s#%02u", "linecard", slot_index);
822+
linecard->hwmon_dev =
823+
hwmon_device_register_with_groups(dev, linecard->name,
824+
linecard, linecard->groups);
825+
if (IS_ERR(linecard->hwmon_dev)) {
826+
dev_err(dev, "Failed to register hwmon objects for line card in slot %d\n",
827+
slot_index);
828+
return;
829+
}
830+
831+
linecard->active = true;
832+
}
833+
834+
static void
835+
mlxsw_hwmon_got_inactive(struct mlxsw_core *mlxsw_core, u8 slot_index,
836+
void *priv)
837+
{
838+
struct mlxsw_hwmon *hwmon = priv;
839+
struct mlxsw_hwmon_dev *linecard;
840+
841+
linecard = &hwmon->line_cards[slot_index];
842+
if (!linecard->active)
843+
return;
844+
linecard->active = false;
845+
hwmon_device_unregister(linecard->hwmon_dev);
846+
/* Reset attributes counter */
847+
linecard->attrs_count = 0;
848+
}
849+
850+
static struct mlxsw_linecards_event_ops mlxsw_hwmon_event_ops = {
851+
.got_active = mlxsw_hwmon_got_active,
852+
.got_inactive = mlxsw_hwmon_got_inactive,
853+
};
854+
783855
int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
784856
const struct mlxsw_bus_info *mlxsw_bus_info,
785857
struct mlxsw_hwmon **p_hwmon)
@@ -836,10 +908,19 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
836908
goto err_hwmon_register;
837909
}
838910

911+
err = mlxsw_linecards_event_ops_register(mlxsw_hwmon->core,
912+
&mlxsw_hwmon_event_ops,
913+
mlxsw_hwmon);
914+
if (err)
915+
goto err_linecards_event_ops_register;
916+
839917
mlxsw_hwmon->line_cards[0].hwmon_dev = hwmon_dev;
918+
mlxsw_hwmon->line_cards[0].active = true;
840919
*p_hwmon = mlxsw_hwmon;
841920
return 0;
842921

922+
err_linecards_event_ops_register:
923+
hwmon_device_unregister(mlxsw_hwmon->line_cards[0].hwmon_dev);
843924
err_hwmon_register:
844925
err_temp_gearbox_init:
845926
err_temp_module_init:
@@ -851,6 +932,9 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
851932

852933
void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon)
853934
{
935+
mlxsw_hwmon->line_cards[0].active = false;
936+
mlxsw_linecards_event_ops_unregister(mlxsw_hwmon->core,
937+
&mlxsw_hwmon_event_ops, mlxsw_hwmon);
854938
hwmon_device_unregister(mlxsw_hwmon->line_cards[0].hwmon_dev);
855939
kfree(mlxsw_hwmon);
856940
}

0 commit comments

Comments
 (0)