Skip to contentSkip to conversation

devlink eswitch inactive mode

PATCH Superseded Saeed Mahameed 3 participants 9 messages Nov 7, 2025 – Nov 11, 2025

Subsystems (7)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover devlink eswitch inactive mode

From: Saeed Mahameed <[email protected]>

v1->v2:
- Introduce new devlink mode instead of state, Jiri's suggestion.
- Address kernel robot issues reported in v1.
no previous prototype for 'mlx5_mpfs_enable'

v1: https://lore.kernel.org/all/[email protected]/

Before having traffic flow through an eswitch, a user may want to have the ability to block traffic towards the FDB until FDB is fully programmed and the user is ready to send traffic to it. For example: when two eswitches are present for vports in a multi-PF setup, one eswitch may take over the traffic from the other when the user chooses. Before this take over, a user may want to first program the inactive eswitch and then once ready redirect traffic to this new eswitch.

This series introduces a user-configurable mode for an eswitch that allows dynamically switching between active and inactive modes. When inactive, traffic does not flow through the eswitch. While inactive, steering pipeline configuration can be done (e.g. adding TC rules, discovering representors, enabling the desired SDN modes such as bridge/OVS/DPDK/etc). Once configuration is completed, a user can set the eswitch mode to active and have traffic flow through. This allows admins to upgrade forwarding pipeline rules with very minimal downtime and packet drops.

A user can start the eswitch in switchdev or switchdev_inactive mode.

Active: Traffic is enabled on this eswitch FDB.
Inactive: Traffic is ignored/dropped on this eswitch FDB.

An example use case:

$ devlink dev eswitch set pci/0000:08:00.1 mode switchdev_inactive
Setup FDB pipeline and netdev representors
...
Once ready to start receiving traffic
$ devlink dev eswitch set pci/0000:08:00.1 mode switchdev

Saeed Mahameed (3):
devlink: Introduce switchdev_inactive eswitch mode net/mlx5: MPFS, add support for dynamic enable/disable net/mlx5: E-Switch, support eswitch inactive mode

 Documentation/netlink/specs/devlink.yaml      |   2 +
 .../devlink/devlink-eswitch-attr.rst          |  13 ++
 .../mellanox/mlx5/core/esw/adj_vport.c        |  15 +-
 .../net/ethernet/mellanox/mlx5/core/eswitch.h |   6 +
 .../mellanox/mlx5/core/eswitch_offloads.c     | 194 +++++++++++++++++-
 .../net/ethernet/mellanox/mlx5/core/fs_core.c |   5 +
 .../ethernet/mellanox/mlx5/core/lib/mpfs.c    | 115 +++++++++--
 .../ethernet/mellanox/mlx5/core/lib/mpfs.h    |   9 +
 include/linux/mlx5/fs.h                       |   1 +
 include/uapi/linux/devlink.h                  |   1 +
 net/devlink/netlink_gen.c                     |   2 +-
 11 files changed, 325 insertions(+), 38 deletions(-)
Signature · 1 line
2.51.1
#1 lore raw

PATCH v2 1/3 devlink: Introduce switchdev_inactive eswitch mode

From: Saeed Mahameed <[email protected]>

Adds DEVLINK_ESWITCH_MODE_SWITCHDEV_INACTIVE attribute to UAPI and documentation.

Before having traffic flow through an eswitch, a user may want to have the ability to block traffic towards the FDB until FDB is fully programmed and the user is ready to send traffic to it. For example: when two eswitches are present for vports in a multi-PF setup, one eswitch may take over the traffic from the other when the user chooses.
Before this take over, a user may want to first program the inactive eswitch and then once ready redirect traffic to this new eswitch.

switchdev modes transition semantics:

legacy->switchdev_inactive: Create switchdev mode normally, traffic not
allowed to flow yet.

switchdev_inactive->switchdev: Enable traffic to flow.

switchdev->switchdev_inactive: Block traffic on the FDB, FDB and
representros state and content is preserved.

When eswitch is configured to this mode, traffic is ignored/dropped on this eswitch FDB, while current configuration is kept, e.g FDB rules and netdev representros are kept available, FDB programming is allowed.

