| .. | .. |
|---|
| 42 | 42 | #define USB_PRODUCT_USB5534B 0x5534 |
|---|
| 43 | 43 | #define USB_VENDOR_CYPRESS 0x04b4 |
|---|
| 44 | 44 | #define USB_PRODUCT_CY7C65632 0x6570 |
|---|
| 45 | +#define USB_VENDOR_TEXAS_INSTRUMENTS 0x0451 |
|---|
| 46 | +#define USB_PRODUCT_TUSB8041_USB3 0x8140 |
|---|
| 47 | +#define USB_PRODUCT_TUSB8041_USB2 0x8142 |
|---|
| 45 | 48 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 |
|---|
| 46 | 49 | #define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02 |
|---|
| 47 | 50 | |
|---|
| .. | .. |
|---|
| 2378 | 2381 | * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal) |
|---|
| 2379 | 2382 | * @udev: newly addressed device (in ADDRESS state) |
|---|
| 2380 | 2383 | * |
|---|
| 2381 | | - * This is only called by usb_new_device() and usb_authorize_device() |
|---|
| 2382 | | - * and FIXME -- all comments that apply to them apply here wrt to |
|---|
| 2383 | | - * environment. |
|---|
| 2384 | + * This is only called by usb_new_device() -- all comments that apply there |
|---|
| 2385 | + * apply here wrt to environment. |
|---|
| 2384 | 2386 | * |
|---|
| 2385 | 2387 | * If the device is WUSB and not authorized, we don't attempt to read |
|---|
| 2386 | 2388 | * the string descriptors, as they will be errored out by the device |
|---|
| .. | .. |
|---|
| 2645 | 2647 | } |
|---|
| 2646 | 2648 | |
|---|
| 2647 | 2649 | if (usb_dev->wusb) { |
|---|
| 2648 | | - result = usb_get_device_descriptor(usb_dev, sizeof(usb_dev->descriptor)); |
|---|
| 2649 | | - if (result < 0) { |
|---|
| 2650 | + struct usb_device_descriptor *descr; |
|---|
| 2651 | + |
|---|
| 2652 | + descr = usb_get_device_descriptor(usb_dev); |
|---|
| 2653 | + if (IS_ERR(descr)) { |
|---|
| 2654 | + result = PTR_ERR(descr); |
|---|
| 2650 | 2655 | dev_err(&usb_dev->dev, "can't re-read device descriptor for " |
|---|
| 2651 | 2656 | "authorization: %d\n", result); |
|---|
| 2652 | 2657 | goto error_device_descriptor; |
|---|
| 2653 | 2658 | } |
|---|
| 2659 | + usb_dev->descriptor = *descr; |
|---|
| 2660 | + kfree(descr); |
|---|
| 2654 | 2661 | } |
|---|
| 2655 | 2662 | |
|---|
| 2656 | 2663 | usb_dev->authorized = 1; |
|---|
| .. | .. |
|---|
| 4593 | 4600 | return hcd->driver->enable_device(hcd, udev); |
|---|
| 4594 | 4601 | } |
|---|
| 4595 | 4602 | |
|---|
| 4603 | +/* |
|---|
| 4604 | + * Get the bMaxPacketSize0 value during initialization by reading the |
|---|
| 4605 | + * device's device descriptor. Since we don't already know this value, |
|---|
| 4606 | + * the transfer is unsafe and it ignores I/O errors, only testing for |
|---|
| 4607 | + * reasonable received values. |
|---|
| 4608 | + * |
|---|
| 4609 | + * For "old scheme" initialization, size will be 8 so we read just the |
|---|
| 4610 | + * start of the device descriptor, which should work okay regardless of |
|---|
| 4611 | + * the actual bMaxPacketSize0 value. For "new scheme" initialization, |
|---|
| 4612 | + * size will be 64 (and buf will point to a sufficiently large buffer), |
|---|
| 4613 | + * which might not be kosher according to the USB spec but it's what |
|---|
| 4614 | + * Windows does and what many devices expect. |
|---|
| 4615 | + * |
|---|
| 4616 | + * Returns: bMaxPacketSize0 or a negative error code. |
|---|
| 4617 | + */ |
|---|
| 4618 | +static int get_bMaxPacketSize0(struct usb_device *udev, |
|---|
| 4619 | + struct usb_device_descriptor *buf, int size, bool first_time) |
|---|
| 4620 | +{ |
|---|
| 4621 | + int i, rc; |
|---|
| 4622 | + |
|---|
| 4623 | + /* |
|---|
| 4624 | + * Retry on all errors; some devices are flakey. |
|---|
| 4625 | + * 255 is for WUSB devices, we actually need to use |
|---|
| 4626 | + * 512 (WUSB1.0[4.8.1]). |
|---|
| 4627 | + */ |
|---|
| 4628 | + for (i = 0; i < GET_MAXPACKET0_TRIES; ++i) { |
|---|
| 4629 | + /* Start with invalid values in case the transfer fails */ |
|---|
| 4630 | + buf->bDescriptorType = buf->bMaxPacketSize0 = 0; |
|---|
| 4631 | + rc = usb_control_msg(udev, usb_rcvaddr0pipe(), |
|---|
| 4632 | + USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, |
|---|
| 4633 | + USB_DT_DEVICE << 8, 0, |
|---|
| 4634 | + buf, size, |
|---|
| 4635 | + initial_descriptor_timeout); |
|---|
| 4636 | + switch (buf->bMaxPacketSize0) { |
|---|
| 4637 | + case 8: case 16: case 32: case 64: case 9: |
|---|
| 4638 | + if (buf->bDescriptorType == USB_DT_DEVICE) { |
|---|
| 4639 | + rc = buf->bMaxPacketSize0; |
|---|
| 4640 | + break; |
|---|
| 4641 | + } |
|---|
| 4642 | + fallthrough; |
|---|
| 4643 | + default: |
|---|
| 4644 | + if (rc >= 0) |
|---|
| 4645 | + rc = -EPROTO; |
|---|
| 4646 | + break; |
|---|
| 4647 | + } |
|---|
| 4648 | + |
|---|
| 4649 | + /* |
|---|
| 4650 | + * Some devices time out if they are powered on |
|---|
| 4651 | + * when already connected. They need a second |
|---|
| 4652 | + * reset, so return early. But only on the first |
|---|
| 4653 | + * attempt, lest we get into a time-out/reset loop. |
|---|
| 4654 | + */ |
|---|
| 4655 | + if (rc > 0 || (rc == -ETIMEDOUT && first_time && |
|---|
| 4656 | + udev->speed > USB_SPEED_FULL)) |
|---|
| 4657 | + break; |
|---|
| 4658 | + } |
|---|
| 4659 | + return rc; |
|---|
| 4660 | +} |
|---|
| 4661 | + |
|---|
| 4662 | +#define GET_DESCRIPTOR_BUFSIZE 64 |
|---|
| 4663 | + |
|---|
| 4596 | 4664 | /* Reset device, (re)assign address, get device descriptor. |
|---|
| 4597 | 4665 | * Device connection must be stable, no more debouncing needed. |
|---|
| 4598 | 4666 | * Returns device in USB_STATE_ADDRESS, except on error. |
|---|
| .. | .. |
|---|
| 4602 | 4670 | * the port lock. For a newly detected device that is not accessible |
|---|
| 4603 | 4671 | * through any global pointers, it's not necessary to lock the device, |
|---|
| 4604 | 4672 | * but it is still necessary to lock the port. |
|---|
| 4673 | + * |
|---|
| 4674 | + * For a newly detected device, @dev_descr must be NULL. The device |
|---|
| 4675 | + * descriptor retrieved from the device will then be stored in |
|---|
| 4676 | + * @udev->descriptor. For an already existing device, @dev_descr |
|---|
| 4677 | + * must be non-NULL. The device descriptor will be stored there, |
|---|
| 4678 | + * not in @udev->descriptor, because descriptors for registered |
|---|
| 4679 | + * devices are meant to be immutable. |
|---|
| 4605 | 4680 | */ |
|---|
| 4606 | 4681 | static int |
|---|
| 4607 | 4682 | hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, |
|---|
| 4608 | | - int retry_counter) |
|---|
| 4683 | + int retry_counter, struct usb_device_descriptor *dev_descr) |
|---|
| 4609 | 4684 | { |
|---|
| 4610 | 4685 | struct usb_device *hdev = hub->hdev; |
|---|
| 4611 | 4686 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); |
|---|
| .. | .. |
|---|
| 4617 | 4692 | int devnum = udev->devnum; |
|---|
| 4618 | 4693 | const char *driver_name; |
|---|
| 4619 | 4694 | bool do_new_scheme; |
|---|
| 4695 | + const bool initial = !dev_descr; |
|---|
| 4696 | + int maxp0; |
|---|
| 4697 | + struct usb_device_descriptor *buf, *descr; |
|---|
| 4698 | + |
|---|
| 4699 | + buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO); |
|---|
| 4700 | + if (!buf) |
|---|
| 4701 | + return -ENOMEM; |
|---|
| 4620 | 4702 | |
|---|
| 4621 | 4703 | /* root hub ports have a slightly longer reset period |
|---|
| 4622 | 4704 | * (from USB 2.0 spec, section 7.1.7.5) |
|---|
| .. | .. |
|---|
| 4649 | 4731 | } |
|---|
| 4650 | 4732 | oldspeed = udev->speed; |
|---|
| 4651 | 4733 | |
|---|
| 4652 | | - /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... |
|---|
| 4653 | | - * it's fixed size except for full speed devices. |
|---|
| 4654 | | - * For Wireless USB devices, ep0 max packet is always 512 (tho |
|---|
| 4655 | | - * reported as 0xff in the device descriptor). WUSB1.0[4.8.1]. |
|---|
| 4656 | | - */ |
|---|
| 4657 | | - switch (udev->speed) { |
|---|
| 4658 | | - case USB_SPEED_SUPER_PLUS: |
|---|
| 4659 | | - case USB_SPEED_SUPER: |
|---|
| 4660 | | - case USB_SPEED_WIRELESS: /* fixed at 512 */ |
|---|
| 4661 | | - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); |
|---|
| 4662 | | - break; |
|---|
| 4663 | | - case USB_SPEED_HIGH: /* fixed at 64 */ |
|---|
| 4664 | | - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); |
|---|
| 4665 | | - break; |
|---|
| 4666 | | - case USB_SPEED_FULL: /* 8, 16, 32, or 64 */ |
|---|
| 4667 | | - /* to determine the ep0 maxpacket size, try to read |
|---|
| 4668 | | - * the device descriptor to get bMaxPacketSize0 and |
|---|
| 4669 | | - * then correct our initial guess. |
|---|
| 4734 | + if (initial) { |
|---|
| 4735 | + /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ... |
|---|
| 4736 | + * it's fixed size except for full speed devices. |
|---|
| 4737 | + * For Wireless USB devices, ep0 max packet is always 512 (tho |
|---|
| 4738 | + * reported as 0xff in the device descriptor). WUSB1.0[4.8.1]. |
|---|
| 4670 | 4739 | */ |
|---|
| 4671 | | - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); |
|---|
| 4672 | | - break; |
|---|
| 4673 | | - case USB_SPEED_LOW: /* fixed at 8 */ |
|---|
| 4674 | | - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); |
|---|
| 4675 | | - break; |
|---|
| 4676 | | - default: |
|---|
| 4677 | | - goto fail; |
|---|
| 4740 | + switch (udev->speed) { |
|---|
| 4741 | + case USB_SPEED_SUPER_PLUS: |
|---|
| 4742 | + case USB_SPEED_SUPER: |
|---|
| 4743 | + case USB_SPEED_WIRELESS: /* fixed at 512 */ |
|---|
| 4744 | + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); |
|---|
| 4745 | + break; |
|---|
| 4746 | + case USB_SPEED_HIGH: /* fixed at 64 */ |
|---|
| 4747 | + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); |
|---|
| 4748 | + break; |
|---|
| 4749 | + case USB_SPEED_FULL: /* 8, 16, 32, or 64 */ |
|---|
| 4750 | + /* to determine the ep0 maxpacket size, try to read |
|---|
| 4751 | + * the device descriptor to get bMaxPacketSize0 and |
|---|
| 4752 | + * then correct our initial guess. |
|---|
| 4753 | + */ |
|---|
| 4754 | + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); |
|---|
| 4755 | + break; |
|---|
| 4756 | + case USB_SPEED_LOW: /* fixed at 8 */ |
|---|
| 4757 | + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8); |
|---|
| 4758 | + break; |
|---|
| 4759 | + default: |
|---|
| 4760 | + goto fail; |
|---|
| 4761 | + } |
|---|
| 4678 | 4762 | } |
|---|
| 4679 | 4763 | |
|---|
| 4680 | 4764 | if (udev->speed == USB_SPEED_WIRELESS) |
|---|
| .. | .. |
|---|
| 4697 | 4781 | if (udev->speed < USB_SPEED_SUPER) |
|---|
| 4698 | 4782 | dev_info(&udev->dev, |
|---|
| 4699 | 4783 | "%s %s USB device number %d using %s\n", |
|---|
| 4700 | | - (udev->config) ? "reset" : "new", speed, |
|---|
| 4784 | + (initial ? "new" : "reset"), speed, |
|---|
| 4701 | 4785 | devnum, driver_name); |
|---|
| 4702 | 4786 | |
|---|
| 4703 | | - /* Set up TT records, if needed */ |
|---|
| 4704 | | - if (hdev->tt) { |
|---|
| 4705 | | - udev->tt = hdev->tt; |
|---|
| 4706 | | - udev->ttport = hdev->ttport; |
|---|
| 4707 | | - } else if (udev->speed != USB_SPEED_HIGH |
|---|
| 4708 | | - && hdev->speed == USB_SPEED_HIGH) { |
|---|
| 4709 | | - if (!hub->tt.hub) { |
|---|
| 4710 | | - dev_err(&udev->dev, "parent hub has no TT\n"); |
|---|
| 4711 | | - retval = -EINVAL; |
|---|
| 4712 | | - goto fail; |
|---|
| 4787 | + if (initial) { |
|---|
| 4788 | + /* Set up TT records, if needed */ |
|---|
| 4789 | + if (hdev->tt) { |
|---|
| 4790 | + udev->tt = hdev->tt; |
|---|
| 4791 | + udev->ttport = hdev->ttport; |
|---|
| 4792 | + } else if (udev->speed != USB_SPEED_HIGH |
|---|
| 4793 | + && hdev->speed == USB_SPEED_HIGH) { |
|---|
| 4794 | + if (!hub->tt.hub) { |
|---|
| 4795 | + dev_err(&udev->dev, "parent hub has no TT\n"); |
|---|
| 4796 | + retval = -EINVAL; |
|---|
| 4797 | + goto fail; |
|---|
| 4798 | + } |
|---|
| 4799 | + udev->tt = &hub->tt; |
|---|
| 4800 | + udev->ttport = port1; |
|---|
| 4713 | 4801 | } |
|---|
| 4714 | | - udev->tt = &hub->tt; |
|---|
| 4715 | | - udev->ttport = port1; |
|---|
| 4716 | 4802 | } |
|---|
| 4717 | 4803 | |
|---|
| 4718 | 4804 | /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way? |
|---|
| .. | .. |
|---|
| 4731 | 4817 | |
|---|
| 4732 | 4818 | for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) { |
|---|
| 4733 | 4819 | if (do_new_scheme) { |
|---|
| 4734 | | - struct usb_device_descriptor *buf; |
|---|
| 4735 | | - int r = 0; |
|---|
| 4736 | | - |
|---|
| 4737 | 4820 | retval = hub_enable_device(udev); |
|---|
| 4738 | 4821 | if (retval < 0) { |
|---|
| 4739 | 4822 | dev_err(&udev->dev, |
|---|
| .. | .. |
|---|
| 4742 | 4825 | goto fail; |
|---|
| 4743 | 4826 | } |
|---|
| 4744 | 4827 | |
|---|
| 4745 | | -#define GET_DESCRIPTOR_BUFSIZE 64 |
|---|
| 4746 | | - buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO); |
|---|
| 4747 | | - if (!buf) { |
|---|
| 4748 | | - retval = -ENOMEM; |
|---|
| 4749 | | - continue; |
|---|
| 4828 | + maxp0 = get_bMaxPacketSize0(udev, buf, |
|---|
| 4829 | + GET_DESCRIPTOR_BUFSIZE, retries == 0); |
|---|
| 4830 | + if (maxp0 > 0 && !initial && |
|---|
| 4831 | + maxp0 != udev->descriptor.bMaxPacketSize0) { |
|---|
| 4832 | + dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); |
|---|
| 4833 | + retval = -ENODEV; |
|---|
| 4834 | + goto fail; |
|---|
| 4750 | 4835 | } |
|---|
| 4751 | | - |
|---|
| 4752 | | - /* Retry on all errors; some devices are flakey. |
|---|
| 4753 | | - * 255 is for WUSB devices, we actually need to use |
|---|
| 4754 | | - * 512 (WUSB1.0[4.8.1]). |
|---|
| 4755 | | - */ |
|---|
| 4756 | | - for (operations = 0; operations < GET_MAXPACKET0_TRIES; |
|---|
| 4757 | | - ++operations) { |
|---|
| 4758 | | - buf->bMaxPacketSize0 = 0; |
|---|
| 4759 | | - r = usb_control_msg(udev, usb_rcvaddr0pipe(), |
|---|
| 4760 | | - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, |
|---|
| 4761 | | - USB_DT_DEVICE << 8, 0, |
|---|
| 4762 | | - buf, GET_DESCRIPTOR_BUFSIZE, |
|---|
| 4763 | | - initial_descriptor_timeout); |
|---|
| 4764 | | - switch (buf->bMaxPacketSize0) { |
|---|
| 4765 | | - case 8: case 16: case 32: case 64: case 255: |
|---|
| 4766 | | - if (buf->bDescriptorType == |
|---|
| 4767 | | - USB_DT_DEVICE) { |
|---|
| 4768 | | - r = 0; |
|---|
| 4769 | | - break; |
|---|
| 4770 | | - } |
|---|
| 4771 | | - fallthrough; |
|---|
| 4772 | | - default: |
|---|
| 4773 | | - if (r == 0) |
|---|
| 4774 | | - r = -EPROTO; |
|---|
| 4775 | | - break; |
|---|
| 4776 | | - } |
|---|
| 4777 | | - /* |
|---|
| 4778 | | - * Some devices time out if they are powered on |
|---|
| 4779 | | - * when already connected. They need a second |
|---|
| 4780 | | - * reset. But only on the first attempt, |
|---|
| 4781 | | - * lest we get into a time out/reset loop |
|---|
| 4782 | | - */ |
|---|
| 4783 | | - if (r == 0 || (r == -ETIMEDOUT && |
|---|
| 4784 | | - retries == 0 && |
|---|
| 4785 | | - udev->speed > USB_SPEED_FULL)) |
|---|
| 4786 | | - break; |
|---|
| 4787 | | - } |
|---|
| 4788 | | - udev->descriptor.bMaxPacketSize0 = |
|---|
| 4789 | | - buf->bMaxPacketSize0; |
|---|
| 4790 | | - kfree(buf); |
|---|
| 4791 | 4836 | |
|---|
| 4792 | 4837 | retval = hub_port_reset(hub, port1, udev, delay, false); |
|---|
| 4793 | 4838 | if (retval < 0) /* error or disconnect */ |
|---|
| .. | .. |
|---|
| 4798 | 4843 | retval = -ENODEV; |
|---|
| 4799 | 4844 | goto fail; |
|---|
| 4800 | 4845 | } |
|---|
| 4801 | | - if (r) { |
|---|
| 4802 | | - if (r != -ENODEV) |
|---|
| 4846 | + if (maxp0 < 0) { |
|---|
| 4847 | + if (maxp0 != -ENODEV) |
|---|
| 4803 | 4848 | dev_err(&udev->dev, "device descriptor read/64, error %d\n", |
|---|
| 4804 | | - r); |
|---|
| 4805 | | - retval = -EMSGSIZE; |
|---|
| 4849 | + maxp0); |
|---|
| 4850 | + retval = maxp0; |
|---|
| 4806 | 4851 | continue; |
|---|
| 4807 | 4852 | } |
|---|
| 4808 | | -#undef GET_DESCRIPTOR_BUFSIZE |
|---|
| 4809 | 4853 | } |
|---|
| 4810 | 4854 | |
|---|
| 4811 | 4855 | /* |
|---|
| .. | .. |
|---|
| 4847 | 4891 | break; |
|---|
| 4848 | 4892 | } |
|---|
| 4849 | 4893 | |
|---|
| 4850 | | - retval = usb_get_device_descriptor(udev, 8); |
|---|
| 4851 | | - if (retval < 8) { |
|---|
| 4894 | + /* !do_new_scheme || wusb */ |
|---|
| 4895 | + maxp0 = get_bMaxPacketSize0(udev, buf, 8, retries == 0); |
|---|
| 4896 | + if (maxp0 < 0) { |
|---|
| 4897 | + retval = maxp0; |
|---|
| 4852 | 4898 | if (retval != -ENODEV) |
|---|
| 4853 | 4899 | dev_err(&udev->dev, |
|---|
| 4854 | 4900 | "device descriptor read/8, error %d\n", |
|---|
| 4855 | 4901 | retval); |
|---|
| 4856 | | - if (retval >= 0) |
|---|
| 4857 | | - retval = -EMSGSIZE; |
|---|
| 4858 | 4902 | } else { |
|---|
| 4859 | 4903 | u32 delay; |
|---|
| 4860 | 4904 | |
|---|
| 4861 | | - retval = 0; |
|---|
| 4905 | + if (!initial && maxp0 != udev->descriptor.bMaxPacketSize0) { |
|---|
| 4906 | + dev_err(&udev->dev, "device reset changed ep0 maxpacket size!\n"); |
|---|
| 4907 | + retval = -ENODEV; |
|---|
| 4908 | + goto fail; |
|---|
| 4909 | + } |
|---|
| 4862 | 4910 | |
|---|
| 4863 | 4911 | delay = udev->parent->hub_delay; |
|---|
| 4864 | 4912 | udev->hub_delay = min_t(u32, delay, |
|---|
| .. | .. |
|---|
| 4877 | 4925 | goto fail; |
|---|
| 4878 | 4926 | |
|---|
| 4879 | 4927 | /* |
|---|
| 4928 | + * Check the ep0 maxpacket guess and correct it if necessary. |
|---|
| 4929 | + * maxp0 is the value stored in the device descriptor; |
|---|
| 4930 | + * i is the value it encodes (logarithmic for SuperSpeed or greater). |
|---|
| 4931 | + */ |
|---|
| 4932 | + i = maxp0; |
|---|
| 4933 | + if (udev->speed >= USB_SPEED_SUPER) { |
|---|
| 4934 | + if (maxp0 <= 16) |
|---|
| 4935 | + i = 1 << maxp0; |
|---|
| 4936 | + else |
|---|
| 4937 | + i = 0; /* Invalid */ |
|---|
| 4938 | + } |
|---|
| 4939 | + if (usb_endpoint_maxp(&udev->ep0.desc) == i) { |
|---|
| 4940 | + ; /* Initial ep0 maxpacket guess is right */ |
|---|
| 4941 | + } else if ((udev->speed == USB_SPEED_FULL || |
|---|
| 4942 | + udev->speed == USB_SPEED_HIGH) && |
|---|
| 4943 | + (i == 8 || i == 16 || i == 32 || i == 64)) { |
|---|
| 4944 | + /* Initial guess is wrong; use the descriptor's value */ |
|---|
| 4945 | + if (udev->speed == USB_SPEED_FULL) |
|---|
| 4946 | + dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); |
|---|
| 4947 | + else |
|---|
| 4948 | + dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); |
|---|
| 4949 | + udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); |
|---|
| 4950 | + usb_ep0_reinit(udev); |
|---|
| 4951 | + } else { |
|---|
| 4952 | + /* Initial guess is wrong and descriptor's value is invalid */ |
|---|
| 4953 | + dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", maxp0); |
|---|
| 4954 | + retval = -EMSGSIZE; |
|---|
| 4955 | + goto fail; |
|---|
| 4956 | + } |
|---|
| 4957 | + |
|---|
| 4958 | + descr = usb_get_device_descriptor(udev); |
|---|
| 4959 | + if (IS_ERR(descr)) { |
|---|
| 4960 | + retval = PTR_ERR(descr); |
|---|
| 4961 | + if (retval != -ENODEV) |
|---|
| 4962 | + dev_err(&udev->dev, "device descriptor read/all, error %d\n", |
|---|
| 4963 | + retval); |
|---|
| 4964 | + goto fail; |
|---|
| 4965 | + } |
|---|
| 4966 | + if (initial) |
|---|
| 4967 | + udev->descriptor = *descr; |
|---|
| 4968 | + else |
|---|
| 4969 | + *dev_descr = *descr; |
|---|
| 4970 | + kfree(descr); |
|---|
| 4971 | + |
|---|
| 4972 | + /* |
|---|
| 4880 | 4973 | * Some superspeed devices have finished the link training process |
|---|
| 4881 | 4974 | * and attached to a superspeed hub port, but the device descriptor |
|---|
| 4882 | 4975 | * got from those devices show they aren't superspeed devices. Warm |
|---|
| .. | .. |
|---|
| 4884 | 4977 | */ |
|---|
| 4885 | 4978 | if ((udev->speed >= USB_SPEED_SUPER) && |
|---|
| 4886 | 4979 | (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) { |
|---|
| 4887 | | - dev_err(&udev->dev, "got a wrong device descriptor, " |
|---|
| 4888 | | - "warm reset device\n"); |
|---|
| 4889 | | - hub_port_reset(hub, port1, udev, |
|---|
| 4890 | | - HUB_BH_RESET_TIME, true); |
|---|
| 4980 | + dev_err(&udev->dev, "got a wrong device descriptor, warm reset device\n"); |
|---|
| 4981 | + hub_port_reset(hub, port1, udev, HUB_BH_RESET_TIME, true); |
|---|
| 4891 | 4982 | retval = -EINVAL; |
|---|
| 4892 | | - goto fail; |
|---|
| 4893 | | - } |
|---|
| 4894 | | - |
|---|
| 4895 | | - if (udev->descriptor.bMaxPacketSize0 == 0xff || |
|---|
| 4896 | | - udev->speed >= USB_SPEED_SUPER) |
|---|
| 4897 | | - i = 512; |
|---|
| 4898 | | - else |
|---|
| 4899 | | - i = udev->descriptor.bMaxPacketSize0; |
|---|
| 4900 | | - if (usb_endpoint_maxp(&udev->ep0.desc) != i) { |
|---|
| 4901 | | - if (udev->speed == USB_SPEED_LOW || |
|---|
| 4902 | | - !(i == 8 || i == 16 || i == 32 || i == 64)) { |
|---|
| 4903 | | - dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i); |
|---|
| 4904 | | - retval = -EMSGSIZE; |
|---|
| 4905 | | - goto fail; |
|---|
| 4906 | | - } |
|---|
| 4907 | | - if (udev->speed == USB_SPEED_FULL) |
|---|
| 4908 | | - dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i); |
|---|
| 4909 | | - else |
|---|
| 4910 | | - dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i); |
|---|
| 4911 | | - udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); |
|---|
| 4912 | | - usb_ep0_reinit(udev); |
|---|
| 4913 | | - } |
|---|
| 4914 | | - |
|---|
| 4915 | | - retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); |
|---|
| 4916 | | - if (retval < (signed)sizeof(udev->descriptor)) { |
|---|
| 4917 | | - if (retval != -ENODEV) |
|---|
| 4918 | | - dev_err(&udev->dev, "device descriptor read/all, error %d\n", |
|---|
| 4919 | | - retval); |
|---|
| 4920 | | - if (retval >= 0) |
|---|
| 4921 | | - retval = -ENOMSG; |
|---|
| 4922 | 4983 | goto fail; |
|---|
| 4923 | 4984 | } |
|---|
| 4924 | 4985 | |
|---|
| .. | .. |
|---|
| 4942 | 5003 | hub_port_disable(hub, port1, 0); |
|---|
| 4943 | 5004 | update_devnum(udev, devnum); /* for disconnect processing */ |
|---|
| 4944 | 5005 | } |
|---|
| 5006 | + kfree(buf); |
|---|
| 4945 | 5007 | return retval; |
|---|
| 4946 | 5008 | } |
|---|
| 4947 | 5009 | |
|---|
| .. | .. |
|---|
| 5022 | 5084 | |
|---|
| 5023 | 5085 | |
|---|
| 5024 | 5086 | static int descriptors_changed(struct usb_device *udev, |
|---|
| 5025 | | - struct usb_device_descriptor *old_device_descriptor, |
|---|
| 5087 | + struct usb_device_descriptor *new_device_descriptor, |
|---|
| 5026 | 5088 | struct usb_host_bos *old_bos) |
|---|
| 5027 | 5089 | { |
|---|
| 5028 | 5090 | int changed = 0; |
|---|
| .. | .. |
|---|
| 5033 | 5095 | int length; |
|---|
| 5034 | 5096 | char *buf; |
|---|
| 5035 | 5097 | |
|---|
| 5036 | | - if (memcmp(&udev->descriptor, old_device_descriptor, |
|---|
| 5037 | | - sizeof(*old_device_descriptor)) != 0) |
|---|
| 5098 | + if (memcmp(&udev->descriptor, new_device_descriptor, |
|---|
| 5099 | + sizeof(*new_device_descriptor)) != 0) |
|---|
| 5038 | 5100 | return 1; |
|---|
| 5039 | 5101 | |
|---|
| 5040 | 5102 | if ((old_bos && !udev->bos) || (!old_bos && udev->bos)) |
|---|
| .. | .. |
|---|
| 5207 | 5269 | } |
|---|
| 5208 | 5270 | |
|---|
| 5209 | 5271 | /* reset (non-USB 3.0 devices) and get descriptor */ |
|---|
| 5210 | | - status = hub_port_init(hub, udev, port1, i); |
|---|
| 5272 | + status = hub_port_init(hub, udev, port1, i, NULL); |
|---|
| 5211 | 5273 | if (status < 0) |
|---|
| 5212 | 5274 | goto loop; |
|---|
| 5213 | 5275 | |
|---|
| .. | .. |
|---|
| 5355 | 5417 | { |
|---|
| 5356 | 5418 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
|---|
| 5357 | 5419 | struct usb_device *udev = port_dev->child; |
|---|
| 5358 | | - struct usb_device_descriptor descriptor; |
|---|
| 5420 | + struct usb_device_descriptor *descr; |
|---|
| 5359 | 5421 | int status = -ENODEV; |
|---|
| 5360 | | - int retval; |
|---|
| 5361 | 5422 | |
|---|
| 5362 | 5423 | dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, |
|---|
| 5363 | 5424 | portchange, portspeed(hub, portstatus)); |
|---|
| .. | .. |
|---|
| 5384 | 5445 | * changed device descriptors before resuscitating the |
|---|
| 5385 | 5446 | * device. |
|---|
| 5386 | 5447 | */ |
|---|
| 5387 | | - descriptor = udev->descriptor; |
|---|
| 5388 | | - retval = usb_get_device_descriptor(udev, |
|---|
| 5389 | | - sizeof(udev->descriptor)); |
|---|
| 5390 | | - if (retval < 0) { |
|---|
| 5448 | + descr = usb_get_device_descriptor(udev); |
|---|
| 5449 | + if (IS_ERR(descr)) { |
|---|
| 5391 | 5450 | dev_dbg(&udev->dev, |
|---|
| 5392 | | - "can't read device descriptor %d\n", |
|---|
| 5393 | | - retval); |
|---|
| 5451 | + "can't read device descriptor %ld\n", |
|---|
| 5452 | + PTR_ERR(descr)); |
|---|
| 5394 | 5453 | } else { |
|---|
| 5395 | | - if (descriptors_changed(udev, &descriptor, |
|---|
| 5454 | + if (descriptors_changed(udev, descr, |
|---|
| 5396 | 5455 | udev->bos)) { |
|---|
| 5397 | 5456 | dev_dbg(&udev->dev, |
|---|
| 5398 | 5457 | "device descriptor has changed\n"); |
|---|
| 5399 | | - /* for disconnect() calls */ |
|---|
| 5400 | | - udev->descriptor = descriptor; |
|---|
| 5401 | 5458 | } else { |
|---|
| 5402 | 5459 | status = 0; /* Nothing to do */ |
|---|
| 5403 | 5460 | } |
|---|
| 5461 | + kfree(descr); |
|---|
| 5404 | 5462 | } |
|---|
| 5405 | 5463 | #ifdef CONFIG_PM |
|---|
| 5406 | 5464 | } else if (udev->state == USB_STATE_SUSPENDED && |
|---|
| .. | .. |
|---|
| 5717 | 5775 | .idVendor = USB_VENDOR_GENESYS_LOGIC, |
|---|
| 5718 | 5776 | .bInterfaceClass = USB_CLASS_HUB, |
|---|
| 5719 | 5777 | .driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND}, |
|---|
| 5778 | + { .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
|---|
| 5779 | + | USB_DEVICE_ID_MATCH_PRODUCT, |
|---|
| 5780 | + .idVendor = USB_VENDOR_TEXAS_INSTRUMENTS, |
|---|
| 5781 | + .idProduct = USB_PRODUCT_TUSB8041_USB2, |
|---|
| 5782 | + .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, |
|---|
| 5783 | + { .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
|---|
| 5784 | + | USB_DEVICE_ID_MATCH_PRODUCT, |
|---|
| 5785 | + .idVendor = USB_VENDOR_TEXAS_INSTRUMENTS, |
|---|
| 5786 | + .idProduct = USB_PRODUCT_TUSB8041_USB3, |
|---|
| 5787 | + .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, |
|---|
| 5720 | 5788 | { .match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS, |
|---|
| 5721 | 5789 | .bDeviceClass = USB_CLASS_HUB}, |
|---|
| 5722 | 5790 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, |
|---|
| .. | .. |
|---|
| 5818 | 5886 | struct usb_device *parent_hdev = udev->parent; |
|---|
| 5819 | 5887 | struct usb_hub *parent_hub; |
|---|
| 5820 | 5888 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
|---|
| 5821 | | - struct usb_device_descriptor descriptor = udev->descriptor; |
|---|
| 5889 | + struct usb_device_descriptor descriptor; |
|---|
| 5822 | 5890 | struct usb_host_bos *bos; |
|---|
| 5823 | 5891 | int i, j, ret = 0; |
|---|
| 5824 | 5892 | int port1 = udev->portnum; |
|---|
| .. | .. |
|---|
| 5860 | 5928 | /* ep0 maxpacket size may change; let the HCD know about it. |
|---|
| 5861 | 5929 | * Other endpoints will be handled by re-enumeration. */ |
|---|
| 5862 | 5930 | usb_ep0_reinit(udev); |
|---|
| 5863 | | - ret = hub_port_init(parent_hub, udev, port1, i); |
|---|
| 5931 | + ret = hub_port_init(parent_hub, udev, port1, i, &descriptor); |
|---|
| 5864 | 5932 | if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) |
|---|
| 5865 | 5933 | break; |
|---|
| 5866 | 5934 | } |
|---|
| .. | .. |
|---|
| 5872 | 5940 | /* Device might have changed firmware (DFU or similar) */ |
|---|
| 5873 | 5941 | if (descriptors_changed(udev, &descriptor, bos)) { |
|---|
| 5874 | 5942 | dev_info(&udev->dev, "device firmware changed\n"); |
|---|
| 5875 | | - udev->descriptor = descriptor; /* for disconnect() calls */ |
|---|
| 5876 | 5943 | goto re_enumerate; |
|---|
| 5877 | 5944 | } |
|---|
| 5878 | 5945 | |
|---|