mlxsw: core_linecards: Register a system event handler
authorVadim Pasternak <vadimp@nvidia.com>
Sun, 21 Aug 2022 16:20:13 +0000 (18:20 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 24 Aug 2022 00:21:59 +0000 (17:21 -0700)
Add line card system event handler. Register it with core. It is
triggered by system interrupts raised from chassis programmable logic
devices to CPU. The purpose is to handle line card state changes over
I2C bus.

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlxsw/core_linecards.c

index 8549ccb..83d2dc9 100644 (file)
@@ -785,6 +785,21 @@ static int mlxsw_linecard_status_get_and_process(struct mlxsw_core *mlxsw_core,
        return mlxsw_linecard_status_process(linecards, linecard, mddq_pl);
 }
 
+static void mlxsw_linecards_irq_event_handler(struct mlxsw_core *mlxsw_core)
+{
+       struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core);
+       int i;
+
+       /* Handle change of line card active state. */
+       for (i = 0; i < linecards->count; i++) {
+               struct mlxsw_linecard *linecard = mlxsw_linecard_get(linecards,
+                                                                    i + 1);
+
+               mlxsw_linecard_status_get_and_process(mlxsw_core, linecards,
+                                                     linecard);
+       }
+}
+
 static const char * const mlxsw_linecard_status_event_type_name[] = {
        [MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION] = "provision",
        [MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION] = "unprovision",
@@ -1521,6 +1536,11 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
        if (err)
                goto err_traps_register;
 
+       err = mlxsw_core_irq_event_handler_register(mlxsw_core,
+                                                   mlxsw_linecards_irq_event_handler);
+       if (err)
+               goto err_irq_event_handler_register;
+
        mlxsw_core_linecards_set(mlxsw_core, linecards);
 
        for (i = 0; i < linecards->count; i++) {
@@ -1545,6 +1565,9 @@ err_linecard_event_delivery_init:
 err_linecard_init:
        for (i--; i >= 0; i--)
                mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
+       mlxsw_core_irq_event_handler_unregister(mlxsw_core,
+                                               mlxsw_linecards_irq_event_handler);
+err_irq_event_handler_register:
        mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener,
                                    ARRAY_SIZE(mlxsw_linecard_listener),
                                    mlxsw_core);
@@ -1566,6 +1589,8 @@ void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core)
                mlxsw_linecard_event_delivery_fini(mlxsw_core, linecards, i + 1);
        for (i = 0; i < linecards->count; i++)
                mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
+       mlxsw_core_irq_event_handler_unregister(mlxsw_core,
+                                               mlxsw_linecards_irq_event_handler);
        mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener,
                                    ARRAY_SIZE(mlxsw_linecard_listener),
                                    mlxsw_core);