Example:

 # start inactive switchdev
devlink dev eswitch set pci/0000:08:00.1 mode switchdev_inactive
 # setup TC rules, representors etc ..
 # activate
devlink dev eswitch set pci/0000:08:00.1 mode switchdev
---
 Documentation/netlink/specs/devlink.yaml            |  2 ++
 .../networking/devlink/devlink-eswitch-attr.rst     | 13 +++++++++++++
 include/uapi/linux/devlink.h                        |  1 +
 net/devlink/netlink_gen.c                           |  2 +-
 4 files changed, 17 insertions(+), 1 deletion(-)
Documentation/netlink/specs/devlink.yaml +2 -0
index 3db59c965869..426d5aa7d955 100644
@@ -99,6 +99,8 @@ definitions:
         name: legacy
       -
         name: switchdev
+      -
+        name: switchdev-inactive
   -
     type: enum
     name: eswitch-inline-mode
Documentation/networking/devlink/devlink-eswitch-attr.rst +13 -0
index 08bb39ab1528..eafe09abc40c 100644
@@ -39,6 +39,10 @@ The following is a list of E-Switch attributes.
          rules.
        * ``switchdev`` allows for more advanced offloading capabilities of
          the E-Switch to hardware.
+       * ``switchdev_inactive`` switchdev mode but starts inactive, doesn't allow traffic
+         until explicitly activated. This mode is useful for orchestrators that
+         want to prepare the device in switchdev mode but only activate it when
+         all configurations are done.
    * - ``inline-mode``
      - enum
      - Some HWs need the VF driver to put part of the packet
@@ -74,3 +78,12 @@ Example Usage
 
     # enable encap-mode with legacy mode
     $ devlink dev eswitch set pci/0000:08:00.0 mode legacy inline-mode none encap-mode basic
+
+    # start switchdev mode in inactive state
+    $ devlink dev eswitch set pci/0000:08:00.0 mode switchdev_inactive
+
+    # setup switchdev configurations, representors, FDB entries, etc..
+    ...
+
+    # activate switchdev mode to allow traffic
+    $ devlink dev eswitch set pci/0000:08:00.0 mode switchdev
include/uapi/linux/devlink.h +1 -0
index bcad11a787a5..157f11d3fb72 100644
@@ -181,6 +181,7 @@ enum devlink_sb_threshold_type {
 enum devlink_eswitch_mode {
 	DEVLINK_ESWITCH_MODE_LEGACY,
 	DEVLINK_ESWITCH_MODE_SWITCHDEV,
+	DEVLINK_ESWITCH_MODE_SWITCHDEV_INACTIVE,
 };
 
 enum devlink_eswitch_inline_mode {
net/devlink/netlink_gen.c +1 -1
index 9fd00977d59e..5ad435aee29d 100644
@@ -229,7 +229,7 @@ static const struct nla_policy devlink_eswitch_get_nl_policy[DEVLINK_ATTR_DEV_NA
 static const struct nla_policy devlink_eswitch_set_nl_policy[DEVLINK_ATTR_ESWITCH_ENCAP_MODE + 1] = {
 	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
 	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
-	[DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_MAX(NLA_U16, 1),
+	[DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_MAX(NLA_U16, 2),
 	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = NLA_POLICY_MAX(NLA_U8, 3),
 	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = NLA_POLICY_MAX(NLA_U8, 1),
 };
Signature · 1 line
2.51.1
#2 lore raw

PATCH v2 2/3 net/mlx5: MPFS, add support for dynamic enable/disable

In reply to Saeed Mahameed

From: Saeed Mahameed <[email protected]>

MPFS (Multi PF Switch) is enabled by default in Multi-Host environments, the driver keeps a list of desired unicast mac addresses of all vports (vfs/Sfs) and applied to HW via L2_table FW command.

Add API to dynamically apply the list of MACs to HW when needed for next patches, to utilize this new API in devlink eswitch active/in-active uAPI.

Issue: 4314625

Change-Id I185c144319e514f787811f556888e1b727bdbf35
---
 .../ethernet/mellanox/mlx5/core/lib/mpfs.c    | 115 +++++++++++++++---
 .../ethernet/mellanox/mlx5/core/lib/mpfs.h    |   9 ++
 2 files changed, 107 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +98 -17
index 4450091e181a..f27b5adb9606 100644
@@ -65,13 +65,14 @@ static int del_l2table_entry_cmd(struct mlx5_core_dev *dev, u32 index)
 /* UC L2 table hash node */
 struct l2table_node {
 	struct l2addr_node node;
-	u32                index; /* index in HW l2 table */
+	int                index; /* index in HW l2 table */
 	int                ref_count;
 };
 
 struct mlx5_mpfs {
 	struct hlist_head    hash[MLX5_L2_ADDR_HASH_SIZE];
 	struct mutex         lock; /* Synchronize l2 table access */
+	bool                 enabled;
 	u32                  size;
 	unsigned long        *bitmap;
 };
@@ -114,6 +115,8 @@ int mlx5_mpfs_init(struct mlx5_core_dev *dev)
 		return -ENOMEM;
 	}
 
+	mpfs->enabled = true;
+
 	dev->priv.mpfs = mpfs;
 	return 0;
 }
@@ -135,7 +138,7 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)
 	struct mlx5_mpfs *mpfs = dev->priv.mpfs;
 	struct l2table_node *l2addr;
 	int err = 0;
-	u32 index;
+	int index;
 
 	if (!mpfs)
 		return 0;
@@ -148,30 +151,34 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)
 		goto out;
 	}
 
