]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/mlx5: Support state get/set for satellite PF ports
authorMoshe Shemesh <moshe@nvidia.com>
Thu, 21 May 2026 11:08:41 +0000 (14:08 +0300)
committerJakub Kicinski <kuba@kernel.org>
Mon, 25 May 2026 20:48:51 +0000 (13:48 -0700)
Extend mlx5_devlink_pf_port_fn_state_get() to support satellite PF
vports by querying their vhca_state from the query_esw_functions output
using the vport's vhca_id.

Extend mlx5_devlink_pf_port_fn_state_set() to support satellite PFs by
using the generic mlx5_esw_pf_enable/disable_hca() functions.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260521110843.367329-11-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index a5b838821979c66d78c7583295407fe9ec9c2dd9..bc3c116f5327dc20053ffcf514ac95401fc26401 100644 (file)
@@ -1208,6 +1208,33 @@ mlx5_esw_get_host_pf_info(struct mlx5_core_dev *dev, const u32 *out)
        return mlx5_esw_host_pf_from_host_params(entry);
 }
 
+bool mlx5_esw_get_spf_disabled(struct mlx5_core_dev *dev, const u32 *out,
+                              u16 vhca_id)
+{
+       int num_entries;
+       const u8 *entry;
+       int i;
+
+       num_entries = MLX5_GET(query_esw_functions_out, out, net_function_num);
+       entry = MLX5_ADDR_OF(query_esw_functions_out, out, net_function_params);
+
+       for (i = 0; i < num_entries; i++) {
+               u16 entry_vhca_id = MLX5_GET(network_function_params,
+                                            entry, vhca_id);
+
+               if (entry_vhca_id == vhca_id) {
+                       int state;
+
+                       state = MLX5_GET(network_function_params, entry,
+                                        vhca_state);
+                       return state != MLX5_VHCA_STATE_IN_USE;
+               }
+               entry += MLX5_UN_SZ_BYTES(net_function_params);
+       }
+
+       return true;
+}
+
 static int mlx5_esw_host_functions_enabled_query(struct mlx5_eswitch *esw)
 {
        struct mlx5_esw_pf_info host_pf_info;
@@ -1475,7 +1502,7 @@ vf_err:
        return err;
 }
 
-static int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
+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;
@@ -1501,7 +1528,7 @@ static int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num)
        return 0;
 }
 
-static int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num)
+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;
index 1720afa3331a2acea33f642ecdbb6378b55e6782..40146ec92ec8ec9d397be3c0a66cb4cd3afc8e0c 100644 (file)
@@ -672,6 +672,10 @@ bool mlx5_esw_multipath_prereq(struct mlx5_core_dev *dev0,
 const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev);
 struct mlx5_esw_pf_info mlx5_esw_get_host_pf_info(struct mlx5_core_dev *dev,
                                                  const u32 *out);
+bool mlx5_esw_get_spf_disabled(struct mlx5_core_dev *dev, const u32 *out,
+                              u16 vhca_id);
+int mlx5_esw_pf_enable_hca(struct mlx5_core_dev *dev, u16 vport_num);
+int mlx5_esw_pf_disable_hca(struct mlx5_core_dev *dev, u16 vport_num);
 int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev);
 int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev);
 
index c229a96a111fbfbe1d2e799609748b8b650326a8..59446c444570b7b8b93aa1ba45a2de6b5221735a 100644 (file)
@@ -4961,10 +4961,11 @@ int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port,
                                      struct netlink_ext_ack *extack)
 {
        struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
-       struct mlx5_esw_pf_info host_pf_info;
+       struct mlx5_eswitch *esw = vport->dev->priv.eswitch;
        const u32 *query_out;
+       bool pf_disabled;
 
-       if (vport->vport != MLX5_VPORT_HOST_PF) {
+       if (mlx5_eswitch_is_vf_vport(esw, vport->vport)) {
                NL_SET_ERR_MSG_MOD(extack, "State get is not supported for VF");
                return -EOPNOTSUPP;
        }
@@ -4976,11 +4977,19 @@ int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port,
        if (IS_ERR(query_out))
                return PTR_ERR(query_out);
 
-       host_pf_info = mlx5_esw_get_host_pf_info(vport->dev, query_out);
+       if (vport->vport == MLX5_VPORT_HOST_PF) {
+               struct mlx5_esw_pf_info host_pf_info;
+
+               host_pf_info = mlx5_esw_get_host_pf_info(vport->dev,
+                                                        query_out);
+               pf_disabled = host_pf_info.pf_disabled;
+       } else {
+               pf_disabled = mlx5_esw_get_spf_disabled(vport->dev, query_out,
+                                                       vport->vhca_id);
+       }
 
-       *opstate = host_pf_info.pf_disabled ?
-                       DEVLINK_PORT_FN_OPSTATE_DETACHED :
-                       DEVLINK_PORT_FN_OPSTATE_ATTACHED;
+       *opstate = pf_disabled ? DEVLINK_PORT_FN_OPSTATE_DETACHED :
+                                DEVLINK_PORT_FN_OPSTATE_ATTACHED;
 
        kvfree(query_out);
        return 0;
@@ -4991,9 +5000,10 @@ int mlx5_devlink_pf_port_fn_state_set(struct devlink_port *port,
                                      struct netlink_ext_ack *extack)
 {
        struct mlx5_vport *vport = mlx5_devlink_port_vport_get(port);
+       struct mlx5_eswitch *esw = vport->dev->priv.eswitch;
        struct mlx5_core_dev *dev;
 
-       if (vport->vport != MLX5_VPORT_HOST_PF) {
+       if (mlx5_eswitch_is_vf_vport(esw, vport->vport)) {
                NL_SET_ERR_MSG_MOD(extack, "State set is not supported for VF");
                return -EOPNOTSUPP;
        }
@@ -5002,9 +5012,9 @@ int mlx5_devlink_pf_port_fn_state_set(struct devlink_port *port,
 
        switch (state) {
        case DEVLINK_PORT_FN_STATE_ACTIVE:
-               return mlx5_esw_host_pf_enable_hca(dev);
+               return mlx5_esw_pf_enable_hca(dev, vport->vport);
        case DEVLINK_PORT_FN_STATE_INACTIVE:
-               return mlx5_esw_host_pf_disable_hca(dev);
+               return mlx5_esw_pf_disable_hca(dev, vport->vport);
        default:
                return -EOPNOTSUPP;
        }