Skip to contentSkip to conversation

net/mlx5: Support devlink port state for host PF

PATCH Applied Tariq Toukan 4 participants 4 messages Feb 3 – Feb 5

Subsystems (4)
lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

PATCH 1/1 net/mlx5: Support devlink port state for host PF

From: Moshe Shemesh <[email protected]>

Add support for devlink port function state get/set operations for the host physical function (PF). Until now, mlx5 only allowed state get/set for subfunctions (SFs) ports. This change enables an administrator with eSwitch manager privileges to query or modify the host PF’s function state, allowing it to be explicitly inactivated or activated. While inactivated, the administrator can modify the functions attributes, such as enable/disable roce.

$ devlink port show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608: type eth netdev eth1 flavour pcipf controller 1 pfnum 0 external true splittable false
  function:
    hw_addr a0:88:c2:45:17:7c state active opstate attached roce enable max_io_eqs 120
$ devlink port function set pci/0000:03:00.0/196608 state inactive
$ devlink port show pci/0000:03:00.0/196608
pci/0000:03:00.0/196608: type eth netdev eth1 flavour pcipf controller 1 pfnum 0 external true splittable false
  function:
    hw_addr a0:88:c2:45:17:7c state inactive opstate detached roce enable max_io_eqs 120
---
 .../net/ethernet/mellanox/mlx5/core/ecpf.c    |  5 +-
 .../mellanox/mlx5/core/esw/devlink_port.c     |  2 +
 .../net/ethernet/mellanox/mlx5/core/eswitch.c | 48 ++++++++++++----
 .../net/ethernet/mellanox/mlx5/core/eswitch.h | 10 ++++
 .../mellanox/mlx5/core/eswitch_offloads.c     | 55 +++++++++++++++++++
 5 files changed, 108 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/ecpf.c +3 -2
index d000236ddbac..15cb27aea2c9 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2019 Mellanox Technologies. */
 
 #include "ecpf.h"
