Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / dev.c
index 20bb372..e8093c4 100644 (file)
@@ -53,7 +53,7 @@ static bool is_eth_rep_supported(struct mlx5_core_dev *dev)
        return true;
 }
 
-static bool is_eth_supported(struct mlx5_core_dev *dev)
+bool mlx5_eth_supported(struct mlx5_core_dev *dev)
 {
        if (!IS_ENABLED(CONFIG_MLX5_CORE_EN))
                return false;
@@ -105,7 +105,18 @@ static bool is_eth_supported(struct mlx5_core_dev *dev)
        return true;
 }
 
-static bool is_vnet_supported(struct mlx5_core_dev *dev)
+static bool is_eth_enabled(struct mlx5_core_dev *dev)
+{
+       union devlink_param_value val;
+       int err;
+
+       err = devlink_param_driverinit_value_get(priv_to_devlink(dev),
+                                                DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
+                                                &val);
+       return err ? false : val.vbool;
+}
+
+bool mlx5_vnet_supported(struct mlx5_core_dev *dev)
 {
        if (!IS_ENABLED(CONFIG_MLX5_VDPA_NET))
                return false;
@@ -127,6 +138,17 @@ static bool is_vnet_supported(struct mlx5_core_dev *dev)
        return true;
 }
 
+static bool is_vnet_enabled(struct mlx5_core_dev *dev)
+{
+       union devlink_param_value val;
+       int err;
+
+       err = devlink_param_driverinit_value_get(priv_to_devlink(dev),
+                                                DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET,
+                                                &val);
+       return err ? false : val.vbool;
+}
+
 static bool is_ib_rep_supported(struct mlx5_core_dev *dev)
 {
        if (!IS_ENABLED(CONFIG_MLX5_INFINIBAND))
@@ -170,7 +192,7 @@ static bool is_mp_supported(struct mlx5_core_dev *dev)
        return true;
 }
 
-static bool is_ib_supported(struct mlx5_core_dev *dev)
+bool mlx5_rdma_supported(struct mlx5_core_dev *dev)
 {
        if (!IS_ENABLED(CONFIG_MLX5_INFINIBAND))
                return false;
@@ -187,6 +209,17 @@ static bool is_ib_supported(struct mlx5_core_dev *dev)
        return true;
 }
 
+static bool is_ib_enabled(struct mlx5_core_dev *dev)
+{
+       union devlink_param_value val;
+       int err;
+
+       err = devlink_param_driverinit_value_get(priv_to_devlink(dev),
+                                                DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
+                                                &val);
+       return err ? false : val.vbool;
+}
+
 enum {
        MLX5_INTERFACE_PROTOCOL_ETH,
        MLX5_INTERFACE_PROTOCOL_ETH_REP,
@@ -201,13 +234,17 @@ enum {
 static const struct mlx5_adev_device {
        const char *suffix;
        bool (*is_supported)(struct mlx5_core_dev *dev);
+       bool (*is_enabled)(struct mlx5_core_dev *dev);
 } mlx5_adev_devices[] = {
        [MLX5_INTERFACE_PROTOCOL_VNET] = { .suffix = "vnet",
-                                          .is_supported = &is_vnet_supported },
+                                          .is_supported = &mlx5_vnet_supported,
+                                          .is_enabled = &is_vnet_enabled },
        [MLX5_INTERFACE_PROTOCOL_IB] = { .suffix = "rdma",
-                                        .is_supported = &is_ib_supported },
+                                        .is_supported = &mlx5_rdma_supported,
+                                        .is_enabled = &is_ib_enabled },
        [MLX5_INTERFACE_PROTOCOL_ETH] = { .suffix = "eth",
-                                         .is_supported = &is_eth_supported },
+                                         .is_supported = &mlx5_eth_supported,
+                                         .is_enabled = &is_eth_enabled },
        [MLX5_INTERFACE_PROTOCOL_ETH_REP] = { .suffix = "eth-rep",
                                           .is_supported = &is_eth_rep_supported },
        [MLX5_INTERFACE_PROTOCOL_IB_REP] = { .suffix = "rdma-rep",
@@ -308,6 +345,14 @@ int mlx5_attach_device(struct mlx5_core_dev *dev)
                if (!priv->adev[i]) {
                        bool is_supported = false;
 
+                       if (mlx5_adev_devices[i].is_enabled) {
+                               bool enabled;
+
+                               enabled = mlx5_adev_devices[i].is_enabled(dev);
+                               if (!enabled)
+                                       continue;
+                       }
+
                        if (mlx5_adev_devices[i].is_supported)
                                is_supported = mlx5_adev_devices[i].is_supported(dev);
 
@@ -360,6 +405,14 @@ void mlx5_detach_device(struct mlx5_core_dev *dev)
                if (!priv->adev[i])
                        continue;
 
+               if (mlx5_adev_devices[i].is_enabled) {
+                       bool enabled;
+
+                       enabled = mlx5_adev_devices[i].is_enabled(dev);
+                       if (!enabled)
+                               goto skip_suspend;
+               }
+
                adev = &priv->adev[i]->adev;
                /* Auxiliary driver was unbind manually through sysfs */
                if (!adev->dev.driver)
@@ -447,12 +500,21 @@ static void delete_drivers(struct mlx5_core_dev *dev)
                if (!priv->adev[i])
                        continue;
 
+               if (mlx5_adev_devices[i].is_enabled) {
+                       bool enabled;
+
+                       enabled = mlx5_adev_devices[i].is_enabled(dev);
+                       if (!enabled)
+                               goto del_adev;
+               }
+
                if (mlx5_adev_devices[i].is_supported && !delete_all)
                        is_supported = mlx5_adev_devices[i].is_supported(dev);
 
                if (is_supported)
                        continue;
 
+del_adev:
                del_adev(&priv->adev[i]->adev);
                priv->adev[i] = NULL;
        }