[PATCH rdma-next 7/9] RDMA/mlx5: Activate the device in a stage of its own

From: Edward Srouji

Date: Sun Nov 22 2026 - 12:40:07 EST


__mlx5_ib_add() sets ib_active after its last stage, and
__mlx5_ib_remove() clears it before cleaning up any. Do both in a new
last stage, MLX5_IB_STAGE_ACTIVE, so that a later patch can fail the
activation and start work from it, and stop that work on removal.

No functional change.

Reviewed-by: Michael Gur <michaelgur@xxxxxxxxxx>
Signed-off-by: Edward Srouji <edwards@xxxxxxxxxx>
---
drivers/infiniband/hw/mlx5/main.c | 23 ++++++++++++++++++++---
drivers/infiniband/hw/mlx5/mlx5_ib.h | 1 +
2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 954b141a9c927d5cf4f20a17cc633de09624b0ef..80399920078edfca8f672fb77514ba6b90966068 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -5022,12 +5022,21 @@ static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev)
cancel_work_sync(&devr->ports[port].pkey_change_work);
}

+static int mlx5_ib_stage_active_init(struct mlx5_ib_dev *dev)
+{
+ dev->ib_active = true;
+ return 0;
+}
+
+static void mlx5_ib_stage_active_cleanup(struct mlx5_ib_dev *dev)
+{
+ dev->ib_active = false;
+}
+
void __mlx5_ib_remove(struct mlx5_ib_dev *dev,
const struct mlx5_ib_profile *profile,
int stage)
{
- dev->ib_active = false;
-
/* Number of stages to cleanup */
while (stage) {
stage--;
@@ -5055,7 +5064,6 @@ int __mlx5_ib_add(struct mlx5_ib_dev *dev,
}
}

- dev->ib_active = true;
return 0;

err_out:
@@ -5129,6 +5137,9 @@ static const struct mlx5_ib_profile pf_profile = {
STAGE_CREATE(MLX5_IB_STAGE_RESTRACK,
mlx5_ib_restrack_init,
NULL),
+ STAGE_CREATE(MLX5_IB_STAGE_ACTIVE,
+ mlx5_ib_stage_active_init,
+ mlx5_ib_stage_active_cleanup),
};

const struct mlx5_ib_profile raw_eth_profile = {
@@ -5189,6 +5200,9 @@ const struct mlx5_ib_profile raw_eth_profile = {
STAGE_CREATE(MLX5_IB_STAGE_RESTRACK,
mlx5_ib_restrack_init,
NULL),
+ STAGE_CREATE(MLX5_IB_STAGE_ACTIVE,
+ mlx5_ib_stage_active_init,
+ mlx5_ib_stage_active_cleanup),
};

static const struct mlx5_ib_profile plane_profile = {
@@ -5216,6 +5230,9 @@ static const struct mlx5_ib_profile plane_profile = {
STAGE_CREATE(MLX5_IB_STAGE_IB_REG,
mlx5_ib_stage_ib_reg_init,
mlx5_ib_stage_ib_reg_cleanup),
+ STAGE_CREATE(MLX5_IB_STAGE_ACTIVE,
+ mlx5_ib_stage_active_init,
+ mlx5_ib_stage_active_cleanup),
};

static struct ib_device *mlx5_ib_add_sub_dev(struct ib_device *parent,
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index b2d4db344071bcc068a767f94ffb64b80df9499d..3884e5524e7dfb2a37515a6f4e8caaa82224c964 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -940,6 +940,7 @@ enum mlx5_ib_stages {
MLX5_IB_STAGE_POST_IB_REG_UMR,
MLX5_IB_STAGE_DELAY_DROP,
MLX5_IB_STAGE_RESTRACK,
+ MLX5_IB_STAGE_ACTIVE,
MLX5_IB_STAGE_MAX,
};


--
2.49.0