hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/usb/core/hub.c
....@@ -29,18 +29,22 @@
2929 #include <linux/mutex.h>
3030 #include <linux/random.h>
3131 #include <linux/pm_qos.h>
32
+#include <linux/kobject.h>
3233
3334 #include <linux/uaccess.h>
3435 #include <asm/byteorder.h>
3536
3637 #include "hub.h"
37
-#include "otg_whitelist.h"
38
+#include "otg_productlist.h"
3839
3940 #define USB_VENDOR_GENESYS_LOGIC 0x05e3
4041 #define USB_VENDOR_SMSC 0x0424
4142 #define USB_PRODUCT_USB5534B 0x5534
4243 #define USB_VENDOR_CYPRESS 0x04b4
4344 #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
4448 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01
4549 #define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02
4650
....@@ -95,7 +99,7 @@
9599 MODULE_PARM_DESC(old_scheme_first,
96100 "start with the old device initialization scheme");
97101
98
-static bool use_both_schemes = 1;
102
+static bool use_both_schemes = true;
99103 module_param(use_both_schemes, bool, S_IRUGO | S_IWUSR);
100104 MODULE_PARM_DESC(use_both_schemes,
101105 "try the other device initialization scheme if the "
....@@ -618,6 +622,36 @@
618622 status, change, NULL);
619623 }
620624
625
+static void hub_resubmit_irq_urb(struct usb_hub *hub)
626
+{
627
+ unsigned long flags;
628
+ int status;
629
+
630
+ spin_lock_irqsave(&hub->irq_urb_lock, flags);
631
+
632
+ if (hub->quiescing) {
633
+ spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
634
+ return;
635
+ }
636
+
637
+ status = usb_submit_urb(hub->urb, GFP_ATOMIC);
638
+ if (status && status != -ENODEV && status != -EPERM &&
639
+ status != -ESHUTDOWN) {
640
+ dev_err(hub->intfdev, "resubmit --> %d\n", status);
641
+ mod_timer(&hub->irq_urb_retry, jiffies + HZ);
642
+ }
643
+
644
+ spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
645
+}
646
+
647
+static void hub_retry_irq_urb(struct timer_list *t)
648
+{
649
+ struct usb_hub *hub = from_timer(hub, t, irq_urb_retry);
650
+
651
+ hub_resubmit_irq_urb(hub);
652
+}
653
+
654
+
621655 static void kick_hub_wq(struct usb_hub *hub)
622656 {
623657 struct usb_interface *intf;
....@@ -702,7 +736,7 @@
702736 if ((++hub->nerrors < 10) || hub->error)
703737 goto resubmit;
704738 hub->error = status;
705
- /* FALL THROUGH */
739
+ fallthrough;
706740
707741 /* let hub_wq handle things */
708742 case 0: /* we got data: port status changed */
....@@ -720,12 +754,7 @@
720754 kick_hub_wq(hub);
721755
722756 resubmit:
723
- if (hub->quiescing)
724
- return;
725
-
726
- status = usb_submit_urb(hub->urb, GFP_ATOMIC);
727
- if (status != 0 && status != -ENODEV && status != -EPERM)
728
- dev_err(hub->intfdev, "resubmit --> %d\n", status);
757
+ hub_resubmit_irq_urb(hub);
729758 }
730759
731760 /* USB 2.0 spec Section 11.24.2.3 */
....@@ -857,7 +886,7 @@
857886 /* info that CLEAR_TT_BUFFER needs */
858887 clear->tt = tt->multi ? udev->ttport : 1;
859888 clear->devinfo = usb_pipeendpoint (pipe);
860
- clear->devinfo |= udev->devnum << 4;
889
+ clear->devinfo |= ((u16)udev->devaddr) << 4;
861890 clear->devinfo |= usb_pipecontrol(pipe)
862891 ? (USB_ENDPOINT_XFER_CONTROL << 11)
863892 : (USB_ENDPOINT_XFER_BULK << 11);
....@@ -1288,10 +1317,13 @@
12881317 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
12891318 {
12901319 struct usb_device *hdev = hub->hdev;
1320
+ unsigned long flags;
12911321 int i;
12921322
12931323 /* hub_wq and related activity won't re-trigger */
1324
+ spin_lock_irqsave(&hub->irq_urb_lock, flags);
12941325 hub->quiescing = 1;
1326
+ spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
12951327
12961328 if (type != HUB_SUSPEND) {
12971329 /* Disconnect all the children */
....@@ -1302,6 +1334,7 @@
13021334 }
13031335
13041336 /* Stop hub_wq and related activity */
1337
+ del_timer_sync(&hub->irq_urb_retry);
13051338 usb_kill_urb(hub->urb);
13061339 if (hub->has_indicators)
13071340 cancel_delayed_work_sync(&hub->leds);
....@@ -1814,7 +1847,7 @@
18141847 return -E2BIG;
18151848 }
18161849
1817
-#ifdef CONFIG_USB_OTG_BLACKLIST_HUB
1850
+#ifdef CONFIG_USB_OTG_DISABLE_EXTERNAL_HUB
18181851 if (hdev->parent) {
18191852 dev_warn(&intf->dev, "ignoring external hub\n");
18201853 return -ENODEV;
....@@ -1839,6 +1872,8 @@
18391872 INIT_DELAYED_WORK(&hub->leds, led_work);
18401873 INIT_DELAYED_WORK(&hub->init_work, NULL);
18411874 INIT_WORK(&hub->events, hub_event);
1875
+ spin_lock_init(&hub->irq_urb_lock);
1876
+ timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0);
18421877 usb_get_intf(intf);
18431878 usb_get_dev(hdev);
18441879
....@@ -2121,6 +2156,8 @@
21212156 /* The address for a WUSB device is managed by wusbcore. */
21222157 if (!udev->wusb)
21232158 udev->devnum = devnum;
2159
+ if (!udev->devaddr)
2160
+ udev->devaddr = (u8)devnum;
21242161 }
21252162
21262163 static void hub_free_dev(struct usb_device *udev)
....@@ -2344,9 +2381,8 @@
23442381 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
23452382 * @udev: newly addressed device (in ADDRESS state)
23462383 *
2347
- * This is only called by usb_new_device() and usb_authorize_device()
2348
- * and FIXME -- all comments that apply to them apply here wrt to
2349
- * environment.
2384
+ * This is only called by usb_new_device() -- all comments that apply there
2385
+ * apply here wrt to environment.
23502386 *
23512387 * If the device is WUSB and not authorized, we don't attempt to read
23522388 * the string descriptors, as they will be errored out by the device
....@@ -2379,7 +2415,7 @@
23792415 if (err < 0)
23802416 return err;
23812417
2382
- if (IS_ENABLED(CONFIG_USB_OTG_WHITELIST) && hcd->tpl_support &&
2418
+ if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support &&
23832419 !is_targeted(udev)) {
23842420 /* Maybe it can talk to us, though we can't talk to it.
23852421 * (Includes HNP test device.)
....@@ -2611,12 +2647,17 @@
26112647 }
26122648
26132649 if (usb_dev->wusb) {
2614
- result = usb_get_device_descriptor(usb_dev, sizeof(usb_dev->descriptor));
2615
- 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);
26162655 dev_err(&usb_dev->dev, "can't re-read device descriptor for "
26172656 "authorization: %d\n", result);
26182657 goto error_device_descriptor;
26192658 }
2659
+ usb_dev->descriptor = *descr;
2660
+ kfree(descr);
26202661 }
26212662
26222663 usb_dev->authorized = 1;
....@@ -2681,11 +2722,20 @@
26812722 }
26822723
26832724
2725
+#ifdef CONFIG_USB_FEW_INIT_RETRIES
2726
+#define PORT_RESET_TRIES 2
2727
+#define SET_ADDRESS_TRIES 1
2728
+#define GET_DESCRIPTOR_TRIES 1
2729
+#define GET_MAXPACKET0_TRIES 1
2730
+#define PORT_INIT_TRIES 4
2731
+
2732
+#else
26842733 #define PORT_RESET_TRIES 5
26852734 #define SET_ADDRESS_TRIES 2
26862735 #define GET_DESCRIPTOR_TRIES 2
2687
-#define SET_CONFIG_TRIES (2 * (use_both_schemes + 1))
2688
-#define USE_NEW_SCHEME(i, scheme) ((i) / 2 == (int)(scheme))
2736
+#define GET_MAXPACKET0_TRIES 3
2737
+#define PORT_INIT_TRIES 4
2738
+#endif /* CONFIG_USB_FEW_INIT_RETRIES */
26892739
26902740 #define HUB_ROOT_RESET_TIME 60 /* times are in msec */
26912741 #define HUB_SHORT_RESET_TIME 10
....@@ -2693,27 +2743,35 @@
26932743 #define HUB_LONG_RESET_TIME 200
26942744 #define HUB_RESET_TIMEOUT 800
26952745
2696
-/*
2697
- * "New scheme" enumeration causes an extra state transition to be
2698
- * exposed to an xhci host and causes USB3 devices to receive control
2699
- * commands in the default state. This has been seen to cause
2700
- * enumeration failures, so disable this enumeration scheme for USB3
2701
- * devices.
2702
- */
27032746 static bool use_new_scheme(struct usb_device *udev, int retry,
27042747 struct usb_port *port_dev)
27052748 {
27062749 int old_scheme_first_port =
2707
- port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME;
2750
+ (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) ||
2751
+ old_scheme_first;
27082752
2753
+ /*
2754
+ * "New scheme" enumeration causes an extra state transition to be
2755
+ * exposed to an xhci host and causes USB3 devices to receive control
2756
+ * commands in the default state. This has been seen to cause
2757
+ * enumeration failures, so disable this enumeration scheme for USB3
2758
+ * devices.
2759
+ */
27092760 if (udev->speed >= USB_SPEED_SUPER)
27102761 return false;
27112762
2712
- return USE_NEW_SCHEME(retry, old_scheme_first_port || old_scheme_first);
2763
+ /*
2764
+ * If use_both_schemes is set, use the first scheme (whichever
2765
+ * it is) for the larger half of the retries, then use the other
2766
+ * scheme. Otherwise, use the first scheme for all the retries.
2767
+ */
2768
+ if (use_both_schemes && retry >= (PORT_INIT_TRIES + 1) / 2)
2769
+ return old_scheme_first_port; /* Second half */
2770
+ return !old_scheme_first_port; /* First half or all */
27132771 }
27142772
27152773 /* Is a USB 3.0 port in the Inactive or Compliance Mode state?
2716
- * Port worm reset is required to recover
2774
+ * Port warm reset is required to recover
27172775 */
27182776 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
27192777 u16 portstatus)
....@@ -3177,13 +3235,14 @@
31773235 }
31783236
31793237 /* Count of wakeup-enabled devices at or below udev */
3180
-static unsigned wakeup_enabled_descendants(struct usb_device *udev)
3238
+unsigned usb_wakeup_enabled_descendants(struct usb_device *udev)
31813239 {
31823240 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
31833241
31843242 return udev->do_remote_wakeup +
31853243 (hub ? hub->wakeup_enabled_descendants : 0);
31863244 }
3245
+EXPORT_SYMBOL_GPL(usb_wakeup_enabled_descendants);
31873246
31883247 /*
31893248 * usb_port_suspend - suspend a usb device's upstream port
....@@ -3285,7 +3344,7 @@
32853344 * Therefore we will turn on the suspend feature if udev or any of its
32863345 * descendants is enabled for remote wakeup.
32873346 */
3288
- else if (PMSG_IS_AUTO(msg) || wakeup_enabled_descendants(udev) > 0)
3347
+ else if (PMSG_IS_AUTO(msg) || usb_wakeup_enabled_descendants(udev) > 0)
32893348 status = set_port_feature(hub->hdev, port1,
32903349 USB_PORT_FEAT_SUSPEND);
32913350 else {
....@@ -3513,7 +3572,7 @@
35133572 u16 portchange, portstatus;
35143573
35153574 if (!test_and_set_bit(port1, hub->child_usage_bits)) {
3516
- status = pm_runtime_get_sync(&port_dev->dev);
3575
+ status = pm_runtime_resume_and_get(&port_dev->dev);
35173576 if (status < 0) {
35183577 dev_dbg(&udev->dev, "can't resume usb port, status %d\n",
35193578 status);
....@@ -3674,7 +3733,6 @@
36743733 struct usb_hub *hub = usb_get_intfdata(intf);
36753734 struct usb_device *hdev = hub->hdev;
36763735 unsigned port1;
3677
- int status;
36783736
36793737 /*
36803738 * Warn if children aren't already suspended.
....@@ -3693,7 +3751,7 @@
36933751 }
36943752 if (udev)
36953753 hub->wakeup_enabled_descendants +=
3696
- wakeup_enabled_descendants(udev);
3754
+ usb_wakeup_enabled_descendants(udev);
36973755 }
36983756
36993757 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) {
....@@ -3708,12 +3766,12 @@
37083766 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) {
37093767 /* Enable hub to send remote wakeup for all ports. */
37103768 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
3711
- status = set_port_feature(hdev,
3712
- port1 |
3713
- USB_PORT_FEAT_REMOTE_WAKE_CONNECT |
3714
- USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT |
3715
- USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT,
3716
- USB_PORT_FEAT_REMOTE_WAKE_MASK);
3769
+ set_port_feature(hdev,
3770
+ port1 |
3771
+ USB_PORT_FEAT_REMOTE_WAKE_CONNECT |
3772
+ USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT |
3773
+ USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT,
3774
+ USB_PORT_FEAT_REMOTE_WAKE_MASK);
37173775 }
37183776 }
37193777
....@@ -4193,7 +4251,7 @@
41934251 if (!udev || !udev->parent ||
41944252 udev->speed < USB_SPEED_SUPER ||
41954253 !udev->lpm_capable ||
4196
- udev->state < USB_STATE_DEFAULT)
4254
+ udev->state < USB_STATE_CONFIGURED)
41974255 return 0;
41984256
41994257 hcd = bus_to_hcd(udev->bus);
....@@ -4252,7 +4310,7 @@
42524310 if (!udev || !udev->parent ||
42534311 udev->speed < USB_SPEED_SUPER ||
42544312 !udev->lpm_capable ||
4255
- udev->state < USB_STATE_DEFAULT)
4313
+ udev->state < USB_STATE_CONFIGURED)
42564314 return;
42574315
42584316 udev->lpm_disable_count--;
....@@ -4542,6 +4600,67 @@
45424600 return hcd->driver->enable_device(hcd, udev);
45434601 }
45444602
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
+
45454664 /* Reset device, (re)assign address, get device descriptor.
45464665 * Device connection must be stable, no more debouncing needed.
45474666 * Returns device in USB_STATE_ADDRESS, except on error.
....@@ -4551,10 +4670,17 @@
45514670 * the port lock. For a newly detected device that is not accessible
45524671 * through any global pointers, it's not necessary to lock the device,
45534672 * 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.
45544680 */
45554681 static int
45564682 hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
4557
- int retry_counter)
4683
+ int retry_counter, struct usb_device_descriptor *dev_descr)
45584684 {
45594685 struct usb_device *hdev = hub->hdev;
45604686 struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
....@@ -4565,6 +4691,14 @@
45654691 const char *speed;
45664692 int devnum = udev->devnum;
45674693 const char *driver_name;
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;
45684702
45694703 /* root hub ports have a slightly longer reset period
45704704 * (from USB 2.0 spec, section 7.1.7.5)
....@@ -4597,32 +4731,34 @@
45974731 }
45984732 oldspeed = udev->speed;
45994733
4600
- /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ...
4601
- * it's fixed size except for full speed devices.
4602
- * For Wireless USB devices, ep0 max packet is always 512 (tho
4603
- * reported as 0xff in the device descriptor). WUSB1.0[4.8.1].
4604
- */
4605
- switch (udev->speed) {
4606
- case USB_SPEED_SUPER_PLUS:
4607
- case USB_SPEED_SUPER:
4608
- case USB_SPEED_WIRELESS: /* fixed at 512 */
4609
- udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512);
4610
- break;
4611
- case USB_SPEED_HIGH: /* fixed at 64 */
4612
- udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
4613
- break;
4614
- case USB_SPEED_FULL: /* 8, 16, 32, or 64 */
4615
- /* to determine the ep0 maxpacket size, try to read
4616
- * the device descriptor to get bMaxPacketSize0 and
4617
- * 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].
46184739 */
4619
- udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
4620
- break;
4621
- case USB_SPEED_LOW: /* fixed at 8 */
4622
- udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8);
4623
- break;
4624
- default:
4625
- 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
+ }
46264762 }
46274763
46284764 if (udev->speed == USB_SPEED_WIRELESS)
....@@ -4645,22 +4781,24 @@
46454781 if (udev->speed < USB_SPEED_SUPER)
46464782 dev_info(&udev->dev,
46474783 "%s %s USB device number %d using %s\n",
4648
- (udev->config) ? "reset" : "new", speed,
4784
+ (initial ? "new" : "reset"), speed,
46494785 devnum, driver_name);
46504786
4651
- /* Set up TT records, if needed */
4652
- if (hdev->tt) {
4653
- udev->tt = hdev->tt;
4654
- udev->ttport = hdev->ttport;
4655
- } else if (udev->speed != USB_SPEED_HIGH
4656
- && hdev->speed == USB_SPEED_HIGH) {
4657
- if (!hub->tt.hub) {
4658
- dev_err(&udev->dev, "parent hub has no TT\n");
4659
- retval = -EINVAL;
4660
- 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;
46614801 }
4662
- udev->tt = &hub->tt;
4663
- udev->ttport = port1;
46644802 }
46654803
46664804 /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way?
....@@ -4675,14 +4813,10 @@
46754813 * first 8 bytes of the device descriptor to get the ep0 maxpacket
46764814 * value.
46774815 */
4816
+ do_new_scheme = use_new_scheme(udev, retry_counter, port_dev);
4817
+
46784818 for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) {
4679
- bool did_new_scheme = false;
4680
-
4681
- if (use_new_scheme(udev, retry_counter, port_dev)) {
4682
- struct usb_device_descriptor *buf;
4683
- int r = 0;
4684
-
4685
- did_new_scheme = true;
4819
+ if (do_new_scheme) {
46864820 retval = hub_enable_device(udev);
46874821 if (retval < 0) {
46884822 dev_err(&udev->dev,
....@@ -4691,51 +4825,14 @@
46914825 goto fail;
46924826 }
46934827
4694
-#define GET_DESCRIPTOR_BUFSIZE 64
4695
- buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO);
4696
- if (!buf) {
4697
- retval = -ENOMEM;
4698
- 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;
46994835 }
4700
-
4701
- /* Retry on all errors; some devices are flakey.
4702
- * 255 is for WUSB devices, we actually need to use
4703
- * 512 (WUSB1.0[4.8.1]).
4704
- */
4705
- for (operations = 0; operations < 3; ++operations) {
4706
- buf->bMaxPacketSize0 = 0;
4707
- r = usb_control_msg(udev, usb_rcvaddr0pipe(),
4708
- USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
4709
- USB_DT_DEVICE << 8, 0,
4710
- buf, GET_DESCRIPTOR_BUFSIZE,
4711
- initial_descriptor_timeout);
4712
- switch (buf->bMaxPacketSize0) {
4713
- case 8: case 16: case 32: case 64: case 255:
4714
- if (buf->bDescriptorType ==
4715
- USB_DT_DEVICE) {
4716
- r = 0;
4717
- break;
4718
- }
4719
- /* FALL THROUGH */
4720
- default:
4721
- if (r == 0)
4722
- r = -EPROTO;
4723
- break;
4724
- }
4725
- /*
4726
- * Some devices time out if they are powered on
4727
- * when already connected. They need a second
4728
- * reset. But only on the first attempt,
4729
- * lest we get into a time out/reset loop
4730
- */
4731
- if (r == 0 || (r == -ETIMEDOUT &&
4732
- retries == 0 &&
4733
- udev->speed > USB_SPEED_FULL))
4734
- break;
4735
- }
4736
- udev->descriptor.bMaxPacketSize0 =
4737
- buf->bMaxPacketSize0;
4738
- kfree(buf);
47394836
47404837 retval = hub_port_reset(hub, port1, udev, delay, false);
47414838 if (retval < 0) /* error or disconnect */
....@@ -4746,14 +4843,13 @@
47464843 retval = -ENODEV;
47474844 goto fail;
47484845 }
4749
- if (r) {
4750
- if (r != -ENODEV)
4846
+ if (maxp0 < 0) {
4847
+ if (maxp0 != -ENODEV)
47514848 dev_err(&udev->dev, "device descriptor read/64, error %d\n",
4752
- r);
4753
- retval = -EMSGSIZE;
4849
+ maxp0);
4850
+ retval = maxp0;
47544851 continue;
47554852 }
4756
-#undef GET_DESCRIPTOR_BUFSIZE
47574853 }
47584854
47594855 /*
....@@ -4791,26 +4887,26 @@
47914887 * - read ep0 maxpacket even for high and low speed,
47924888 */
47934889 msleep(10);
4794
- /* use_new_scheme() checks the speed which may have
4795
- * changed since the initial look so we cache the result
4796
- * in did_new_scheme
4797
- */
4798
- if (did_new_scheme)
4890
+ if (do_new_scheme)
47994891 break;
48004892 }
48014893
4802
- retval = usb_get_device_descriptor(udev, 8);
4803
- if (retval < 8) {
4894
+ /* !do_new_scheme || wusb */
4895
+ maxp0 = get_bMaxPacketSize0(udev, buf, 8, retries == 0);
4896
+ if (maxp0 < 0) {
4897
+ retval = maxp0;
48044898 if (retval != -ENODEV)
48054899 dev_err(&udev->dev,
48064900 "device descriptor read/8, error %d\n",
48074901 retval);
4808
- if (retval >= 0)
4809
- retval = -EMSGSIZE;
48104902 } else {
48114903 u32 delay;
48124904
4813
- 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
+ }
48144910
48154911 delay = udev->parent->hub_delay;
48164912 udev->hub_delay = min_t(u32, delay,
....@@ -4829,6 +4925,51 @@
48294925 goto fail;
48304926
48314927 /*
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
+ /*
48324973 * Some superspeed devices have finished the link training process
48334974 * and attached to a superspeed hub port, but the device descriptor
48344975 * got from those devices show they aren't superspeed devices. Warm
....@@ -4836,41 +4977,9 @@
48364977 */
48374978 if ((udev->speed >= USB_SPEED_SUPER) &&
48384979 (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) {
4839
- dev_err(&udev->dev, "got a wrong device descriptor, "
4840
- "warm reset device\n");
4841
- hub_port_reset(hub, port1, udev,
4842
- 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);
48434982 retval = -EINVAL;
4844
- goto fail;
4845
- }
4846
-
4847
- if (udev->descriptor.bMaxPacketSize0 == 0xff ||
4848
- udev->speed >= USB_SPEED_SUPER)
4849
- i = 512;
4850
- else
4851
- i = udev->descriptor.bMaxPacketSize0;
4852
- if (usb_endpoint_maxp(&udev->ep0.desc) != i) {
4853
- if (udev->speed == USB_SPEED_LOW ||
4854
- !(i == 8 || i == 16 || i == 32 || i == 64)) {
4855
- dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i);
4856
- retval = -EMSGSIZE;
4857
- goto fail;
4858
- }
4859
- if (udev->speed == USB_SPEED_FULL)
4860
- dev_dbg(&udev->dev, "ep0 maxpacket = %d\n", i);
4861
- else
4862
- dev_warn(&udev->dev, "Using ep0 maxpacket: %d\n", i);
4863
- udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i);
4864
- usb_ep0_reinit(udev);
4865
- }
4866
-
4867
- retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE);
4868
- if (retval < (signed)sizeof(udev->descriptor)) {
4869
- if (retval != -ENODEV)
4870
- dev_err(&udev->dev, "device descriptor read/all, error %d\n",
4871
- retval);
4872
- if (retval >= 0)
4873
- retval = -ENOMSG;
48744983 goto fail;
48754984 }
48764985
....@@ -4894,6 +5003,7 @@
48945003 hub_port_disable(hub, port1, 0);
48955004 update_devnum(udev, devnum); /* for disconnect processing */
48965005 }
5006
+ kfree(buf);
48975007 return retval;
48985008 }
48995009
....@@ -4972,6 +5082,91 @@
49725082 return remaining;
49735083 }
49745084
5085
+
5086
+static int descriptors_changed(struct usb_device *udev,
5087
+ struct usb_device_descriptor *new_device_descriptor,
5088
+ struct usb_host_bos *old_bos)
5089
+{
5090
+ int changed = 0;
5091
+ unsigned index;
5092
+ unsigned serial_len = 0;
5093
+ unsigned len;
5094
+ unsigned old_length;
5095
+ int length;
5096
+ char *buf;
5097
+
5098
+ if (memcmp(&udev->descriptor, new_device_descriptor,
5099
+ sizeof(*new_device_descriptor)) != 0)
5100
+ return 1;
5101
+
5102
+ if ((old_bos && !udev->bos) || (!old_bos && udev->bos))
5103
+ return 1;
5104
+ if (udev->bos) {
5105
+ len = le16_to_cpu(udev->bos->desc->wTotalLength);
5106
+ if (len != le16_to_cpu(old_bos->desc->wTotalLength))
5107
+ return 1;
5108
+ if (memcmp(udev->bos->desc, old_bos->desc, len))
5109
+ return 1;
5110
+ }
5111
+
5112
+ /* Since the idVendor, idProduct, and bcdDevice values in the
5113
+ * device descriptor haven't changed, we will assume the
5114
+ * Manufacturer and Product strings haven't changed either.
5115
+ * But the SerialNumber string could be different (e.g., a
5116
+ * different flash card of the same brand).
5117
+ */
5118
+ if (udev->serial)
5119
+ serial_len = strlen(udev->serial) + 1;
5120
+
5121
+ len = serial_len;
5122
+ for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5123
+ old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5124
+ len = max(len, old_length);
5125
+ }
5126
+
5127
+ buf = kmalloc(len, GFP_NOIO);
5128
+ if (!buf)
5129
+ /* assume the worst */
5130
+ return 1;
5131
+
5132
+ for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5133
+ old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5134
+ length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf,
5135
+ old_length);
5136
+ if (length != old_length) {
5137
+ dev_dbg(&udev->dev, "config index %d, error %d\n",
5138
+ index, length);
5139
+ changed = 1;
5140
+ break;
5141
+ }
5142
+ if (memcmp(buf, udev->rawdescriptors[index], old_length)
5143
+ != 0) {
5144
+ dev_dbg(&udev->dev, "config index %d changed (#%d)\n",
5145
+ index,
5146
+ ((struct usb_config_descriptor *) buf)->
5147
+ bConfigurationValue);
5148
+ changed = 1;
5149
+ break;
5150
+ }
5151
+ }
5152
+
5153
+ if (!changed && serial_len) {
5154
+ length = usb_string(udev, udev->descriptor.iSerialNumber,
5155
+ buf, serial_len);
5156
+ if (length + 1 != serial_len) {
5157
+ dev_dbg(&udev->dev, "serial string error %d\n",
5158
+ length);
5159
+ changed = 1;
5160
+ } else if (memcmp(buf, udev->serial, length) != 0) {
5161
+ dev_dbg(&udev->dev, "serial string changed\n");
5162
+ changed = 1;
5163
+ }
5164
+ }
5165
+
5166
+ kfree(buf);
5167
+ return changed;
5168
+}
5169
+
49755170 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
49765171 u16 portchange)
49775172 {
....@@ -5040,11 +5235,10 @@
50405235
50415236 status = 0;
50425237
5043
- for (i = 0; i < SET_CONFIG_TRIES; i++) {
5238
+ for (i = 0; i < PORT_INIT_TRIES; i++) {
50445239 usb_lock_port(port_dev);
50455240 mutex_lock(hcd->address0_mutex);
50465241 retry_locked = true;
5047
-
50485242 /* reallocate for each attempt, since references
50495243 * to the previous one can escape in various ways
50505244 */
....@@ -5075,7 +5269,7 @@
50755269 }
50765270
50775271 /* reset (non-USB 3.0 devices) and get descriptor */
5078
- status = hub_port_init(hub, udev, port1, i);
5272
+ status = hub_port_init(hub, udev, port1, i, NULL);
50795273 if (status < 0)
50805274 goto loop;
50815275
....@@ -5184,11 +5378,10 @@
51845378 break;
51855379
51865380 /* When halfway through our retry count, power-cycle the port */
5187
- if (i == (SET_CONFIG_TRIES / 2) - 1) {
5381
+ if (i == (PORT_INIT_TRIES - 1) / 2) {
51885382 dev_info(&port_dev->dev, "attempt power cycle\n");
51895383 usb_hub_set_port_power(hdev, hub, port1, false);
51905384 msleep(2 * hub_power_on_good_delay(hub));
5191
- set_bit(HCD_FLAG_POWER_ON, &hcd->flags);
51925385 usb_hub_set_port_power(hdev, hub, port1, true);
51935386 msleep(hub_power_on_good_delay(hub));
51945387 }
....@@ -5205,7 +5398,7 @@
52055398 hub_port_disable(hub, port1, 1);
52065399 if (hcd->driver->relinquish_port && !hub->hdev->parent) {
52075400 if ((status != -ENOTCONN && status != -ENODEV) ||
5208
- (status == -ENOTCONN && hcd->rk3288_relinquish_port_quirk))
5401
+ (status == -ENOTCONN && of_machine_is_compatible("rockchip,rk3288")))
52095402 hcd->driver->relinquish_port(hcd, port1);
52105403 }
52115404 }
....@@ -5224,6 +5417,7 @@
52245417 {
52255418 struct usb_port *port_dev = hub->ports[port1 - 1];
52265419 struct usb_device *udev = port_dev->child;
5420
+ struct usb_device_descriptor *descr;
52275421 int status = -ENODEV;
52285422
52295423 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus,
....@@ -5245,7 +5439,27 @@
52455439 if ((portstatus & USB_PORT_STAT_CONNECTION) && udev &&
52465440 udev->state != USB_STATE_NOTATTACHED) {
52475441 if (portstatus & USB_PORT_STAT_ENABLE) {
5248
- status = 0; /* Nothing to do */
5442
+ /*
5443
+ * USB-3 connections are initialized automatically by
5444
+ * the hostcontroller hardware. Therefore check for
5445
+ * changed device descriptors before resuscitating the
5446
+ * device.
5447
+ */
5448
+ descr = usb_get_device_descriptor(udev);
5449
+ if (IS_ERR(descr)) {
5450
+ dev_dbg(&udev->dev,
5451
+ "can't read device descriptor %ld\n",
5452
+ PTR_ERR(descr));
5453
+ } else {
5454
+ if (descriptors_changed(udev, descr,
5455
+ udev->bos)) {
5456
+ dev_dbg(&udev->dev,
5457
+ "device descriptor has changed\n");
5458
+ } else {
5459
+ status = 0; /* Nothing to do */
5460
+ }
5461
+ kfree(descr);
5462
+ }
52495463 #ifdef CONFIG_PM
52505464 } else if (udev->state == USB_STATE_SUSPENDED &&
52515465 udev->persist_enabled) {
....@@ -5269,6 +5483,43 @@
52695483 usb_unlock_port(port_dev);
52705484 hub_port_connect(hub, port1, portstatus, portchange);
52715485 usb_lock_port(port_dev);
5486
+}
5487
+
5488
+/* Handle notifying userspace about hub over-current events */
5489
+static void port_over_current_notify(struct usb_port *port_dev)
5490
+{
5491
+ char *envp[3];
5492
+ struct device *hub_dev;
5493
+ char *port_dev_path;
5494
+
5495
+ sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count");
5496
+
5497
+ hub_dev = port_dev->dev.parent;
5498
+
5499
+ if (!hub_dev)
5500
+ return;
5501
+
5502
+ port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL);
5503
+ if (!port_dev_path)
5504
+ return;
5505
+
5506
+ envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
5507
+ if (!envp[0])
5508
+ goto exit_path;
5509
+
5510
+ envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
5511
+ port_dev->over_current_count);
5512
+ if (!envp[1])
5513
+ goto exit;
5514
+
5515
+ envp[2] = NULL;
5516
+ kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp);
5517
+
5518
+ kfree(envp[1]);
5519
+exit:
5520
+ kfree(envp[0]);
5521
+exit_path:
5522
+ kfree(port_dev_path);
52725523 }
52735524
52745525 static void port_event(struct usb_hub *hub, int port1)
....@@ -5313,6 +5564,7 @@
53135564 if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
53145565 u16 status = 0, unused;
53155566 port_dev->over_current_count++;
5567
+ port_over_current_notify(port_dev);
53165568
53175569 dev_dbg(&port_dev->dev, "over-current change #%u\n",
53185570 port_dev->over_current_count);
....@@ -5367,24 +5619,7 @@
53675619 } else {
53685620 usb_unlock_port(port_dev);
53695621 usb_lock_device(udev);
5370
-
5371
- /**
5372
- * Some special SoCs (e.g. rk322xh) USB3 PHY lose the
5373
- * ability to detect a disconnection when USB3 device
5374
- * plug out, fortunately, it can detect port link state
5375
- * change here, so we can do soft disconnect according
5376
- * to the PLC here.
5377
- *
5378
- * And we only need to do the soft disconnect for root
5379
- * hub. In addition, we just reuse the autosuspend quirk
5380
- * but not add a new quirk for this issue. Because this
5381
- * issue always occurs with autosuspend problem.
5382
- */
5383
- if (!hub->hdev->parent && (hdev->quirks &
5384
- USB_QUIRK_AUTO_SUSPEND))
5385
- usb_remove_device(udev);
5386
- else
5387
- usb_reset_device(udev);
5622
+ usb_reset_device(udev);
53885623 usb_unlock_device(udev);
53895624 usb_lock_port(port_dev);
53905625 connect_change = 0;
....@@ -5540,6 +5775,16 @@
55405775 .idVendor = USB_VENDOR_GENESYS_LOGIC,
55415776 .bInterfaceClass = USB_CLASS_HUB,
55425777 .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},
55435788 { .match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS,
55445789 .bDeviceClass = USB_CLASS_HUB},
55455790 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
....@@ -5602,90 +5847,6 @@
56025847 usb_deregister(&hub_driver);
56035848 } /* usb_hub_cleanup() */
56045849
5605
-static int descriptors_changed(struct usb_device *udev,
5606
- struct usb_device_descriptor *old_device_descriptor,
5607
- struct usb_host_bos *old_bos)
5608
-{
5609
- int changed = 0;
5610
- unsigned index;
5611
- unsigned serial_len = 0;
5612
- unsigned len;
5613
- unsigned old_length;
5614
- int length;
5615
- char *buf;
5616
-
5617
- if (memcmp(&udev->descriptor, old_device_descriptor,
5618
- sizeof(*old_device_descriptor)) != 0)
5619
- return 1;
5620
-
5621
- if ((old_bos && !udev->bos) || (!old_bos && udev->bos))
5622
- return 1;
5623
- if (udev->bos) {
5624
- len = le16_to_cpu(udev->bos->desc->wTotalLength);
5625
- if (len != le16_to_cpu(old_bos->desc->wTotalLength))
5626
- return 1;
5627
- if (memcmp(udev->bos->desc, old_bos->desc, len))
5628
- return 1;
5629
- }
5630
-
5631
- /* Since the idVendor, idProduct, and bcdDevice values in the
5632
- * device descriptor haven't changed, we will assume the
5633
- * Manufacturer and Product strings haven't changed either.
5634
- * But the SerialNumber string could be different (e.g., a
5635
- * different flash card of the same brand).
5636
- */
5637
- if (udev->serial)
5638
- serial_len = strlen(udev->serial) + 1;
5639
-
5640
- len = serial_len;
5641
- for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5642
- old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5643
- len = max(len, old_length);
5644
- }
5645
-
5646
- buf = kmalloc(len, GFP_NOIO);
5647
- if (!buf)
5648
- /* assume the worst */
5649
- return 1;
5650
-
5651
- for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5652
- old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5653
- length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf,
5654
- old_length);
5655
- if (length != old_length) {
5656
- dev_dbg(&udev->dev, "config index %d, error %d\n",
5657
- index, length);
5658
- changed = 1;
5659
- break;
5660
- }
5661
- if (memcmp(buf, udev->rawdescriptors[index], old_length)
5662
- != 0) {
5663
- dev_dbg(&udev->dev, "config index %d changed (#%d)\n",
5664
- index,
5665
- ((struct usb_config_descriptor *) buf)->
5666
- bConfigurationValue);
5667
- changed = 1;
5668
- break;
5669
- }
5670
- }
5671
-
5672
- if (!changed && serial_len) {
5673
- length = usb_string(udev, udev->descriptor.iSerialNumber,
5674
- buf, serial_len);
5675
- if (length + 1 != serial_len) {
5676
- dev_dbg(&udev->dev, "serial string error %d\n",
5677
- length);
5678
- changed = 1;
5679
- } else if (memcmp(buf, udev->serial, length) != 0) {
5680
- dev_dbg(&udev->dev, "serial string changed\n");
5681
- changed = 1;
5682
- }
5683
- }
5684
-
5685
- kfree(buf);
5686
- return changed;
5687
-}
5688
-
56895850 /**
56905851 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
56915852 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state)
....@@ -5725,7 +5886,7 @@
57255886 struct usb_device *parent_hdev = udev->parent;
57265887 struct usb_hub *parent_hub;
57275888 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
5728
- struct usb_device_descriptor descriptor = udev->descriptor;
5889
+ struct usb_device_descriptor descriptor;
57295890 struct usb_host_bos *bos;
57305891 int i, j, ret = 0;
57315892 int port1 = udev->portnum;
....@@ -5762,12 +5923,12 @@
57625923
57635924 mutex_lock(hcd->address0_mutex);
57645925
5765
- for (i = 0; i < SET_CONFIG_TRIES; ++i) {
5926
+ for (i = 0; i < PORT_INIT_TRIES; ++i) {
57665927
57675928 /* ep0 maxpacket size may change; let the HCD know about it.
57685929 * Other endpoints will be handled by re-enumeration. */
57695930 usb_ep0_reinit(udev);
5770
- ret = hub_port_init(parent_hub, udev, port1, i);
5931
+ ret = hub_port_init(parent_hub, udev, port1, i, &descriptor);
57715932 if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV)
57725933 break;
57735934 }
....@@ -5779,7 +5940,6 @@
57795940 /* Device might have changed firmware (DFU or similar) */
57805941 if (descriptors_changed(udev, &descriptor, bos)) {
57815942 dev_info(&udev->dev, "device firmware changed\n");
5782
- udev->descriptor = descriptor; /* for disconnect() calls */
57835943 goto re_enumerate;
57845944 }
57855945