diff mbox series

[net-next,2/2] net: dsa: Set the master device's MTU to account for DSA overheads

Message ID 1544092565-11311-3-git-send-email-andrew@lunn.ch
State Accepted, archived
Delegated to: David Miller
Headers show
Series Adjust MTU of DSA master interface | expand

Commit Message

Andrew Lunn Dec. 6, 2018, 10:36 a.m. UTC
DSA tagging of frames sent over the master interface to the switch
increases the size of the frame. Such frames can then be bigger than
the normal MTU of the master interface, and it may drop them. Use the
overhead information from the tagger to set the MTU of the master
device to include this overhead.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 net/dsa/master.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Florian Fainelli Dec. 6, 2018, 8:21 p.m. UTC | #1
On 12/6/18 2:36 AM, Andrew Lunn wrote:
> DSA tagging of frames sent over the master interface to the switch
> increases the size of the frame. Such frames can then be bigger than
> the normal MTU of the master interface, and it may drop them. Use the
> overhead information from the tagger to set the MTU of the master
> device to include this overhead.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  net/dsa/master.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/net/dsa/master.c b/net/dsa/master.c
> index c90ee3227dea..42f525bc68e2 100644
> --- a/net/dsa/master.c
> +++ b/net/dsa/master.c
> @@ -158,8 +158,24 @@ static void dsa_master_ethtool_teardown(struct net_device *dev)
>  	cpu_dp->orig_ethtool_ops = NULL;
>  }
>  
> +void dsa_master_set_mtu(struct net_device *dev, struct dsa_port *cpu_dp)
> +{
> +	unsigned int mtu = ETH_DATA_LEN + cpu_dp->tag_ops->overhead;
> +	int err;
> +
> +	rtnl_lock();
> +	if (mtu <= dev->max_mtu) {
> +		err = dev_set_mtu(dev, mtu);
> +		if (err)
> +			netdev_dbg(dev, "Unable to set MTU to include for DSA overheads\n");
> +	}

Would it make sense to warn the user that there might be
transmit/receive issues with the DSA tagging protocol if either
dev_set_mtu() fails or mtu > dev->max_mtu?

> +	rtnl_unlock();
> +}
> +
>  int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
>  {
> +	dsa_master_set_mtu(dev,  cpu_dp);

Not that I think it matters too much to people because unbinding the
switch driver and expecting the CPU port to continue operating is
wishful thinking, but we should probably unwind that operation in
dsa_master_teardown(), right?

> +
>  	/* If we use a tagging format that doesn't have an ethertype
>  	 * field, make sure that all packets from this point on get
>  	 * sent to the tag format's receive function.
>
Andrew Lunn Dec. 6, 2018, 8:48 p.m. UTC | #2
On Thu, Dec 06, 2018 at 12:21:31PM -0800, Florian Fainelli wrote:
> On 12/6/18 2:36 AM, Andrew Lunn wrote:
> > DSA tagging of frames sent over the master interface to the switch
> > increases the size of the frame. Such frames can then be bigger than
> > the normal MTU of the master interface, and it may drop them. Use the
> > overhead information from the tagger to set the MTU of the master
> > device to include this overhead.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> >  net/dsa/master.c | 16 ++++++++++++++++
> >  1 file changed, 16 insertions(+)
> > 
> > diff --git a/net/dsa/master.c b/net/dsa/master.c
> > index c90ee3227dea..42f525bc68e2 100644
> > --- a/net/dsa/master.c
> > +++ b/net/dsa/master.c
> > @@ -158,8 +158,24 @@ static void dsa_master_ethtool_teardown(struct net_device *dev)
> >  	cpu_dp->orig_ethtool_ops = NULL;
> >  }
> >  
> > +void dsa_master_set_mtu(struct net_device *dev, struct dsa_port *cpu_dp)
> > +{
> > +	unsigned int mtu = ETH_DATA_LEN + cpu_dp->tag_ops->overhead;
> > +	int err;
> > +
> > +	rtnl_lock();
> > +	if (mtu <= dev->max_mtu) {
> > +		err = dev_set_mtu(dev, mtu);
> > +		if (err)
> > +			netdev_dbg(dev, "Unable to set MTU to include for DSA overheads\n");
> > +	}
> 
> Would it make sense to warn the user that there might be
> transmit/receive issues with the DSA tagging protocol if either
> dev_set_mtu() fails or mtu > dev->max_mtu?

I thought about that. But we have setups which work today with the
standard MTU. The master might not implement the set_mtu op, or might
impose the standard MTU, but be quite happy to deal with our DSA
packets. So i wanted to make this a hint to the master device, not a
strong requirement.

> Not that I think it matters too much to people because unbinding the
> switch driver and expecting the CPU port to continue operating is
> wishful thinking, but we should probably unwind that operation in
> dsa_master_teardown(), right?

That would make sense.

David has already accepted the patchset, so i will add a followup
patch.

	Andrew
David Miller Dec. 6, 2018, 9:35 p.m. UTC | #3
From: Andrew Lunn <andrew@lunn.ch>
Date: Thu, 6 Dec 2018 21:48:46 +0100

> David has already accepted the patchset, so i will add a followup
> patch.

Yeah sorry for jumping the gun, the changes looked pretty
straightforward to me. :-/
Stephen Hemminger Dec. 6, 2018, 10:14 p.m. UTC | #4
On Thu,  6 Dec 2018 11:36:05 +0100
Andrew Lunn <andrew@lunn.ch> wrote:

> +void dsa_master_set_mtu(struct net_device *dev, struct dsa_port *cpu_dp)
> +{
> +	unsigned int mtu = ETH_DATA_LEN + cpu_dp->tag_ops->overhead;
> +	int err;
> +
> +	rtnl_lock();
> +	if (mtu <= dev->max_mtu) {
> +		err = dev_set_mtu(dev, mtu);
> +		if (err)
> +			netdev_dbg(dev, "Unable to set MTU to include for DSA overheads\n");
> +	}
> +	rtnl_unlock();
> +}
> +

You don't need the debug message. Use err_ack instead?

Debug messages are usually disabled in most distributions.
diff mbox series

Patch

diff --git a/net/dsa/master.c b/net/dsa/master.c
index c90ee3227dea..42f525bc68e2 100644
--- a/net/dsa/master.c
+++ b/net/dsa/master.c
@@ -158,8 +158,24 @@  static void dsa_master_ethtool_teardown(struct net_device *dev)
 	cpu_dp->orig_ethtool_ops = NULL;
 }
 
+void dsa_master_set_mtu(struct net_device *dev, struct dsa_port *cpu_dp)
+{
+	unsigned int mtu = ETH_DATA_LEN + cpu_dp->tag_ops->overhead;
+	int err;
+
+	rtnl_lock();
+	if (mtu <= dev->max_mtu) {
+		err = dev_set_mtu(dev, mtu);
+		if (err)
+			netdev_dbg(dev, "Unable to set MTU to include for DSA overheads\n");
+	}
+	rtnl_unlock();
+}
+
 int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
 {
+	dsa_master_set_mtu(dev,  cpu_dp);
+
 	/* If we use a tagging format that doesn't have an ethertype
 	 * field, make sure that all packets from this point on get
 	 * sent to the tag format's receive function.