Lines Matching +full:generic +full:- +full:xhci

1 // SPDX-License-Identifier: GPL-2.0+
4 * (C) Copyright Johannes Erdfelt 1999-2001
9 * (C) Copyright David Brownell 2000-2002
23 #include <linux/dma-mapping.h>
45 /*-------------------------------------------------------------------------*/
51 * HCD-specific behaviors/bugs.
62 * threads releasing resources, or completing actions) is all generic.
70 * Roman Weissgaerber, Rory Bolt, Greg Kroah-Hartman, ...
73 * 2002-02-21 Pull in most of the usb_bus support from usb.c; some
75 * 2001-12-12 Initial patch version for Linux 2.5.1 kernel.
78 /*-------------------------------------------------------------------------*/
107 /*-------------------------------------------------------------------------*/
113 /*-------------------------------------------------------------------------*/
204 /*-------------------------------------------------------------------------*/
219 6: Self-powered,
252 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */
266 6: Self-powered,
301 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
314 6: Self-powered,
338 0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
350 * -1 is authorized for all devices (leftover from wireless USB)
355 #define USB_AUTHORIZE_WIRED -1
363 …uthorized, 1 is authorized (default), 2 is authorized for internal devices, -1 is authorized (same…
364 /*-------------------------------------------------------------------------*/
367 * ascii2desc() - Helper routine for producing UTF-16LE string descriptors
368 * @s: Null-terminated ASCII (actually ISO-8859-1) string
369 * @buf: Buffer for USB string descriptor (header + UTF-16LE)
392 while (n--) { in ascii2desc()
394 if (!n--) in ascii2desc()
403 * rh_string() - provides string descriptors for root hub
425 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ in rh_string()
433 s = hcd->self.bus_name; in rh_string()
437 s = hcd->product_desc; in rh_string()
441 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, in rh_string()
442 init_utsname()->release, hcd->driver->description); in rh_string()
459 u8 *ubuf = urb->transfer_buffer; in rh_call_control()
475 urb->hcpriv = hcd; /* Indicate it's queued */ in rh_call_control()
477 cmd = (struct usb_ctrlrequest *) urb->setup_packet; in rh_call_control()
478 typeReq = (cmd->bRequestType << 8) | cmd->bRequest; in rh_call_control()
479 wValue = le16_to_cpu (cmd->wValue); in rh_call_control()
480 wIndex = le16_to_cpu (cmd->wIndex); in rh_call_control()
481 wLength = le16_to_cpu (cmd->wLength); in rh_call_control()
483 if (wLength > urb->transfer_buffer_length) in rh_call_control()
493 status = -ENOMEM; in rh_call_control()
500 urb->actual_length = 0; in rh_call_control()
522 tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
530 device_set_wakeup_enable(&hcd->self.root_hub->dev, 0); in rh_call_control()
535 if (device_can_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
537 device_set_wakeup_enable(&hcd->self.root_hub->dev, 1); in rh_call_control()
550 switch (hcd->speed) { in rh_call_control()
568 if (hcd->has_tt) in rh_call_control()
572 switch (hcd->speed) { in rh_call_control()
590 if (device_can_wakeup(&hcd->self.root_hub->dev)) in rh_call_control()
595 urb->actual_length = rh_string(wValue & 0xff, in rh_call_control()
597 else /* unsupported IDs --> "protocol stall" */ in rh_call_control()
613 /* wValue == urb->dev->devaddr */ in rh_call_control()
614 dev_dbg (hcd->self.controller, "root hub device address %d\n", in rh_call_control()
630 dev_dbg (hcd->self.controller, "no endpoint features yet\n"); in rh_call_control()
637 /* non-generic request */ in rh_call_control()
656 status = hcd->driver->hub_control (hcd, in rh_call_control()
661 usb_hub_adjust_deviceremovable(hcd->self.root_hub, in rh_call_control()
666 status = -EPIPE; in rh_call_control()
671 if (status != -EPIPE) { in rh_call_control()
672 dev_dbg (hcd->self.controller, in rh_call_control()
684 if (urb->transfer_buffer_length < len) in rh_call_control()
685 len = urb->transfer_buffer_length; in rh_call_control()
686 urb->actual_length = len; in rh_call_control()
694 ((struct usb_config_descriptor *)ubuf)->bmAttributes in rh_call_control()
701 ((struct usb_device_descriptor *) ubuf)-> in rh_call_control()
716 /*-------------------------------------------------------------------------*/
733 if (unlikely(!hcd->rh_pollable)) in usb_hcd_poll_rh_status()
735 if (!hcd->uses_new_polling && !hcd->status_urb) in usb_hcd_poll_rh_status()
738 length = hcd->driver->hub_status_data(hcd, buffer); in usb_hcd_poll_rh_status()
743 urb = hcd->status_urb; in usb_hcd_poll_rh_status()
745 clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
746 hcd->status_urb = NULL; in usb_hcd_poll_rh_status()
747 if (urb->transfer_buffer_length >= length) { in usb_hcd_poll_rh_status()
750 status = -EOVERFLOW; in usb_hcd_poll_rh_status()
751 length = urb->transfer_buffer_length; in usb_hcd_poll_rh_status()
753 urb->actual_length = length; in usb_hcd_poll_rh_status()
754 memcpy(urb->transfer_buffer, buffer, length); in usb_hcd_poll_rh_status()
760 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
769 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : in usb_hcd_poll_rh_status()
770 (length == 0 && hcd->status_urb != NULL)) in usb_hcd_poll_rh_status()
771 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in usb_hcd_poll_rh_status()
783 /*-------------------------------------------------------------------------*/
789 unsigned len = 1 + (urb->dev->maxchild / 8); in rh_queue_status()
792 if (hcd->status_urb || urb->transfer_buffer_length < len) { in rh_queue_status()
793 dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); in rh_queue_status()
794 retval = -EINVAL; in rh_queue_status()
802 hcd->status_urb = urb; in rh_queue_status()
803 urb->hcpriv = hcd; /* indicate it's queued */ in rh_queue_status()
804 if (!hcd->uses_new_polling) in rh_queue_status()
805 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in rh_queue_status()
809 mod_timer(&hcd->rh_timer, jiffies); in rh_queue_status()
818 if (usb_endpoint_xfer_int(&urb->ep->desc)) in rh_urb_enqueue()
820 if (usb_endpoint_xfer_control(&urb->ep->desc)) in rh_urb_enqueue()
822 return -EINVAL; in rh_urb_enqueue()
825 /*-------------------------------------------------------------------------*/
827 /* Unlinks of root-hub control URBs are legal, but they don't do anything
840 if (usb_endpoint_num(&urb->ep->desc) == 0) { /* Control URB */ in usb_rh_urb_dequeue()
844 if (!hcd->uses_new_polling) in usb_rh_urb_dequeue()
845 timer_delete(&hcd->rh_timer); in usb_rh_urb_dequeue()
846 if (urb == hcd->status_urb) { in usb_rh_urb_dequeue()
847 hcd->status_urb = NULL; in usb_rh_urb_dequeue()
858 /*-------------------------------------------------------------------------*/
861 * usb_bus_init - shared initialization code
869 memset(&bus->devmap, 0, sizeof(bus->devmap)); in usb_bus_init()
871 bus->devnum_next = 1; in usb_bus_init()
873 bus->root_hub = NULL; in usb_bus_init()
874 bus->busnum = -1; in usb_bus_init()
875 bus->bandwidth_allocated = 0; in usb_bus_init()
876 bus->bandwidth_int_reqs = 0; in usb_bus_init()
877 bus->bandwidth_isoc_reqs = 0; in usb_bus_init()
878 mutex_init(&bus->devnum_next_mutex); in usb_bus_init()
881 /*-------------------------------------------------------------------------*/
884 * usb_register_bus - registers the USB host controller with the usb core
896 int result = -E2BIG; in usb_register_bus()
905 bus->busnum = busnum; in usb_register_bus()
910 dev_info (bus->controller, "new USB bus registered, assigned bus " in usb_register_bus()
911 "number %d\n", bus->busnum); in usb_register_bus()
920 * usb_deregister_bus - deregisters the USB host controller
930 dev_info (bus->controller, "USB bus %d deregistered\n", bus->busnum); in usb_deregister_bus()
938 idr_remove(&usb_bus_idr, bus->busnum); in usb_deregister_bus()
945 * register_root_hub - called by usb_add_hcd() to register a root hub
957 struct device *parent_dev = hcd->self.controller; in register_root_hub()
958 struct usb_device *usb_dev = hcd->self.root_hub; in register_root_hub()
963 usb_dev->devnum = devnum; in register_root_hub()
964 usb_dev->bus->devnum_next = devnum + 1; in register_root_hub()
965 set_bit(devnum, usb_dev->bus->devmap); in register_root_hub()
970 usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in register_root_hub()
976 dev_name(&usb_dev->dev), retval); in register_root_hub()
979 usb_dev->descriptor = *descr; in register_root_hub()
982 if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) { in register_root_hub()
985 usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev); in register_root_hub()
986 } else if (usb_dev->speed >= USB_SPEED_SUPER) { in register_root_hub()
989 dev_name(&usb_dev->dev), retval); in register_root_hub()
997 dev_name(&usb_dev->dev), retval); in register_root_hub()
1000 hcd->rh_registered = 1; in register_root_hub()
1013 * usb_hcd_start_port_resume - a root-hub port is sending a resume signal
1018 * being sent to a root-hub port. The root hub will be prevented from
1027 if (!(bus->resuming_ports & bit)) { in usb_hcd_start_port_resume()
1028 bus->resuming_ports |= bit; in usb_hcd_start_port_resume()
1029 pm_runtime_get_noresume(&bus->root_hub->dev); in usb_hcd_start_port_resume()
1035 * usb_hcd_end_port_resume - a root-hub port has stopped sending a resume signal
1040 * stopped being sent to a root-hub port. The root hub will be allowed to
1049 if (bus->resuming_ports & bit) { in usb_hcd_end_port_resume()
1050 bus->resuming_ports &= ~bit; in usb_hcd_end_port_resume()
1051 pm_runtime_put_noidle(&bus->root_hub->dev); in usb_hcd_end_port_resume()
1056 /*-------------------------------------------------------------------------*/
1059 * usb_calc_bus_time - approximate periodic transaction time in nanoseconds
1060 * @speed: from dev->speed; USB_SPEED_{LOW,FULL,HIGH}
1101 return -1; in usb_calc_bus_time()
1107 /*-------------------------------------------------------------------------*/
1110 * Generic HC operations.
1113 /*-------------------------------------------------------------------------*/
1116 * usb_hcd_link_urb_to_ep - add an URB to its endpoint queue
1137 if (unlikely(atomic_read(&urb->reject))) { in usb_hcd_link_urb_to_ep()
1138 rc = -EPERM; in usb_hcd_link_urb_to_ep()
1142 if (unlikely(!urb->ep->enabled)) { in usb_hcd_link_urb_to_ep()
1143 rc = -ENOENT; in usb_hcd_link_urb_to_ep()
1147 if (unlikely(!urb->dev->can_submit)) { in usb_hcd_link_urb_to_ep()
1148 rc = -EHOSTUNREACH; in usb_hcd_link_urb_to_ep()
1157 urb->unlinked = 0; in usb_hcd_link_urb_to_ep()
1158 list_add_tail(&urb->urb_list, &urb->ep->urb_list); in usb_hcd_link_urb_to_ep()
1160 rc = -ESHUTDOWN; in usb_hcd_link_urb_to_ep()
1170 * usb_hcd_check_unlink_urb - check whether an URB may be unlinked
1183 * -EIDRM: @urb was not submitted or has already completed.
1186 * -EBUSY: @urb has already been unlinked.
1194 list_for_each(tmp, &urb->ep->urb_list) { in usb_hcd_check_unlink_urb()
1195 if (tmp == &urb->urb_list) in usb_hcd_check_unlink_urb()
1198 if (tmp != &urb->urb_list) in usb_hcd_check_unlink_urb()
1199 return -EIDRM; in usb_hcd_check_unlink_urb()
1201 /* Any status except -EINPROGRESS means something already started to in usb_hcd_check_unlink_urb()
1204 if (urb->unlinked) in usb_hcd_check_unlink_urb()
1205 return -EBUSY; in usb_hcd_check_unlink_urb()
1206 urb->unlinked = status; in usb_hcd_check_unlink_urb()
1212 * usb_hcd_unlink_urb_from_ep - remove an URB from its endpoint queue
1225 list_del_init(&urb->urb_list); in usb_hcd_unlink_urb_from_ep()
1234 * using regular system memory - like pci devices doing bus mastering.
1238 * hcd->localmem_pool using usb_hcd_setup_local_mem().
1240 * The initialized hcd->localmem_pool then tells the usb code to allocate all
1245 * - We need "local" memory, canonical example being
1251 * - So we use that, even though the primary requirement
1266 return -EFAULT; in hcd_alloc_coherent()
1272 return -ENOMEM; in hcd_alloc_coherent()
1312 (urb->transfer_flags & URB_SETUP_MAP_SINGLE)) in usb_hcd_unmap_urb_setup_for_dma()
1313 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_setup_for_dma()
1314 urb->setup_dma, in usb_hcd_unmap_urb_setup_for_dma()
1317 else if (urb->transfer_flags & URB_SETUP_MAP_LOCAL) in usb_hcd_unmap_urb_setup_for_dma()
1318 hcd_free_coherent(urb->dev->bus, in usb_hcd_unmap_urb_setup_for_dma()
1319 &urb->setup_dma, in usb_hcd_unmap_urb_setup_for_dma()
1320 (void **) &urb->setup_packet, in usb_hcd_unmap_urb_setup_for_dma()
1325 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); in usb_hcd_unmap_urb_setup_for_dma()
1331 if (hcd->driver->unmap_urb_for_dma) in unmap_urb_for_dma()
1332 hcd->driver->unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1345 (urb->transfer_flags & URB_DMA_MAP_SG)) { in usb_hcd_unmap_urb_for_dma()
1346 dma_unmap_sg(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1347 urb->sg, in usb_hcd_unmap_urb_for_dma()
1348 urb->num_sgs, in usb_hcd_unmap_urb_for_dma()
1351 (urb->transfer_flags & URB_DMA_MAP_PAGE)) { in usb_hcd_unmap_urb_for_dma()
1352 dma_unmap_page(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1353 urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1354 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1357 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) { in usb_hcd_unmap_urb_for_dma()
1358 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1359 urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1360 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1362 } else if (urb->transfer_flags & URB_MAP_LOCAL) { in usb_hcd_unmap_urb_for_dma()
1363 hcd_free_coherent(urb->dev->bus, in usb_hcd_unmap_urb_for_dma()
1364 &urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1365 &urb->transfer_buffer, in usb_hcd_unmap_urb_for_dma()
1366 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1368 } else if ((urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) && urb->sgt) { in usb_hcd_unmap_urb_for_dma()
1369 dma_sync_sgtable_for_cpu(hcd->self.sysdev, urb->sgt, dir); in usb_hcd_unmap_urb_for_dma()
1371 invalidate_kernel_vmap_range(urb->transfer_buffer, in usb_hcd_unmap_urb_for_dma()
1372 urb->transfer_buffer_length); in usb_hcd_unmap_urb_for_dma()
1376 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | in usb_hcd_unmap_urb_for_dma()
1384 if (hcd->driver->map_urb_for_dma) in map_urb_for_dma()
1385 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1402 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1403 if (hcd->self.uses_pio_for_control) in usb_hcd_map_urb_for_dma()
1405 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1407 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1408 &urb->setup_dma, in usb_hcd_map_urb_for_dma()
1409 (void **)&urb->setup_packet, in usb_hcd_map_urb_for_dma()
1414 urb->transfer_flags |= URB_SETUP_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1416 if (object_is_on_stack(urb->setup_packet)) { in usb_hcd_map_urb_for_dma()
1418 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1421 urb->setup_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1422 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1423 urb->setup_packet, in usb_hcd_map_urb_for_dma()
1426 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1427 urb->setup_dma)) in usb_hcd_map_urb_for_dma()
1428 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1429 urb->transfer_flags |= URB_SETUP_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1434 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) { in usb_hcd_map_urb_for_dma()
1435 if (!urb->sgt) in usb_hcd_map_urb_for_dma()
1439 flush_kernel_vmap_range(urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1440 urb->transfer_buffer_length); in usb_hcd_map_urb_for_dma()
1441 dma_sync_sgtable_for_device(hcd->self.sysdev, urb->sgt, dir); in usb_hcd_map_urb_for_dma()
1442 } else if (urb->transfer_buffer_length != 0) { in usb_hcd_map_urb_for_dma()
1443 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1445 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1446 &urb->transfer_dma, in usb_hcd_map_urb_for_dma()
1447 &urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1448 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1451 urb->transfer_flags |= URB_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1453 if (urb->num_sgs) { in usb_hcd_map_urb_for_dma()
1457 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1459 return -EINVAL; in usb_hcd_map_urb_for_dma()
1463 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1464 urb->sg, in usb_hcd_map_urb_for_dma()
1465 urb->num_sgs, in usb_hcd_map_urb_for_dma()
1468 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1470 urb->transfer_flags |= URB_DMA_MAP_SG; in usb_hcd_map_urb_for_dma()
1471 urb->num_mapped_sgs = n; in usb_hcd_map_urb_for_dma()
1472 if (n != urb->num_sgs) in usb_hcd_map_urb_for_dma()
1473 urb->transfer_flags |= in usb_hcd_map_urb_for_dma()
1475 } else if (urb->sg) { in usb_hcd_map_urb_for_dma()
1476 struct scatterlist *sg = urb->sg; in usb_hcd_map_urb_for_dma()
1477 urb->transfer_dma = dma_map_page( in usb_hcd_map_urb_for_dma()
1478 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1480 sg->offset, in usb_hcd_map_urb_for_dma()
1481 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1483 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1484 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1485 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1487 urb->transfer_flags |= URB_DMA_MAP_PAGE; in usb_hcd_map_urb_for_dma()
1488 } else if (object_is_on_stack(urb->transfer_buffer)) { in usb_hcd_map_urb_for_dma()
1490 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1492 urb->transfer_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1493 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1494 urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1495 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1497 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1498 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1499 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1501 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1504 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | in usb_hcd_map_urb_for_dma()
1512 /*-------------------------------------------------------------------------*/
1514 /* may be called in any context with a valid urb->dev usecount
1522 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_submit_urb()
1529 atomic_inc(&urb->use_count); in usb_hcd_submit_urb()
1530 atomic_inc(&urb->dev->urbnum); in usb_hcd_submit_urb()
1531 usbmon_urb_submit(&hcd->self, urb); in usb_hcd_submit_urb()
1533 /* NOTE requirements on root-hub callers (usbfs and the hub in usb_hcd_submit_urb()
1534 * driver, for now): URBs' urb->transfer_buffer must be in usb_hcd_submit_urb()
1541 if (is_root_hub(urb->dev)) { in usb_hcd_submit_urb()
1546 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1553 usbmon_urb_submit_error(&hcd->self, urb, status); in usb_hcd_submit_urb()
1554 urb->hcpriv = NULL; in usb_hcd_submit_urb()
1555 INIT_LIST_HEAD(&urb->urb_list); in usb_hcd_submit_urb()
1556 atomic_dec(&urb->use_count); in usb_hcd_submit_urb()
1558 * Order the write of urb->use_count above before the read in usb_hcd_submit_urb()
1559 * of urb->reject below. Pairs with the memory barriers in in usb_hcd_submit_urb()
1564 atomic_dec(&urb->dev->urbnum); in usb_hcd_submit_urb()
1565 if (atomic_read(&urb->reject)) in usb_hcd_submit_urb()
1572 /*-------------------------------------------------------------------------*/
1583 if (is_root_hub(urb->dev)) in unlink1()
1590 value = hcd->driver->urb_dequeue(hcd, urb, status); in unlink1()
1604 struct usb_device *udev = urb->dev; in usb_hcd_unlink_urb()
1605 int retval = -EIDRM; in usb_hcd_unlink_urb()
1610 * then urb->use_count must be 0, since disconnected in usb_hcd_unlink_urb()
1614 if (atomic_read(&urb->use_count) > 0) { in usb_hcd_unlink_urb()
1620 hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_unlink_urb()
1623 retval = -EINPROGRESS; in usb_hcd_unlink_urb()
1624 else if (retval != -EIDRM && retval != -EBUSY) in usb_hcd_unlink_urb()
1625 dev_dbg(&udev->dev, "hcd_unlink_urb %p fail %d\n", in usb_hcd_unlink_urb()
1632 /*-------------------------------------------------------------------------*/
1636 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in __usb_hcd_giveback_urb()
1637 struct usb_anchor *anchor = urb->anchor; in __usb_hcd_giveback_urb()
1638 int status = urb->unlinked; in __usb_hcd_giveback_urb()
1640 urb->hcpriv = NULL; in __usb_hcd_giveback_urb()
1641 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && in __usb_hcd_giveback_urb()
1642 urb->actual_length < urb->transfer_buffer_length && in __usb_hcd_giveback_urb()
1644 status = -EREMOTEIO; in __usb_hcd_giveback_urb()
1647 usbmon_urb_complete(&hcd->self, urb, status); in __usb_hcd_giveback_urb()
1654 urb->status = status; in __usb_hcd_giveback_urb()
1660 kcov_remote_start_usb_softirq((u64)urb->dev->bus->busnum); in __usb_hcd_giveback_urb()
1661 urb->complete(urb); in __usb_hcd_giveback_urb()
1665 atomic_dec(&urb->use_count); in __usb_hcd_giveback_urb()
1667 * Order the write of urb->use_count above before the read in __usb_hcd_giveback_urb()
1668 * of urb->reject below. Pairs with the memory barriers in in __usb_hcd_giveback_urb()
1673 if (unlikely(atomic_read(&urb->reject))) in __usb_hcd_giveback_urb()
1684 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1685 bh->running = true; in usb_giveback_urb_bh()
1686 list_replace_init(&bh->head, &local_list); in usb_giveback_urb_bh()
1687 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1693 list_del_init(&urb->urb_list); in usb_giveback_urb_bh()
1694 bh->completing_ep = urb->ep; in usb_giveback_urb_bh()
1696 bh->completing_ep = NULL; in usb_giveback_urb_bh()
1703 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1704 if (!list_empty(&bh->head)) { in usb_giveback_urb_bh()
1705 if (bh->high_prio) in usb_giveback_urb_bh()
1706 queue_work(system_bh_highpri_wq, &bh->bh); in usb_giveback_urb_bh()
1708 queue_work(system_bh_wq, &bh->bh); in usb_giveback_urb_bh()
1710 bh->running = false; in usb_giveback_urb_bh()
1711 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1715 * usb_hcd_giveback_urb - return URB from HCD to device driver
1726 * completion function. The HCD has freed all per-urb resources
1727 * (and is done using urb->hcpriv). It also released all HCD locks;
1732 * @urb->unlinked. Erroneous short transfers are detected in case
1741 if (likely(!urb->unlinked)) in usb_hcd_giveback_urb()
1742 urb->unlinked = status; in usb_hcd_giveback_urb()
1744 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) { in usb_hcd_giveback_urb()
1749 if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) in usb_hcd_giveback_urb()
1750 bh = &hcd->high_prio_bh; in usb_hcd_giveback_urb()
1752 bh = &hcd->low_prio_bh; in usb_hcd_giveback_urb()
1754 spin_lock(&bh->lock); in usb_hcd_giveback_urb()
1755 list_add_tail(&urb->urb_list, &bh->head); in usb_hcd_giveback_urb()
1756 running = bh->running; in usb_hcd_giveback_urb()
1757 spin_unlock(&bh->lock); in usb_hcd_giveback_urb()
1761 else if (bh->high_prio) in usb_hcd_giveback_urb()
1762 queue_work(system_bh_highpri_wq, &bh->bh); in usb_hcd_giveback_urb()
1764 queue_work(system_bh_wq, &bh->bh); in usb_hcd_giveback_urb()
1768 /*-------------------------------------------------------------------------*/
1783 hcd = bus_to_hcd(udev->bus); in usb_hcd_flush_endpoint()
1788 list_for_each_entry_reverse(urb, &ep->urb_list, urb_list) { in usb_hcd_flush_endpoint()
1791 if (urb->unlinked) in usb_hcd_flush_endpoint()
1798 unlink1(hcd, urb, -ESHUTDOWN); in usb_hcd_flush_endpoint()
1799 dev_dbg (hcd->self.controller, in usb_hcd_flush_endpoint()
1800 "shutdown urb %p ep%d%s-%s\n", in usb_hcd_flush_endpoint()
1801 urb, usb_endpoint_num(&ep->desc), in usb_hcd_flush_endpoint()
1803 usb_ep_type_string(usb_endpoint_type(&ep->desc))); in usb_hcd_flush_endpoint()
1813 while (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1818 if (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1819 urb = list_entry (ep->urb_list.prev, struct urb, in usb_hcd_flush_endpoint()
1833 * usb_hcd_alloc_bandwidth - check whether a new bandwidth setting exceeds
1864 hcd = bus_to_hcd(udev->bus); in usb_hcd_alloc_bandwidth()
1865 if (!hcd->driver->check_bandwidth) in usb_hcd_alloc_bandwidth()
1868 /* Configuration is being removed - set configuration 0 */ in usb_hcd_alloc_bandwidth()
1871 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1873 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1874 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1876 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1878 hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1887 num_intfs = new_config->desc.bNumInterfaces; in usb_hcd_alloc_bandwidth()
1892 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1894 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1898 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1900 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1909 first_alt = &new_config->intf_cache[i]->altsetting[0]; in usb_hcd_alloc_bandwidth()
1910 iface_num = first_alt->desc.bInterfaceNumber; in usb_hcd_alloc_bandwidth()
1917 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in usb_hcd_alloc_bandwidth()
1918 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); in usb_hcd_alloc_bandwidth()
1926 cur_alt->desc.bInterfaceNumber); in usb_hcd_alloc_bandwidth()
1929 return -EINVAL; in usb_hcd_alloc_bandwidth()
1930 if (iface->resetting_device) { in usb_hcd_alloc_bandwidth()
1932 * The USB core just reset the device, so the xHCI host in usb_hcd_alloc_bandwidth()
1942 cur_alt = &iface->altsetting[0]; in usb_hcd_alloc_bandwidth()
1946 for (i = 0; i < cur_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1947 ret = hcd->driver->drop_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1948 &cur_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1953 for (i = 0; i < new_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1954 ret = hcd->driver->add_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1955 &new_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1960 ret = hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1963 hcd->driver->reset_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1972 * example: a qh stored in ep->hcpriv, holding state related to endpoint
1981 hcd = bus_to_hcd(udev->bus); in usb_hcd_disable_endpoint()
1982 if (hcd->driver->endpoint_disable) in usb_hcd_disable_endpoint()
1983 hcd->driver->endpoint_disable(hcd, ep); in usb_hcd_disable_endpoint()
1987 * usb_hcd_reset_endpoint - reset host endpoint state
1997 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_reset_endpoint()
1999 if (hcd->driver->endpoint_reset) in usb_hcd_reset_endpoint()
2000 hcd->driver->endpoint_reset(hcd, ep); in usb_hcd_reset_endpoint()
2002 int epnum = usb_endpoint_num(&ep->desc); in usb_hcd_reset_endpoint()
2003 int is_out = usb_endpoint_dir_out(&ep->desc); in usb_hcd_reset_endpoint()
2004 int is_control = usb_endpoint_xfer_control(&ep->desc); in usb_hcd_reset_endpoint()
2013 * usb_alloc_streams - allocate bulk endpoint stream IDs.
2036 hcd = bus_to_hcd(dev->bus); in usb_alloc_streams()
2037 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams) in usb_alloc_streams()
2038 return -EINVAL; in usb_alloc_streams()
2039 if (dev->speed < USB_SPEED_SUPER) in usb_alloc_streams()
2040 return -EINVAL; in usb_alloc_streams()
2041 if (dev->state < USB_STATE_CONFIGURED) in usb_alloc_streams()
2042 return -ENODEV; in usb_alloc_streams()
2046 if (!usb_endpoint_xfer_bulk(&eps[i]->desc)) in usb_alloc_streams()
2047 return -EINVAL; in usb_alloc_streams()
2048 /* Re-alloc is not allowed */ in usb_alloc_streams()
2049 if (eps[i]->streams) in usb_alloc_streams()
2050 return -EINVAL; in usb_alloc_streams()
2053 ret = hcd->driver->alloc_streams(hcd, dev, eps, num_eps, in usb_alloc_streams()
2059 eps[i]->streams = ret; in usb_alloc_streams()
2066 * usb_free_streams - free bulk endpoint stream IDs.
2086 hcd = bus_to_hcd(dev->bus); in usb_free_streams()
2087 if (dev->speed < USB_SPEED_SUPER) in usb_free_streams()
2088 return -EINVAL; in usb_free_streams()
2090 /* Double-free is not allowed */ in usb_free_streams()
2092 if (!eps[i] || !eps[i]->streams) in usb_free_streams()
2093 return -EINVAL; in usb_free_streams()
2095 ret = hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); in usb_free_streams()
2100 eps[i]->streams = 0; in usb_free_streams()
2117 /*-------------------------------------------------------------------------*/
2122 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_get_frame_number()
2125 return -ESHUTDOWN; in usb_hcd_get_frame_number()
2126 return hcd->driver->get_frame_number (hcd); in usb_hcd_get_frame_number()
2129 /*-------------------------------------------------------------------------*/
2134 struct completion *done = urb->context; in usb_ehset_completion()
2151 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in request_single_step_set_feature_urb()
2157 urb->pipe = usb_rcvctrlpipe(udev, 0); in request_single_step_set_feature_urb()
2159 urb->ep = &udev->ep0; in request_single_step_set_feature_urb()
2160 urb->dev = udev; in request_single_step_set_feature_urb()
2161 urb->setup_packet = (void *)dr; in request_single_step_set_feature_urb()
2162 urb->transfer_buffer = buf; in request_single_step_set_feature_urb()
2163 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE; in request_single_step_set_feature_urb()
2164 urb->complete = usb_ehset_completion; in request_single_step_set_feature_urb()
2165 urb->status = -EINPROGRESS; in request_single_step_set_feature_urb()
2166 urb->actual_length = 0; in request_single_step_set_feature_urb()
2167 urb->transfer_flags = URB_DIR_IN | URB_NO_TRANSFER_DMA_MAP; in request_single_step_set_feature_urb()
2169 atomic_inc(&urb->use_count); in request_single_step_set_feature_urb()
2170 atomic_inc(&urb->dev->urbnum); in request_single_step_set_feature_urb()
2177 urb->context = done; in request_single_step_set_feature_urb()
2183 int retval = -ENOMEM; in ehset_single_step_set_feature()
2191 udev = usb_hub_find_child(hcd->self.root_hub, port); in ehset_single_step_set_feature()
2193 dev_err(hcd->self.controller, "No device attached to the RootHub\n"); in ehset_single_step_set_feature()
2194 return -ENODEV; in ehset_single_step_set_feature()
2198 return -ENOMEM; in ehset_single_step_set_feature()
2203 return -ENOMEM; in ehset_single_step_set_feature()
2207 dr->bRequestType = USB_DIR_IN; in ehset_single_step_set_feature()
2208 dr->bRequest = USB_REQ_GET_DESCRIPTOR; in ehset_single_step_set_feature()
2209 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8); in ehset_single_step_set_feature()
2210 dr->wIndex = 0; in ehset_single_step_set_feature()
2211 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE); in ehset_single_step_set_feature()
2217 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 1); in ehset_single_step_set_feature()
2222 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2223 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2230 urb->status = -EINPROGRESS; in ehset_single_step_set_feature()
2231 urb->transfer_flags &= ~URB_NO_TRANSFER_DMA_MAP; in ehset_single_step_set_feature()
2233 atomic_inc(&urb->use_count); in ehset_single_step_set_feature()
2234 atomic_inc(&urb->dev->urbnum); in ehset_single_step_set_feature()
2240 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0); in ehset_single_step_set_feature()
2244 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2245 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2258 /*-------------------------------------------------------------------------*/
2264 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_suspend()
2266 int old_state = hcd->state; in hcd_bus_suspend()
2268 dev_dbg(&rhdev->dev, "bus %ssuspend, wakeup %d\n", in hcd_bus_suspend()
2269 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in hcd_bus_suspend()
2270 rhdev->do_remote_wakeup); in hcd_bus_suspend()
2272 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend"); in hcd_bus_suspend()
2276 if (!hcd->driver->bus_suspend) { in hcd_bus_suspend()
2277 status = -ENOENT; in hcd_bus_suspend()
2279 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2280 hcd->state = HC_STATE_QUIESCING; in hcd_bus_suspend()
2281 status = hcd->driver->bus_suspend(hcd); in hcd_bus_suspend()
2285 hcd->state = HC_STATE_SUSPENDED; in hcd_bus_suspend()
2288 usb_phy_roothub_suspend(hcd->self.sysdev, in hcd_bus_suspend()
2289 hcd->phy_roothub); in hcd_bus_suspend()
2291 /* Did we race with a root-hub wakeup event? */ in hcd_bus_suspend()
2292 if (rhdev->do_remote_wakeup) { in hcd_bus_suspend()
2295 status = hcd->driver->hub_status_data(hcd, buffer); in hcd_bus_suspend()
2297 dev_dbg(&rhdev->dev, "suspend raced with wakeup event\n"); in hcd_bus_suspend()
2299 status = -EBUSY; in hcd_bus_suspend()
2305 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2306 hcd->state = old_state; in hcd_bus_suspend()
2309 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_suspend()
2317 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_resume()
2319 int old_state = hcd->state; in hcd_bus_resume()
2321 dev_dbg(&rhdev->dev, "usb %sresume\n", in hcd_bus_resume()
2322 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in hcd_bus_resume()
2324 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); in hcd_bus_resume()
2329 status = usb_phy_roothub_resume(hcd->self.sysdev, in hcd_bus_resume()
2330 hcd->phy_roothub); in hcd_bus_resume()
2335 if (!hcd->driver->bus_resume) in hcd_bus_resume()
2336 return -ENOENT; in hcd_bus_resume()
2340 hcd->state = HC_STATE_RESUMING; in hcd_bus_resume()
2341 status = hcd->driver->bus_resume(hcd); in hcd_bus_resume()
2342 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in hcd_bus_resume()
2344 status = usb_phy_roothub_calibrate(hcd->phy_roothub); in hcd_bus_resume()
2352 usb_set_device_state(rhdev, rhdev->actconfig in hcd_bus_resume()
2355 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_resume()
2356 hcd->state = HC_STATE_RUNNING; in hcd_bus_resume()
2363 * (this is what the USB-2 spec calls a "global resume"). in hcd_bus_resume()
2367 if (udev->state != USB_STATE_NOTATTACHED && in hcd_bus_resume()
2368 !udev->port_is_suspended) { in hcd_bus_resume()
2374 hcd->state = old_state; in hcd_bus_resume()
2375 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); in hcd_bus_resume()
2376 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_resume()
2378 if (status != -ESHUTDOWN) in hcd_bus_resume()
2384 /* Workqueue routine for root-hub remote wakeup */
2388 struct usb_device *udev = hcd->self.root_hub; in hcd_resume_work()
2394 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2407 if (hcd->rh_registered) { in usb_hcd_resume_root_hub()
2408 pm_wakeup_event(&hcd->self.root_hub->dev, 0); in usb_hcd_resume_root_hub()
2409 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in usb_hcd_resume_root_hub()
2410 queue_work(pm_wq, &hcd->wakeup_work); in usb_hcd_resume_root_hub()
2418 /*-------------------------------------------------------------------------*/
2423 * usb_bus_start_enum - start immediate enumeration (for OTG)
2425 * @port_num: 1-based number of port; usually bus->otg_port
2438 int status = -EOPNOTSUPP; in usb_bus_start_enum()
2445 if (port_num && hcd->driver->start_port_reset) in usb_bus_start_enum()
2446 status = hcd->driver->start_port_reset(hcd, port_num); in usb_bus_start_enum()
2452 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); in usb_bus_start_enum()
2459 /*-------------------------------------------------------------------------*/
2462 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
2478 else if (hcd->driver->irq(hcd) == IRQ_NONE) in usb_hcd_irq()
2487 /*-------------------------------------------------------------------------*/
2489 /* Workqueue routine for when the root-hub has died. */
2499 kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env); in hcd_died_work()
2503 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
2508 * by the PCI glue, so only glue for non-PCI busses should need to call it.
2516 dev_err (hcd->self.controller, "HC died; cleaning up\n"); in usb_hc_died()
2519 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2520 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2521 if (hcd->rh_registered) { in usb_hc_died()
2522 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2525 usb_set_device_state (hcd->self.root_hub, in usb_hc_died()
2527 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2529 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { in usb_hc_died()
2530 hcd = hcd->shared_hcd; in usb_hc_died()
2531 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2532 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2533 if (hcd->rh_registered) { in usb_hc_died()
2534 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2537 usb_set_device_state(hcd->self.root_hub, in usb_hc_died()
2539 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2545 schedule_work(&hcd->died_work); in usb_hc_died()
2547 schedule_work(&hcd->primary_hcd->died_work); in usb_hc_died()
2554 /*-------------------------------------------------------------------------*/
2559 spin_lock_init(&bh->lock); in init_giveback_urb_bh()
2560 INIT_LIST_HEAD(&bh->head); in init_giveback_urb_bh()
2561 INIT_WORK(&bh->bh, usb_giveback_urb_bh); in init_giveback_urb_bh()
2570 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); in __usb_create_hcd()
2574 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), in __usb_create_hcd()
2576 if (!hcd->address0_mutex) { in __usb_create_hcd()
2581 mutex_init(hcd->address0_mutex); in __usb_create_hcd()
2582 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), in __usb_create_hcd()
2584 if (!hcd->bandwidth_mutex) { in __usb_create_hcd()
2585 kfree(hcd->address0_mutex); in __usb_create_hcd()
2590 mutex_init(hcd->bandwidth_mutex); in __usb_create_hcd()
2594 hcd->address0_mutex = primary_hcd->address0_mutex; in __usb_create_hcd()
2595 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; in __usb_create_hcd()
2596 hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2597 primary_hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2598 hcd->shared_hcd = primary_hcd; in __usb_create_hcd()
2599 primary_hcd->shared_hcd = hcd; in __usb_create_hcd()
2603 kref_init(&hcd->kref); in __usb_create_hcd()
2605 usb_bus_init(&hcd->self); in __usb_create_hcd()
2606 hcd->self.controller = dev; in __usb_create_hcd()
2607 hcd->self.sysdev = sysdev; in __usb_create_hcd()
2608 hcd->self.bus_name = bus_name; in __usb_create_hcd()
2610 timer_setup(&hcd->rh_timer, rh_timer_func, 0); in __usb_create_hcd()
2612 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); in __usb_create_hcd()
2615 INIT_WORK(&hcd->died_work, hcd_died_work); in __usb_create_hcd()
2617 hcd->driver = driver; in __usb_create_hcd()
2618 hcd->speed = driver->flags & HCD_MASK; in __usb_create_hcd()
2619 hcd->product_desc = (driver->product_desc) ? driver->product_desc : in __usb_create_hcd()
2626 * usb_create_shared_hcd - create and initialize an HCD structure
2628 * @dev: device for this HC, stored in hcd->self.controller
2629 * @bus_name: value to store in hcd->self.bus_name
2636 * HC driver's private data. Initialize the generic members of the
2651 * usb_create_hcd - create and initialize an HCD structure
2653 * @dev: device for this HC, stored in hcd->self.controller
2654 * @bus_name: value to store in hcd->self.bus_name
2659 * HC driver's private data. Initialize the generic members of the
2679 * invalidate the peer's ->shared_hcd and ->primary_hcd pointers.
2686 if (hcd->shared_hcd) { in hcd_release()
2687 struct usb_hcd *peer = hcd->shared_hcd; in hcd_release()
2689 peer->shared_hcd = NULL; in hcd_release()
2690 peer->primary_hcd = NULL; in hcd_release()
2692 kfree(hcd->address0_mutex); in hcd_release()
2693 kfree(hcd->bandwidth_mutex); in hcd_release()
2702 kref_get (&hcd->kref); in usb_get_hcd()
2710 kref_put (&hcd->kref, hcd_release); in usb_put_hcd()
2716 if (!hcd->primary_hcd) in usb_hcd_is_primary_hcd()
2718 return hcd == hcd->primary_hcd; in usb_hcd_is_primary_hcd()
2724 if (!hcd->driver->find_raw_port_number) in usb_hcd_find_raw_port_number()
2727 return hcd->driver->find_raw_port_number(hcd, port1); in usb_hcd_find_raw_port_number()
2735 if (hcd->driver->irq) { in usb_hcd_request_irqs()
2737 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in usb_hcd_request_irqs()
2738 hcd->driver->description, hcd->self.busnum); in usb_hcd_request_irqs()
2740 hcd->irq_descr, hcd); in usb_hcd_request_irqs()
2742 dev_err(hcd->self.controller, in usb_hcd_request_irqs()
2747 hcd->irq = irqnum; in usb_hcd_request_irqs()
2748 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, in usb_hcd_request_irqs()
2749 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2751 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2753 hcd->irq = 0; in usb_hcd_request_irqs()
2754 if (hcd->rsrc_start) in usb_hcd_request_irqs()
2755 dev_info(hcd->self.controller, "%s 0x%08llx\n", in usb_hcd_request_irqs()
2756 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2758 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2764 * Before we free this root hub, flush in-flight peering attempts
2772 rhdev = hcd->self.root_hub; in usb_put_invalidate_rhdev()
2773 hcd->self.root_hub = NULL; in usb_put_invalidate_rhdev()
2779 * usb_stop_hcd - Halt the HCD
2782 * Stop the root-hub polling timer and invoke the HCD's ->stop callback.
2786 hcd->rh_pollable = 0; in usb_stop_hcd()
2787 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2788 timer_delete_sync(&hcd->rh_timer); in usb_stop_hcd()
2790 hcd->driver->stop(hcd); in usb_stop_hcd()
2791 hcd->state = HC_STATE_HALT; in usb_stop_hcd()
2794 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2795 timer_delete_sync(&hcd->rh_timer); in usb_stop_hcd()
2799 * usb_add_hcd - finish generic HCD structure initialization and register
2804 * Finish the remaining parts of generic HCD initialization: allocate the
2817 skip_phy_initialization = hcd->skip_phy_initialization; in usb_add_hcd()
2819 skip_phy_initialization = hcd->primary_hcd->skip_phy_initialization; in usb_add_hcd()
2823 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); in usb_add_hcd()
2824 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2825 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2827 hcd->phy_roothub = usb_phy_roothub_alloc_usb3_phy(hcd->self.sysdev); in usb_add_hcd()
2828 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2829 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2832 retval = usb_phy_roothub_init(hcd->phy_roothub); in usb_add_hcd()
2836 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2839 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2844 retval = usb_phy_roothub_power_on(hcd->phy_roothub); in usb_add_hcd()
2849 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); in usb_add_hcd()
2853 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; in usb_add_hcd()
2857 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; in usb_add_hcd()
2863 hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; in usb_add_hcd()
2867 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in usb_add_hcd()
2870 set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags); in usb_add_hcd()
2872 /* HC is in reset state, but accessible. Now do the one-time init, in usb_add_hcd()
2878 dev_dbg(hcd->self.sysdev, "pool alloc failed\n"); in usb_add_hcd()
2882 retval = usb_register_bus(&hcd->self); in usb_add_hcd()
2886 rhdev = usb_alloc_dev(NULL, &hcd->self, 0); in usb_add_hcd()
2888 dev_err(hcd->self.sysdev, "unable to allocate root hub\n"); in usb_add_hcd()
2889 retval = -ENOMEM; in usb_add_hcd()
2893 hcd->self.root_hub = rhdev; in usb_add_hcd()
2896 rhdev->rx_lanes = 1; in usb_add_hcd()
2897 rhdev->tx_lanes = 1; in usb_add_hcd()
2898 rhdev->ssp_rate = USB_SSP_GEN_UNKNOWN; in usb_add_hcd()
2900 switch (hcd->speed) { in usb_add_hcd()
2902 rhdev->speed = USB_SPEED_FULL; in usb_add_hcd()
2905 rhdev->speed = USB_SPEED_HIGH; in usb_add_hcd()
2908 rhdev->speed = USB_SPEED_SUPER; in usb_add_hcd()
2911 rhdev->rx_lanes = 2; in usb_add_hcd()
2912 rhdev->tx_lanes = 2; in usb_add_hcd()
2913 rhdev->ssp_rate = USB_SSP_GEN_2x2; in usb_add_hcd()
2914 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2917 rhdev->ssp_rate = USB_SSP_GEN_2x1; in usb_add_hcd()
2918 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2921 retval = -EINVAL; in usb_add_hcd()
2929 device_set_wakeup_capable(&rhdev->dev, 1); in usb_add_hcd()
2935 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_add_hcd()
2937 /* "reset" is misnamed; its role is now one-time init. the controller in usb_add_hcd()
2940 if (hcd->driver->reset) { in usb_add_hcd()
2941 retval = hcd->driver->reset(hcd); in usb_add_hcd()
2943 dev_err(hcd->self.controller, "can't setup: %d\n", in usb_add_hcd()
2948 hcd->rh_pollable = 1; in usb_add_hcd()
2950 retval = usb_phy_roothub_calibrate(hcd->phy_roothub); in usb_add_hcd()
2955 if (device_can_wakeup(hcd->self.controller) in usb_add_hcd()
2956 && device_can_wakeup(&hcd->self.root_hub->dev)) in usb_add_hcd()
2957 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); in usb_add_hcd()
2960 init_giveback_urb_bh(&hcd->high_prio_bh); in usb_add_hcd()
2961 hcd->high_prio_bh.high_prio = true; in usb_add_hcd()
2962 init_giveback_urb_bh(&hcd->low_prio_bh); in usb_add_hcd()
2973 hcd->state = HC_STATE_RUNNING; in usb_add_hcd()
2974 retval = hcd->driver->start(hcd); in usb_add_hcd()
2976 dev_err(hcd->self.controller, "startup error %d\n", retval); in usb_add_hcd()
2981 shared_hcd = hcd->shared_hcd; in usb_add_hcd()
2987 if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd)) in usb_add_hcd()
2997 if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) in usb_add_hcd()
3006 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) in usb_add_hcd()
3013 usb_deregister_bus(&hcd->self); in usb_add_hcd()
3017 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_add_hcd()
3019 usb_phy_roothub_exit(hcd->phy_roothub); in usb_add_hcd()
3026 * usb_remove_hcd - shutdown processing for generic HCDs
3043 rhdev = hcd->self.root_hub; in usb_remove_hcd()
3045 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); in usb_remove_hcd()
3048 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_remove_hcd()
3049 if (HC_IS_RUNNING (hcd->state)) in usb_remove_hcd()
3050 hcd->state = HC_STATE_QUIESCING; in usb_remove_hcd()
3052 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); in usb_remove_hcd()
3054 rh_registered = hcd->rh_registered; in usb_remove_hcd()
3055 hcd->rh_registered = 0; in usb_remove_hcd()
3059 cancel_work_sync(&hcd->wakeup_work); in usb_remove_hcd()
3061 cancel_work_sync(&hcd->died_work); in usb_remove_hcd()
3070 * - driver's disconnect() called from usb_disconnect() should in usb_remove_hcd()
3074 * - it is too late to run complete() here since driver may have in usb_remove_hcd()
3078 /* Prevent any more root-hub status calls from the timer. in usb_remove_hcd()
3086 if (hcd->irq > 0) in usb_remove_hcd()
3087 free_irq(hcd->irq, hcd); in usb_remove_hcd()
3090 usb_deregister_bus(&hcd->self); in usb_remove_hcd()
3093 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_remove_hcd()
3094 usb_phy_roothub_exit(hcd->phy_roothub); in usb_remove_hcd()
3097 hcd->flags = 0; in usb_remove_hcd()
3107 pm_runtime_get_sync(&dev->dev); in usb_hcd_platform_shutdown()
3109 if (hcd->driver->shutdown) in usb_hcd_platform_shutdown()
3110 hcd->driver->shutdown(hcd); in usb_hcd_platform_shutdown()
3120 hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4, in usb_hcd_setup_local_mem()
3121 dev_to_node(hcd->self.sysdev), in usb_hcd_setup_local_mem()
3122 dev_name(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3123 if (IS_ERR(hcd->localmem_pool)) in usb_hcd_setup_local_mem()
3124 return PTR_ERR(hcd->localmem_pool); in usb_hcd_setup_local_mem()
3131 local_mem = devm_memremap(hcd->self.sysdev, phys_addr, in usb_hcd_setup_local_mem()
3134 local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma, in usb_hcd_setup_local_mem()
3140 return -ENOMEM; in usb_hcd_setup_local_mem()
3150 err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem, in usb_hcd_setup_local_mem()
3151 dma, size, dev_to_node(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3153 dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n", in usb_hcd_setup_local_mem()
3162 /*-------------------------------------------------------------------------*/
3172 * Notice that the code is minimally error-proof. Because usbmon needs
3180 return -EBUSY; in usb_mon_register()