forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/usb/core/hcd.c
....@@ -29,6 +29,9 @@
2929 #include <linux/workqueue.h>
3030 #include <linux/pm_runtime.h>
3131 #include <linux/types.h>
32
+#include <linux/genalloc.h>
33
+#include <linux/io.h>
34
+#include <linux/kcov.h>
3235
3336 #include <linux/phy/phy.h>
3437 #include <linux/usb.h>
....@@ -100,11 +103,6 @@
100103
101104 /* wait queue for synchronous unlinks */
102105 DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);
103
-
104
-static inline int is_root_hub(struct usb_device *udev)
105
-{
106
- return (udev->parent == NULL);
107
-}
108106
109107 /*-------------------------------------------------------------------------*/
110108
....@@ -373,13 +371,19 @@
373371 * -1 is authorized for all devices except wireless (old behaviour)
374372 * 0 is unauthorized for all devices
375373 * 1 is authorized for all devices
374
+ * 2 is authorized for internal devices
376375 */
377
-static int authorized_default = -1;
376
+#define USB_AUTHORIZE_WIRED -1
377
+#define USB_AUTHORIZE_NONE 0
378
+#define USB_AUTHORIZE_ALL 1
379
+#define USB_AUTHORIZE_INTERNAL 2
380
+
381
+static int authorized_default = USB_AUTHORIZE_WIRED;
378382 module_param(authorized_default, int, S_IRUGO|S_IWUSR);
379383 MODULE_PARM_DESC(authorized_default,
380384 "Default USB device authorization: 0 is not authorized, 1 is "
381
- "authorized, -1 is authorized except for wireless USB (default, "
382
- "old behaviour");
385
+ "authorized, 2 is authorized for internal devices, -1 is "
386
+ "authorized except for wireless USB (default, old behaviour)");
383387 /*-------------------------------------------------------------------------*/
384388
385389 /**
....@@ -560,7 +564,7 @@
560564 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
561565 tbuf[0] = 1;
562566 len = 1;
563
- /* FALLTHROUGH */
567
+ fallthrough;
564568 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
565569 break;
566570 case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
....@@ -629,7 +633,7 @@
629633 case DeviceRequest | USB_REQ_GET_INTERFACE:
630634 tbuf[0] = 0;
631635 len = 1;
632
- /* FALLTHROUGH */
636
+ fallthrough;
633637 case DeviceOutRequest | USB_REQ_SET_INTERFACE:
634638 break;
635639 case DeviceOutRequest | USB_REQ_SET_ADDRESS:
....@@ -647,7 +651,7 @@
647651 tbuf[0] = 0;
648652 tbuf[1] = 0;
649653 len = 2;
650
- /* FALLTHROUGH */
654
+ fallthrough;
651655 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
652656 case EndpointOutRequest | USB_REQ_SET_FEATURE:
653657 dev_dbg (hcd->self.controller, "no endpoint features yet\n");
....@@ -879,104 +883,6 @@
879883 }
880884
881885
882
-
883
-/*
884
- * Show & store the current value of authorized_default
885
- */
886
-static ssize_t authorized_default_show(struct device *dev,
887
- struct device_attribute *attr, char *buf)
888
-{
889
- struct usb_device *rh_usb_dev = to_usb_device(dev);
890
- struct usb_bus *usb_bus = rh_usb_dev->bus;
891
- struct usb_hcd *hcd;
892
-
893
- hcd = bus_to_hcd(usb_bus);
894
- return snprintf(buf, PAGE_SIZE, "%u\n", !!HCD_DEV_AUTHORIZED(hcd));
895
-}
896
-
897
-static ssize_t authorized_default_store(struct device *dev,
898
- struct device_attribute *attr,
899
- const char *buf, size_t size)
900
-{
901
- ssize_t result;
902
- unsigned val;
903
- struct usb_device *rh_usb_dev = to_usb_device(dev);
904
- struct usb_bus *usb_bus = rh_usb_dev->bus;
905
- struct usb_hcd *hcd;
906
-
907
- hcd = bus_to_hcd(usb_bus);
908
- result = sscanf(buf, "%u\n", &val);
909
- if (result == 1) {
910
- if (val)
911
- set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
912
- else
913
- clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
914
-
915
- result = size;
916
- } else {
917
- result = -EINVAL;
918
- }
919
- return result;
920
-}
921
-static DEVICE_ATTR_RW(authorized_default);
922
-
923
-/*
924
- * interface_authorized_default_show - show default authorization status
925
- * for USB interfaces
926
- *
927
- * note: interface_authorized_default is the default value
928
- * for initializing the authorized attribute of interfaces
929
- */
930
-static ssize_t interface_authorized_default_show(struct device *dev,
931
- struct device_attribute *attr, char *buf)
932
-{
933
- struct usb_device *usb_dev = to_usb_device(dev);
934
- struct usb_hcd *hcd = bus_to_hcd(usb_dev->bus);
935
-
936
- return sprintf(buf, "%u\n", !!HCD_INTF_AUTHORIZED(hcd));
937
-}
938
-
939
-/*
940
- * interface_authorized_default_store - store default authorization status
941
- * for USB interfaces
942
- *
943
- * note: interface_authorized_default is the default value
944
- * for initializing the authorized attribute of interfaces
945
- */
946
-static ssize_t interface_authorized_default_store(struct device *dev,
947
- struct device_attribute *attr, const char *buf, size_t count)
948
-{
949
- struct usb_device *usb_dev = to_usb_device(dev);
950
- struct usb_hcd *hcd = bus_to_hcd(usb_dev->bus);
951
- int rc = count;
952
- bool val;
953
-
954
- if (strtobool(buf, &val) != 0)
955
- return -EINVAL;
956
-
957
- if (val)
958
- set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags);
959
- else
960
- clear_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags);
961
-
962
- return rc;
963
-}
964
-static DEVICE_ATTR_RW(interface_authorized_default);
965
-
966
-/* Group all the USB bus attributes */
967
-static struct attribute *usb_bus_attrs[] = {
968
- &dev_attr_authorized_default.attr,
969
- &dev_attr_interface_authorized_default.attr,
970
- NULL,
971
-};
972
-
973
-static const struct attribute_group usb_bus_attr_group = {
974
- .name = NULL, /* we want them in the same directory */
975
- .attrs = usb_bus_attrs,
976
-};
977
-
978
-
979
-
980886 /*-------------------------------------------------------------------------*/
981887
982888 /**
....@@ -1081,8 +987,6 @@
1081987
1082988 usb_dev->devnum = devnum;
1083989 usb_dev->bus->devnum_next = devnum + 1;
1084
- memset (&usb_dev->bus->devmap.devicemap, 0,
1085
- sizeof usb_dev->bus->devmap.devicemap);
1086990 set_bit (devnum, usb_dev->bus->devmap.devicemap);
1087991 usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
1088992
....@@ -1351,14 +1255,11 @@
13511255 * using regular system memory - like pci devices doing bus mastering.
13521256 *
13531257 * To support host controllers with limited dma capabilities we provide dma
1354
- * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag.
1355
- * For this to work properly the host controller code must first use the
1356
- * function dma_declare_coherent_memory() to point out which memory area
1357
- * that should be used for dma allocations.
1258
+ * bounce buffers. This feature can be enabled by initializing
1259
+ * hcd->localmem_pool using usb_hcd_setup_local_mem().
13581260 *
1359
- * The HCD_LOCAL_MEM flag then tells the usb code to allocate all data for
1360
- * dma using dma_alloc_coherent() which in turn allocates from the memory
1361
- * area pointed out with dma_declare_coherent_memory().
1261
+ * The initialized hcd->localmem_pool then tells the usb code to allocate all
1262
+ * data for dma using the genalloc API.
13621263 *
13631264 * So, to summarize...
13641265 *
....@@ -1367,9 +1268,6 @@
13671268 * only memory that the controller can read ...
13681269 * (a) "normal" kernel memory is no good, and
13691270 * (b) there's not enough to share
1370
- *
1371
- * - The only *portable* hook for such stuff in the
1372
- * DMA framework is dma_declare_coherent_memory()
13731271 *
13741272 * - So we use that, even though the primary requirement
13751273 * is that the memory be "local" (hence addressable
....@@ -1519,11 +1417,18 @@
15191417 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
15201418 if (hcd->self.uses_pio_for_control)
15211419 return ret;
1522
- if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
1523
- if (is_vmalloc_addr(urb->setup_packet)) {
1524
- WARN_ONCE(1, "setup packet is not dma capable\n");
1525
- return -EAGAIN;
1526
- } else if (object_is_on_stack(urb->setup_packet)) {
1420
+ if (hcd->localmem_pool) {
1421
+ ret = hcd_alloc_coherent(
1422
+ urb->dev->bus, mem_flags,
1423
+ &urb->setup_dma,
1424
+ (void **)&urb->setup_packet,
1425
+ sizeof(struct usb_ctrlrequest),
1426
+ DMA_TO_DEVICE);
1427
+ if (ret)
1428
+ return ret;
1429
+ urb->transfer_flags |= URB_SETUP_MAP_LOCAL;
1430
+ } else if (hcd_uses_dma(hcd)) {
1431
+ if (object_is_on_stack(urb->setup_packet)) {
15271432 WARN_ONCE(1, "setup packet is on stack\n");
15281433 return -EAGAIN;
15291434 }
....@@ -1537,23 +1442,22 @@
15371442 urb->setup_dma))
15381443 return -EAGAIN;
15391444 urb->transfer_flags |= URB_SETUP_MAP_SINGLE;
1540
- } else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1541
- ret = hcd_alloc_coherent(
1542
- urb->dev->bus, mem_flags,
1543
- &urb->setup_dma,
1544
- (void **)&urb->setup_packet,
1545
- sizeof(struct usb_ctrlrequest),
1546
- DMA_TO_DEVICE);
1547
- if (ret)
1548
- return ret;
1549
- urb->transfer_flags |= URB_SETUP_MAP_LOCAL;
15501445 }
15511446 }
15521447
15531448 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
15541449 if (urb->transfer_buffer_length != 0
15551450 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1556
- if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
1451
+ if (hcd->localmem_pool) {
1452
+ ret = hcd_alloc_coherent(
1453
+ urb->dev->bus, mem_flags,
1454
+ &urb->transfer_dma,
1455
+ &urb->transfer_buffer,
1456
+ urb->transfer_buffer_length,
1457
+ dir);
1458
+ if (ret == 0)
1459
+ urb->transfer_flags |= URB_MAP_LOCAL;
1460
+ } else if (hcd_uses_dma(hcd)) {
15571461 if (urb->num_sgs) {
15581462 int n;
15591463
....@@ -1589,9 +1493,6 @@
15891493 ret = -EAGAIN;
15901494 else
15911495 urb->transfer_flags |= URB_DMA_MAP_PAGE;
1592
- } else if (is_vmalloc_addr(urb->transfer_buffer)) {
1593
- WARN_ONCE(1, "transfer buffer not dma capable\n");
1594
- ret = -EAGAIN;
15951496 } else if (object_is_on_stack(urb->transfer_buffer)) {
15961497 WARN_ONCE(1, "transfer buffer is on stack\n");
15971498 ret = -EAGAIN;
....@@ -1607,15 +1508,6 @@
16071508 else
16081509 urb->transfer_flags |= URB_DMA_MAP_SINGLE;
16091510 }
1610
- } else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1611
- ret = hcd_alloc_coherent(
1612
- urb->dev->bus, mem_flags,
1613
- &urb->transfer_dma,
1614
- &urb->transfer_buffer,
1615
- urb->transfer_buffer_length,
1616
- dir);
1617
- if (ret == 0)
1618
- urb->transfer_flags |= URB_MAP_LOCAL;
16191511 }
16201512 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
16211513 URB_SETUP_MAP_LOCAL)))
....@@ -1752,7 +1644,6 @@
17521644 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
17531645 struct usb_anchor *anchor = urb->anchor;
17541646 int status = urb->unlinked;
1755
- unsigned long flags;
17561647
17571648 urb->hcpriv = NULL;
17581649 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
....@@ -1769,20 +1660,16 @@
17691660
17701661 /* pass ownership to the completion handler */
17711662 urb->status = status;
1772
-
17731663 /*
1774
- * We disable local IRQs here avoid possible deadlock because
1775
- * drivers may call spin_lock() to hold lock which might be
1776
- * acquired in one hard interrupt handler.
1777
- *
1778
- * The local_irq_save()/local_irq_restore() around complete()
1779
- * will be removed if current USB drivers have been cleaned up
1780
- * and no one may trigger the above deadlock situation when
1781
- * running complete() in tasklet.
1664
+ * This function can be called in task context inside another remote
1665
+ * coverage collection section, but KCOV doesn't support that kind of
1666
+ * recursion yet. Only collect coverage in softirq context for now.
17821667 */
1783
- local_irq_save(flags);
1668
+ if (in_serving_softirq())
1669
+ kcov_remote_start_usb((u64)urb->dev->bus->busnum);
17841670 urb->complete(urb);
1785
- local_irq_restore(flags);
1671
+ if (in_serving_softirq())
1672
+ kcov_remote_stop();
17861673
17871674 usb_anchor_resume_wakeups(anchor);
17881675 atomic_dec(&urb->use_count);
....@@ -1798,9 +1685,9 @@
17981685 usb_put_urb(urb);
17991686 }
18001687
1801
-static void usb_giveback_urb_bh(unsigned long param)
1688
+static void usb_giveback_urb_bh(struct tasklet_struct *t)
18021689 {
1803
- struct giveback_urb_bh *bh = (struct giveback_urb_bh *)param;
1690
+ struct giveback_urb_bh *bh = from_tasklet(bh, t, bh);
18041691 struct list_head local_list;
18051692
18061693 spin_lock_irq(&bh->lock);
....@@ -1912,23 +1799,10 @@
19121799 /* kick hcd */
19131800 unlink1(hcd, urb, -ESHUTDOWN);
19141801 dev_dbg (hcd->self.controller,
1915
- "shutdown urb %pK ep%d%s%s\n",
1802
+ "shutdown urb %pK ep%d%s-%s\n",
19161803 urb, usb_endpoint_num(&ep->desc),
19171804 is_in ? "in" : "out",
1918
- ({ char *s;
1919
-
1920
- switch (usb_endpoint_type(&ep->desc)) {
1921
- case USB_ENDPOINT_XFER_CONTROL:
1922
- s = ""; break;
1923
- case USB_ENDPOINT_XFER_BULK:
1924
- s = "-bulk"; break;
1925
- case USB_ENDPOINT_XFER_INT:
1926
- s = "-intr"; break;
1927
- default:
1928
- s = "-iso"; break;
1929
- };
1930
- s;
1931
- }));
1805
+ usb_ep_type_string(usb_endpoint_type(&ep->desc)));
19321806 usb_put_urb (urb);
19331807
19341808 /* list contents may have changed */
....@@ -2254,71 +2128,7 @@
22542128 return hcd->driver->get_frame_number (hcd);
22552129 }
22562130
2257
-int usb_hcd_sec_event_ring_setup(struct usb_device *udev,
2258
- unsigned int intr_num)
2259
-{
2260
- struct usb_hcd *hcd = bus_to_hcd(udev->bus);
2261
-
2262
- if (!HCD_RH_RUNNING(hcd))
2263
- return 0;
2264
-
2265
- return hcd->driver->sec_event_ring_setup(hcd, intr_num);
2266
-}
2267
-
2268
-int usb_hcd_sec_event_ring_cleanup(struct usb_device *udev,
2269
- unsigned int intr_num)
2270
-{
2271
- struct usb_hcd *hcd = bus_to_hcd(udev->bus);
2272
-
2273
- if (!HCD_RH_RUNNING(hcd))
2274
- return 0;
2275
-
2276
- return hcd->driver->sec_event_ring_cleanup(hcd, intr_num);
2277
-}
2278
-
22792131 /*-------------------------------------------------------------------------*/
2280
-
2281
-phys_addr_t
2282
-usb_hcd_get_sec_event_ring_phys_addr(struct usb_device *udev,
2283
- unsigned int intr_num, dma_addr_t *dma)
2284
-{
2285
- struct usb_hcd *hcd = bus_to_hcd(udev->bus);
2286
-
2287
- if (!HCD_RH_RUNNING(hcd))
2288
- return 0;
2289
-
2290
- return hcd->driver->get_sec_event_ring_phys_addr(hcd, intr_num, dma);
2291
-}
2292
-
2293
-phys_addr_t
2294
-usb_hcd_get_xfer_ring_phys_addr(struct usb_device *udev,
2295
- struct usb_host_endpoint *ep, dma_addr_t *dma)
2296
-{
2297
- struct usb_hcd *hcd = bus_to_hcd(udev->bus);
2298
-
2299
- if (!HCD_RH_RUNNING(hcd))
2300
- return 0;
2301
-
2302
- return hcd->driver->get_xfer_ring_phys_addr(hcd, udev, ep, dma);
2303
-}
2304
-
2305
-int usb_hcd_get_controller_id(struct usb_device *udev)
2306
-{
2307
- struct usb_hcd *hcd = bus_to_hcd(udev->bus);
2308
-
2309
- if (!HCD_RH_RUNNING(hcd))
2310
- return -EINVAL;
2311
-
2312
- return hcd->driver->get_core_id(hcd);
2313
-}
2314
-
2315
-int usb_hcd_stop_endpoint(struct usb_device *udev,
2316
- struct usb_host_endpoint *ep)
2317
-{
2318
- struct usb_hcd *hcd = bus_to_hcd(udev->bus);
2319
-
2320
- return hcd->driver->stop_endpoint(hcd, udev, ep);
2321
-}
23222132
23232133 #ifdef CONFIG_PM
23242134
....@@ -2403,6 +2213,9 @@
24032213 hcd->state = HC_STATE_RESUMING;
24042214 status = hcd->driver->bus_resume(hcd);
24052215 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
2216
+ if (status == 0)
2217
+ status = usb_phy_roothub_calibrate(hcd->phy_roothub);
2218
+
24062219 if (status == 0) {
24072220 struct usb_device *udev;
24082221 int port1;
....@@ -2546,6 +2359,19 @@
25462359
25472360 /*-------------------------------------------------------------------------*/
25482361
2362
+/* Workqueue routine for when the root-hub has died. */
2363
+static void hcd_died_work(struct work_struct *work)
2364
+{
2365
+ struct usb_hcd *hcd = container_of(work, struct usb_hcd, died_work);
2366
+ static char *env[] = {
2367
+ "ERROR=DEAD",
2368
+ NULL
2369
+ };
2370
+
2371
+ /* Notify user space that the host controller has died */
2372
+ kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env);
2373
+}
2374
+
25492375 /**
25502376 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
25512377 * @hcd: pointer to the HCD representing the controller
....@@ -2586,9 +2412,15 @@
25862412 usb_kick_hub_wq(hcd->self.root_hub);
25872413 }
25882414 }
2415
+
2416
+ /* Handle the case where this function gets called with a shared HCD */
2417
+ if (usb_hcd_is_primary_hcd(hcd))
2418
+ schedule_work(&hcd->died_work);
2419
+ else
2420
+ schedule_work(&hcd->primary_hcd->died_work);
2421
+
25892422 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
25902423 /* Make sure that the other roothub is also deallocated. */
2591
- usb_atomic_notify_dead_bus(&hcd->self);
25922424 }
25932425 EXPORT_SYMBOL_GPL (usb_hc_died);
25942426
....@@ -2599,7 +2431,7 @@
25992431
26002432 spin_lock_init(&bh->lock);
26012433 INIT_LIST_HEAD(&bh->head);
2602
- tasklet_init(&bh->bh, usb_giveback_urb_bh, (unsigned long)bh);
2434
+ tasklet_setup(&bh->bh, usb_giveback_urb_bh);
26032435 }
26042436
26052437 struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
....@@ -2647,12 +2479,13 @@
26472479 hcd->self.controller = dev;
26482480 hcd->self.sysdev = sysdev;
26492481 hcd->self.bus_name = bus_name;
2650
- hcd->self.uses_dma = (sysdev->dma_mask != NULL);
26512482
26522483 timer_setup(&hcd->rh_timer, rh_timer_func, 0);
26532484 #ifdef CONFIG_PM
26542485 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
26552486 #endif
2487
+
2488
+ INIT_WORK(&hcd->died_work, hcd_died_work);
26562489
26572490 hcd->driver = driver;
26582491 hcd->speed = driver->flags & HCD_MASK;
....@@ -2828,6 +2661,7 @@
28282661 {
28292662 int retval;
28302663 struct usb_device *rhdev;
2664
+ struct usb_hcd *shared_hcd;
28312665
28322666 if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
28332667 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
....@@ -2838,6 +2672,14 @@
28382672 if (retval)
28392673 return retval;
28402674
2675
+ retval = usb_phy_roothub_set_mode(hcd->phy_roothub,
2676
+ PHY_MODE_USB_HOST_SS);
2677
+ if (retval)
2678
+ retval = usb_phy_roothub_set_mode(hcd->phy_roothub,
2679
+ PHY_MODE_USB_HOST);
2680
+ if (retval)
2681
+ goto err_usb_phy_roothub_power_on;
2682
+
28412683 retval = usb_phy_roothub_power_on(hcd->phy_roothub);
28422684 if (retval)
28432685 goto err_usb_phy_roothub_power_on;
....@@ -2845,18 +2687,26 @@
28452687
28462688 dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
28472689
2848
- /* Keep old behaviour if authorized_default is not in [0, 1]. */
2849
- if (authorized_default < 0 || authorized_default > 1) {
2850
- if (hcd->wireless)
2851
- clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
2852
- else
2853
- set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
2854
- } else {
2855
- if (authorized_default)
2856
- set_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
2857
- else
2858
- clear_bit(HCD_FLAG_DEV_AUTHORIZED, &hcd->flags);
2690
+ switch (authorized_default) {
2691
+ case USB_AUTHORIZE_NONE:
2692
+ hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE;
2693
+ break;
2694
+
2695
+ case USB_AUTHORIZE_ALL:
2696
+ hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL;
2697
+ break;
2698
+
2699
+ case USB_AUTHORIZE_INTERNAL:
2700
+ hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL;
2701
+ break;
2702
+
2703
+ case USB_AUTHORIZE_WIRED:
2704
+ default:
2705
+ hcd->dev_policy = hcd->wireless ?
2706
+ USB_DEVICE_AUTHORIZE_NONE : USB_DEVICE_AUTHORIZE_ALL;
2707
+ break;
28592708 }
2709
+
28602710 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
28612711
28622712 /* per default all interfaces are authorized */
....@@ -2905,7 +2755,7 @@
29052755 case HCD_USB32:
29062756 rhdev->rx_lanes = 2;
29072757 rhdev->tx_lanes = 2;
2908
- /* fall through */
2758
+ fallthrough;
29092759 case HCD_USB31:
29102760 rhdev->speed = USB_SPEED_SUPER_PLUS;
29112761 break;
....@@ -2939,6 +2789,10 @@
29392789 }
29402790 hcd->rh_pollable = 1;
29412791
2792
+ retval = usb_phy_roothub_calibrate(hcd->phy_roothub);
2793
+ if (retval)
2794
+ goto err_hcd_driver_setup;
2795
+
29422796 /* NOTE: root hub and controller capabilities may not be the same */
29432797 if (device_can_wakeup(hcd->self.controller)
29442798 && device_can_wakeup(&hcd->self.root_hub->dev))
....@@ -2964,36 +2818,29 @@
29642818 goto err_hcd_driver_start;
29652819 }
29662820
2967
- /* starting here, usbcore will pay attention to this root hub */
2968
- retval = register_root_hub(hcd);
2969
- if (retval != 0)
2970
- goto err_register_root_hub;
2821
+ /* starting here, usbcore will pay attention to the shared HCD roothub */
2822
+ shared_hcd = hcd->shared_hcd;
2823
+ if (!usb_hcd_is_primary_hcd(hcd) && shared_hcd && HCD_DEFER_RH_REGISTER(shared_hcd)) {
2824
+ retval = register_root_hub(shared_hcd);
2825
+ if (retval != 0)
2826
+ goto err_register_root_hub;
29712827
2972
- retval = sysfs_create_group(&rhdev->dev.kobj, &usb_bus_attr_group);
2973
- if (retval < 0) {
2974
- printk(KERN_ERR "Cannot register USB bus sysfs attributes: %d\n",
2975
- retval);
2976
- goto error_create_attr_group;
2828
+ if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd))
2829
+ usb_hcd_poll_rh_status(shared_hcd);
29772830 }
2978
- if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
2979
- usb_hcd_poll_rh_status(hcd);
2831
+
2832
+ /* starting here, usbcore will pay attention to this root hub */
2833
+ if (!HCD_DEFER_RH_REGISTER(hcd)) {
2834
+ retval = register_root_hub(hcd);
2835
+ if (retval != 0)
2836
+ goto err_register_root_hub;
2837
+
2838
+ if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
2839
+ usb_hcd_poll_rh_status(hcd);
2840
+ }
29802841
29812842 return retval;
29822843
2983
-error_create_attr_group:
2984
- clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2985
- if (HC_IS_RUNNING(hcd->state))
2986
- hcd->state = HC_STATE_QUIESCING;
2987
- spin_lock_irq(&hcd_root_hub_lock);
2988
- hcd->rh_registered = 0;
2989
- spin_unlock_irq(&hcd_root_hub_lock);
2990
-
2991
-#ifdef CONFIG_PM
2992
- cancel_work_sync(&hcd->wakeup_work);
2993
-#endif
2994
- mutex_lock(&usb_bus_idr_lock);
2995
- usb_disconnect(&rhdev); /* Sets rhdev to NULL */
2996
- mutex_unlock(&usb_bus_idr_lock);
29972844 err_register_root_hub:
29982845 hcd->rh_pollable = 0;
29992846 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
....@@ -3033,27 +2880,29 @@
30332880 void usb_remove_hcd(struct usb_hcd *hcd)
30342881 {
30352882 struct usb_device *rhdev = hcd->self.root_hub;
2883
+ bool rh_registered;
30362884
30372885 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state);
30382886
30392887 usb_get_dev(rhdev);
3040
- sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
3041
-
30422888 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
30432889 if (HC_IS_RUNNING (hcd->state))
30442890 hcd->state = HC_STATE_QUIESCING;
30452891
30462892 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n");
30472893 spin_lock_irq (&hcd_root_hub_lock);
2894
+ rh_registered = hcd->rh_registered;
30482895 hcd->rh_registered = 0;
30492896 spin_unlock_irq (&hcd_root_hub_lock);
30502897
30512898 #ifdef CONFIG_PM
30522899 cancel_work_sync(&hcd->wakeup_work);
30532900 #endif
2901
+ cancel_work_sync(&hcd->died_work);
30542902
30552903 mutex_lock(&usb_bus_idr_lock);
3056
- usb_disconnect(&rhdev); /* Sets rhdev to NULL */
2904
+ if (rh_registered)
2905
+ usb_disconnect(&rhdev); /* Sets rhdev to NULL */
30572906 mutex_unlock(&usb_bus_idr_lock);
30582907
30592908 /*
....@@ -3111,6 +2960,40 @@
31112960 }
31122961 EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
31132962
2963
+int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr,
2964
+ dma_addr_t dma, size_t size)
2965
+{
2966
+ int err;
2967
+ void *local_mem;
2968
+
2969
+ hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4,
2970
+ dev_to_node(hcd->self.sysdev),
2971
+ dev_name(hcd->self.sysdev));
2972
+ if (IS_ERR(hcd->localmem_pool))
2973
+ return PTR_ERR(hcd->localmem_pool);
2974
+
2975
+ local_mem = devm_memremap(hcd->self.sysdev, phys_addr,
2976
+ size, MEMREMAP_WC);
2977
+ if (IS_ERR(local_mem))
2978
+ return PTR_ERR(local_mem);
2979
+
2980
+ /*
2981
+ * Here we pass a dma_addr_t but the arg type is a phys_addr_t.
2982
+ * It's not backed by system memory and thus there's no kernel mapping
2983
+ * for it.
2984
+ */
2985
+ err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem,
2986
+ dma, size, dev_to_node(hcd->self.sysdev));
2987
+ if (err < 0) {
2988
+ dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n",
2989
+ err);
2990
+ return err;
2991
+ }
2992
+
2993
+ return 0;
2994
+}
2995
+EXPORT_SYMBOL_GPL(usb_hcd_setup_local_mem);
2996
+
31142997 /*-------------------------------------------------------------------------*/
31152998
31162999 #if IS_ENABLED(CONFIG_USB_MON)