-	err = alloc_l2table_index(mpfs, &index);
-	if (err)
-		goto out;
-
 	l2addr = l2addr_hash_add(mpfs->hash, mac, struct l2table_node, GFP_KERNEL);
 	if (!l2addr) {
 		err = -ENOMEM;
-		goto hash_add_err;
+		goto out;
 	}
 
-	err = set_l2table_entry_cmd(dev, index, mac);
-	if (err)
-		goto set_table_entry_err;
+	index = -1;
+
+	if (mpfs->enabled) {
+		err = alloc_l2table_index(mpfs, &index);
+		if (err)
+			goto hash_del;
+		err = set_l2table_entry_cmd(dev, index, mac);
+		if (err)
+			goto free_l2table_index;
+		mlx5_core_dbg(dev, "MPFS entry %pM, set @index (%d)\n",
+			      l2addr->node.addr, l2addr->index);
+	}
 
 	l2addr->index = index;
 	l2addr->ref_count = 1;
 
 	mlx5_core_dbg(dev, "MPFS mac added %pM, index (%d)\n", mac, index);
 	goto out;
-
-set_table_entry_err:
-	l2addr_hash_del(l2addr);
-hash_add_err:
+free_l2table_index:
 	free_l2table_index(mpfs, index);
+hash_del:
+	l2addr_hash_del(l2addr);
 out:
 	mutex_unlock(&mpfs->lock);
 	return err;
@@ -183,7 +190,7 @@ int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac)
 	struct mlx5_mpfs *mpfs = dev->priv.mpfs;
 	struct l2table_node *l2addr;
 	int err = 0;
-	u32 index;
+	int index;
 
 	if (!mpfs)
 		return 0;
@@ -200,12 +207,86 @@ int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac)
 		goto unlock;
 
 	index = l2addr->index;
-	del_l2table_entry_cmd(dev, index);
+	if (index >= 0) {
+		del_l2table_entry_cmd(dev, index);
+		free_l2table_index(mpfs, index);
+		mlx5_core_dbg(dev, "MPFS entry %pM, deleted @index (%d)\n",
+			      mac, index);
+	}
 	l2addr_hash_del(l2addr);
-	free_l2table_index(mpfs, index);
 	mlx5_core_dbg(dev, "MPFS mac deleted %pM, index (%d)\n", mac, index);
 unlock:
 	mutex_unlock(&mpfs->lock);
 	return err;
 }
 EXPORT_SYMBOL(mlx5_mpfs_del_mac);
