diff mbox series

[net,1/2] net: dsa: be compatible with DSA masters with max_mtu of 1500 or less

Message ID 20200421123110.13733-2-olteanv@gmail.com
State New
Headers show
Series [net,1/2] net: dsa: be compatible with DSA masters with max_mtu of 1500 or less | expand

Commit Message

Vladimir Oltean April 21, 2020, 12:31 p.m. UTC
From: Vladimir Oltean <vladimir.oltean@nxp.com>

It would be ideal if the DSA switch ports would support an MTU of 1500
bytes by default, same as any other net device. But there are 2 cases of
issues with trying to do that:

- Drivers that are legitimately MTU-challenged and don't support
  anything larger than ETH_DATA_LEN. A very quick search shows that
  sungem.c is one such example - there may be many others.

- Drivers that simply don't populate netdev->max_mtu. In that case, it
  seems that the ether_setup function sets dev->max_mtu to a default
  value of ETH_DATA_LEN. And due to the above cases which really are
  MTU-challenged, we can't really make any guesses.

So for these cases, if the max_mtu of the master net_device is lower
than 1500, use that (minus the tagger overhead) as the max MTU of the
switch ports.

Fixes: bfcb813203e6 ("net: dsa: configure the MTU for switch ports")
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/slave.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index e94eb1aac602..3776a6f6d312 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1723,6 +1723,7 @@  int dsa_slave_create(struct dsa_port *port)
 	const char *name = port->name;
 	struct net_device *slave_dev;
 	struct dsa_slave_priv *p;
+	int mtu;
 	int ret;
 
 	if (!ds->num_tx_queues)
@@ -1767,8 +1768,10 @@  int dsa_slave_create(struct dsa_port *port)
 	p->xmit = cpu_dp->tag_ops->xmit;
 	port->slave = slave_dev;
 
+	mtu = min_t(int, master->max_mtu - cpu_dp->tag_ops->overhead,
+		    ETH_DATA_LEN);
 	rtnl_lock();
-	ret = dsa_slave_change_mtu(slave_dev, ETH_DATA_LEN);
+	ret = dsa_slave_change_mtu(slave_dev, mtu);
 	rtnl_unlock();
 	if (ret && ret != -EOPNOTSUPP) {
 		dev_err(ds->dev, "error %d setting MTU on port %d\n",