net/mlx5e: Add listener to trap event
authorAya Levin <ayal@nvidia.com>
Tue, 26 Jan 2021 23:24:17 +0000 (15:24 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 28 Jan 2021 03:53:53 +0000 (19:53 -0800)
Add support for listening to blocking events in the ETH driver. Listen
on trap event. If received, call mlx5e_handle_trap_event() which:
1) Verifies if driver needs open/close trap-RQ with respect to the
active traps count.
2) Inspects trap id and its action (trap/drop) and add/remove the flow
steering rule accordingly.
Otherwise, return an error.

Signed-off-by: Aya Levin <ayal@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en_main.c

index f439a977ad612697a744de6a9dd49e67b2ae40ae..39f389cc40fc937d676f86a4d72ff2b4e8b6bad9 100644 (file)
@@ -859,6 +859,7 @@ struct mlx5e_priv {
        u16                        q_counter;
        u16                        drop_rq_q_counter;
        struct notifier_block      events_nb;
+       struct notifier_block      blocking_events_nb;
        int                        num_tc_x_num_ch;
 
        struct udp_tunnel_nic_info nic_info;
index ec5bb48cb54a1a5a16d0bc613856ded3fac725ce..3252919ec7bfd56a40fc2d73e176a19a0aee4c36 100644 (file)
@@ -66,6 +66,7 @@
 #include "lib/mlx5.h"
 #include "en/ptp.h"
 #include "qos.h"
+#include "en/trap.h"
 
 bool mlx5e_check_fragmented_striding_rq_cap(struct mlx5_core_dev *mdev)
 {
@@ -212,6 +213,33 @@ static void mlx5e_disable_async_events(struct mlx5e_priv *priv)
        mlx5_notifier_unregister(priv->mdev, &priv->events_nb);
 }
 
+static int blocking_event(struct notifier_block *nb, unsigned long event, void *data)
+{
+       struct mlx5e_priv *priv = container_of(nb, struct mlx5e_priv, blocking_events_nb);
+       int err;
+
+       switch (event) {
+       case MLX5_DRIVER_EVENT_TYPE_TRAP:
+               err = mlx5e_handle_trap_event(priv, data);
+               break;
+       default:
+               netdev_warn(priv->netdev, "Sync event: Unknouwn event %ld\n", event);
+               err = -EINVAL;
+       }
+       return err;
+}
+
+static void mlx5e_enable_blocking_events(struct mlx5e_priv *priv)
+{
+       priv->blocking_events_nb.notifier_call = blocking_event;
+       mlx5_blocking_notifier_register(priv->mdev, &priv->blocking_events_nb);
+}
+
+static void mlx5e_disable_blocking_events(struct mlx5e_priv *priv)
+{
+       mlx5_blocking_notifier_unregister(priv->mdev, &priv->blocking_events_nb);
+}
+
 static inline void mlx5e_build_umr_wqe(struct mlx5e_rq *rq,
                                       struct mlx5e_icosq *sq,
                                       struct mlx5e_umr_wqe *wqe)
@@ -5341,6 +5369,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
        mlx5_lag_add(mdev, netdev);
 
        mlx5e_enable_async_events(priv);
+       mlx5e_enable_blocking_events(priv);
        if (mlx5e_monitor_counter_supported(priv))
                mlx5e_monitor_counter_init(priv);
 
@@ -5378,6 +5407,12 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
        if (mlx5e_monitor_counter_supported(priv))
                mlx5e_monitor_counter_cleanup(priv);
 
+       mlx5e_disable_blocking_events(priv);
+       if (priv->en_trap) {
+               mlx5e_deactivate_trap(priv);
+               mlx5e_close_trap(priv->en_trap);
+               priv->en_trap = NULL;
+       }
        mlx5e_disable_async_events(priv);
        mlx5_lag_remove(mdev);
        mlx5_vxlan_reset_to_default(mdev->vxlan);