+
+int mlx5_mpfs_enable(struct mlx5_core_dev *dev)
+{
+	struct mlx5_mpfs *mpfs = dev->priv.mpfs;
+	struct l2table_node *l2addr;
+	struct hlist_node *n;
+	int err = 0;
+
+	if (!mpfs)
+		return -ENODEV;
+
+	mutex_lock(&mpfs->lock);
+	if (mpfs->enabled)
+		goto out;
+	mpfs->enabled = true;
+	mlx5_core_dbg(dev, "MPFS enabling mpfs\n");
+
+	mlx5_mpfs_foreach(l2addr, n, mpfs) {
+		u32 index;
+
+		err = alloc_l2table_index(mpfs, &index);
+		if (err) {
+			mlx5_core_err(dev, "Failed to allocated MPFS index for %pM, err(%d)\n",
+				      l2addr->node.addr, err);
+			goto out;
+		}
+
+		err = set_l2table_entry_cmd(dev, index, l2addr->node.addr);
+		if (err) {
+			mlx5_core_err(dev, "Failed to set MPFS l2table entry for %pM index=%d, err(%d)\n",
+				      l2addr->node.addr, index, err);
+			free_l2table_index(mpfs, index);
+			goto out;
+		}
+
+		l2addr->index = index;
+		mlx5_core_dbg(dev, "MPFS entry %pM, set @index (%d)\n",
+			      l2addr->node.addr, l2addr->index);
+	}
+out:
+	mutex_unlock(&mpfs->lock);
+	return err;
+}
+
+void mlx5_mpfs_disable(struct mlx5_core_dev *dev)
+{
+	struct mlx5_mpfs *mpfs = dev->priv.mpfs;
+	struct l2table_node *l2addr;
+	struct hlist_node *n;
+
+	if (!mpfs)
+		return;
+
+	mutex_lock(&mpfs->lock);
+	if (!mpfs->enabled)
+		goto unlock;
+	mlx5_mpfs_foreach(l2addr, n, mpfs) {
+		if (l2addr->index < 0)
+			continue;
+		del_l2table_entry_cmd(dev, l2addr->index);
+		free_l2table_index(mpfs, l2addr->index);
+		mlx5_core_dbg(dev, "MPFS entry %pM, deleted @index (%d)\n",
+			      l2addr->node.addr, l2addr->index);
+		l2addr->index = -1;
+	}
+	mpfs->enabled = false;
+	mlx5_core_dbg(dev, "MPFS disabled\n");
+unlock:
+	mutex_unlock(&mpfs->lock);
+}
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.h +9 -0
index 4a293542a7aa..be0ccdd5a0aa 100644
@@ -45,6 +45,10 @@ struct l2addr_node {
 	u8                addr[ETH_ALEN];
 };
 
+#define mlx5_mpfs_foreach(hs, tmp, mpfs) \
+	for (int j = 0; j < MLX5_L2_ADDR_HASH_SIZE; j++) \
+		hlist_for_each_entry_safe(hs, tmp, &(mpfs)->hash[j], node.hlist)
+
 #define for_each_l2hash_node(hn, tmp, hash, i) \
 	for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \
 		hlist_for_each_entry_safe(hn, tmp, &(hash)[i], hlist)
@@ -82,11 +86,16 @@ struct l2addr_node {
 })
 
 #ifdef CONFIG_MLX5_MPFS
+struct mlx5_core_dev;
 int  mlx5_mpfs_init(struct mlx5_core_dev *dev);
 void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev);
+int mlx5_mpfs_enable(struct mlx5_core_dev *dev);
+void mlx5_mpfs_disable(struct mlx5_core_dev *dev);
 #else /* #ifndef CONFIG_MLX5_MPFS */
 static inline int  mlx5_mpfs_init(struct mlx5_core_dev *dev) { return 0; }
 static inline void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev) {}
+static inline int mlx5_mpfs_enable(struct mlx5_core_dev *dev) { return 0; }
+static inline void mlx5_mpfs_disable(struct mlx5_core_dev *dev) {}
 #endif
 
 #endif
