]> www.infradead.org Git - users/hch/misc.git/commitdiff
net/mlx5: Lag, move devcom registration to LAG layer
authorShay Drory <shayd@nvidia.com>
Mon, 15 Sep 2025 12:41:08 +0000 (15:41 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 17 Sep 2025 00:25:53 +0000 (17:25 -0700)
Move the devcom registration for the HCA_PORTS component from the core
initialization path into the LAG logic. This better reflects the logical
ownership of this component and ensures proper alignment with the LAG
lifecycle.

Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/1757940070-618661-3-git-send-email-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
drivers/net/ethernet/mellanox/mlx5/core/main.c

index d058cbb4a00c772e841973fafbb18429f84d0c04..ccb22ed13f847bdb545e132b565c449ad96021fa 100644 (file)
@@ -1404,6 +1404,34 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)
        return 0;
 }
 
+static void mlx5_lag_unregister_hca_devcom_comp(struct mlx5_core_dev *dev)
+{
+       mlx5_devcom_unregister_component(dev->priv.hca_devcom_comp);
+}
+
+static int mlx5_lag_register_hca_devcom_comp(struct mlx5_core_dev *dev)
+{
+       struct mlx5_devcom_match_attr attr = {
+               .key.val = mlx5_query_nic_system_image_guid(dev),
+       };
+
+       /* This component is use to sync adding core_dev to lag_dev and to sync
+        * changes of mlx5_adev_devices between LAG layer and other layers.
+        */
+       dev->priv.hca_devcom_comp =
+               mlx5_devcom_register_component(dev->priv.devc,
+                                              MLX5_DEVCOM_HCA_PORTS,
+                                              &attr, NULL, dev);
+       if (IS_ERR(dev->priv.hca_devcom_comp)) {
+               mlx5_core_err(dev,
+                             "Failed to register devcom HCA component, err: %ld\n",
+                             PTR_ERR(dev->priv.hca_devcom_comp));
+               return PTR_ERR(dev->priv.hca_devcom_comp);
+       }
+
+       return 0;
+}
+
 void mlx5_lag_remove_mdev(struct mlx5_core_dev *dev)
 {
        struct mlx5_lag *ldev;
@@ -1425,6 +1453,7 @@ recheck:
        }
        mlx5_ldev_remove_mdev(ldev, dev);
        mutex_unlock(&ldev->lock);
+       mlx5_lag_unregister_hca_devcom_comp(dev);
        mlx5_ldev_put(ldev);
 }
 
@@ -1435,7 +1464,7 @@ void mlx5_lag_add_mdev(struct mlx5_core_dev *dev)
        if (!mlx5_lag_is_supported(dev))
                return;
 
-       if (IS_ERR_OR_NULL(dev->priv.hca_devcom_comp))
+       if (mlx5_lag_register_hca_devcom_comp(dev))
                return;
 
 recheck:
index 1f7942202e14593d99b4725c75374a238fdb5805..eb3ac98a262128f978bbb1c62103ea0d427f0359 100644 (file)
@@ -973,30 +973,6 @@ static void mlx5_pci_close(struct mlx5_core_dev *dev)
        mlx5_pci_disable_device(dev);
 }
 
-static void mlx5_register_hca_devcom_comp(struct mlx5_core_dev *dev)
-{
-       struct mlx5_devcom_match_attr attr = {
-               .key.val = mlx5_query_nic_system_image_guid(dev),
-       };
-
-       /* This component is use to sync adding core_dev to lag_dev and to sync
-        * changes of mlx5_adev_devices between LAG layer and other layers.
-        */
-       if (!mlx5_lag_is_supported(dev))
-               return;
-
-       dev->priv.hca_devcom_comp =
-               mlx5_devcom_register_component(dev->priv.devc, MLX5_DEVCOM_HCA_PORTS,
-                                              &attr, NULL, dev);
-       if (IS_ERR(dev->priv.hca_devcom_comp))
-               mlx5_core_err(dev, "Failed to register devcom HCA component\n");
-}
-
-static void mlx5_unregister_hca_devcom_comp(struct mlx5_core_dev *dev)
-{
-       mlx5_devcom_unregister_component(dev->priv.hca_devcom_comp);
-}
-
 static int mlx5_init_once(struct mlx5_core_dev *dev)
 {
        int err;
@@ -1005,7 +981,6 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)
        if (IS_ERR(dev->priv.devc))
                mlx5_core_warn(dev, "failed to register devcom device %ld\n",
                               PTR_ERR(dev->priv.devc));
-       mlx5_register_hca_devcom_comp(dev);
 
        err = mlx5_query_board_id(dev);
        if (err) {
@@ -1143,7 +1118,6 @@ err_eq_cleanup:
 err_irq_cleanup:
        mlx5_irq_table_cleanup(dev);
 err_devcom:
-       mlx5_unregister_hca_devcom_comp(dev);
        mlx5_devcom_unregister_device(dev->priv.devc);
 
        return err;
@@ -1174,7 +1148,6 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev)
        mlx5_events_cleanup(dev);
        mlx5_eq_table_cleanup(dev);
        mlx5_irq_table_cleanup(dev);
-       mlx5_unregister_hca_devcom_comp(dev);
        mlx5_devcom_unregister_device(dev->priv.devc);
 }