hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
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 /**
....@@ -1076,26 +982,28 @@
1076982 {
1077983 struct device *parent_dev = hcd->self.controller;
1078984 struct usb_device *usb_dev = hcd->self.root_hub;
985
+ struct usb_device_descriptor *descr;
1079986 const int devnum = 1;
1080987 int retval;
1081988
1082989 usb_dev->devnum = devnum;
1083990 usb_dev->bus->devnum_next = devnum + 1;
1084
- memset (&usb_dev->bus->devmap.devicemap, 0,
1085
- sizeof usb_dev->bus->devmap.devicemap);
1086991 set_bit (devnum, usb_dev->bus->devmap.devicemap);
1087992 usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
1088993
1089994 mutex_lock(&usb_bus_idr_lock);
1090995
1091996 usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
1092
- retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
1093
- if (retval != sizeof usb_dev->descriptor) {
997
+ descr = usb_get_device_descriptor(usb_dev);
998
+ if (IS_ERR(descr)) {
999
+ retval = PTR_ERR(descr);
10941000 mutex_unlock(&usb_bus_idr_lock);
10951001 dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
10961002 dev_name(&usb_dev->dev), retval);
1097
- return (retval < 0) ? retval : -EMSGSIZE;
1003
+ return retval;
10981004 }
1005
+ usb_dev->descriptor = *descr;
1006
+ kfree(descr);
10991007
11001008 if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) {
11011009 retval = usb_get_bos_descriptor(usb_dev);
....@@ -1351,14 +1259,11 @@
13511259 * using regular system memory - like pci devices doing bus mastering.
13521260 *
13531261 * 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.
1262
+ * bounce buffers. This feature can be enabled by initializing
1263
+ * hcd->localmem_pool using usb_hcd_setup_local_mem().
13581264 *
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().
1265
+ * The initialized hcd->localmem_pool then tells the usb code to allocate all
1266
+ * data for dma using the genalloc API.
13621267 *
13631268 * So, to summarize...
13641269 *
....@@ -1367,9 +1272,6 @@
13671272 * only memory that the controller can read ...
13681273 * (a) "normal" kernel memory is no good, and
13691274 * (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()
13731275 *
13741276 * - So we use that, even though the primary requirement
13751277 * is that the memory be "local" (hence addressable
....@@ -1519,11 +1421,18 @@
15191421 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
15201422 if (hcd->self.uses_pio_for_control)
15211423 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)) {
1424
+ if (hcd->localmem_pool) {
1425
+ ret = hcd_alloc_coherent(
1426
+ urb->dev->bus, mem_flags,
1427
+ &urb->setup_dma,
1428
+ (void **)&urb->setup_packet,
1429
+ sizeof(struct usb_ctrlrequest),
1430
+ DMA_TO_DEVICE);
1431
+ if (ret)
1432
+ return ret;
1433
+ urb->transfer_flags |= URB_SETUP_MAP_LOCAL;
1434
+ } else if (hcd_uses_dma(hcd)) {
1435
+ if (object_is_on_stack(urb->setup_packet)) {
15271436 WARN_ONCE(1, "setup packet is on stack\n");
15281437 return -EAGAIN;
15291438 }
....@@ -1537,23 +1446,22 @@
15371446 urb->setup_dma))
15381447 return -EAGAIN;
15391448 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;
15501449 }
15511450 }
15521451
15531452 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
15541453 if (urb->transfer_buffer_length != 0
15551454 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1556
- if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
1455
+ if (hcd->localmem_pool) {
1456
+ ret = hcd_alloc_coherent(
1457
+ urb->dev->bus, mem_flags,
1458
+ &urb->transfer_dma,
1459
+ &urb->transfer_buffer,
1460
+ urb->transfer_buffer_length,
1461
+ dir);
1462
+ if (ret == 0)
1463
+ urb->transfer_flags |= URB_MAP_LOCAL;
1464
+ } else if (hcd_uses_dma(hcd)) {
15571465 if (urb->num_sgs) {
15581466 int n;
15591467
....@@ -1589,9 +1497,6 @@
15891497 ret = -EAGAIN;
15901498 else
15911499 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;
15951500 } else if (object_is_on_stack(urb->transfer_buffer)) {
15961501 WARN_ONCE(1, "transfer buffer is on stack\n");
15971502 ret = -EAGAIN;
....@@ -1607,15 +1512,6 @@
16071512 else
16081513 urb->transfer_flags |= URB_DMA_MAP_SINGLE;
16091514 }
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;
16191515 }
16201516 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
16211517 URB_SETUP_MAP_LOCAL)))
....@@ -1752,7 +1648,6 @@
17521648 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
17531649 struct usb_anchor *anchor = urb->anchor;
17541650 int status = urb->unlinked;
1755
- unsigned long flags;
17561651
17571652 urb->hcpriv = NULL;
17581653 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
....@@ -1769,20 +1664,16 @@
17691664
17701665 /* pass ownership to the completion handler */
17711666 urb->status = status;
1772
-
17731667 /*
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.
1668
+ * This function can be called in task context inside another remote
1669
+ * coverage collection section, but KCOV doesn't support that kind of
1670
+ * recursion yet. Only collect coverage in softirq context for now.
17821671 */
1783
- local_irq_save(flags);
1672
+ if (in_serving_softirq())
1673
+ kcov_remote_start_usb((u64)urb->dev->bus->busnum);
17841674 urb->complete(urb);
1785
- local_irq_restore(flags);
1675
+ if (in_serving_softirq())
1676
+ kcov_remote_stop();
17861677
17871678 usb_anchor_resume_wakeups(anchor);
17881679 atomic_dec(&urb->use_count);
....@@ -1798,9 +1689,9 @@
17981689 usb_put_urb(urb);
17991690 }
18001691
1801
-static void usb_giveback_urb_bh(unsigned long param)
1692
+static void usb_giveback_urb_bh(struct tasklet_struct *t)
18021693 {
1803
- struct giveback_urb_bh *bh = (struct giveback_urb_bh *)param;
1694
+ struct giveback_urb_bh *bh = from_tasklet(bh, t, bh);
18041695 struct list_head local_list;
18051696
18061697 spin_lock_irq(&bh->lock);
....@@ -1912,23 +1803,10 @@
19121803 /* kick hcd */
19131804 unlink1(hcd, urb, -ESHUTDOWN);
19141805 dev_dbg (hcd->self.controller,
1915
- "shutdown urb %pK ep%d%s%s\n",
1806
+ "shutdown urb %pK ep%d%s-%s\n",
19161807 urb, usb_endpoint_num(&ep->desc),
19171808 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
- }));
1809
+ usb_ep_type_string(usb_endpoint_type(&ep->desc)));
19321810 usb_put_urb (urb);
19331811
19341812 /* list contents may have changed */
....@@ -2254,71 +2132,7 @@
22542132 return hcd->driver->get_frame_number (hcd);
22552133 }
22562134
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
-
22792135 /*-------------------------------------------------------------------------*/
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
-}
23222136
23232137 #ifdef CONFIG_PM
23242138
....@@ -2403,6 +2217,9 @@
24032217 hcd->state = HC_STATE_RESUMING;
24042218 status = hcd->driver->bus_resume(hcd);
24052219 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
2220
+ if (status == 0)
2221
+ status = usb_phy_roothub_calibrate(hcd->phy_roothub);
2222
+
24062223 if (status == 0) {
24072224 struct usb_device *udev;
24082225 int port1;
....@@ -2546,6 +2363,19 @@
25462363
25472364 /*-------------------------------------------------------------------------*/
25482365
2366
+/* Workqueue routine for when the root-hub has died. */
2367
+static void hcd_died_work(struct work_struct *work)
2368
+{
2369
+ struct usb_hcd *hcd = container_of(work, struct usb_hcd, died_work);
2370
+ static char *env[] = {
2371
+ "ERROR=DEAD",
2372
+ NULL
2373
+ };
2374
+
2375
+ /* Notify user space that the host controller has died */
2376
+ kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env);
2377
+}
2378
+
25492379 /**
25502380 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
25512381 * @hcd: pointer to the HCD representing the controller
....@@ -2586,9 +2416,15 @@
25862416 usb_kick_hub_wq(hcd->self.root_hub);
25872417 }
25882418 }
2419
+
2420
+ /* Handle the case where this function gets called with a shared HCD */
2421
+ if (usb_hcd_is_primary_hcd(hcd))
2422
+ schedule_work(&hcd->died_work);
2423
+ else
2424
+ schedule_work(&hcd->primary_hcd->died_work);
2425
+
25892426 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
25902427 /* Make sure that the other roothub is also deallocated. */
2591
- usb_atomic_notify_dead_bus(&hcd->self);
25922428 }
25932429 EXPORT_SYMBOL_GPL (usb_hc_died);
25942430
....@@ -2599,7 +2435,7 @@
25992435
26002436 spin_lock_init(&bh->lock);
26012437 INIT_LIST_HEAD(&bh->head);
2602
- tasklet_init(&bh->bh, usb_giveback_urb_bh, (unsigned long)bh);
2438
+ tasklet_setup(&bh->bh, usb_giveback_urb_bh);
26032439 }
26042440
26052441 struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
....@@ -2647,12 +2483,13 @@
26472483 hcd->self.controller = dev;
26482484 hcd->self.sysdev = sysdev;
26492485 hcd->self.bus_name = bus_name;
2650
- hcd->self.uses_dma = (sysdev->dma_mask != NULL);
26512486
26522487 timer_setup(&hcd->rh_timer, rh_timer_func, 0);
26532488 #ifdef CONFIG_PM
26542489 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
26552490 #endif
2491
+
2492
+ INIT_WORK(&hcd->died_work, hcd_died_work);
26562493
26572494 hcd->driver = driver;
26582495 hcd->speed = driver->flags & HCD_MASK;
....@@ -2828,6 +2665,7 @@
28282665 {
28292666 int retval;
28302667 struct usb_device *rhdev;
2668
+ struct usb_hcd *shared_hcd;
28312669
28322670 if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) {
28332671 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev);
....@@ -2838,6 +2676,14 @@
28382676 if (retval)
28392677 return retval;
28402678
2679
+ retval = usb_phy_roothub_set_mode(hcd->phy_roothub,
2680
+ PHY_MODE_USB_HOST_SS);
2681
+ if (retval)
2682
+ retval = usb_phy_roothub_set_mode(hcd->phy_roothub,
2683
+ PHY_MODE_USB_HOST);
2684
+ if (retval)
2685
+ goto err_usb_phy_roothub_power_on;
2686
+
28412687 retval = usb_phy_roothub_power_on(hcd->phy_roothub);
28422688 if (retval)
28432689 goto err_usb_phy_roothub_power_on;
....@@ -2845,18 +2691,26 @@
28452691
28462692 dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
28472693
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);
2694
+ switch (authorized_default) {
2695
+ case USB_AUTHORIZE_NONE:
2696
+ hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE;
2697
+ break;
2698
+
2699
+ case USB_AUTHORIZE_ALL:
2700
+ hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL;
2701
+ break;
2702
+
2703
+ case USB_AUTHORIZE_INTERNAL:
2704
+ hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL;
2705
+ break;
2706
+
2707
+ case USB_AUTHORIZE_WIRED:
2708
+ default:
2709
+ hcd->dev_policy = hcd->wireless ?
2710
+ USB_DEVICE_AUTHORIZE_NONE : USB_DEVICE_AUTHORIZE_ALL;
2711
+ break;
28592712 }
2713
+
28602714 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
28612715
28622716 /* per default all interfaces are authorized */
....@@ -2905,7 +2759,7 @@
29052759 case HCD_USB32:
29062760 rhdev->rx_lanes = 2;
29072761 rhdev->tx_lanes = 2;
2908
- /* fall through */
2762
+ fallthrough;
29092763 case HCD_USB31:
29102764 rhdev->speed = USB_SPEED_SUPER_PLUS;
29112765 break;
....@@ -2939,6 +2793,10 @@
29392793 }
29402794 hcd->rh_pollable = 1;
29412795
2796
+ retval = usb_phy_roothub_calibrate(hcd->phy_roothub);
2797
+ if (retval)
2798
+ goto err_hcd_driver_setup;
2799
+
29422800 /* NOTE: root hub and controller capabilities may not be the same */
29432801 if (device_can_wakeup(hcd->self.controller)
29442802 && device_can_wakeup(&hcd->self.root_hub->dev))
....@@ -2964,36 +2822,29 @@
29642822 goto err_hcd_driver_start;
29652823 }
29662824
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;
2825
+ /* starting here, usbcore will pay attention to the shared HCD roothub */
2826
+ shared_hcd = hcd->shared_hcd;
2827
+ if (!usb_hcd_is_primary_hcd(hcd) && shared_hcd && HCD_DEFER_RH_REGISTER(shared_hcd)) {
2828
+ retval = register_root_hub(shared_hcd);
2829
+ if (retval != 0)
2830
+ goto err_register_root_hub;
29712831
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;
2832
+ if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd))
2833
+ usb_hcd_poll_rh_status(shared_hcd);
29772834 }
2978
- if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
2979
- usb_hcd_poll_rh_status(hcd);
2835
+
2836
+ /* starting here, usbcore will pay attention to this root hub */
2837
+ if (!HCD_DEFER_RH_REGISTER(hcd)) {
2838
+ retval = register_root_hub(hcd);
2839
+ if (retval != 0)
2840
+ goto err_register_root_hub;
2841
+
2842
+ if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
2843
+ usb_hcd_poll_rh_status(hcd);
2844
+ }
29802845
29812846 return retval;
29822847
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);
29972848 err_register_root_hub:
29982849 hcd->rh_pollable = 0;
29992850 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
....@@ -3033,27 +2884,29 @@
30332884 void usb_remove_hcd(struct usb_hcd *hcd)
30342885 {
30352886 struct usb_device *rhdev = hcd->self.root_hub;
2887
+ bool rh_registered;
30362888
30372889 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state);
30382890
30392891 usb_get_dev(rhdev);
3040
- sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
3041
-
30422892 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
30432893 if (HC_IS_RUNNING (hcd->state))
30442894 hcd->state = HC_STATE_QUIESCING;
30452895
30462896 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n");
30472897 spin_lock_irq (&hcd_root_hub_lock);
2898
+ rh_registered = hcd->rh_registered;
30482899 hcd->rh_registered = 0;
30492900 spin_unlock_irq (&hcd_root_hub_lock);
30502901
30512902 #ifdef CONFIG_PM
30522903 cancel_work_sync(&hcd->wakeup_work);
30532904 #endif
2905
+ cancel_work_sync(&hcd->died_work);
30542906
30552907 mutex_lock(&usb_bus_idr_lock);
3056
- usb_disconnect(&rhdev); /* Sets rhdev to NULL */
2908
+ if (rh_registered)
2909
+ usb_disconnect(&rhdev); /* Sets rhdev to NULL */
30572910 mutex_unlock(&usb_bus_idr_lock);
30582911
30592912 /*
....@@ -3111,6 +2964,40 @@
31112964 }
31122965 EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
31132966
2967
+int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr,
2968
+ dma_addr_t dma, size_t size)
2969
+{
2970
+ int err;
2971
+ void *local_mem;
2972
+
2973
+ hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4,
2974
+ dev_to_node(hcd->self.sysdev),
2975
+ dev_name(hcd->self.sysdev));
2976
+ if (IS_ERR(hcd->localmem_pool))
2977
+ return PTR_ERR(hcd->localmem_pool);
2978
+
2979
+ local_mem = devm_memremap(hcd->self.sysdev, phys_addr,
2980
+ size, MEMREMAP_WC);
2981
+ if (IS_ERR(local_mem))
2982
+ return PTR_ERR(local_mem);
2983
+
2984
+ /*
2985
+ * Here we pass a dma_addr_t but the arg type is a phys_addr_t.
2986
+ * It's not backed by system memory and thus there's no kernel mapping
2987
+ * for it.
2988
+ */
2989
+ err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem,
2990
+ dma, size, dev_to_node(hcd->self.sysdev));
2991
+ if (err < 0) {
2992
+ dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n",
2993
+ err);
2994
+ return err;
2995
+ }
2996
+
2997
+ return 0;
2998
+}
2999
+EXPORT_SYMBOL_GPL(usb_hcd_setup_local_mem);
3000
+
31143001 /*-------------------------------------------------------------------------*/
31153002
31163003 #if IS_ENABLED(CONFIG_USB_MON)