Skip to contentSkip to conversation

usb: gadget: ether: Allow changing the MTU

PATCH In review Mike Looijmans 2 participants 3 messages Nov 30, 2015 – Dec 16, 2015 USB

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: gadget: ether: Allow changing the MTU

The gadget ethernet driver supports changing the MTU, but only allows this when the USB cable is removed. The comment indicates that this is because the "peer won't know". Even if the network link is still down and only the USB link is established, the driver won't allow the change.

Other network interfaces allow changing the MTU any time, and don't force the link to be disabled. This makes perfect sense, because in order to be able to negotiate the MTU, the link needs to be up.

Remove the restriction so that it is now actually possible to change the MTU (e.g. using "ifconfig usb0 mtu 15000") without having to manually pull the plug or change the driver's default setting.

This is especially important after commit bba787a860fa ("usb: gadget: ether: Allow jumbo frames")

---
v2: Fix commit reference (checkpatch) and unused variable 'dev' (kbuild test robot)

 drivers/usb/gadget/function/u_ether.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/usb/gadget/function/u_ether.c +4 -14
index 6554322..637809e 100644
@@ -143,21 +143,11 @@ static inline int qlen(struct usb_gadget *gadget, unsigned qmult)
 
 static int ueth_change_mtu(struct net_device *net, int new_mtu)
 {
-	struct eth_dev	*dev = netdev_priv(net);
-	unsigned long	flags;
-	int		status = 0;
+	if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN)
+		return -ERANGE;
+	net->mtu = new_mtu;
 
-	/* don't change MTU on "live" link (peer won't know) */
-	spin_lock_irqsave(&dev->lock, flags);
-	if (dev->port_usb)
-		status = -EBUSY;
-	else if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN)
-		status = -ERANGE;
-	else
-		net->mtu = new_mtu;
-	spin_unlock_irqrestore(&dev->lock, flags);
-
-	return status;
+	return 0;
 }
 
 static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
Signature · 1 line
1.9.1
#1 lore raw

Just a "ping" reminder, I'd like to inquire about the status of this patch...

Quoted 44 lines · Mike Looijmans

The gadget ethernet driver supports changing the MTU, but only allows this when the USB cable is removed. The comment indicates that this is because the "peer won't know". Even if the network link is still down and only the USB link is established, the driver won't allow the change.

Other network interfaces allow changing the MTU any time, and don't force the link to be disabled. This makes perfect sense, because in order to be able to negotiate the MTU, the link needs to be up.

Remove the restriction so that it is now actually possible to change the MTU (e.g. using "ifconfig usb0 mtu 15000") without having to manually pull the plug or change the driver's default setting.

This is especially important after commit bba787a860fa ("usb: gadget: ether: Allow jumbo frames")

---
v2: Fix commit reference (checkpatch) and unused variable 'dev' (kbuild test robot)

  drivers/usb/gadget/function/u_ether.c | 18 ++++--------------
  1 file changed, 4 insertions(+), 14 deletions(-)
drivers/usb/gadget/function/u_ether.c +3 -8
index 6554322..637809e 100644
@@ -143,21 +143,11 @@ static inline int qlen(struct usb_gadget *gadget, unsigned qmult)
 
  static int ueth_change_mtu(struct net_device *net, int new_mtu)
  {
-	struct eth_dev	*dev = netdev_priv(net);
-	unsigned long	flags;
-	int		status = 0;
+	if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN)
+		return -ERANGE;
+	net->mtu = new_mtu;
 
-	/* don't change MTU on "live" link (peer won't know) */
-	spin_lock_irqsave(&dev->lock, flags);
-	if (dev->port_usb)
-		status = -EBUSY;
-	else if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN)

drivers/usb/gadget/function/u_ether.c static inline int qlen(struct usb_gadget *gadget, unsigned qmult) · line 153

Quoted 10 lines
drivers/usb/gadget/function/u_ether.c +1 -6
-		status = -ERANGE;
-	else
-		net->mtu = new_mtu;
-	spin_unlock_irqrestore(&dev->lock, flags);
-
-	return status;
+	return 0;
  }
 
  static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)

Kind regards,

Mike Looijmans
System Expert

TOPIC Embedded Products Eindhovenseweg 32-C, NL-5683 KH Best Postbus 440, NL-5680 AK Best
Telefoon: +31 (0) 499 33 69 79
Telefax: +31 (0) 499 33 69 70
E-mail: [email protected]
Website: www.topicproducts.com

Please consider the environment before printing this e-mail

#2 lore raw

Hi,

Quoted 2 lines · Mike Looijmans

Just a "ping" reminder, I'd like to inquire about the status of this patch...

in my testing/next

Signature · 1 line
balbi