]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/mlx5: Generalize enable/disable HCA for any PF vport
authorMoshe Shemesh <moshe@nvidia.com>
Mon, 18 May 2026 07:13:56 +0000 (10:13 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 21 May 2026 10:12:00 +0000 (12:12 +0200)
Refactor the host-PF-specific mlx5_cmd_host_pf_enable/disable_hca()
into generic mlx5_cmd_pf_enable/disable_hca() that accept a vport
number. The new functions use vhca_id as function_id when supported.

Similarly, refactor the eswitch layer into generic static helpers
mlx5_esw_pf_enable/disable_hca() with thin wrappers for the host PF
case, in preparation for enable_hca on satellite PF vports.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260518071356.345723-9-tariqt@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlx5/core/ecpf.c
drivers/net/ethernet/mellanox/mlx5/core/ecpf.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
drivers/net/ethernet/mellanox/mlx5/core/vport.c

index 15cb27aea2c9e443c24d1c96f4567664345fe9fa..350c47d3643b9275f8764720a39ea4a76c1e82a9 100644 (file)
@@ -18,25 +18,35 @@ static bool mlx5_ecpf_esw_admins_host_pf(const struct mlx5_core_dev *dev)
        return mlx5_core_is_ecpf_esw_manager(dev);
 }
 
-int mlx5_cmd_host_pf_enable_hca(struct mlx5_core_dev *dev)
+int mlx5_cmd_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
 {
        u32 out[MLX5_ST_SZ_DW(enable_hca_out)] = {};
        u32 in[MLX5_ST_SZ_DW(enable_hca_in)]   = {};
+       u16 vhca_id;
 
        MLX5_SET(enable_hca_in, in, opcode, MLX5_CMD_OP_ENABLE_HCA);
-       MLX5_SET(enable_hca_in, in, function_id, 0);
-       MLX5_SET(enable_hca_in, in, embedded_cpu_function, 0);
-       return mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out));
+       if (mlx5_vport_use_vhca_id_as_func_id(dev, vport_num, &vhca_id)) {
+               MLX5_SET(enable_hca_in, in, function_id, vhca_id);
+               MLX5_SET(enable_hca_in, in, function_id_type, 1);
+       } else {
+               MLX5_SET(enable_hca_in, in, function_id, vport_num);
+       }
+       return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
 
-int mlx5_cmd_host_pf_disable_hca(struct mlx5_core_dev *dev)
+int mlx5_cmd_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num)
 {
        u32 out[MLX5_ST_SZ_DW(disable_hca_out)] = {};
        u32 in[MLX5_ST_SZ_DW(disable_hca_in)]   = {};
+       u16 vhca_id;
 
        MLX5_SET(disable_hca_in, in, opcode, MLX5_CMD_OP_DISABLE_HCA);
-       MLX5_SET(disable_hca_in, in, function_id, 0);
-       MLX5_SET(disable_hca_in, in, embedded_cpu_function, 0);
+       if (mlx5_vport_use_vhca_id_as_func_id(dev, vport_num, &vhca_id)) {
+               MLX5_SET(disable_hca_in, in, function_id, vhca_id);
+               MLX5_SET(disable_hca_in, in, function_id_type, 1);
+       } else {
+               MLX5_SET(disable_hca_in, in, function_id, vport_num);
+       }
        return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
 
index 40b6ad76dca656980c58bac006b4c79f778a1378..d9f9a53b019b0ac6fff314f6fd4b9d9913b9ffbd 100644 (file)
@@ -17,8 +17,8 @@ bool mlx5_read_embedded_cpu(struct mlx5_core_dev *dev);
 int mlx5_ec_init(struct mlx5_core_dev *dev);
 void mlx5_ec_cleanup(struct mlx5_core_dev *dev);
 
-int mlx5_cmd_host_pf_enable_hca(struct mlx5_core_dev *dev);
-int mlx5_cmd_host_pf_disable_hca(struct mlx5_core_dev *dev);
+int mlx5_cmd_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num);
+int mlx5_cmd_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num);
 
 #else  /* CONFIG_MLX5_ESWITCH */
 
