net: cdc_ncm: respect operator preferred MTU reported by MBIM
authorBen Chan <benchan@chromium.org>
Wed, 19 Mar 2014 21:00:06 +0000 (14:00 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 20 Mar 2014 20:57:35 +0000 (16:57 -0400)
According to "Universal Serial Bus Communications Class Subclass
Specification for Mobile Broadband Interface Model, Revision 1.0,
Errata-1" published by USB-IF, the wMTU field of the MBIM extended
functional descriptor indicates the operator preferred MTU for IP data
streams.

This patch modifies cdc_ncm_setup to ensure that the MTU value set on
the usbnet device does not exceed the operator preferred MTU indicated
by wMTU if the MBIM device exposes a MBIM extended functional
descriptor.

Signed-off-by: Ben Chan <benchan@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/usb/cdc_ncm.c
include/linux/usb/cdc_ncm.h

index dbff290ed0e4f5ac4752efbe56eeea0fda0c419f..e8711a8cfa0187a6866436779743d7293ebc924e 100644 (file)
@@ -74,6 +74,7 @@ static int cdc_ncm_setup(struct usbnet *dev)
        u8 iface_no;
        int err;
        int eth_hlen;
+       u16 mbim_mtu;
        u16 ntb_fmt_supported;
        __le16 max_datagram_size;
 
@@ -261,6 +262,14 @@ out:
        /* set MTU to max supported by the device if necessary */
        if (dev->net->mtu > ctx->max_datagram_size - eth_hlen)
                dev->net->mtu = ctx->max_datagram_size - eth_hlen;
+
+       /* do not exceed operater preferred MTU */
+       if (ctx->mbim_extended_desc) {
+               mbim_mtu = le16_to_cpu(ctx->mbim_extended_desc->wMTU);
+               if (mbim_mtu != 0 && mbim_mtu < dev->net->mtu)
+                       dev->net->mtu = mbim_mtu;
+       }
+
        return 0;
 }
 
@@ -399,6 +408,14 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
                        ctx->mbim_desc = (const struct usb_cdc_mbim_desc *)buf;
                        break;
 
+               case USB_CDC_MBIM_EXTENDED_TYPE:
+                       if (buf[0] < sizeof(*(ctx->mbim_extended_desc)))
+                               break;
+
+                       ctx->mbim_extended_desc =
+                               (const struct usb_cdc_mbim_extended_desc *)buf;
+                       break;
+
                default:
                        break;
                }
index c3fa807459967286c0407c18da294ca6d95ced42..bdf05fb3672944d322f3ccbf35d122162ffeb55d 100644 (file)
@@ -93,6 +93,7 @@ struct cdc_ncm_ctx {
 
        const struct usb_cdc_ncm_desc *func_desc;
        const struct usb_cdc_mbim_desc *mbim_desc;
+       const struct usb_cdc_mbim_extended_desc *mbim_extended_desc;
        const struct usb_cdc_ether_desc *ether_desc;
 
        struct usb_interface *control;