netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Woudstra <ericwouds@gmail.com>
To: Ido Schimmel <idosch@nvidia.com>, Petr Machata <petrm@nvidia.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	Nikolay Aleksandrov <razor@blackwall.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Eric Woudstra <ericwouds@gmail.com>
Subject: [RFC PATCH v1 net-next] net: mlxsw_sp: Use switchdev_handle_port_obj_add_foreign() for vxlan
Date: Sat,  8 Feb 2025 15:15:18 +0100	[thread overview]
Message-ID: <20250208141518.191782-1-ericwouds@gmail.com> (raw)

Sending as RFC as I do not own this hardware. This code is not tested.

Vladimir found this part of the spectrum switchdev, while looking at
another issue here:

https://lore.kernel.org/all/20250207220408.zipucrmm2yafj4wu@skbuf/

As vxlan seems a foreign port, wouldn't it be better to use
switchdev_handle_port_obj_add_foreign() ?

Note that port_obj_info->handled = true is set in
__switchdev_handle_port_obj_add() and can be removed.

Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
---
 .../net/ethernet/mellanox/mlxsw/spectrum.c    |  6 ++
 .../net/ethernet/mellanox/mlxsw/spectrum.h    |  2 +
 .../mellanox/mlxsw/spectrum_switchdev.c       | 92 ++++++++++---------
 3 files changed, 56 insertions(+), 44 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index d714311fd884..f03b489f7b99 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -4002,6 +4002,12 @@ bool mlxsw_sp_port_dev_check(const struct net_device *dev)
 	return dev->netdev_ops == &mlxsw_sp_port_netdev_ops;
 }
 
+bool mlxsw_sp_foreign_dev_check(const struct net_device *dev,
+				const struct net_device *foreign_dev)
+{
+	return netif_is_vxlan(foreign_dev);
+}
+
 static int mlxsw_sp_lower_dev_walk(struct net_device *lower_dev,
 				   struct netdev_nested_priv *priv)
 {
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index b10f80fc651b..4264468c5a6f 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -709,6 +709,8 @@ int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
 				unsigned int counter_index);
 bool mlxsw_sp_port_dev_check(const struct net_device *dev);
+bool mlxsw_sp_foreign_dev_check(const struct net_device *dev,
+				const struct net_device *foreign_dev);
 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev);
 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev);
 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 6397ff0dc951..0ab80cb22bc4 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -2252,6 +2252,14 @@ mlxsw_sp_port_mrouter_update_mdb(struct mlxsw_sp_port *mlxsw_sp_port,
 	}
 }
 
+static int
+mlxsw_sp_switchdev_handle_vxlan_obj_add(struct net_device *vxlan_dev,
+					const struct switchdev_obj *obj,
+					struct netlink_ext_ack *extack);
+static void
+mlxsw_sp_switchdev_handle_vxlan_obj_del(struct net_device *vxlan_dev,
+					const struct switchdev_obj *obj);
+
 static int mlxsw_sp_port_obj_add(struct net_device *dev, const void *ctx,
 				 const struct switchdev_obj *obj,
 				 struct netlink_ext_ack *extack)
