diff mbox series

[net-next,1/4] net: dsa: don't offload switchdev objects on ports that don't offload the bridge

Message ID 20210214155326.1783266-2-olteanv@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Software fallback for bridging in DSA | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 3 maintainers not CCed: linux-mediatek@lists.infradead.org matthias.bgg@gmail.com linux-arm-kernel@lists.infradead.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 33 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Vladimir Oltean Feb. 14, 2021, 3:53 p.m. UTC
From: Vladimir Oltean <vladimir.oltean@nxp.com>

Starting with commit 058102a6e9eb ("net: dsa: Link aggregation support"),
DSA warns that certain configurations of upper interfaces are not offloaded
to hardware. When a DSA port does not offload a LAG interface, the
dp->lag_dev pointer is always NULL. However the same cannot be said about
offloading a bridge: dp->bridge_dev will get populated regardless of
whether the driver can put the port into the bridge's forwarding domain
or not.

Instead of silently returning 0 if the driver doesn't implement
.port_bridge_join, return -EOPNOTSUPP instead, and print a message via
netlink extack that the configuration was not offloaded to hardware.

Now we can use the check whether dp->bridge_dev is NULL in order to
avoid offloading at all switchdev attributes and objects for ports that
don't even offload the basic operation of switching. Those can still do
the required L2 forwarding using the bridge software datapath, but
enabling any hardware features specific to the bridge such as address
learning would just ask for problems.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/dsa_priv.h | 2 ++
 net/dsa/slave.c    | 5 +++++
 net/dsa/switch.c   | 7 +++++--
 3 files changed, 12 insertions(+), 2 deletions(-)

Comments

Tobias Waldekranz Feb. 25, 2021, 7:23 p.m. UTC | #1
On Sun, Feb 14, 2021 at 17:53, Vladimir Oltean <olteanv@gmail.com> wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
>
> Starting with commit 058102a6e9eb ("net: dsa: Link aggregation support"),
> DSA warns that certain configurations of upper interfaces are not offloaded
> to hardware. When a DSA port does not offload a LAG interface, the
> dp->lag_dev pointer is always NULL. However the same cannot be said about
> offloading a bridge: dp->bridge_dev will get populated regardless of
> whether the driver can put the port into the bridge's forwarding domain
> or not.
>
> Instead of silently returning 0 if the driver doesn't implement
> .port_bridge_join, return -EOPNOTSUPP instead, and print a message via
> netlink extack that the configuration was not offloaded to hardware.
>
> Now we can use the check whether dp->bridge_dev is NULL in order to
> avoid offloading at all switchdev attributes and objects for ports that
> don't even offload the basic operation of switching. Those can still do
> the required L2 forwarding using the bridge software datapath, but
> enabling any hardware features specific to the bridge such as address
> learning would just ask for problems.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---

Reviewed-by: Tobias Waldekranz <tobias@waldekranz.com>
diff mbox series

Patch

diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index f5949b39f6f7..7b0dd2d5f3f8 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -205,6 +205,8 @@  static inline bool dsa_port_offloads_netdev(struct dsa_port *dp,
 					    struct net_device *dev)
 {
 	/* Switchdev offloading can be configured on: */
+	if (!dp->bridge_dev)
+		return false;
 
 	if (dev == dp->slave)
 		/* DSA ports directly connected to a bridge, and event
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 8c9a41a7209a..94bce3596eb6 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1922,6 +1922,11 @@  static int dsa_slave_changeupper(struct net_device *dev,
 			err = dsa_port_bridge_join(dp, info->upper_dev);
 			if (!err)
 				dsa_bridge_mtu_normalization(dp);
+			if (err == -EOPNOTSUPP) {
+				NL_SET_ERR_MSG_MOD(info->info.extack,
+						   "Offloading not supported");
+				err = 0;
+			}
 			err = notifier_from_errno(err);
 		} else {
 			dsa_port_bridge_leave(dp, info->upper_dev);
diff --git a/net/dsa/switch.c b/net/dsa/switch.c
index 1906179e59f7..4137716d0de5 100644
--- a/net/dsa/switch.c
+++ b/net/dsa/switch.c
@@ -88,9 +88,12 @@  static int dsa_switch_bridge_join(struct dsa_switch *ds,
 {
 	struct dsa_switch_tree *dst = ds->dst;
 
-	if (dst->index == info->tree_index && ds->index == info->sw_index &&
-	    ds->ops->port_bridge_join)
+	if (dst->index == info->tree_index && ds->index == info->sw_index) {
+		if (!ds->ops->port_bridge_join)
+			return -EOPNOTSUPP;
+
 		return ds->ops->port_bridge_join(ds, info->port, info->br);
+	}
 
 	if ((dst->index != info->tree_index || ds->index != info->sw_index) &&
 	    ds->ops->crosschip_bridge_join)