index 9a7de7c9a667bde5e3e0de08877b2784b9584de7..206911817a0448917f408d6c8c60b0beeedd3f04 100644 (file)
@@ -1452,7 +1452,7 @@ vf_err:
        return err;
 }
 
-int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
+static int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
 {
        struct mlx5_eswitch *esw = dev->priv.eswitch;
        struct mlx5_vport *vport;
@@ -1461,15 +1461,15 @@ int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
        if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw))
                return 0;
 
-       vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_HOST_PF);
+       vport = mlx5_eswitch_get_vport(esw, vport_num);
        if (IS_ERR(vport))
                return PTR_ERR(vport);
 
-       /* Once vport and representor are ready, take out the external host PF
-        * out of initializing state. Enabling HCA clears the iser->initializing
-        * bit and host PF driver loading can progress.
+       /* Once vport and representor are ready, take the PF out of
+        * initializing state. Enabling HCA clears the iser->initializing
+        * bit and PF driver loading can progress.
         */
-       err = mlx5_cmd_host_pf_enable_hca(dev);
+       err = mlx5_cmd_pf_enable_hca(dev, vport_num);
        if (err)
                return err;
 
@@ -1478,7 +1478,7 @@ int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
        return 0;
 }
 
-int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
+static int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num)
 {
        struct mlx5_eswitch *esw = dev->priv.eswitch;
        struct mlx5_vport *vport;
@@ -1487,11 +1487,11 @@ int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
        if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw))
                return 0;
 
-       vport = mlx5_eswitch_get_vport(esw, MLX5_VPORT_HOST_PF);
+       vport = mlx5_eswitch_get_vport(esw, vport_num);
        if (IS_ERR(vport))
                return PTR_ERR(vport);
 
-       err = mlx5_cmd_host_pf_disable_hca(dev);
+       err = mlx5_cmd_pf_disable_hca(dev, vport_num);
        if (err)
                return err;
 
@@ -1500,6 +1500,16 @@ int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
        return 0;
 }
 
+int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
+{
+       return mlx5_esw_pf_enable_hca(dev, MLX5_VPORT_HOST_PF);
+}
+
+int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev)
+{
+       return mlx5_esw_pf_disable_hca(dev, MLX5_VPORT_HOST_PF);
+}
+
 /* mlx5_eswitch_enable_pf_vf_vports() enables vports of PF, ECPF and VFs
  * whichever are present on the eswitch.
  */
index 2eba141bd5213031e0630fba9131d1fee8b1ca15..51637e58a48b82775262d02a51ddb22817535606 100644 (file)
@@ -452,6 +452,8 @@ void mlx5_unload_one_light(struct mlx5_core_dev *dev);
 
 void mlx5_query_nic_sw_system_image_guid(struct mlx5_core_dev *mdev, u8 *buf,
                                         u8 *len);
+bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
+                                      u16 vport_num, u16 *vhca_id);
 int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap, u16 vport,
                                  u16 opmod);
 #define mlx5_vport_get_other_func_general_cap(dev, vport, out)         \
index f8e6b1ab7c5c9581fb5c4b4bc5dcaa70b62fea09..e0848f4e88dd45f68ad6c6972b12b1ddbd9bc1d8 100644 (file)
@@ -1283,8 +1283,8 @@ void mlx5_query_nic_sw_system_image_guid(struct mlx5_core_dev *mdev, u8 *buf,
                buf[(*len)++] = MLX5_CAP_GEN_2(mdev, load_balance_id);
 }
 
-static bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
-                                             u16 vport_num, u16 *vhca_id)
+bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
+                                      u16 vport_num, u16 *vhca_id)
 {
        if (!MLX5_CAP_GEN_2(dev, function_id_type_vhca_id))
                return false;