| .. | .. |
|---|
| 29 | 29 | #include <linux/mutex.h> |
|---|
| 30 | 30 | #include <linux/random.h> |
|---|
| 31 | 31 | #include <linux/pm_qos.h> |
|---|
| 32 | +#include <linux/kobject.h> |
|---|
| 32 | 33 | |
|---|
| 33 | 34 | #include <linux/uaccess.h> |
|---|
| 34 | 35 | #include <asm/byteorder.h> |
|---|
| 35 | 36 | |
|---|
| 36 | 37 | #include "hub.h" |
|---|
| 37 | | -#include "otg_whitelist.h" |
|---|
| 38 | +#include "otg_productlist.h" |
|---|
| 38 | 39 | |
|---|
| 39 | 40 | #define USB_VENDOR_GENESYS_LOGIC 0x05e3 |
|---|
| 40 | 41 | #define USB_VENDOR_SMSC 0x0424 |
|---|
| 41 | 42 | #define USB_PRODUCT_USB5534B 0x5534 |
|---|
| 42 | 43 | #define USB_VENDOR_CYPRESS 0x04b4 |
|---|
| 43 | 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 |
|---|
| 44 | 48 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 |
|---|
| 45 | 49 | #define HUB_QUIRK_DISABLE_AUTOSUSPEND 0x02 |
|---|
| 46 | 50 | |
|---|
| .. | .. |
|---|
| 95 | 99 | MODULE_PARM_DESC(old_scheme_first, |
|---|
| 96 | 100 | "start with the old device initialization scheme"); |
|---|
| 97 | 101 | |
|---|
| 98 | | -static bool use_both_schemes = 1; |
|---|
| 102 | +static bool use_both_schemes = true; |
|---|
| 99 | 103 | module_param(use_both_schemes, bool, S_IRUGO | S_IWUSR); |
|---|
| 100 | 104 | MODULE_PARM_DESC(use_both_schemes, |
|---|
| 101 | 105 | "try the other device initialization scheme if the " |
|---|
| .. | .. |
|---|
| 618 | 622 | status, change, NULL); |
|---|
| 619 | 623 | } |
|---|
| 620 | 624 | |
|---|
| 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 | + |
|---|
| 621 | 655 | static void kick_hub_wq(struct usb_hub *hub) |
|---|
| 622 | 656 | { |
|---|
| 623 | 657 | struct usb_interface *intf; |
|---|
| .. | .. |
|---|
| 702 | 736 | if ((++hub->nerrors < 10) || hub->error) |
|---|
| 703 | 737 | goto resubmit; |
|---|
| 704 | 738 | hub->error = status; |
|---|
| 705 | | - /* FALL THROUGH */ |
|---|
| 739 | + fallthrough; |
|---|
| 706 | 740 | |
|---|
| 707 | 741 | /* let hub_wq handle things */ |
|---|
| 708 | 742 | case 0: /* we got data: port status changed */ |
|---|
| .. | .. |
|---|
| 720 | 754 | kick_hub_wq(hub); |
|---|
| 721 | 755 | |
|---|
| 722 | 756 | 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); |
|---|
| 729 | 758 | } |
|---|
| 730 | 759 | |
|---|
| 731 | 760 | /* USB 2.0 spec Section 11.24.2.3 */ |
|---|
| .. | .. |
|---|
| 857 | 886 | /* info that CLEAR_TT_BUFFER needs */ |
|---|
| 858 | 887 | clear->tt = tt->multi ? udev->ttport : 1; |
|---|
| 859 | 888 | clear->devinfo = usb_pipeendpoint (pipe); |
|---|
| 860 | | - clear->devinfo |= udev->devnum << 4; |
|---|
| 889 | + clear->devinfo |= ((u16)udev->devaddr) << 4; |
|---|
| 861 | 890 | clear->devinfo |= usb_pipecontrol(pipe) |
|---|
| 862 | 891 | ? (USB_ENDPOINT_XFER_CONTROL << 11) |
|---|
| 863 | 892 | : (USB_ENDPOINT_XFER_BULK << 11); |
|---|
| .. | .. |
|---|
| 1288 | 1317 | static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) |
|---|
| 1289 | 1318 | { |
|---|
| 1290 | 1319 | struct usb_device *hdev = hub->hdev; |
|---|
| 1320 | + unsigned long flags; |
|---|
| 1291 | 1321 | int i; |
|---|
| 1292 | 1322 | |
|---|
| 1293 | 1323 | /* hub_wq and related activity won't re-trigger */ |
|---|
| 1324 | + spin_lock_irqsave(&hub->irq_urb_lock, flags); |
|---|
| 1294 | 1325 | hub->quiescing = 1; |
|---|
| 1326 | + spin_unlock_irqrestore(&hub->irq_urb_lock, flags); |
|---|
| 1295 | 1327 | |
|---|
| 1296 | 1328 | if (type != HUB_SUSPEND) { |
|---|
| 1297 | 1329 | /* Disconnect all the children */ |
|---|
| .. | .. |
|---|
| 1302 | 1334 | } |
|---|
| 1303 | 1335 | |
|---|
| 1304 | 1336 | /* Stop hub_wq and related activity */ |
|---|
| 1337 | + del_timer_sync(&hub->irq_urb_retry); |
|---|
| 1305 | 1338 | usb_kill_urb(hub->urb); |
|---|
| 1306 | 1339 | if (hub->has_indicators) |
|---|
| 1307 | 1340 | cancel_delayed_work_sync(&hub->leds); |
|---|
| .. | .. |
|---|
| 1814 | 1847 | return -E2BIG; |
|---|
| 1815 | 1848 | } |
|---|
| 1816 | 1849 | |
|---|
| 1817 | | -#ifdef CONFIG_USB_OTG_BLACKLIST_HUB |
|---|
| 1850 | +#ifdef CONFIG_USB_OTG_DISABLE_EXTERNAL_HUB |
|---|
| 1818 | 1851 | if (hdev->parent) { |
|---|
| 1819 | 1852 | dev_warn(&intf->dev, "ignoring external hub\n"); |
|---|
| 1820 | 1853 | return -ENODEV; |
|---|
| .. | .. |
|---|
| 1839 | 1872 | INIT_DELAYED_WORK(&hub->leds, led_work); |
|---|
| 1840 | 1873 | INIT_DELAYED_WORK(&hub->init_work, NULL); |
|---|
| 1841 | 1874 | 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); |
|---|
| 1842 | 1877 | usb_get_intf(intf); |
|---|
| 1843 | 1878 | usb_get_dev(hdev); |
|---|
| 1844 | 1879 | |
|---|
| .. | .. |
|---|
| 2121 | 2156 | /* The address for a WUSB device is managed by wusbcore. */ |
|---|
| 2122 | 2157 | if (!udev->wusb) |
|---|
| 2123 | 2158 | udev->devnum = devnum; |
|---|
| 2159 | + if (!udev->devaddr) |
|---|
| 2160 | + udev->devaddr = (u8)devnum; |
|---|
| 2124 | 2161 | } |
|---|
| 2125 | 2162 | |
|---|
| 2126 | 2163 | static void hub_free_dev(struct usb_device *udev) |
|---|
| .. | .. |
|---|
| 2344 | 2381 | * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal) |
|---|
| 2345 | 2382 | * @udev: newly addressed device (in ADDRESS state) |
|---|
| 2346 | 2383 | * |
|---|
| 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. |
|---|
| 2350 | 2386 | * |
|---|
| 2351 | 2387 | * If the device is WUSB and not authorized, we don't attempt to read |
|---|
| 2352 | 2388 | * the string descriptors, as they will be errored out by the device |
|---|
| .. | .. |
|---|
| 2379 | 2415 | if (err < 0) |
|---|
| 2380 | 2416 | return err; |
|---|
| 2381 | 2417 | |
|---|
| 2382 | | - if (IS_ENABLED(CONFIG_USB_OTG_WHITELIST) && hcd->tpl_support && |
|---|
| 2418 | + if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support && |
|---|
| 2383 | 2419 | !is_targeted(udev)) { |
|---|
| 2384 | 2420 | /* Maybe it can talk to us, though we can't talk to it. |
|---|
| 2385 | 2421 | * (Includes HNP test device.) |
|---|
| .. | .. |
|---|
| 2611 | 2647 | } |
|---|
| 2612 | 2648 | |
|---|
| 2613 | 2649 | 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); |
|---|
| 2616 | 2655 | dev_err(&usb_dev->dev, "can't re-read device descriptor for " |
|---|
| 2617 | 2656 | "authorization: %d\n", result); |
|---|
| 2618 | 2657 | goto error_device_descriptor; |
|---|
| 2619 | 2658 | } |
|---|
| 2659 | + usb_dev->descriptor = *descr; |
|---|
| 2660 | + kfree(descr); |
|---|
| 2620 | 2661 | } |
|---|
| 2621 | 2662 | |
|---|
| 2622 | 2663 | usb_dev->authorized = 1; |
|---|
| .. | .. |
|---|
| 2681 | 2722 | } |
|---|
| 2682 | 2723 | |
|---|
| 2683 | 2724 | |
|---|
| 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 |
|---|
| 2684 | 2733 | #define PORT_RESET_TRIES 5 |
|---|
| 2685 | 2734 | #define SET_ADDRESS_TRIES 2 |
|---|
| 2686 | 2735 | #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 */ |
|---|
| 2689 | 2739 | |
|---|
| 2690 | 2740 | #define HUB_ROOT_RESET_TIME 60 /* times are in msec */ |
|---|
| 2691 | 2741 | #define HUB_SHORT_RESET_TIME 10 |
|---|
| .. | .. |
|---|
| 2693 | 2743 | #define HUB_LONG_RESET_TIME 200 |
|---|
| 2694 | 2744 | #define HUB_RESET_TIMEOUT 800 |
|---|
| 2695 | 2745 | |
|---|
| 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 | | - */ |
|---|
| 2703 | 2746 | static bool use_new_scheme(struct usb_device *udev, int retry, |
|---|
| 2704 | 2747 | struct usb_port *port_dev) |
|---|
| 2705 | 2748 | { |
|---|
| 2706 | 2749 | 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; |
|---|
| 2708 | 2752 | |
|---|
| 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 | + */ |
|---|
| 2709 | 2760 | if (udev->speed >= USB_SPEED_SUPER) |
|---|
| 2710 | 2761 | return false; |
|---|
| 2711 | 2762 | |
|---|
| 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 */ |
|---|
| 2713 | 2771 | } |
|---|
| 2714 | 2772 | |
|---|
| 2715 | 2773 | /* 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 |
|---|
| 2717 | 2775 | */ |
|---|
| 2718 | 2776 | static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1, |
|---|
| 2719 | 2777 | u16 portstatus) |
|---|
| .. | .. |
|---|
| 3177 | 3235 | } |
|---|
| 3178 | 3236 | |
|---|
| 3179 | 3237 | /* 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) |
|---|
| 3181 | 3239 | { |
|---|
| 3182 | 3240 | struct usb_hub *hub = usb_hub_to_struct_hub(udev); |
|---|
| 3183 | 3241 | |
|---|
| 3184 | 3242 | return udev->do_remote_wakeup + |
|---|
| 3185 | 3243 | (hub ? hub->wakeup_enabled_descendants : 0); |
|---|
| 3186 | 3244 | } |
|---|
| 3245 | +EXPORT_SYMBOL_GPL(usb_wakeup_enabled_descendants); |
|---|
| 3187 | 3246 | |
|---|
| 3188 | 3247 | /* |
|---|
| 3189 | 3248 | * usb_port_suspend - suspend a usb device's upstream port |
|---|
| .. | .. |
|---|
| 3285 | 3344 | * Therefore we will turn on the suspend feature if udev or any of its |
|---|
| 3286 | 3345 | * descendants is enabled for remote wakeup. |
|---|
| 3287 | 3346 | */ |
|---|
| 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) |
|---|
| 3289 | 3348 | status = set_port_feature(hub->hdev, port1, |
|---|
| 3290 | 3349 | USB_PORT_FEAT_SUSPEND); |
|---|
| 3291 | 3350 | else { |
|---|
| .. | .. |
|---|
| 3513 | 3572 | u16 portchange, portstatus; |
|---|
| 3514 | 3573 | |
|---|
| 3515 | 3574 | 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); |
|---|
| 3517 | 3576 | if (status < 0) { |
|---|
| 3518 | 3577 | dev_dbg(&udev->dev, "can't resume usb port, status %d\n", |
|---|
| 3519 | 3578 | status); |
|---|
| .. | .. |
|---|
| 3674 | 3733 | struct usb_hub *hub = usb_get_intfdata(intf); |
|---|
| 3675 | 3734 | struct usb_device *hdev = hub->hdev; |
|---|
| 3676 | 3735 | unsigned port1; |
|---|
| 3677 | | - int status; |
|---|
| 3678 | 3736 | |
|---|
| 3679 | 3737 | /* |
|---|
| 3680 | 3738 | * Warn if children aren't already suspended. |
|---|
| .. | .. |
|---|
| 3693 | 3751 | } |
|---|
| 3694 | 3752 | if (udev) |
|---|
| 3695 | 3753 | hub->wakeup_enabled_descendants += |
|---|
| 3696 | | - wakeup_enabled_descendants(udev); |
|---|
| 3754 | + usb_wakeup_enabled_descendants(udev); |
|---|
| 3697 | 3755 | } |
|---|
| 3698 | 3756 | |
|---|
| 3699 | 3757 | if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { |
|---|
| .. | .. |
|---|
| 3708 | 3766 | if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) { |
|---|
| 3709 | 3767 | /* Enable hub to send remote wakeup for all ports. */ |
|---|
| 3710 | 3768 | 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); |
|---|
| 3717 | 3775 | } |
|---|
| 3718 | 3776 | } |
|---|
| 3719 | 3777 | |
|---|
| .. | .. |
|---|
| 4193 | 4251 | if (!udev || !udev->parent || |
|---|
| 4194 | 4252 | udev->speed < USB_SPEED_SUPER || |
|---|
| 4195 | 4253 | !udev->lpm_capable || |
|---|
| 4196 | | - udev->state < USB_STATE_DEFAULT) |
|---|
| 4254 | + udev->state < USB_STATE_CONFIGURED) |
|---|
| 4197 | 4255 | return 0; |
|---|
| 4198 | 4256 | |
|---|
| 4199 | 4257 | hcd = bus_to_hcd(udev->bus); |
|---|
| .. | .. |
|---|
| 4252 | 4310 | if (!udev || !udev->parent || |
|---|
| 4253 | 4311 | udev->speed < USB_SPEED_SUPER || |
|---|
| 4254 | 4312 | !udev->lpm_capable || |
|---|
| 4255 | | - udev->state < USB_STATE_DEFAULT) |
|---|
| 4313 | + udev->state < USB_STATE_CONFIGURED) |
|---|
| 4256 | 4314 | return; |
|---|
| 4257 | 4315 | |
|---|
| 4258 | 4316 | udev->lpm_disable_count--; |
|---|
| .. | .. |
|---|
| 4542 | 4600 | return hcd->driver->enable_device(hcd, udev); |
|---|
| 4543 | 4601 | } |
|---|
| 4544 | 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 | + |
|---|
| 4545 | 4664 | /* Reset device, (re)assign address, get device descriptor. |
|---|
| 4546 | 4665 | * Device connection must be stable, no more debouncing needed. |
|---|
| 4547 | 4666 | * Returns device in USB_STATE_ADDRESS, except on error. |
|---|
| .. | .. |
|---|
| 4551 | 4670 | * the port lock. For a newly detected device that is not accessible |
|---|
| 4552 | 4671 | * through any global pointers, it's not necessary to lock the device, |
|---|
| 4553 | 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. |
|---|
| 4554 | 4680 | */ |
|---|
| 4555 | 4681 | static int |
|---|
| 4556 | 4682 | 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) |
|---|
| 4558 | 4684 | { |
|---|
| 4559 | 4685 | struct usb_device *hdev = hub->hdev; |
|---|
| 4560 | 4686 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); |
|---|
| .. | .. |
|---|
| 4565 | 4691 | const char *speed; |
|---|
| 4566 | 4692 | int devnum = udev->devnum; |
|---|
| 4567 | 4693 | 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; |
|---|
| 4568 | 4702 | |
|---|
| 4569 | 4703 | /* root hub ports have a slightly longer reset period |
|---|
| 4570 | 4704 | * (from USB 2.0 spec, section 7.1.7.5) |
|---|
| .. | .. |
|---|
| 4597 | 4731 | } |
|---|
| 4598 | 4732 | oldspeed = udev->speed; |
|---|
| 4599 | 4733 | |
|---|
| 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]. |
|---|
| 4618 | 4739 | */ |
|---|
| 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 | + } |
|---|
| 4626 | 4762 | } |
|---|
| 4627 | 4763 | |
|---|
| 4628 | 4764 | if (udev->speed == USB_SPEED_WIRELESS) |
|---|
| .. | .. |
|---|
| 4645 | 4781 | if (udev->speed < USB_SPEED_SUPER) |
|---|
| 4646 | 4782 | dev_info(&udev->dev, |
|---|
| 4647 | 4783 | "%s %s USB device number %d using %s\n", |
|---|
| 4648 | | - (udev->config) ? "reset" : "new", speed, |
|---|
| 4784 | + (initial ? "new" : "reset"), speed, |
|---|
| 4649 | 4785 | devnum, driver_name); |
|---|
| 4650 | 4786 | |
|---|
| 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; |
|---|
| 4661 | 4801 | } |
|---|
| 4662 | | - udev->tt = &hub->tt; |
|---|
| 4663 | | - udev->ttport = port1; |
|---|
| 4664 | 4802 | } |
|---|
| 4665 | 4803 | |
|---|
| 4666 | 4804 | /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way? |
|---|
| .. | .. |
|---|
| 4675 | 4813 | * first 8 bytes of the device descriptor to get the ep0 maxpacket |
|---|
| 4676 | 4814 | * value. |
|---|
| 4677 | 4815 | */ |
|---|
| 4816 | + do_new_scheme = use_new_scheme(udev, retry_counter, port_dev); |
|---|
| 4817 | + |
|---|
| 4678 | 4818 | 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) { |
|---|
| 4686 | 4820 | retval = hub_enable_device(udev); |
|---|
| 4687 | 4821 | if (retval < 0) { |
|---|
| 4688 | 4822 | dev_err(&udev->dev, |
|---|
| .. | .. |
|---|
| 4691 | 4825 | goto fail; |
|---|
| 4692 | 4826 | } |
|---|
| 4693 | 4827 | |
|---|
| 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; |
|---|
| 4699 | 4835 | } |
|---|
| 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); |
|---|
| 4739 | 4836 | |
|---|
| 4740 | 4837 | retval = hub_port_reset(hub, port1, udev, delay, false); |
|---|
| 4741 | 4838 | if (retval < 0) /* error or disconnect */ |
|---|
| .. | .. |
|---|
| 4746 | 4843 | retval = -ENODEV; |
|---|
| 4747 | 4844 | goto fail; |
|---|
| 4748 | 4845 | } |
|---|
| 4749 | | - if (r) { |
|---|
| 4750 | | - if (r != -ENODEV) |
|---|
| 4846 | + if (maxp0 < 0) { |
|---|
| 4847 | + if (maxp0 != -ENODEV) |
|---|
| 4751 | 4848 | dev_err(&udev->dev, "device descriptor read/64, error %d\n", |
|---|
| 4752 | | - r); |
|---|
| 4753 | | - retval = -EMSGSIZE; |
|---|
| 4849 | + maxp0); |
|---|
| 4850 | + retval = maxp0; |
|---|
| 4754 | 4851 | continue; |
|---|
| 4755 | 4852 | } |
|---|
| 4756 | | -#undef GET_DESCRIPTOR_BUFSIZE |
|---|
| 4757 | 4853 | } |
|---|
| 4758 | 4854 | |
|---|
| 4759 | 4855 | /* |
|---|
| .. | .. |
|---|
| 4791 | 4887 | * - read ep0 maxpacket even for high and low speed, |
|---|
| 4792 | 4888 | */ |
|---|
| 4793 | 4889 | 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) |
|---|
| 4799 | 4891 | break; |
|---|
| 4800 | 4892 | } |
|---|
| 4801 | 4893 | |
|---|
| 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; |
|---|
| 4804 | 4898 | if (retval != -ENODEV) |
|---|
| 4805 | 4899 | dev_err(&udev->dev, |
|---|
| 4806 | 4900 | "device descriptor read/8, error %d\n", |
|---|
| 4807 | 4901 | retval); |
|---|
| 4808 | | - if (retval >= 0) |
|---|
| 4809 | | - retval = -EMSGSIZE; |
|---|
| 4810 | 4902 | } else { |
|---|
| 4811 | 4903 | u32 delay; |
|---|
| 4812 | 4904 | |
|---|
| 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 | + } |
|---|
| 4814 | 4910 | |
|---|
| 4815 | 4911 | delay = udev->parent->hub_delay; |
|---|
| 4816 | 4912 | udev->hub_delay = min_t(u32, delay, |
|---|
| .. | .. |
|---|
| 4829 | 4925 | goto fail; |
|---|
| 4830 | 4926 | |
|---|
| 4831 | 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 | + /* |
|---|
| 4832 | 4973 | * Some superspeed devices have finished the link training process |
|---|
| 4833 | 4974 | * and attached to a superspeed hub port, but the device descriptor |
|---|
| 4834 | 4975 | * got from those devices show they aren't superspeed devices. Warm |
|---|
| .. | .. |
|---|
| 4836 | 4977 | */ |
|---|
| 4837 | 4978 | if ((udev->speed >= USB_SPEED_SUPER) && |
|---|
| 4838 | 4979 | (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); |
|---|
| 4843 | 4982 | 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; |
|---|
| 4874 | 4983 | goto fail; |
|---|
| 4875 | 4984 | } |
|---|
| 4876 | 4985 | |
|---|
| .. | .. |
|---|
| 4894 | 5003 | hub_port_disable(hub, port1, 0); |
|---|
| 4895 | 5004 | update_devnum(udev, devnum); /* for disconnect processing */ |
|---|
| 4896 | 5005 | } |
|---|
| 5006 | + kfree(buf); |
|---|
| 4897 | 5007 | return retval; |
|---|
| 4898 | 5008 | } |
|---|
| 4899 | 5009 | |
|---|
| .. | .. |
|---|
| 4972 | 5082 | return remaining; |
|---|
| 4973 | 5083 | } |
|---|
| 4974 | 5084 | |
|---|
| 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 | + |
|---|
| 4975 | 5170 | static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, |
|---|
| 4976 | 5171 | u16 portchange) |
|---|
| 4977 | 5172 | { |
|---|
| .. | .. |
|---|
| 5040 | 5235 | |
|---|
| 5041 | 5236 | status = 0; |
|---|
| 5042 | 5237 | |
|---|
| 5043 | | - for (i = 0; i < SET_CONFIG_TRIES; i++) { |
|---|
| 5238 | + for (i = 0; i < PORT_INIT_TRIES; i++) { |
|---|
| 5044 | 5239 | usb_lock_port(port_dev); |
|---|
| 5045 | 5240 | mutex_lock(hcd->address0_mutex); |
|---|
| 5046 | 5241 | retry_locked = true; |
|---|
| 5047 | | - |
|---|
| 5048 | 5242 | /* reallocate for each attempt, since references |
|---|
| 5049 | 5243 | * to the previous one can escape in various ways |
|---|
| 5050 | 5244 | */ |
|---|
| .. | .. |
|---|
| 5075 | 5269 | } |
|---|
| 5076 | 5270 | |
|---|
| 5077 | 5271 | /* 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); |
|---|
| 5079 | 5273 | if (status < 0) |
|---|
| 5080 | 5274 | goto loop; |
|---|
| 5081 | 5275 | |
|---|
| .. | .. |
|---|
| 5184 | 5378 | break; |
|---|
| 5185 | 5379 | |
|---|
| 5186 | 5380 | /* 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) { |
|---|
| 5188 | 5382 | dev_info(&port_dev->dev, "attempt power cycle\n"); |
|---|
| 5189 | 5383 | usb_hub_set_port_power(hdev, hub, port1, false); |
|---|
| 5190 | 5384 | msleep(2 * hub_power_on_good_delay(hub)); |
|---|
| 5191 | | - set_bit(HCD_FLAG_POWER_ON, &hcd->flags); |
|---|
| 5192 | 5385 | usb_hub_set_port_power(hdev, hub, port1, true); |
|---|
| 5193 | 5386 | msleep(hub_power_on_good_delay(hub)); |
|---|
| 5194 | 5387 | } |
|---|
| .. | .. |
|---|
| 5205 | 5398 | hub_port_disable(hub, port1, 1); |
|---|
| 5206 | 5399 | if (hcd->driver->relinquish_port && !hub->hdev->parent) { |
|---|
| 5207 | 5400 | if ((status != -ENOTCONN && status != -ENODEV) || |
|---|
| 5208 | | - (status == -ENOTCONN && hcd->rk3288_relinquish_port_quirk)) |
|---|
| 5401 | + (status == -ENOTCONN && of_machine_is_compatible("rockchip,rk3288"))) |
|---|
| 5209 | 5402 | hcd->driver->relinquish_port(hcd, port1); |
|---|
| 5210 | 5403 | } |
|---|
| 5211 | 5404 | } |
|---|
| .. | .. |
|---|
| 5224 | 5417 | { |
|---|
| 5225 | 5418 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
|---|
| 5226 | 5419 | struct usb_device *udev = port_dev->child; |
|---|
| 5420 | + struct usb_device_descriptor *descr; |
|---|
| 5227 | 5421 | int status = -ENODEV; |
|---|
| 5228 | 5422 | |
|---|
| 5229 | 5423 | dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, |
|---|
| .. | .. |
|---|
| 5245 | 5439 | if ((portstatus & USB_PORT_STAT_CONNECTION) && udev && |
|---|
| 5246 | 5440 | udev->state != USB_STATE_NOTATTACHED) { |
|---|
| 5247 | 5441 | 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 | + } |
|---|
| 5249 | 5463 | #ifdef CONFIG_PM |
|---|
| 5250 | 5464 | } else if (udev->state == USB_STATE_SUSPENDED && |
|---|
| 5251 | 5465 | udev->persist_enabled) { |
|---|
| .. | .. |
|---|
| 5269 | 5483 | usb_unlock_port(port_dev); |
|---|
| 5270 | 5484 | hub_port_connect(hub, port1, portstatus, portchange); |
|---|
| 5271 | 5485 | 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); |
|---|
| 5272 | 5523 | } |
|---|
| 5273 | 5524 | |
|---|
| 5274 | 5525 | static void port_event(struct usb_hub *hub, int port1) |
|---|
| .. | .. |
|---|
| 5313 | 5564 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { |
|---|
| 5314 | 5565 | u16 status = 0, unused; |
|---|
| 5315 | 5566 | port_dev->over_current_count++; |
|---|
| 5567 | + port_over_current_notify(port_dev); |
|---|
| 5316 | 5568 | |
|---|
| 5317 | 5569 | dev_dbg(&port_dev->dev, "over-current change #%u\n", |
|---|
| 5318 | 5570 | port_dev->over_current_count); |
|---|
| .. | .. |
|---|
| 5367 | 5619 | } else { |
|---|
| 5368 | 5620 | usb_unlock_port(port_dev); |
|---|
| 5369 | 5621 | 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); |
|---|
| 5388 | 5623 | usb_unlock_device(udev); |
|---|
| 5389 | 5624 | usb_lock_port(port_dev); |
|---|
| 5390 | 5625 | connect_change = 0; |
|---|
| .. | .. |
|---|
| 5540 | 5775 | .idVendor = USB_VENDOR_GENESYS_LOGIC, |
|---|
| 5541 | 5776 | .bInterfaceClass = USB_CLASS_HUB, |
|---|
| 5542 | 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}, |
|---|
| 5543 | 5788 | { .match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS, |
|---|
| 5544 | 5789 | .bDeviceClass = USB_CLASS_HUB}, |
|---|
| 5545 | 5790 | { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, |
|---|
| .. | .. |
|---|
| 5602 | 5847 | usb_deregister(&hub_driver); |
|---|
| 5603 | 5848 | } /* usb_hub_cleanup() */ |
|---|
| 5604 | 5849 | |
|---|
| 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 | | - |
|---|
| 5689 | 5850 | /** |
|---|
| 5690 | 5851 | * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device |
|---|
| 5691 | 5852 | * @udev: device to reset (not in SUSPENDED or NOTATTACHED state) |
|---|
| .. | .. |
|---|
| 5725 | 5886 | struct usb_device *parent_hdev = udev->parent; |
|---|
| 5726 | 5887 | struct usb_hub *parent_hub; |
|---|
| 5727 | 5888 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
|---|
| 5728 | | - struct usb_device_descriptor descriptor = udev->descriptor; |
|---|
| 5889 | + struct usb_device_descriptor descriptor; |
|---|
| 5729 | 5890 | struct usb_host_bos *bos; |
|---|
| 5730 | 5891 | int i, j, ret = 0; |
|---|
| 5731 | 5892 | int port1 = udev->portnum; |
|---|
| .. | .. |
|---|
| 5762 | 5923 | |
|---|
| 5763 | 5924 | mutex_lock(hcd->address0_mutex); |
|---|
| 5764 | 5925 | |
|---|
| 5765 | | - for (i = 0; i < SET_CONFIG_TRIES; ++i) { |
|---|
| 5926 | + for (i = 0; i < PORT_INIT_TRIES; ++i) { |
|---|
| 5766 | 5927 | |
|---|
| 5767 | 5928 | /* ep0 maxpacket size may change; let the HCD know about it. |
|---|
| 5768 | 5929 | * Other endpoints will be handled by re-enumeration. */ |
|---|
| 5769 | 5930 | 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); |
|---|
| 5771 | 5932 | if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) |
|---|
| 5772 | 5933 | break; |
|---|
| 5773 | 5934 | } |
|---|
| .. | .. |
|---|
| 5779 | 5940 | /* Device might have changed firmware (DFU or similar) */ |
|---|
| 5780 | 5941 | if (descriptors_changed(udev, &descriptor, bos)) { |
|---|
| 5781 | 5942 | dev_info(&udev->dev, "device firmware changed\n"); |
|---|
| 5782 | | - udev->descriptor = descriptor; /* for disconnect() calls */ |
|---|
| 5783 | 5943 | goto re_enumerate; |
|---|
| 5784 | 5944 | } |
|---|
| 5785 | 5945 | |
|---|