Skip to content

Commit 75f82a7

Browse files
mrkikogregkh
authored andcommitted
cdc_ncm: Set NTB format again after altsetting switch for Huawei devices
commit 2b02c20ce0c28974b44e69a2e2f5ddc6a470ad6f upstream. Some firmwares in Huawei E3372H devices have been observed to switch back to NTB 32-bit format after altsetting switch. This patch implements a driver flag to check for the device settings and set NTB format to 16-bit again if needed. The flag has been activated for devices controlled by the huawei_cdc_ncm.c driver. V1->V2: - fixed broken error checks - some corrections to the commit message V2->V3: - variable name changes, to clarify what's happening - check (and possibly set) the NTB format later in the common bind code path Signed-off-by: Enrico Mioso <mrkiko.rs@gmail.com> Reported-and-tested-by: Christian Panton <christian@panton.org> Reviewed-by: Bjørn Mork <bjorn@mork.no> CC: Bjørn Mork <bjorn@mork.no> CC: Christian Panton <christian@panton.org> CC: linux-usb@vger.kernel.org CC: netdev@vger.kernel.org CC: Oliver Neukum <oliver@neukum.org> Signed-off-by: David S. Miller <davem@davemloft.net> Cc: Porto Rio <porto.rio@gmx.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5ffc673 commit 75f82a7

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

drivers/net/usb/cdc_ncm.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,10 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
724724
u8 *buf;
725725
int len;
726726
int temp;
727+
int err;
727728
u8 iface_no;
728729
struct usb_cdc_parsed_header hdr;
730+
u16 curr_ntb_format;
729731

730732
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
731733
if (!ctx)
@@ -823,6 +825,32 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
823825
goto error2;
824826
}
825827

828+
/*
829+
* Some Huawei devices have been observed to come out of reset in NDP32 mode.
830+
* Let's check if this is the case, and set the device to NDP16 mode again if
831+
* needed.
832+
*/
833+
if (ctx->drvflags & CDC_NCM_FLAG_RESET_NTB16) {
834+
err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_FORMAT,
835+
USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE,
836+
0, iface_no, &curr_ntb_format, 2);
837+
if (err < 0) {
838+
goto error2;
839+
}
840+
841+
if (curr_ntb_format == USB_CDC_NCM_NTB32_FORMAT) {
842+
dev_info(&intf->dev, "resetting NTB format to 16-bit");
843+
err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_FORMAT,
844+
USB_TYPE_CLASS | USB_DIR_OUT
845+
| USB_RECIP_INTERFACE,
846+
USB_CDC_NCM_NTB16_FORMAT,
847+
iface_no, NULL, 0);
848+
849+
if (err < 0)
850+
goto error2;
851+
}
852+
}
853+
826854
cdc_ncm_find_endpoints(dev, ctx->data);
827855
cdc_ncm_find_endpoints(dev, ctx->control);
828856
if (!dev->in || !dev->out || !dev->status) {

drivers/net/usb/huawei_cdc_ncm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ static int huawei_cdc_ncm_bind(struct usbnet *usbnet_dev,
8080
* be at the end of the frame.
8181
*/
8282
drvflags |= CDC_NCM_FLAG_NDP_TO_END;
83+
84+
/* Additionally, it has been reported that some Huawei E3372H devices, with
85+
* firmware version 21.318.01.00.541, come out of reset in NTB32 format mode, hence
86+
* needing to be set to the NTB16 one again.
87+
*/
88+
drvflags |= CDC_NCM_FLAG_RESET_NTB16;
8389
ret = cdc_ncm_bind_common(usbnet_dev, intf, 1, drvflags);
8490
if (ret)
8591
goto err;

include/linux/usb/cdc_ncm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383
/* Driver flags */
8484
#define CDC_NCM_FLAG_NDP_TO_END 0x02 /* NDP is placed at end of frame */
85+
#define CDC_NCM_FLAG_RESET_NTB16 0x08 /* set NDP16 one more time after altsetting switch */
8586

8687
#define cdc_ncm_comm_intf_is_mbim(x) ((x)->desc.bInterfaceSubClass == USB_CDC_SUBCLASS_MBIM && \
8788
(x)->desc.bInterfaceProtocol == USB_CDC_PROTO_NONE)

0 commit comments

Comments
 (0)