+#include "eswitch.h"
 
 bool mlx5_read_embedded_cpu(struct mlx5_core_dev *dev)
 {
@@ -49,7 +50,7 @@ static int mlx5_host_pf_init(struct mlx5_core_dev *dev)
 	/* ECPF shall enable HCA for host PF in the same way a PF
 	 * does this for its VFs when ECPF is not a eswitch manager.
 	 */
-	err = mlx5_cmd_host_pf_enable_hca(dev);
+	err = mlx5_esw_host_pf_enable_hca(dev);
 	if (err)
 		mlx5_core_err(dev, "Failed to enable external host PF HCA err(%d)\n", err);
 
@@ -63,7 +64,7 @@ static void mlx5_host_pf_cleanup(struct mlx5_core_dev *dev)
 	if (mlx5_ecpf_esw_admins_host_pf(dev))
 		return;
 
-	err = mlx5_cmd_host_pf_disable_hca(dev);
+	err = mlx5_esw_host_pf_disable_hca(dev);
 	if (err) {
 		mlx5_core_err(dev, "Failed to disable external host PF HCA err(%d)\n", err);
 		return;
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +2 -0
index 89a58dee50b3..cd60bc500ec5 100644
@@ -99,6 +99,8 @@ static const struct devlink_port_ops mlx5_esw_pf_vf_dl_port_ops = {
 	.port_fn_roce_set = mlx5_devlink_port_fn_roce_set,
 	.port_fn_migratable_get = mlx5_devlink_port_fn_migratable_get,
 	.port_fn_migratable_set = mlx5_devlink_port_fn_migratable_set,
+	.port_fn_state_get = mlx5_devlink_pf_port_fn_state_get,
+	.port_fn_state_set = mlx5_devlink_pf_port_fn_state_set,
 #ifdef CONFIG_XFRM_OFFLOAD
 	.port_fn_ipsec_crypto_get = mlx5_devlink_port_fn_ipsec_crypto_get,
 	.port_fn_ipsec_crypto_set = mlx5_devlink_port_fn_ipsec_crypto_set,
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +38 -10

83 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +10 -0
index 714ad28e8445..6841caef02d1 100644
@@ -243,6 +243,7 @@ struct mlx5_vport {
 	u16 vport;
 	bool                    enabled;
 	bool max_eqs_set;
+	bool pf_activated;
 	enum mlx5_eswitch_vport_event enabled_events;
 	int index;
 	struct mlx5_devlink_port *dl_port;
@@ -587,6 +588,13 @@ int mlx5_devlink_port_fn_migratable_get(struct devlink_port *port, bool *is_enab
 					struct netlink_ext_ack *extack);
 int mlx5_devlink_port_fn_migratable_set(struct devlink_port *port, bool enable,
 					struct netlink_ext_ack *extack);
+int mlx5_devlink_pf_port_fn_state_get(struct devlink_port *port,
+				      enum devlink_port_fn_state *state,
+				      enum devlink_port_fn_opstate *opstate,
+				      struct netlink_ext_ack *extack);
+int mlx5_devlink_pf_port_fn_state_set(struct devlink_port *port,
+				      enum devlink_port_fn_state state,
+				      struct netlink_ext_ack *extack);
 #ifdef CONFIG_XFRM_OFFLOAD
 int mlx5_devlink_port_fn_ipsec_crypto_get(struct devlink_port *port, bool *is_enabled,
 					  struct netlink_ext_ack *extack);
@@ -634,6 +642,8 @@ bool mlx5_esw_multipath_prereq(struct mlx5_core_dev *dev0,
 			       struct mlx5_core_dev *dev1);
 
 const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev);
+int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev);
+int mlx5_esw_host_pf_disable_hca(struct mlx5_core_dev *dev);
 
 void mlx5_esw_adjacent_vhcas_setup(struct mlx5_eswitch *esw);
 void mlx5_esw_adjacent_vhcas_cleanup(struct mlx5_eswitch *esw);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +55 -0

61 lines not on this page · raw message

base-commit: fae1c659d7bd5640012be21b5b5d6490b83c0df8

Signature · 1 line
2.44.0
#1 lore raw
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 11 lines · On Tue, 3 Feb 2026 12:24:02 +0200 you wrote:

From: Moshe Shemesh <[email protected]>

Add support for devlink port function state get/set operations for the host physical function (PF). Until now, mlx5 only allowed state get/set for subfunctions (SFs) ports. This change enables an administrator with eSwitch manager privileges to query or modify the host PF’s function state, allowing it to be explicitly inactivated or activated. While inactivated, the administrator can modify the functions attributes, such as enable/disable roce.

[...]

Here is the summary with links:
- [net-next] net/mlx5: Support devlink port state for host PF

    https://git.kernel.org/netdev/net-next/c/0e6c95c98829

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
maintainer
#2 lore raw
In reply to Tariq Toukan
Quoted 8 lines · Tariq Toukan
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0 -0
index 4b7a1ce7f406..5fbfabe28bdb 100644
@@ -1304,24 +1304,52 @@ static int mlx5_eswitch_load_ec_vf_vports(struct mlx5_eswitch *esw, u16 num_ec_v
 	return err;
 }
 

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static int mlx5_eswitch_load_ec_vf_vports(struct mlx5_eswitch *esw, u16 num_ec_v · line 1314

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +6 -2
-static int host_pf_enable_hca(struct mlx5_core_dev *dev)
+int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
 {
-	if (!mlx5_core_is_ecpf(dev))
+	struct mlx5_eswitch *esw = dev->priv.eswitch;
+	struct mlx5_vport *vport;
+	int err;
+
+	if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw))
 		return 0;

I was able to miss the AI feedback here:

---
The old host_pf_enable_hca() only checked mlx5_core_is_ecpf(dev) before calling mlx5_cmd_host_pf_enable_hca(). The new function adds a check for mlx5_esw_allowed(esw), which returns false when esw is NULL or when the device is not an eswitch manager.

When called from mlx5_host_pf_init() in ecpf.c on an ECPF device that is not an eswitch manager (the path when mlx5_ecpf_esw_admins_host_pf() returns false), this new condition will cause the function to return 0 without enabling the HCA.

Is this behavior change intentional? The old code would enable the HCA in this configuration, but the new code skips it.

The same concern applies to mlx5_esw_host_pf_disable_hca() below.
---

and indeed it looks relevant. I think you have to follow-up or send a revert, whatever it's easier/faster.

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c mlx5_eswitch_enable_pf_vf_vports(struct mlx5_eswitch *esw, · line 1378

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1 -1
@@ -1347,7 +1375,7 @@ mlx5_eswitch_enable_pf_vf_vports(struct mlx5_eswitch *esw,
 
 	if (mlx5_esw_host_functions_enabled(esw->dev)) {
 		/* Enable external host PF HCA */
-		ret = host_pf_enable_hca(esw->dev);
+		ret = mlx5_esw_host_pf_enable_hca(esw->dev);

Just FTR, more AI feedback here:

---
The old host_pf_disable_hca() was a void function. The new mlx5_esw_host_pf_disable_hca() returns int and can fail, but the return value is not checked here in the error path.

If mlx5_esw_host_pf_disable_hca() fails, it returns without setting vport->pf_activated = false. This leaves pf_activated set to true even though the HCA state may be inconsistent.

Later, mlx5_devlink_pf_port_fn_state_get() reads vport->pf_activated to report state to userspace, which could then report incorrect state.

Should the return value be checked, or should the pf_activated flag be updated unconditionally to reflect the intended state?

The same pattern appears in mlx5_eswitch_disable_pf_vf_vports().
---

#3 lore raw
Quoted 29 lines · Paolo Abeni
Quoted 8 lines · Tariq Toukan
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0 -0
index 4b7a1ce7f406..5fbfabe28bdb 100644
@@ -1304,24 +1304,52 @@ static int mlx5_eswitch_load_ec_vf_vports(struct mlx5_eswitch *esw, u16 num_ec_v
       return err;
  }
 

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static int mlx5_eswitch_load_ec_vf_vports(struct mlx5_eswitch *esw, u16 num_ec_v · line 1314

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +6 -2
-static int host_pf_enable_hca(struct mlx5_core_dev *dev)
+int mlx5_esw_host_pf_enable_hca(struct mlx5_core_dev *dev)
  {
-     if (!mlx5_core_is_ecpf(dev))
+     struct mlx5_eswitch *esw = dev->priv.eswitch;
+     struct mlx5_vport *vport;
+     int err;
+
+     if (!mlx5_core_is_ecpf(dev) || !mlx5_esw_allowed(esw))
               return 0;

I was able to miss the AI feedback here:

---
The old host_pf_enable_hca() only checked mlx5_core_is_ecpf(dev) before calling mlx5_cmd_host_pf_enable_hca(). The new function adds a check for mlx5_esw_allowed(esw), which returns false when esw is NULL or when the device is not an eswitch manager.

Quoted 4 lines

When called from mlx5_host_pf_init() in ecpf.c on an ECPF device that is not an eswitch manager (the path when mlx5_ecpf_esw_admins_host_pf() returns false), this new condition will cause the function to return 0 without enabling the HCA.

The additional check I added here is actually redundant either if we get from old code path or from the new caller, both will call it as eswitch manager only. So there is no concern on the old code behavior change, but I can follow up with a patch to remove the redundant check, though not critical.

Quoted 28 lines

Is this behavior change intentional? The old code would enable the HCA in this configuration, but the new code skips it.

The same concern applies to mlx5_esw_host_pf_disable_hca() below.
---

and indeed it looks relevant. I think you have to follow-up or send a revert, whatever it's easier/faster.

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c mlx5_eswitch_enable_pf_vf_vports(struct mlx5_eswitch *esw, · line 1378

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1 -1
@@ -1347,7 +1375,7 @@ mlx5_eswitch_enable_pf_vf_vports(struct mlx5_eswitch *esw,
 
       if (mlx5_esw_host_functions_enabled(esw->dev)) {
               /* Enable external host PF HCA */
-             ret = host_pf_enable_hca(esw->dev);
+             ret = mlx5_esw_host_pf_enable_hca(esw->dev);

Just FTR, more AI feedback here:

---
The old host_pf_disable_hca() was a void function. The new mlx5_esw_host_pf_disable_hca() returns int and can fail, but the return value is not checked here in the error path.

If mlx5_esw_host_pf_disable_hca() fails, it returns without setting vport->pf_activated = false. This leaves pf_activated set to true even though the HCA state may be inconsistent.

Quoted 5 lines

Later, mlx5_devlink_pf_port_fn_state_get() reads vport->pf_activated to report state to userspace, which could then report incorrect state.

Should the return value be checked, or should the pf_activated flag be updated unconditionally to reflect the intended state?

When disable function is part of the unload/teardown/error flows we don't check result. The function is not void anymore only for the new use case that it is called from devlink and return value is checked there. Thanks, Moshe.

Quoted 4 lines

The same pattern appears in mlx5_eswitch_disable_pf_vf_vports().
---