Signature · 1 line
2.51.1
reviewer
#3 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5: MPFS, add support for dynamic enable/disable

Quoted 11 lines · Saeed Mahameed

From: Saeed Mahameed <[email protected]>

MPFS (Multi PF Switch) is enabled by default in Multi-Host environments, the driver keeps a list of desired unicast mac addresses of all vports (vfs/Sfs) and applied to HW via L2_table FW command.

Add API to dynamically apply the list of MACs to HW when needed for next patches, to utilize this new API in devlink eswitch active/in-active uAPI.

Issue: 4314625
Change-Id: I185c144319e514f787811f556888e1b727bdbf35

nit: the issue and Change-Id should be dropped when upstreaming patches.

Quoted 9 lines
---
 .../ethernet/mellanox/mlx5/core/lib/mpfs.c    | 115 +++++++++++++++---
 .../ethernet/mellanox/mlx5/core/lib/mpfs.h    |   9 ++
 2 files changed, 107 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +0 -0

...

Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +0 -0
@@ -148,30 +151,34 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)

...

drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac) · line 170

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +9 -0
+	if (mpfs->enabled) {
+		err = alloc_l2table_index(mpfs, &index);
+		if (err)
+			goto hash_del;
+		err = set_l2table_entry_cmd(dev, index, mac);
+		if (err)
+			goto free_l2table_index;
+		mlx5_core_dbg(dev, "MPFS entry %pM, set @index (%d)\n",
+			      l2addr->node.addr, l2addr->index);

nit: the following patch updates the line above to:

			      l2addr->node.addr, index);

     I don't think that change belongs in the following patch.

...

Quoted 30 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +30 -0
+int mlx5_mpfs_enable(struct mlx5_core_dev *dev)
+{
+	struct mlx5_mpfs *mpfs = dev->priv.mpfs;
+	struct l2table_node *l2addr;
+	struct hlist_node *n;
+	int err = 0;
+
+	if (!mpfs)
+		return -ENODEV;
+
+	mutex_lock(&mpfs->lock);
+	if (mpfs->enabled)
+		goto out;
+	mpfs->enabled = true;
+	mlx5_core_dbg(dev, "MPFS enabling mpfs\n");
+
+	mlx5_mpfs_foreach(l2addr, n, mpfs) {
+		u32 index;
+
+		err = alloc_l2table_index(mpfs, &index);
+		if (err) {
+			mlx5_core_err(dev, "Failed to allocated MPFS index for %pM, err(%d)\n",
+				      l2addr->node.addr, err);
+			goto out;
+		}
+
+		err = set_l2table_entry_cmd(dev, index, l2addr->node.addr);
+		if (err) {
+			mlx5_core_err(dev, "Failed to set MPFS l2table entry for %pM index=%d, err(%d)\n",
+				      l2addr->node.addr, index, err);

drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac) · line 263

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +10 -0
+			free_l2table_index(mpfs, index);
+			goto out;
+		}
+
+		l2addr->index = index;
+		mlx5_core_dbg(dev, "MPFS entry %pM, set @index (%d)\n",
+			      l2addr->node.addr, l2addr->index);
+	}
+out:
+	mutex_unlock(&mpfs->lock);

I realise that error handling can be complex at best, and particularly so when configuration ends up being partially applied. But I am wondering if the cleanup here is sufficient.

In a similar vein, I also note that although this function returns an error, it is ignored by callers which are added by the following patch. Likewise for mlx5_esw_fdb_drop_create() which is also added by the following patch.

Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +2 -0
+	return err;
+}

...

#4 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5: MPFS, add support for dynamic enable/disable

Quoted 7 lines · Simon Horman
Quoted 6 lines · Saeed Mahameed

From: Saeed Mahameed <[email protected]>

MPFS (Multi PF Switch) is enabled by default in Multi-Host environments, the driver keeps a list of desired unicast mac addresses of all vports (vfs/Sfs) and applied to HW via L2_table FW command.

Quoted 7 lines
Quoted 5 lines

Add API to dynamically apply the list of MACs to HW when needed for next patches, to utilize this new API in devlink eswitch active/in-active uAPI.