@@ -2262,16 +2270,20 @@ static int mlxsw_sp_port_obj_add(struct net_device *dev, const void *ctx,
 
 	switch (obj->id) {
 	case SWITCHDEV_OBJ_ID_PORT_VLAN:
-		vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
-
-		err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, extack);
-
-		/* The event is emitted before the changes are actually
-		 * applied to the bridge. Therefore schedule the respin
-		 * call for later, so that the respin logic sees the
-		 * updated bridge state.
-		 */
-		mlxsw_sp_span_respin(mlxsw_sp_port->mlxsw_sp);
+		if (netif_is_vxlan(dev)) {
+			err = mlxsw_sp_switchdev_handle_vxlan_obj_add(dev, obj, extack);
+		} else {
+			vlan = SWITCHDEV_OBJ_PORT_VLAN(obj);
+
+			err = mlxsw_sp_port_vlans_add(mlxsw_sp_port, vlan, extack);
+
+			/* The event is emitted before the changes are actually
+			 * applied to the bridge. Therefore schedule the respin
+			 * call for later, so that the respin logic sees the
+			 * updated bridge state.
+			 */
+			mlxsw_sp_span_respin(mlxsw_sp_port->mlxsw_sp);
+		}
 		break;
 	case SWITCHDEV_OBJ_ID_PORT_MDB:
 		err = mlxsw_sp_port_mdb_add(mlxsw_sp_port,
@@ -2401,8 +2413,12 @@ static int mlxsw_sp_port_obj_del(struct net_device *dev, const void *ctx,
 
 	switch (obj->id) {
 	case SWITCHDEV_OBJ_ID_PORT_VLAN:
-		err = mlxsw_sp_port_vlans_del(mlxsw_sp_port,
-					      SWITCHDEV_OBJ_PORT_VLAN(obj));
+		if (netif_is_vxlan(dev)) {
+			mlxsw_sp_switchdev_handle_vxlan_obj_del(dev, obj);
+		} else {
+			err = mlxsw_sp_port_vlans_del(mlxsw_sp_port,
+						      SWITCHDEV_OBJ_PORT_VLAN(obj));
+		}
 		break;
 	case SWITCHDEV_OBJ_ID_PORT_MDB:
 		err = mlxsw_sp_port_mdb_del(mlxsw_sp_port,
@@ -3931,19 +3947,17 @@ mlxsw_sp_switchdev_vxlan_vlan_del(struct mlxsw_sp *mlxsw_sp,
 
 static int
 mlxsw_sp_switchdev_vxlan_vlans_add(struct net_device *vxlan_dev,
-				   struct switchdev_notifier_port_obj_info *
-				   port_obj_info)
+				   const struct switchdev_obj *obj,
+				   struct netlink_ext_ack *extack)
 {
 	struct switchdev_obj_port_vlan *vlan =
-		SWITCHDEV_OBJ_PORT_VLAN(port_obj_info->obj);
+		SWITCHDEV_OBJ_PORT_VLAN(obj);
 	bool flag_untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
 	bool flag_pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
 	struct mlxsw_sp_bridge_device *bridge_device;
-	struct netlink_ext_ack *extack;
 	struct mlxsw_sp *mlxsw_sp;
 	struct net_device *br_dev;
 
-	extack = switchdev_notifier_info_to_extack(&port_obj_info->info);
 	br_dev = netdev_master_upper_dev_get(vxlan_dev);
 	if (!br_dev)
 		return 0;
@@ -3952,8 +3966,6 @@ mlxsw_sp_switchdev_vxlan_vlans_add(struct net_device *vxlan_dev,
 	if (!mlxsw_sp)
 		return 0;
 
-	port_obj_info->handled = true;
-
 	bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
 	if (!bridge_device)
 		return -EINVAL;
@@ -3969,11 +3981,10 @@ mlxsw_sp_switchdev_vxlan_vlans_add(struct net_device *vxlan_dev,
 
 static void
 mlxsw_sp_switchdev_vxlan_vlans_del(struct net_device *vxlan_dev,
-				   struct switchdev_notifier_port_obj_info *
-				   port_obj_info)
+				   const struct switchdev_obj *obj)
 {
 	struct switchdev_obj_port_vlan *vlan =
-		SWITCHDEV_OBJ_PORT_VLAN(port_obj_info->obj);
+		SWITCHDEV_OBJ_PORT_VLAN(obj);
 	struct mlxsw_sp_bridge_device *bridge_device;
 	struct mlxsw_sp *mlxsw_sp;
 	struct net_device *br_dev;
@@ -3986,8 +3997,6 @@ mlxsw_sp_switchdev_vxlan_vlans_del(struct net_device *vxlan_dev,
 	if (!mlxsw_sp)
 		return;
 
-	port_obj_info->handled = true;
-
 	bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev);
 	if (!bridge_device)
 		return;
@@ -4001,15 +4010,15 @@ mlxsw_sp_switchdev_vxlan_vlans_del(struct net_device *vxlan_dev,
 
 static int
 mlxsw_sp_switchdev_handle_vxlan_obj_add(struct net_device *vxlan_dev,
-					struct switchdev_notifier_port_obj_info *
-					port_obj_info)
+					const struct switchdev_obj *obj,
+					struct netlink_ext_ack *extack)
 {
 	int err = 0;
 
-	switch (port_obj_info->obj->id) {
+	switch (obj->id) {
 	case SWITCHDEV_OBJ_ID_PORT_VLAN:
 		err = mlxsw_sp_switchdev_vxlan_vlans_add(vxlan_dev,
-							 port_obj_info);
+							 obj, extack);
 		break;
 	default:
 		break;
@@ -4020,12 +4029,11 @@ mlxsw_sp_switchdev_handle_vxlan_obj_add(struct net_device *vxlan_dev,
 
 static void
 mlxsw_sp_switchdev_handle_vxlan_obj_del(struct net_device *vxlan_dev,
-					struct switchdev_notifier_port_obj_info *
-					port_obj_info)
+					const struct switchdev_obj *obj)
 {
-	switch (port_obj_info->obj->id) {
+	switch (obj->id) {
 	case SWITCHDEV_OBJ_ID_PORT_VLAN:
-		mlxsw_sp_switchdev_vxlan_vlans_del(vxlan_dev, port_obj_info);
+		mlxsw_sp_switchdev_vxlan_vlans_del(vxlan_dev, obj);
 		break;
 	default:
 		break;
@@ -4040,20 +4048,16 @@ static int mlxsw_sp_switchdev_blocking_event(struct notifier_block *unused,
 
 	switch (event) {
 	case SWITCHDEV_PORT_OBJ_ADD:
-		if (netif_is_vxlan(dev))
-			err = mlxsw_sp_switchdev_handle_vxlan_obj_add(dev, ptr);
-		else
-			err = switchdev_handle_port_obj_add(dev, ptr,
-							mlxsw_sp_port_dev_check,
-							mlxsw_sp_port_obj_add);
+		err = switchdev_handle_port_obj_add_foreign(dev, ptr,
+							    mlxsw_sp_port_dev_check,
+							    mlxsw_sp_foreign_dev_check,
+							    mlxsw_sp_port_obj_add);
 		return notifier_from_errno(err);
 	case SWITCHDEV_PORT_OBJ_DEL:
-		if (netif_is_vxlan(dev))
-			mlxsw_sp_switchdev_handle_vxlan_obj_del(dev, ptr);
-		else
-			err = switchdev_handle_port_obj_del(dev, ptr,
-							mlxsw_sp_port_dev_check,
-							mlxsw_sp_port_obj_del);
+		err = switchdev_handle_port_obj_del_foreign(dev, ptr,
+							    mlxsw_sp_port_dev_check,
+							    mlxsw_sp_foreign_dev_check,
+							    mlxsw_sp_port_obj_del);
 		return notifier_from_errno(err);
 	case SWITCHDEV_PORT_ATTR_SET:
 		err = switchdev_handle_port_attr_set(dev, ptr,
-- 
2.47.1


             reply	other threads:[~2025-02-08 14:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-08 14:15 Eric Woudstra [this message]
2025-02-10  6:48 ` [RFC PATCH v1 net-next] net: mlxsw_sp: Use switchdev_handle_port_obj_add_foreign() for vxlan Ido Schimmel
2025-02-10 15:22   ` Vladimir Oltean
2025-02-11 14:31     ` Ido Schimmel
2025-02-11 15:23       ` Vladimir Oltean
2025-02-12 14:07         ` Ido Schimmel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250208141518.191782-1-ericwouds@gmail.com \
    --to=ericwouds@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=razor@blackwall.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).