forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/drivers/usb/core/hub.c
....@@ -29,12 +29,13 @@
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
....@@ -95,7 +96,7 @@
9596 MODULE_PARM_DESC(old_scheme_first,
9697 "start with the old device initialization scheme");
9798
98
-static bool use_both_schemes = 1;
99
+static bool use_both_schemes = true;
99100 module_param(use_both_schemes, bool, S_IRUGO | S_IWUSR);
100101 MODULE_PARM_DESC(use_both_schemes,
101102 "try the other device initialization scheme if the "
....@@ -618,6 +619,36 @@
618619 status, change, NULL);
619620 }
620621
622
+static void hub_resubmit_irq_urb(struct usb_hub *hub)
623
+{
624
+ unsigned long flags;
625
+ int status;
626
+
627
+ spin_lock_irqsave(&hub->irq_urb_lock, flags);
628
+
629
+ if (hub->quiescing) {
630
+ spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
631
+ return;
632
+ }
633
+
634
+ status = usb_submit_urb(hub->urb, GFP_ATOMIC);
635
+ if (status && status != -ENODEV && status != -EPERM &&
636
+ status != -ESHUTDOWN) {
637
+ dev_err(hub->intfdev, "resubmit --> %d\n", status);
638
+ mod_timer(&hub->irq_urb_retry, jiffies + HZ);
639
+ }
640
+
641
+ spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
642
+}
643
+
644
+static void hub_retry_irq_urb(struct timer_list *t)
645
+{
646
+ struct usb_hub *hub = from_timer(hub, t, irq_urb_retry);
647
+
648
+ hub_resubmit_irq_urb(hub);
649
+}
650
+
651
+
621652 static void kick_hub_wq(struct usb_hub *hub)
622653 {
623654 struct usb_interface *intf;
....@@ -702,7 +733,7 @@
702733 if ((++hub->nerrors < 10) || hub->error)
703734 goto resubmit;
704735 hub->error = status;
705
- /* FALL THROUGH */
736
+ fallthrough;
706737
707738 /* let hub_wq handle things */
708739 case 0: /* we got data: port status changed */
....@@ -720,12 +751,7 @@
720751 kick_hub_wq(hub);
721752
722753 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);
754
+ hub_resubmit_irq_urb(hub);
729755 }
730756
731757 /* USB 2.0 spec Section 11.24.2.3 */
....@@ -857,7 +883,7 @@
857883 /* info that CLEAR_TT_BUFFER needs */
858884 clear->tt = tt->multi ? udev->ttport : 1;
859885 clear->devinfo = usb_pipeendpoint (pipe);
860
- clear->devinfo |= udev->devnum << 4;
886
+ clear->devinfo |= ((u16)udev->devaddr) << 4;
861887 clear->devinfo |= usb_pipecontrol(pipe)
862888 ? (USB_ENDPOINT_XFER_CONTROL << 11)
863889 : (USB_ENDPOINT_XFER_BULK << 11);
....@@ -1288,10 +1314,13 @@
12881314 static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type)
12891315 {
12901316 struct usb_device *hdev = hub->hdev;
1317
+ unsigned long flags;
12911318 int i;
12921319
12931320 /* hub_wq and related activity won't re-trigger */
1321
+ spin_lock_irqsave(&hub->irq_urb_lock, flags);
12941322 hub->quiescing = 1;
1323
+ spin_unlock_irqrestore(&hub->irq_urb_lock, flags);
12951324
12961325 if (type != HUB_SUSPEND) {
12971326 /* Disconnect all the children */
....@@ -1302,6 +1331,7 @@
13021331 }
13031332
13041333 /* Stop hub_wq and related activity */
1334
+ del_timer_sync(&hub->irq_urb_retry);
13051335 usb_kill_urb(hub->urb);
13061336 if (hub->has_indicators)
13071337 cancel_delayed_work_sync(&hub->leds);
....@@ -1814,7 +1844,7 @@
18141844 return -E2BIG;
18151845 }
18161846
1817
-#ifdef CONFIG_USB_OTG_BLACKLIST_HUB
1847
+#ifdef CONFIG_USB_OTG_DISABLE_EXTERNAL_HUB
18181848 if (hdev->parent) {
18191849 dev_warn(&intf->dev, "ignoring external hub\n");
18201850 return -ENODEV;
....@@ -1839,6 +1869,8 @@
18391869 INIT_DELAYED_WORK(&hub->leds, led_work);
18401870 INIT_DELAYED_WORK(&hub->init_work, NULL);
18411871 INIT_WORK(&hub->events, hub_event);
1872
+ spin_lock_init(&hub->irq_urb_lock);
1873
+ timer_setup(&hub->irq_urb_retry, hub_retry_irq_urb, 0);
18421874 usb_get_intf(intf);
18431875 usb_get_dev(hdev);
18441876
....@@ -2121,6 +2153,8 @@
21212153 /* The address for a WUSB device is managed by wusbcore. */
21222154 if (!udev->wusb)
21232155 udev->devnum = devnum;
2156
+ if (!udev->devaddr)
2157
+ udev->devaddr = (u8)devnum;
21242158 }
21252159
21262160 static void hub_free_dev(struct usb_device *udev)
....@@ -2379,7 +2413,7 @@
23792413 if (err < 0)
23802414 return err;
23812415
2382
- if (IS_ENABLED(CONFIG_USB_OTG_WHITELIST) && hcd->tpl_support &&
2416
+ if (IS_ENABLED(CONFIG_USB_OTG_PRODUCTLIST) && hcd->tpl_support &&
23832417 !is_targeted(udev)) {
23842418 /* Maybe it can talk to us, though we can't talk to it.
23852419 * (Includes HNP test device.)
....@@ -2681,11 +2715,20 @@
26812715 }
26822716
26832717
2718
+#ifdef CONFIG_USB_FEW_INIT_RETRIES
2719
+#define PORT_RESET_TRIES 2
2720
+#define SET_ADDRESS_TRIES 1
2721
+#define GET_DESCRIPTOR_TRIES 1
2722
+#define GET_MAXPACKET0_TRIES 1
2723
+#define PORT_INIT_TRIES 4
2724
+
2725
+#else
26842726 #define PORT_RESET_TRIES 5
26852727 #define SET_ADDRESS_TRIES 2
26862728 #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))
2729
+#define GET_MAXPACKET0_TRIES 3
2730
+#define PORT_INIT_TRIES 4
2731
+#endif /* CONFIG_USB_FEW_INIT_RETRIES */
26892732
26902733 #define HUB_ROOT_RESET_TIME 60 /* times are in msec */
26912734 #define HUB_SHORT_RESET_TIME 10
....@@ -2693,27 +2736,35 @@
26932736 #define HUB_LONG_RESET_TIME 200
26942737 #define HUB_RESET_TIMEOUT 800
26952738
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
- */
27032739 static bool use_new_scheme(struct usb_device *udev, int retry,
27042740 struct usb_port *port_dev)
27052741 {
27062742 int old_scheme_first_port =
2707
- port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME;
2743
+ (port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME) ||
2744
+ old_scheme_first;
27082745
2746
+ /*
2747
+ * "New scheme" enumeration causes an extra state transition to be
2748
+ * exposed to an xhci host and causes USB3 devices to receive control
2749
+ * commands in the default state. This has been seen to cause
2750
+ * enumeration failures, so disable this enumeration scheme for USB3
2751
+ * devices.
2752
+ */
27092753 if (udev->speed >= USB_SPEED_SUPER)
27102754 return false;
27112755
2712
- return USE_NEW_SCHEME(retry, old_scheme_first_port || old_scheme_first);
2756
+ /*
2757
+ * If use_both_schemes is set, use the first scheme (whichever
2758
+ * it is) for the larger half of the retries, then use the other
2759
+ * scheme. Otherwise, use the first scheme for all the retries.
2760
+ */
2761
+ if (use_both_schemes && retry >= (PORT_INIT_TRIES + 1) / 2)
2762
+ return old_scheme_first_port; /* Second half */
2763
+ return !old_scheme_first_port; /* First half or all */
27132764 }
27142765
27152766 /* Is a USB 3.0 port in the Inactive or Compliance Mode state?
2716
- * Port worm reset is required to recover
2767
+ * Port warm reset is required to recover
27172768 */
27182769 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
27192770 u16 portstatus)
....@@ -3177,13 +3228,14 @@
31773228 }
31783229
31793230 /* Count of wakeup-enabled devices at or below udev */
3180
-static unsigned wakeup_enabled_descendants(struct usb_device *udev)
3231
+unsigned usb_wakeup_enabled_descendants(struct usb_device *udev)
31813232 {
31823233 struct usb_hub *hub = usb_hub_to_struct_hub(udev);
31833234
31843235 return udev->do_remote_wakeup +
31853236 (hub ? hub->wakeup_enabled_descendants : 0);
31863237 }
3238
+EXPORT_SYMBOL_GPL(usb_wakeup_enabled_descendants);
31873239
31883240 /*
31893241 * usb_port_suspend - suspend a usb device's upstream port
....@@ -3285,7 +3337,7 @@
32853337 * Therefore we will turn on the suspend feature if udev or any of its
32863338 * descendants is enabled for remote wakeup.
32873339 */
3288
- else if (PMSG_IS_AUTO(msg) || wakeup_enabled_descendants(udev) > 0)
3340
+ else if (PMSG_IS_AUTO(msg) || usb_wakeup_enabled_descendants(udev) > 0)
32893341 status = set_port_feature(hub->hdev, port1,
32903342 USB_PORT_FEAT_SUSPEND);
32913343 else {
....@@ -3513,7 +3565,7 @@
35133565 u16 portchange, portstatus;
35143566
35153567 if (!test_and_set_bit(port1, hub->child_usage_bits)) {
3516
- status = pm_runtime_get_sync(&port_dev->dev);
3568
+ status = pm_runtime_resume_and_get(&port_dev->dev);
35173569 if (status < 0) {
35183570 dev_dbg(&udev->dev, "can't resume usb port, status %d\n",
35193571 status);
....@@ -3674,7 +3726,6 @@
36743726 struct usb_hub *hub = usb_get_intfdata(intf);
36753727 struct usb_device *hdev = hub->hdev;
36763728 unsigned port1;
3677
- int status;
36783729
36793730 /*
36803731 * Warn if children aren't already suspended.
....@@ -3693,7 +3744,7 @@
36933744 }
36943745 if (udev)
36953746 hub->wakeup_enabled_descendants +=
3696
- wakeup_enabled_descendants(udev);
3747
+ usb_wakeup_enabled_descendants(udev);
36973748 }
36983749
36993750 if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) {
....@@ -3708,12 +3759,12 @@
37083759 if (hub_is_superspeed(hdev) && hdev->do_remote_wakeup) {
37093760 /* Enable hub to send remote wakeup for all ports. */
37103761 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);
3762
+ set_port_feature(hdev,
3763
+ port1 |
3764
+ USB_PORT_FEAT_REMOTE_WAKE_CONNECT |
3765
+ USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT |
3766
+ USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT,
3767
+ USB_PORT_FEAT_REMOTE_WAKE_MASK);
37173768 }
37183769 }
37193770
....@@ -4193,7 +4244,7 @@
41934244 if (!udev || !udev->parent ||
41944245 udev->speed < USB_SPEED_SUPER ||
41954246 !udev->lpm_capable ||
4196
- udev->state < USB_STATE_DEFAULT)
4247
+ udev->state < USB_STATE_CONFIGURED)
41974248 return 0;
41984249
41994250 hcd = bus_to_hcd(udev->bus);
....@@ -4252,7 +4303,7 @@
42524303 if (!udev || !udev->parent ||
42534304 udev->speed < USB_SPEED_SUPER ||
42544305 !udev->lpm_capable ||
4255
- udev->state < USB_STATE_DEFAULT)
4306
+ udev->state < USB_STATE_CONFIGURED)
42564307 return;
42574308
42584309 udev->lpm_disable_count--;
....@@ -4565,6 +4616,7 @@
45654616 const char *speed;
45664617 int devnum = udev->devnum;
45674618 const char *driver_name;
4619
+ bool do_new_scheme;
45684620
45694621 /* root hub ports have a slightly longer reset period
45704622 * (from USB 2.0 spec, section 7.1.7.5)
....@@ -4675,14 +4727,13 @@
46754727 * first 8 bytes of the device descriptor to get the ep0 maxpacket
46764728 * value.
46774729 */
4678
- for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) {
4679
- bool did_new_scheme = false;
4730
+ do_new_scheme = use_new_scheme(udev, retry_counter, port_dev);
46804731
4681
- if (use_new_scheme(udev, retry_counter, port_dev)) {
4732
+ for (retries = 0; retries < GET_DESCRIPTOR_TRIES; (++retries, msleep(100))) {
4733
+ if (do_new_scheme) {
46824734 struct usb_device_descriptor *buf;
46834735 int r = 0;
46844736
4685
- did_new_scheme = true;
46864737 retval = hub_enable_device(udev);
46874738 if (retval < 0) {
46884739 dev_err(&udev->dev,
....@@ -4702,7 +4753,8 @@
47024753 * 255 is for WUSB devices, we actually need to use
47034754 * 512 (WUSB1.0[4.8.1]).
47044755 */
4705
- for (operations = 0; operations < 3; ++operations) {
4756
+ for (operations = 0; operations < GET_MAXPACKET0_TRIES;
4757
+ ++operations) {
47064758 buf->bMaxPacketSize0 = 0;
47074759 r = usb_control_msg(udev, usb_rcvaddr0pipe(),
47084760 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
....@@ -4716,7 +4768,7 @@
47164768 r = 0;
47174769 break;
47184770 }
4719
- /* FALL THROUGH */
4771
+ fallthrough;
47204772 default:
47214773 if (r == 0)
47224774 r = -EPROTO;
....@@ -4791,11 +4843,7 @@
47914843 * - read ep0 maxpacket even for high and low speed,
47924844 */
47934845 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)
4846
+ if (do_new_scheme)
47994847 break;
48004848 }
48014849
....@@ -4972,6 +5020,91 @@
49725020 return remaining;
49735021 }
49745022
5023
+
5024
+static int descriptors_changed(struct usb_device *udev,
5025
+ struct usb_device_descriptor *old_device_descriptor,
5026
+ struct usb_host_bos *old_bos)
5027
+{
5028
+ int changed = 0;
5029
+ unsigned index;
5030
+ unsigned serial_len = 0;
5031
+ unsigned len;
5032
+ unsigned old_length;
5033
+ int length;
5034
+ char *buf;
5035
+
5036
+ if (memcmp(&udev->descriptor, old_device_descriptor,
5037
+ sizeof(*old_device_descriptor)) != 0)
5038
+ return 1;
5039
+
5040
+ if ((old_bos && !udev->bos) || (!old_bos && udev->bos))
5041
+ return 1;
5042
+ if (udev->bos) {
5043
+ len = le16_to_cpu(udev->bos->desc->wTotalLength);
5044
+ if (len != le16_to_cpu(old_bos->desc->wTotalLength))
5045
+ return 1;
5046
+ if (memcmp(udev->bos->desc, old_bos->desc, len))
5047
+ return 1;
5048
+ }
5049
+
5050
+ /* Since the idVendor, idProduct, and bcdDevice values in the
5051
+ * device descriptor haven't changed, we will assume the
5052
+ * Manufacturer and Product strings haven't changed either.
5053
+ * But the SerialNumber string could be different (e.g., a
5054
+ * different flash card of the same brand).
5055
+ */
5056
+ if (udev->serial)
5057
+ serial_len = strlen(udev->serial) + 1;
5058
+
5059
+ len = serial_len;
5060
+ for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5061
+ old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5062
+ len = max(len, old_length);
5063
+ }
5064
+
5065
+ buf = kmalloc(len, GFP_NOIO);
5066
+ if (!buf)
5067
+ /* assume the worst */
5068
+ return 1;
5069
+
5070
+ for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5071
+ old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5072
+ length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf,
5073
+ old_length);
5074
+ if (length != old_length) {
5075
+ dev_dbg(&udev->dev, "config index %d, error %d\n",
5076
+ index, length);
5077
+ changed = 1;
5078
+ break;
5079
+ }
5080
+ if (memcmp(buf, udev->rawdescriptors[index], old_length)
5081
+ != 0) {
5082
+ dev_dbg(&udev->dev, "config index %d changed (#%d)\n",
5083
+ index,
5084
+ ((struct usb_config_descriptor *) buf)->
5085
+ bConfigurationValue);
5086
+ changed = 1;
5087
+ break;
5088
+ }
5089
+ }
5090
+
5091
+ if (!changed && serial_len) {
5092
+ length = usb_string(udev, udev->descriptor.iSerialNumber,
5093
+ buf, serial_len);
5094
+ if (length + 1 != serial_len) {
5095
+ dev_dbg(&udev->dev, "serial string error %d\n",
5096
+ length);
5097
+ changed = 1;
5098
+ } else if (memcmp(buf, udev->serial, length) != 0) {
5099
+ dev_dbg(&udev->dev, "serial string changed\n");
5100
+ changed = 1;
5101
+ }
5102
+ }
5103
+
5104
+ kfree(buf);
5105
+ return changed;
5106
+}
5107
+
49755108 static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
49765109 u16 portchange)
49775110 {
....@@ -5040,11 +5173,10 @@
50405173
50415174 status = 0;
50425175
5043
- for (i = 0; i < SET_CONFIG_TRIES; i++) {
5176
+ for (i = 0; i < PORT_INIT_TRIES; i++) {
50445177 usb_lock_port(port_dev);
50455178 mutex_lock(hcd->address0_mutex);
50465179 retry_locked = true;
5047
-
50485180 /* reallocate for each attempt, since references
50495181 * to the previous one can escape in various ways
50505182 */
....@@ -5184,7 +5316,7 @@
51845316 break;
51855317
51865318 /* When halfway through our retry count, power-cycle the port */
5187
- if (i == (SET_CONFIG_TRIES / 2) - 1) {
5319
+ if (i == (PORT_INIT_TRIES - 1) / 2) {
51885320 dev_info(&port_dev->dev, "attempt power cycle\n");
51895321 usb_hub_set_port_power(hdev, hub, port1, false);
51905322 msleep(2 * hub_power_on_good_delay(hub));
....@@ -5204,7 +5336,7 @@
52045336 hub_port_disable(hub, port1, 1);
52055337 if (hcd->driver->relinquish_port && !hub->hdev->parent) {
52065338 if ((status != -ENOTCONN && status != -ENODEV) ||
5207
- (status == -ENOTCONN && hcd->rk3288_relinquish_port_quirk))
5339
+ (status == -ENOTCONN && of_machine_is_compatible("rockchip,rk3288")))
52085340 hcd->driver->relinquish_port(hcd, port1);
52095341 }
52105342 }
....@@ -5223,7 +5355,9 @@
52235355 {
52245356 struct usb_port *port_dev = hub->ports[port1 - 1];
52255357 struct usb_device *udev = port_dev->child;
5358
+ struct usb_device_descriptor descriptor;
52265359 int status = -ENODEV;
5360
+ int retval;
52275361
52285362 dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus,
52295363 portchange, portspeed(hub, portstatus));
....@@ -5244,7 +5378,30 @@
52445378 if ((portstatus & USB_PORT_STAT_CONNECTION) && udev &&
52455379 udev->state != USB_STATE_NOTATTACHED) {
52465380 if (portstatus & USB_PORT_STAT_ENABLE) {
5247
- status = 0; /* Nothing to do */
5381
+ /*
5382
+ * USB-3 connections are initialized automatically by
5383
+ * the hostcontroller hardware. Therefore check for
5384
+ * changed device descriptors before resuscitating the
5385
+ * device.
5386
+ */
5387
+ descriptor = udev->descriptor;
5388
+ retval = usb_get_device_descriptor(udev,
5389
+ sizeof(udev->descriptor));
5390
+ if (retval < 0) {
5391
+ dev_dbg(&udev->dev,
5392
+ "can't read device descriptor %d\n",
5393
+ retval);
5394
+ } else {
5395
+ if (descriptors_changed(udev, &descriptor,
5396
+ udev->bos)) {
5397
+ dev_dbg(&udev->dev,
5398
+ "device descriptor has changed\n");
5399
+ /* for disconnect() calls */
5400
+ udev->descriptor = descriptor;
5401
+ } else {
5402
+ status = 0; /* Nothing to do */
5403
+ }
5404
+ }
52485405 #ifdef CONFIG_PM
52495406 } else if (udev->state == USB_STATE_SUSPENDED &&
52505407 udev->persist_enabled) {
....@@ -5268,6 +5425,43 @@
52685425 usb_unlock_port(port_dev);
52695426 hub_port_connect(hub, port1, portstatus, portchange);
52705427 usb_lock_port(port_dev);
5428
+}
5429
+
5430
+/* Handle notifying userspace about hub over-current events */
5431
+static void port_over_current_notify(struct usb_port *port_dev)
5432
+{
5433
+ char *envp[3];
5434
+ struct device *hub_dev;
5435
+ char *port_dev_path;
5436
+
5437
+ sysfs_notify(&port_dev->dev.kobj, NULL, "over_current_count");
5438
+
5439
+ hub_dev = port_dev->dev.parent;
5440
+
5441
+ if (!hub_dev)
5442
+ return;
5443
+
5444
+ port_dev_path = kobject_get_path(&port_dev->dev.kobj, GFP_KERNEL);
5445
+ if (!port_dev_path)
5446
+ return;
5447
+
5448
+ envp[0] = kasprintf(GFP_KERNEL, "OVER_CURRENT_PORT=%s", port_dev_path);
5449
+ if (!envp[0])
5450
+ goto exit_path;
5451
+
5452
+ envp[1] = kasprintf(GFP_KERNEL, "OVER_CURRENT_COUNT=%u",
5453
+ port_dev->over_current_count);
5454
+ if (!envp[1])
5455
+ goto exit;
5456
+
5457
+ envp[2] = NULL;
5458
+ kobject_uevent_env(&hub_dev->kobj, KOBJ_CHANGE, envp);
5459
+
5460
+ kfree(envp[1]);
5461
+exit:
5462
+ kfree(envp[0]);
5463
+exit_path:
5464
+ kfree(port_dev_path);
52715465 }
52725466
52735467 static void port_event(struct usb_hub *hub, int port1)
....@@ -5312,6 +5506,7 @@
53125506 if (portchange & USB_PORT_STAT_C_OVERCURRENT) {
53135507 u16 status = 0, unused;
53145508 port_dev->over_current_count++;
5509
+ port_over_current_notify(port_dev);
53155510
53165511 dev_dbg(&port_dev->dev, "over-current change #%u\n",
53175512 port_dev->over_current_count);
....@@ -5366,24 +5561,7 @@
53665561 } else {
53675562 usb_unlock_port(port_dev);
53685563 usb_lock_device(udev);
5369
-
5370
- /**
5371
- * Some special SoCs (e.g. rk322xh) USB3 PHY lose the
5372
- * ability to detect a disconnection when USB3 device
5373
- * plug out, fortunately, it can detect port link state
5374
- * change here, so we can do soft disconnect according
5375
- * to the PLC here.
5376
- *
5377
- * And we only need to do the soft disconnect for root
5378
- * hub. In addition, we just reuse the autosuspend quirk
5379
- * but not add a new quirk for this issue. Because this
5380
- * issue always occurs with autosuspend problem.
5381
- */
5382
- if (!hub->hdev->parent && (hdev->quirks &
5383
- USB_QUIRK_AUTO_SUSPEND))
5384
- usb_remove_device(udev);
5385
- else
5386
- usb_reset_device(udev);
5564
+ usb_reset_device(udev);
53875565 usb_unlock_device(udev);
53885566 usb_lock_port(port_dev);
53895567 connect_change = 0;
....@@ -5601,90 +5779,6 @@
56015779 usb_deregister(&hub_driver);
56025780 } /* usb_hub_cleanup() */
56035781
5604
-static int descriptors_changed(struct usb_device *udev,
5605
- struct usb_device_descriptor *old_device_descriptor,
5606
- struct usb_host_bos *old_bos)
5607
-{
5608
- int changed = 0;
5609
- unsigned index;
5610
- unsigned serial_len = 0;
5611
- unsigned len;
5612
- unsigned old_length;
5613
- int length;
5614
- char *buf;
5615
-
5616
- if (memcmp(&udev->descriptor, old_device_descriptor,
5617
- sizeof(*old_device_descriptor)) != 0)
5618
- return 1;
5619
-
5620
- if ((old_bos && !udev->bos) || (!old_bos && udev->bos))
5621
- return 1;
5622
- if (udev->bos) {
5623
- len = le16_to_cpu(udev->bos->desc->wTotalLength);
5624
- if (len != le16_to_cpu(old_bos->desc->wTotalLength))
5625
- return 1;
5626
- if (memcmp(udev->bos->desc, old_bos->desc, len))
5627
- return 1;
5628
- }
5629
-
5630
- /* Since the idVendor, idProduct, and bcdDevice values in the
5631
- * device descriptor haven't changed, we will assume the
5632
- * Manufacturer and Product strings haven't changed either.
5633
- * But the SerialNumber string could be different (e.g., a
5634
- * different flash card of the same brand).
5635
- */
5636
- if (udev->serial)
5637
- serial_len = strlen(udev->serial) + 1;
5638
-
5639
- len = serial_len;
5640
- for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5641
- old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5642
- len = max(len, old_length);
5643
- }
5644
-
5645
- buf = kmalloc(len, GFP_NOIO);
5646
- if (!buf)
5647
- /* assume the worst */
5648
- return 1;
5649
-
5650
- for (index = 0; index < udev->descriptor.bNumConfigurations; index++) {
5651
- old_length = le16_to_cpu(udev->config[index].desc.wTotalLength);
5652
- length = usb_get_descriptor(udev, USB_DT_CONFIG, index, buf,
5653
- old_length);
5654
- if (length != old_length) {
5655
- dev_dbg(&udev->dev, "config index %d, error %d\n",
5656
- index, length);
5657
- changed = 1;
5658
- break;
5659
- }
5660
- if (memcmp(buf, udev->rawdescriptors[index], old_length)
5661
- != 0) {
5662
- dev_dbg(&udev->dev, "config index %d changed (#%d)\n",
5663
- index,
5664
- ((struct usb_config_descriptor *) buf)->
5665
- bConfigurationValue);
5666
- changed = 1;
5667
- break;
5668
- }
5669
- }
5670
-
5671
- if (!changed && serial_len) {
5672
- length = usb_string(udev, udev->descriptor.iSerialNumber,
5673
- buf, serial_len);
5674
- if (length + 1 != serial_len) {
5675
- dev_dbg(&udev->dev, "serial string error %d\n",
5676
- length);
5677
- changed = 1;
5678
- } else if (memcmp(buf, udev->serial, length) != 0) {
5679
- dev_dbg(&udev->dev, "serial string changed\n");
5680
- changed = 1;
5681
- }
5682
- }
5683
-
5684
- kfree(buf);
5685
- return changed;
5686
-}
5687
-
56885782 /**
56895783 * usb_reset_and_verify_device - perform a USB port reset to reinitialize a device
56905784 * @udev: device to reset (not in SUSPENDED or NOTATTACHED state)
....@@ -5761,7 +5855,7 @@
57615855
57625856 mutex_lock(hcd->address0_mutex);
57635857
5764
- for (i = 0; i < SET_CONFIG_TRIES; ++i) {
5858
+ for (i = 0; i < PORT_INIT_TRIES; ++i) {
57655859
57665860 /* ep0 maxpacket size may change; let the HCD know about it.
57675861 * Other endpoints will be handled by re-enumeration. */