Issue: 4314625
Change-Id: I185c144319e514f787811f556888e1b727bdbf35

nit: the issue and Change-Id should be dropped when upstreaming patches.

Removed in V3.

Quoted 29 lines
Quoted 10 lines
---
 .../ethernet/mellanox/mlx5/core/lib/mpfs.c    | 115 +++++++++++++++---
 .../ethernet/mellanox/mlx5/core/lib/mpfs.h    |   9 ++
 2 files changed, 107 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +0 -0

...

Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +0 -0
@@ -148,30 +151,34 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)

...

drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac) · line 170

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +9 -0
+	if (mpfs->enabled) {
+		err = alloc_l2table_index(mpfs, &index);
+		if (err)
+			goto hash_del;
+		err = set_l2table_entry_cmd(dev, index, mac);
+		if (err)
+			goto free_l2table_index;
+		mlx5_core_dbg(dev, "MPFS entry %pM, set @index (%d)\n",
+			      l2addr->node.addr, l2addr->index);

nit: the following patch updates the line above to:

Quoted 4 lines
			      l2addr->node.addr, index);

    I don't think that change belongs in the following patch.

You are right, still in V3 also I will fix this.

Quoted 38 lines

...

Quoted 36 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +36 -0
+int mlx5_mpfs_enable(struct mlx5_core_dev *dev)
+{
+	struct mlx5_mpfs *mpfs = dev->priv.mpfs;
+	struct l2table_node *l2addr;
+	struct hlist_node *n;
+	int err = 0;
+
+	if (!mpfs)
+		return -ENODEV;
+
+	mutex_lock(&mpfs->lock);
+	if (mpfs->enabled)
+		goto out;
+	mpfs->enabled = true;
+	mlx5_core_dbg(dev, "MPFS enabling mpfs\n");
+
+	mlx5_mpfs_foreach(l2addr, n, mpfs) {
+		u32 index;
+
+		err = alloc_l2table_index(mpfs, &index);
+		if (err) {
+			mlx5_core_err(dev, "Failed to allocated MPFS index for %pM, err(%d)\n",
+				      l2addr->node.addr, err);
+			goto out;
+		}
+
+		err = set_l2table_entry_cmd(dev, index, l2addr->node.addr);
+		if (err) {
+			mlx5_core_err(dev, "Failed to set MPFS l2table entry for %pM index=%d, err(%d)\n",
+				      l2addr->node.addr, index, err);
+			free_l2table_index(mpfs, index);
+			goto out;
+		}
+
+		l2addr->index = index;
+		mlx5_core_dbg(dev, "MPFS entry %pM, set @index (%d)\n",
Quoted 9 lines

drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac) · line 263

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +4 -0
+			      l2addr->node.addr, l2addr->index);
+	}
+out:
+	mutex_unlock(&mpfs->lock);

I realise that error handling can be complex at best, and particularly so when configuration ends up being partially applied. But I am wondering if the cleanup here is sufficient.

Cleanup is sufficient, the use of index -1 is an indication of the entry was not successfully written to HW, so only if index is positive we will delete it from hw on cleanup.

Quoted 5 lines

In a similar vein, I also note that although this function returns an error, it is ignored by callers which are added by the following patch. Likewise for mlx5_esw_fdb_drop_create() which is also added by the following patch.

This is best effort as there could be a lot of l2 entries and we might run out of space, we don't want to cripple the whole system just because one VF mac didn't make it to the mpfs table, the approach here is similar to set_rx_mode ndo expectation, which this function also serves.

reviewer
#5 lore raw

Re: [PATCH net-next V2 2/3] net/mlx5: MPFS, add support for dynamic enable/disable

Quoted 2 lines · Saeed Mahameed
Quoted 1 line · Simon Horman

On Thu, Nov 06, 2025 at 04:08:30PM -0800, Saeed Mahameed wrote:

...

Quoted 15 lines
Quoted 4 lines

I realise that error handling can be complex at best, and particularly so when configuration ends up being partially applied. But I am wondering if the cleanup here is sufficient.

