Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: ehci tolerates some buggy devices

This teaches EHCI how to to work around bugs in certain high speed
devices, by accomodating "bulk" packets that exceed the 512 byte
constant value required by the USB 2.0 specification. (Have a
look at section 5.8.3, paragraphs 1 and 3.)

It also makes the descriptor parsing code warn when it encounters
such bugs. (We've had reports of maybe two or three such devices,
all pretty recent.)

Such devices are nonconformant. The proper fix is have the vendors
of those devices do the simple, obvious, and correct thing ... which
will let them be used with USB hosts that don't have workarounds for
this particular vendor bug. But unless/until they do, we can at least
have one of the high speed HCDs work with such buggy devices.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

David Brownell and committed by
Greg Kroah-Hartman
caa9ef67 e01e7fe3

+32 -1
+17
drivers/usb/core/config.c
··· 145 145 endpoint->desc.wMaxPacketSize = cpu_to_le16(8); 146 146 } 147 147 148 + /* 149 + * Some buggy high speed devices have bulk endpoints using 150 + * maxpacket sizes other than 512. High speed HCDs may not 151 + * be able to handle that particular bug, so let's warn... 152 + */ 153 + if (to_usb_device(ddev)->speed == USB_SPEED_HIGH 154 + && usb_endpoint_xfer_bulk(d)) { 155 + unsigned maxp; 156 + 157 + maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize) & 0x07ff; 158 + if (maxp != 512) 159 + dev_warn(ddev, "config %d interface %d altsetting %d " 160 + "bulk endpoint 0x%X has invalid maxpacket %d\n", 161 + cfgno, inum, asnum, d->bEndpointAddress, 162 + maxp); 163 + } 164 + 148 165 /* Skip over any Class Specific or Vendor Specific descriptors; 149 166 * find the next endpoint or interface descriptor */ 150 167 endpoint->extra = buffer;
+15 -1
drivers/usb/host/ehci-q.c
··· 657 657 type = usb_pipetype (urb->pipe); 658 658 maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input); 659 659 660 + /* 1024 byte maxpacket is a hardware ceiling. High bandwidth 661 + * acts like up to 3KB, but is built from smaller packets. 662 + */ 663 + if (max_packet(maxp) > 1024) { 664 + ehci_dbg(ehci, "bogus qh maxpacket %d\n", max_packet(maxp)); 665 + goto done; 666 + } 667 + 660 668 /* Compute interrupt scheduling parameters just once, and save. 661 669 * - allowing for high bandwidth, how many nsec/uframe are used? 662 670 * - split transactions need a second CSPLIT uframe; same question ··· 765 757 info2 |= (EHCI_TUNE_MULT_HS << 30); 766 758 } else if (type == PIPE_BULK) { 767 759 info1 |= (EHCI_TUNE_RL_HS << 28); 768 - info1 |= 512 << 16; /* usb2 fixed maxpacket */ 760 + /* The USB spec says that high speed bulk endpoints 761 + * always use 512 byte maxpacket. But some device 762 + * vendors decided to ignore that, and MSFT is happy 763 + * to help them do so. So now people expect to use 764 + * such nonconformant devices with Linux too; sigh. 765 + */ 766 + info1 |= max_packet(maxp) << 16; 769 767 info2 |= (EHCI_TUNE_MULT_HS << 30); 770 768 } else { /* PIPE_INTERRUPT */ 771 769 info1 |= max_packet (maxp) << 16;