Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[sfrench/cifs-2.6.git] / drivers / net / usb / cdc_ncm.c
index b401ba9e6ddccdd3a10b3cbd5a59956aff4c7949..811b18215cae1f3f6636d15050d5e76ea5be441f 100644 (file)
@@ -768,8 +768,10 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
        u8 *buf;
        int len;
        int temp;
+       int err;
        u8 iface_no;
        struct usb_cdc_parsed_header hdr;
+       u16 curr_ntb_format;
 
        ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
        if (!ctx)
@@ -874,6 +876,32 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
                goto error2;
        }
 
+       /*
+        * Some Huawei devices have been observed to come out of reset in NDP32 mode.
+        * Let's check if this is the case, and set the device to NDP16 mode again if
+        * needed.
+       */
+       if (ctx->drvflags & CDC_NCM_FLAG_RESET_NTB16) {
+               err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_FORMAT,
+                                     USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE,
+                                     0, iface_no, &curr_ntb_format, 2);
+               if (err < 0) {
+                       goto error2;
+               }
+
+               if (curr_ntb_format == USB_CDC_NCM_NTB32_FORMAT) {
+                       dev_info(&intf->dev, "resetting NTB format to 16-bit");
+                       err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_FORMAT,
+                                              USB_TYPE_CLASS | USB_DIR_OUT
+                                              | USB_RECIP_INTERFACE,
+                                              USB_CDC_NCM_NTB16_FORMAT,
+                                              iface_no, NULL, 0);
+
+                       if (err < 0)
+                               goto error2;
+               }
+       }
+
        cdc_ncm_find_endpoints(dev, ctx->data);
        cdc_ncm_find_endpoints(dev, ctx->control);
        if (!dev->in || !dev->out || !dev->status) {