Cleanup is sufficient, the use of index -1 is an indication of the entry was not successfully written to HW, so only if index is positive we will delete it from hw on cleanup.

Quoted 5 lines

In a similar vein, I also note that although this function returns an error, it is ignored by callers which are added by the following patch. Likewise for mlx5_esw_fdb_drop_create() which is also added by the following patch.

Quoted 5 lines

This is best effort as there could be a lot of l2 entries and we might run out of space, we don't want to cripple the whole system just because one VF mac didn't make it to the mpfs table, the approach here is similar to set_rx_mode ndo expectation, which this function also serves.

Thanks for the clarification, I agree this is a reasonable approach.

#6 lore raw

PATCH v2 3/3 net/mlx5: E-Switch, support eswitch inactive mode

In reply to Saeed Mahameed

From: Saeed Mahameed <[email protected]>

Add support for eswitch switchdev inactive mode

Inactive mode: Drop all traffic going to FDB, Remove mpfs l2 rules and disconnect adjacent vports.

Active mode: Traffic flows through FDB, mpfs table populated, and adjacent vports are connected.

---
 .../mellanox/mlx5/core/esw/adj_vport.c        |  15 +-
 .../net/ethernet/mellanox/mlx5/core/eswitch.h |   6 +
 .../mellanox/mlx5/core/eswitch_offloads.c     | 194 +++++++++++++++++-
 .../net/ethernet/mellanox/mlx5/core/fs_core.c |   5 +
 .../ethernet/mellanox/mlx5/core/lib/mpfs.c    |   2 +-
 include/linux/mlx5/fs.h                       |   1 +
 6 files changed, 202 insertions(+), 21 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c +4 -11
index 0091ba697bae..250af09b5af2 100644
@@ -4,13 +4,8 @@
 #include "fs_core.h"
 #include "eswitch.h"
 
-enum {
-	MLX5_ADJ_VPORT_DISCONNECT = 0x0,
-	MLX5_ADJ_VPORT_CONNECT = 0x1,
-};
-
-static int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev,
-				     u16 vport, bool connect)
+int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev, u16 vport,
+			      bool connect)
 {
 	u32 in[MLX5_ST_SZ_DW(modify_vport_state_in)] = {};
 
@@ -24,7 +19,7 @@ static int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev,
 	MLX5_SET(modify_vport_state_in, in, egress_connect_valid, 1);
 	MLX5_SET(modify_vport_state_in, in, ingress_connect, connect);
 	MLX5_SET(modify_vport_state_in, in, egress_connect, connect);
-
+	MLX5_SET(modify_vport_state_in, in, admin_state, connect);
 	return mlx5_cmd_exec_in(dev, modify_vport_state, in);
 }
 
@@ -96,7 +91,6 @@ static int mlx5_esw_adj_vport_create(struct mlx5_eswitch *esw, u16 vhca_id,
 	if (err)
 		goto acl_ns_remove;
 
-	mlx5_esw_adj_vport_modify(esw->dev, vport_num, MLX5_ADJ_VPORT_CONNECT);
 	return 0;
 
 acl_ns_remove:
@@ -117,8 +111,7 @@ static void mlx5_esw_adj_vport_destroy(struct mlx5_eswitch *esw,
 
 	esw_debug(esw->dev, "Destroying adjacent vport %d for vhca_id 0x%x\n",
 		  vport_num, vport->vhca_id);
-	mlx5_esw_adj_vport_modify(esw->dev, vport_num,
-				  MLX5_ADJ_VPORT_DISCONNECT);
+
 	mlx5_esw_offloads_rep_remove(esw, vport);
 	mlx5_fs_vport_egress_acl_ns_remove(esw->dev->priv.steering,
 					   vport->index);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +6 -0
index 16eb99aba2a7..368ef2032825 100644
@@ -264,6 +264,9 @@ struct mlx5_eswitch_fdb {
 
 		struct offloads_fdb {
 			struct mlx5_flow_namespace *ns;
+			struct mlx5_flow_table *drop_root;
+			struct mlx5_flow_handle *drop_root_rule;
+			struct mlx5_fc *drop_root_counter;
 			struct mlx5_flow_table *tc_miss_table;
 			struct mlx5_flow_table *slow_fdb;
 			struct mlx5_flow_group *send_to_vport_grp;
@@ -392,6 +395,7 @@ struct mlx5_eswitch {
 	struct mlx5_esw_offload offloads;
 	u32 last_vport_idx;
 	int                     mode;
+	bool                    offloads_inactive;
 	u16                     manager_vport;
 	u16                     first_host_vport;
 	u8			num_peers;
@@ -634,6 +638,8 @@ const u32 *mlx5_esw_query_functions(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);
+int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev, u16 vport,
+			      bool connect);
 
 #define MLX5_DEBUG_ESWITCH_MASK BIT(3)
 
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +185 -9

285 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c +5 -0
index 2db3ffb0a2b2..2ca3bddbdf05 100644
@@ -3520,6 +3520,11 @@ static int init_fdb_root_ns(struct mlx5_flow_steering *steering)
 	if (!steering->fdb_root_ns)
 		return -ENOMEM;
 
+	maj_prio = fs_create_prio(&steering->fdb_root_ns->ns, FDB_DROP_ROOT, 1);
+	err = PTR_ERR_OR_ZERO(maj_prio);
+	if (err)
+		goto out_err;
+
 	err = create_fdb_bypass(steering);
 	if (err)
 		goto out_err;
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c +1 -1
index f27b5adb9606..3777aef600d1 100644
@@ -167,7 +167,7 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)
 		if (err)
 			goto free_l2table_index;
 		mlx5_core_dbg(dev, "MPFS entry %pM, set @index (%d)\n",
-			      l2addr->node.addr, l2addr->index);
+			      l2addr->node.addr, index);
 	}
 
 	l2addr->index = index;
include/linux/mlx5/fs.h +1 -0
index 6ac76a0c3827..7bf2449c53b2 100644
@@ -116,6 +116,7 @@ enum mlx5_flow_namespace_type {
 };
 
 enum {
+	FDB_DROP_ROOT,
 	FDB_BYPASS_PATH,
 	FDB_CRYPTO_INGRESS,
 	FDB_TC_OFFLOAD,
Signature · 1 line
2.51.1
maintainer
#7 lore raw

Re: [PATCH net-next V2 3/3] net/mlx5: E-Switch, support eswitch inactive mode

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c static void esw_mode_change(struct mlx5_eswitch *esw, u16 mode) · line 2399

Quoted 5 lines · On Thu, 6 Nov 2025 16:08:31 -0800 Saeed Mahameed wrote:
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +5 -0
+	if (IS_ERR(table)) {
+		esw_warn(dev, "Failed to create fdb drop root table, err %ld\n",
+			 PTR_ERR(table));
+		return PTR_ERR(table);
+	}

cocci says:

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c:2397:4-11: WARNING: Consider using %pe to print PTR_ERR()

While I have you, could you please help this one along (dare I say, first, due to the extack propagation?):
https://lore.kernel.org/all/[email protected]/

#8 lore raw

Re: [PATCH net-next V2 3/3] net/mlx5: E-Switch, support eswitch inactive mode

Quoted 11 lines · Jakub Kicinski

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c static void esw_mode_change(struct mlx5_eswitch *esw, u16 mode) · line 2399

Quoted 5 lines · On Thu, 6 Nov 2025 16:08:31 -0800 Saeed Mahameed wrote:
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +5 -0
+	if (IS_ERR(table)) {
+		esw_warn(dev, "Failed to create fdb drop root table, err %ld\n",
+			 PTR_ERR(table));
+		return PTR_ERR(table);
+	}

cocci says:

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c:2397:4-11: WARNING: Consider using %pe to print PTR_ERR()

I was planing to do this now, but then saw your message bellow :).

Quoted 2 lines

While I have you, could you please help this one along (dare I say, first, due to the extack propagation?):

Sure, what do you need just review? I see that the series is straight forward, but let me take a deeper look.

Quoted 1 line

https://lore.kernel.org/all/[email protected]/