Lines Matching +full:report +full:- +full:speed +full:- +full:hz
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.
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 /*-------------------------------------------------------------------------*/
180 /* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
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()
690 /* report whether RH hardware supports remote wakeup */ in rh_call_control()
694 ((struct usb_config_descriptor *)ubuf)->bmAttributes in rh_call_control()
697 /* report whether RH hardware has an integrated TT */ 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()
766 * exceed that limit if HZ is 100. The math is more clunky than 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()
807 /* If a status change has already occurred, report it ASAP */ 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 del_timer (&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}
1071 long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount) in usb_calc_bus_time() argument
1075 switch (speed) { in usb_calc_bus_time()
1100 pr_debug ("%s: bogus device speed!\n", usbcore_name); in usb_calc_bus_time()
1101 return -1; in usb_calc_bus_time()
1107 /*-------------------------------------------------------------------------*/
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()
1279 * memory footprint over access speed since the amount 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()
1370 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | in usb_hcd_unmap_urb_for_dma()
1378 if (hcd->driver->map_urb_for_dma) in map_urb_for_dma()
1379 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1396 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1397 if (hcd->self.uses_pio_for_control) in usb_hcd_map_urb_for_dma()
1399 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1401 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1402 &urb->setup_dma, in usb_hcd_map_urb_for_dma()
1403 (void **)&urb->setup_packet, in usb_hcd_map_urb_for_dma()
1408 urb->transfer_flags |= URB_SETUP_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1410 if (object_is_on_stack(urb->setup_packet)) { in usb_hcd_map_urb_for_dma()
1412 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1415 urb->setup_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1416 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1417 urb->setup_packet, in usb_hcd_map_urb_for_dma()
1420 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1421 urb->setup_dma)) in usb_hcd_map_urb_for_dma()
1422 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1423 urb->transfer_flags |= URB_SETUP_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1428 if (urb->transfer_buffer_length != 0 in usb_hcd_map_urb_for_dma()
1429 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in usb_hcd_map_urb_for_dma()
1430 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1432 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1433 &urb->transfer_dma, in usb_hcd_map_urb_for_dma()
1434 &urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1435 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1438 urb->transfer_flags |= URB_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1440 if (urb->num_sgs) { in usb_hcd_map_urb_for_dma()
1444 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1446 return -EINVAL; in usb_hcd_map_urb_for_dma()
1450 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1451 urb->sg, in usb_hcd_map_urb_for_dma()
1452 urb->num_sgs, in usb_hcd_map_urb_for_dma()
1455 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1457 urb->transfer_flags |= URB_DMA_MAP_SG; in usb_hcd_map_urb_for_dma()
1458 urb->num_mapped_sgs = n; in usb_hcd_map_urb_for_dma()
1459 if (n != urb->num_sgs) in usb_hcd_map_urb_for_dma()
1460 urb->transfer_flags |= in usb_hcd_map_urb_for_dma()
1462 } else if (urb->sg) { in usb_hcd_map_urb_for_dma()
1463 struct scatterlist *sg = urb->sg; in usb_hcd_map_urb_for_dma()
1464 urb->transfer_dma = dma_map_page( in usb_hcd_map_urb_for_dma()
1465 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1467 sg->offset, in usb_hcd_map_urb_for_dma()
1468 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1470 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1471 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1472 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1474 urb->transfer_flags |= URB_DMA_MAP_PAGE; in usb_hcd_map_urb_for_dma()
1475 } else if (object_is_on_stack(urb->transfer_buffer)) { in usb_hcd_map_urb_for_dma()
1477 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1479 urb->transfer_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1480 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1481 urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1482 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1484 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1485 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1486 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1488 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1491 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | in usb_hcd_map_urb_for_dma()
1499 /*-------------------------------------------------------------------------*/
1501 /* may be called in any context with a valid urb->dev usecount
1509 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_submit_urb()
1516 atomic_inc(&urb->use_count); in usb_hcd_submit_urb()
1517 atomic_inc(&urb->dev->urbnum); in usb_hcd_submit_urb()
1518 usbmon_urb_submit(&hcd->self, urb); in usb_hcd_submit_urb()
1520 /* NOTE requirements on root-hub callers (usbfs and the hub in usb_hcd_submit_urb()
1521 * driver, for now): URBs' urb->transfer_buffer must be in usb_hcd_submit_urb()
1528 if (is_root_hub(urb->dev)) { in usb_hcd_submit_urb()
1533 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1540 usbmon_urb_submit_error(&hcd->self, urb, status); in usb_hcd_submit_urb()
1541 urb->hcpriv = NULL; in usb_hcd_submit_urb()
1542 INIT_LIST_HEAD(&urb->urb_list); in usb_hcd_submit_urb()
1543 atomic_dec(&urb->use_count); in usb_hcd_submit_urb()
1545 * Order the write of urb->use_count above before the read in usb_hcd_submit_urb()
1546 * of urb->reject below. Pairs with the memory barriers in in usb_hcd_submit_urb()
1551 atomic_dec(&urb->dev->urbnum); in usb_hcd_submit_urb()
1552 if (atomic_read(&urb->reject)) in usb_hcd_submit_urb()
1559 /*-------------------------------------------------------------------------*/
1570 if (is_root_hub(urb->dev)) in unlink1()
1577 value = hcd->driver->urb_dequeue(hcd, urb, status); in unlink1()
1591 struct usb_device *udev = urb->dev; in usb_hcd_unlink_urb()
1592 int retval = -EIDRM; in usb_hcd_unlink_urb()
1597 * then urb->use_count must be 0, since disconnected in usb_hcd_unlink_urb()
1601 if (atomic_read(&urb->use_count) > 0) { in usb_hcd_unlink_urb()
1607 hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_unlink_urb()
1610 retval = -EINPROGRESS; in usb_hcd_unlink_urb()
1611 else if (retval != -EIDRM && retval != -EBUSY) in usb_hcd_unlink_urb()
1612 dev_dbg(&udev->dev, "hcd_unlink_urb %pK fail %d\n", in usb_hcd_unlink_urb()
1619 /*-------------------------------------------------------------------------*/
1623 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in __usb_hcd_giveback_urb()
1624 struct usb_anchor *anchor = urb->anchor; in __usb_hcd_giveback_urb()
1625 int status = urb->unlinked; in __usb_hcd_giveback_urb()
1628 urb->hcpriv = NULL; in __usb_hcd_giveback_urb()
1629 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && in __usb_hcd_giveback_urb()
1630 urb->actual_length < urb->transfer_buffer_length && in __usb_hcd_giveback_urb()
1632 status = -EREMOTEIO; in __usb_hcd_giveback_urb()
1635 usbmon_urb_complete(&hcd->self, urb, status); in __usb_hcd_giveback_urb()
1642 urb->status = status; in __usb_hcd_giveback_urb()
1649 flags = kcov_remote_start_usb_softirq((u64)urb->dev->bus->busnum); in __usb_hcd_giveback_urb()
1650 urb->complete(urb); in __usb_hcd_giveback_urb()
1654 atomic_dec(&urb->use_count); in __usb_hcd_giveback_urb()
1656 * Order the write of urb->use_count above before the read in __usb_hcd_giveback_urb()
1657 * of urb->reject below. Pairs with the memory barriers in in __usb_hcd_giveback_urb()
1662 if (unlikely(atomic_read(&urb->reject))) in __usb_hcd_giveback_urb()
1673 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1674 bh->running = true; in usb_giveback_urb_bh()
1675 list_replace_init(&bh->head, &local_list); in usb_giveback_urb_bh()
1676 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1682 list_del_init(&urb->urb_list); in usb_giveback_urb_bh()
1683 bh->completing_ep = urb->ep; in usb_giveback_urb_bh()
1685 bh->completing_ep = NULL; in usb_giveback_urb_bh()
1692 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1693 if (!list_empty(&bh->head)) { in usb_giveback_urb_bh()
1694 if (bh->high_prio) in usb_giveback_urb_bh()
1695 queue_work(system_bh_highpri_wq, &bh->bh); in usb_giveback_urb_bh()
1697 queue_work(system_bh_wq, &bh->bh); in usb_giveback_urb_bh()
1699 bh->running = false; in usb_giveback_urb_bh()
1700 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1704 * usb_hcd_giveback_urb - return URB from HCD to device driver
1715 * completion function. The HCD has freed all per-urb resources
1716 * (and is done using urb->hcpriv). It also released all HCD locks;
1721 * @urb->unlinked. Erroneous short transfers are detected in case
1730 if (likely(!urb->unlinked)) in usb_hcd_giveback_urb()
1731 urb->unlinked = status; in usb_hcd_giveback_urb()
1733 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) { in usb_hcd_giveback_urb()
1738 if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) in usb_hcd_giveback_urb()
1739 bh = &hcd->high_prio_bh; in usb_hcd_giveback_urb()
1741 bh = &hcd->low_prio_bh; in usb_hcd_giveback_urb()
1743 spin_lock(&bh->lock); in usb_hcd_giveback_urb()
1744 list_add_tail(&urb->urb_list, &bh->head); in usb_hcd_giveback_urb()
1745 running = bh->running; in usb_hcd_giveback_urb()
1746 spin_unlock(&bh->lock); in usb_hcd_giveback_urb()
1750 else if (bh->high_prio) in usb_hcd_giveback_urb()
1751 queue_work(system_bh_highpri_wq, &bh->bh); in usb_hcd_giveback_urb()
1753 queue_work(system_bh_wq, &bh->bh); in usb_hcd_giveback_urb()
1757 /*-------------------------------------------------------------------------*/
1772 hcd = bus_to_hcd(udev->bus); in usb_hcd_flush_endpoint()
1777 list_for_each_entry_reverse(urb, &ep->urb_list, urb_list) { in usb_hcd_flush_endpoint()
1780 if (urb->unlinked) in usb_hcd_flush_endpoint()
1787 unlink1(hcd, urb, -ESHUTDOWN); in usb_hcd_flush_endpoint()
1788 dev_dbg (hcd->self.controller, in usb_hcd_flush_endpoint()
1789 "shutdown urb %pK ep%d%s-%s\n", in usb_hcd_flush_endpoint()
1790 urb, usb_endpoint_num(&ep->desc), in usb_hcd_flush_endpoint()
1792 usb_ep_type_string(usb_endpoint_type(&ep->desc))); in usb_hcd_flush_endpoint()
1802 while (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1807 if (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1808 urb = list_entry (ep->urb_list.prev, struct urb, in usb_hcd_flush_endpoint()
1822 * usb_hcd_alloc_bandwidth - check whether a new bandwidth setting exceeds
1853 hcd = bus_to_hcd(udev->bus); in usb_hcd_alloc_bandwidth()
1854 if (!hcd->driver->check_bandwidth) in usb_hcd_alloc_bandwidth()
1857 /* Configuration is being removed - set configuration 0 */ in usb_hcd_alloc_bandwidth()
1860 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1862 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1863 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1865 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1867 hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1876 num_intfs = new_config->desc.bNumInterfaces; in usb_hcd_alloc_bandwidth()
1881 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1883 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1887 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1889 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1898 first_alt = &new_config->intf_cache[i]->altsetting[0]; in usb_hcd_alloc_bandwidth()
1899 iface_num = first_alt->desc.bInterfaceNumber; in usb_hcd_alloc_bandwidth()
1906 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in usb_hcd_alloc_bandwidth()
1907 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); in usb_hcd_alloc_bandwidth()
1915 cur_alt->desc.bInterfaceNumber); in usb_hcd_alloc_bandwidth()
1918 return -EINVAL; in usb_hcd_alloc_bandwidth()
1919 if (iface->resetting_device) { in usb_hcd_alloc_bandwidth()
1931 cur_alt = &iface->altsetting[0]; in usb_hcd_alloc_bandwidth()
1935 for (i = 0; i < cur_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1936 ret = hcd->driver->drop_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1937 &cur_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1942 for (i = 0; i < new_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1943 ret = hcd->driver->add_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1944 &new_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1949 ret = hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1952 hcd->driver->reset_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1961 * example: a qh stored in ep->hcpriv, holding state related to endpoint
1970 hcd = bus_to_hcd(udev->bus); in usb_hcd_disable_endpoint()
1971 if (hcd->driver->endpoint_disable) in usb_hcd_disable_endpoint()
1972 hcd->driver->endpoint_disable(hcd, ep); in usb_hcd_disable_endpoint()
1976 * usb_hcd_reset_endpoint - reset host endpoint state
1986 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_reset_endpoint()
1988 if (hcd->driver->endpoint_reset) in usb_hcd_reset_endpoint()
1989 hcd->driver->endpoint_reset(hcd, ep); in usb_hcd_reset_endpoint()
1991 int epnum = usb_endpoint_num(&ep->desc); in usb_hcd_reset_endpoint()
1992 int is_out = usb_endpoint_dir_out(&ep->desc); in usb_hcd_reset_endpoint()
1993 int is_control = usb_endpoint_xfer_control(&ep->desc); in usb_hcd_reset_endpoint()
2002 * usb_alloc_streams - allocate bulk endpoint stream IDs.
2025 hcd = bus_to_hcd(dev->bus); in usb_alloc_streams()
2026 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams) in usb_alloc_streams()
2027 return -EINVAL; in usb_alloc_streams()
2028 if (dev->speed < USB_SPEED_SUPER) in usb_alloc_streams()
2029 return -EINVAL; in usb_alloc_streams()
2030 if (dev->state < USB_STATE_CONFIGURED) in usb_alloc_streams()
2031 return -ENODEV; in usb_alloc_streams()
2035 if (!usb_endpoint_xfer_bulk(&eps[i]->desc)) in usb_alloc_streams()
2036 return -EINVAL; in usb_alloc_streams()
2037 /* Re-alloc is not allowed */ in usb_alloc_streams()
2038 if (eps[i]->streams) in usb_alloc_streams()
2039 return -EINVAL; in usb_alloc_streams()
2042 ret = hcd->driver->alloc_streams(hcd, dev, eps, num_eps, in usb_alloc_streams()
2048 eps[i]->streams = ret; in usb_alloc_streams()
2055 * usb_free_streams - free bulk endpoint stream IDs.
2075 hcd = bus_to_hcd(dev->bus); in usb_free_streams()
2076 if (dev->speed < USB_SPEED_SUPER) in usb_free_streams()
2077 return -EINVAL; in usb_free_streams()
2079 /* Double-free is not allowed */ in usb_free_streams()
2081 if (!eps[i] || !eps[i]->streams) in usb_free_streams()
2082 return -EINVAL; in usb_free_streams()
2084 ret = hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); in usb_free_streams()
2089 eps[i]->streams = 0; in usb_free_streams()
2106 /*-------------------------------------------------------------------------*/
2111 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_get_frame_number()
2114 return -ESHUTDOWN; in usb_hcd_get_frame_number()
2115 return hcd->driver->get_frame_number (hcd); in usb_hcd_get_frame_number()
2118 /*-------------------------------------------------------------------------*/
2123 struct completion *done = urb->context; in usb_ehset_completion()
2140 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in request_single_step_set_feature_urb()
2146 urb->pipe = usb_rcvctrlpipe(udev, 0); in request_single_step_set_feature_urb()
2148 urb->ep = &udev->ep0; in request_single_step_set_feature_urb()
2149 urb->dev = udev; in request_single_step_set_feature_urb()
2150 urb->setup_packet = (void *)dr; in request_single_step_set_feature_urb()
2151 urb->transfer_buffer = buf; in request_single_step_set_feature_urb()
2152 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE; in request_single_step_set_feature_urb()
2153 urb->complete = usb_ehset_completion; in request_single_step_set_feature_urb()
2154 urb->status = -EINPROGRESS; in request_single_step_set_feature_urb()
2155 urb->actual_length = 0; in request_single_step_set_feature_urb()
2156 urb->transfer_flags = URB_DIR_IN; in request_single_step_set_feature_urb()
2158 atomic_inc(&urb->use_count); in request_single_step_set_feature_urb()
2159 atomic_inc(&urb->dev->urbnum); in request_single_step_set_feature_urb()
2166 urb->context = done; in request_single_step_set_feature_urb()
2172 int retval = -ENOMEM; in ehset_single_step_set_feature()
2180 udev = usb_hub_find_child(hcd->self.root_hub, port); in ehset_single_step_set_feature()
2182 dev_err(hcd->self.controller, "No device attached to the RootHub\n"); in ehset_single_step_set_feature()
2183 return -ENODEV; in ehset_single_step_set_feature()
2187 return -ENOMEM; in ehset_single_step_set_feature()
2192 return -ENOMEM; in ehset_single_step_set_feature()
2196 dr->bRequestType = USB_DIR_IN; in ehset_single_step_set_feature()
2197 dr->bRequest = USB_REQ_GET_DESCRIPTOR; in ehset_single_step_set_feature()
2198 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8); in ehset_single_step_set_feature()
2199 dr->wIndex = 0; in ehset_single_step_set_feature()
2200 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE); in ehset_single_step_set_feature()
2206 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 1); in ehset_single_step_set_feature()
2211 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2212 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2219 urb->status = -EINPROGRESS; in ehset_single_step_set_feature()
2221 atomic_inc(&urb->use_count); in ehset_single_step_set_feature()
2222 atomic_inc(&urb->dev->urbnum); in ehset_single_step_set_feature()
2223 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0); in ehset_single_step_set_feature()
2227 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2228 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2241 /*-------------------------------------------------------------------------*/
2247 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_suspend()
2249 int old_state = hcd->state; in hcd_bus_suspend()
2251 dev_dbg(&rhdev->dev, "bus %ssuspend, wakeup %d\n", in hcd_bus_suspend()
2252 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in hcd_bus_suspend()
2253 rhdev->do_remote_wakeup); in hcd_bus_suspend()
2255 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend"); in hcd_bus_suspend()
2259 if (!hcd->driver->bus_suspend) { in hcd_bus_suspend()
2260 status = -ENOENT; in hcd_bus_suspend()
2262 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2263 hcd->state = HC_STATE_QUIESCING; in hcd_bus_suspend()
2264 status = hcd->driver->bus_suspend(hcd); in hcd_bus_suspend()
2268 hcd->state = HC_STATE_SUSPENDED; in hcd_bus_suspend()
2271 usb_phy_roothub_suspend(hcd->self.sysdev, in hcd_bus_suspend()
2272 hcd->phy_roothub); in hcd_bus_suspend()
2274 /* Did we race with a root-hub wakeup event? */ in hcd_bus_suspend()
2275 if (rhdev->do_remote_wakeup) { in hcd_bus_suspend()
2278 status = hcd->driver->hub_status_data(hcd, buffer); in hcd_bus_suspend()
2280 dev_dbg(&rhdev->dev, "suspend raced with wakeup event\n"); in hcd_bus_suspend()
2282 status = -EBUSY; in hcd_bus_suspend()
2288 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2289 hcd->state = old_state; in hcd_bus_suspend()
2292 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_suspend()
2300 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_resume()
2302 int old_state = hcd->state; in hcd_bus_resume()
2304 dev_dbg(&rhdev->dev, "usb %sresume\n", in hcd_bus_resume()
2305 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in hcd_bus_resume()
2307 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); in hcd_bus_resume()
2312 status = usb_phy_roothub_resume(hcd->self.sysdev, in hcd_bus_resume()
2313 hcd->phy_roothub); in hcd_bus_resume()
2318 if (!hcd->driver->bus_resume) in hcd_bus_resume()
2319 return -ENOENT; in hcd_bus_resume()
2323 hcd->state = HC_STATE_RESUMING; in hcd_bus_resume()
2324 status = hcd->driver->bus_resume(hcd); in hcd_bus_resume()
2325 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in hcd_bus_resume()
2327 status = usb_phy_roothub_calibrate(hcd->phy_roothub); in hcd_bus_resume()
2335 usb_set_device_state(rhdev, rhdev->actconfig in hcd_bus_resume()
2338 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_resume()
2339 hcd->state = HC_STATE_RUNNING; in hcd_bus_resume()
2346 * (this is what the USB-2 spec calls a "global resume"). in hcd_bus_resume()
2350 if (udev->state != USB_STATE_NOTATTACHED && in hcd_bus_resume()
2351 !udev->port_is_suspended) { in hcd_bus_resume()
2357 hcd->state = old_state; in hcd_bus_resume()
2358 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); in hcd_bus_resume()
2359 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_resume()
2361 if (status != -ESHUTDOWN) in hcd_bus_resume()
2367 /* Workqueue routine for root-hub remote wakeup */
2371 struct usb_device *udev = hcd->self.root_hub; in hcd_resume_work()
2377 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2390 if (hcd->rh_registered) { in usb_hcd_resume_root_hub()
2391 pm_wakeup_event(&hcd->self.root_hub->dev, 0); in usb_hcd_resume_root_hub()
2392 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in usb_hcd_resume_root_hub()
2393 queue_work(pm_wq, &hcd->wakeup_work); in usb_hcd_resume_root_hub()
2401 /*-------------------------------------------------------------------------*/
2406 * usb_bus_start_enum - start immediate enumeration (for OTG)
2408 * @port_num: 1-based number of port; usually bus->otg_port
2421 int status = -EOPNOTSUPP; in usb_bus_start_enum()
2428 if (port_num && hcd->driver->start_port_reset) in usb_bus_start_enum()
2429 status = hcd->driver->start_port_reset(hcd, port_num); in usb_bus_start_enum()
2435 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); in usb_bus_start_enum()
2442 /*-------------------------------------------------------------------------*/
2445 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
2461 else if (hcd->driver->irq(hcd) == IRQ_NONE) in usb_hcd_irq()
2470 /*-------------------------------------------------------------------------*/
2472 /* Workqueue routine for when the root-hub has died. */
2482 kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env); in hcd_died_work()
2486 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
2489 * This is called by bus glue to report a USB host controller that died
2491 * by the PCI glue, so only glue for non-PCI busses should need to call it.
2499 dev_err (hcd->self.controller, "HC died; cleaning up\n"); in usb_hc_died()
2502 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2503 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2504 if (hcd->rh_registered) { in usb_hc_died()
2505 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2508 usb_set_device_state (hcd->self.root_hub, in usb_hc_died()
2510 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2512 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { in usb_hc_died()
2513 hcd = hcd->shared_hcd; in usb_hc_died()
2514 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2515 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2516 if (hcd->rh_registered) { in usb_hc_died()
2517 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2520 usb_set_device_state(hcd->self.root_hub, in usb_hc_died()
2522 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2528 schedule_work(&hcd->died_work); in usb_hc_died()
2530 schedule_work(&hcd->primary_hcd->died_work); in usb_hc_died()
2537 /*-------------------------------------------------------------------------*/
2542 spin_lock_init(&bh->lock); in init_giveback_urb_bh()
2543 INIT_LIST_HEAD(&bh->head); in init_giveback_urb_bh()
2544 INIT_WORK(&bh->bh, usb_giveback_urb_bh); in init_giveback_urb_bh()
2553 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); in __usb_create_hcd()
2557 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), in __usb_create_hcd()
2559 if (!hcd->address0_mutex) { in __usb_create_hcd()
2564 mutex_init(hcd->address0_mutex); in __usb_create_hcd()
2565 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), in __usb_create_hcd()
2567 if (!hcd->bandwidth_mutex) { in __usb_create_hcd()
2568 kfree(hcd->address0_mutex); in __usb_create_hcd()
2573 mutex_init(hcd->bandwidth_mutex); in __usb_create_hcd()
2577 hcd->address0_mutex = primary_hcd->address0_mutex; in __usb_create_hcd()
2578 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; in __usb_create_hcd()
2579 hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2580 primary_hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2581 hcd->shared_hcd = primary_hcd; in __usb_create_hcd()
2582 primary_hcd->shared_hcd = hcd; in __usb_create_hcd()
2586 kref_init(&hcd->kref); in __usb_create_hcd()
2588 usb_bus_init(&hcd->self); in __usb_create_hcd()
2589 hcd->self.controller = dev; in __usb_create_hcd()
2590 hcd->self.sysdev = sysdev; in __usb_create_hcd()
2591 hcd->self.bus_name = bus_name; in __usb_create_hcd()
2593 timer_setup(&hcd->rh_timer, rh_timer_func, 0); in __usb_create_hcd()
2595 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); in __usb_create_hcd()
2598 INIT_WORK(&hcd->died_work, hcd_died_work); in __usb_create_hcd()
2600 hcd->driver = driver; in __usb_create_hcd()
2601 hcd->speed = driver->flags & HCD_MASK; in __usb_create_hcd()
2602 hcd->product_desc = (driver->product_desc) ? driver->product_desc : in __usb_create_hcd()
2609 * usb_create_shared_hcd - create and initialize an HCD structure
2611 * @dev: device for this HC, stored in hcd->self.controller
2612 * @bus_name: value to store in hcd->self.bus_name
2634 * usb_create_hcd - create and initialize an HCD structure
2636 * @dev: device for this HC, stored in hcd->self.controller
2637 * @bus_name: value to store in hcd->self.bus_name
2662 * invalidate the peer's ->shared_hcd and ->primary_hcd pointers.
2669 if (hcd->shared_hcd) { in hcd_release()
2670 struct usb_hcd *peer = hcd->shared_hcd; in hcd_release()
2672 peer->shared_hcd = NULL; in hcd_release()
2673 peer->primary_hcd = NULL; in hcd_release()
2675 kfree(hcd->address0_mutex); in hcd_release()
2676 kfree(hcd->bandwidth_mutex); in hcd_release()
2685 kref_get (&hcd->kref); in usb_get_hcd()
2693 kref_put (&hcd->kref, hcd_release); in usb_put_hcd()
2699 if (!hcd->primary_hcd) in usb_hcd_is_primary_hcd()
2701 return hcd == hcd->primary_hcd; in usb_hcd_is_primary_hcd()
2707 if (!hcd->driver->find_raw_port_number) in usb_hcd_find_raw_port_number()
2710 return hcd->driver->find_raw_port_number(hcd, port1); in usb_hcd_find_raw_port_number()
2718 if (hcd->driver->irq) { in usb_hcd_request_irqs()
2720 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in usb_hcd_request_irqs()
2721 hcd->driver->description, hcd->self.busnum); in usb_hcd_request_irqs()
2723 hcd->irq_descr, hcd); in usb_hcd_request_irqs()
2725 dev_err(hcd->self.controller, in usb_hcd_request_irqs()
2730 hcd->irq = irqnum; in usb_hcd_request_irqs()
2731 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, in usb_hcd_request_irqs()
2732 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2734 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2736 hcd->irq = 0; in usb_hcd_request_irqs()
2737 if (hcd->rsrc_start) in usb_hcd_request_irqs()
2738 dev_info(hcd->self.controller, "%s 0x%08llx\n", in usb_hcd_request_irqs()
2739 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2741 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2747 * Before we free this root hub, flush in-flight peering attempts
2755 rhdev = hcd->self.root_hub; in usb_put_invalidate_rhdev()
2756 hcd->self.root_hub = NULL; in usb_put_invalidate_rhdev()
2762 * usb_stop_hcd - Halt the HCD
2765 * Stop the root-hub polling timer and invoke the HCD's ->stop callback.
2769 hcd->rh_pollable = 0; in usb_stop_hcd()
2770 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2771 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2773 hcd->driver->stop(hcd); in usb_stop_hcd()
2774 hcd->state = HC_STATE_HALT; in usb_stop_hcd()
2777 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2778 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2782 * usb_add_hcd - finish generic HCD structure initialization and register
2798 if (!hcd->skip_phy_initialization) { in usb_add_hcd()
2800 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); in usb_add_hcd()
2801 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2802 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2804 hcd->phy_roothub = usb_phy_roothub_alloc_usb3_phy(hcd->self.sysdev); in usb_add_hcd()
2805 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2806 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2809 retval = usb_phy_roothub_init(hcd->phy_roothub); in usb_add_hcd()
2813 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2816 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2821 retval = usb_phy_roothub_power_on(hcd->phy_roothub); in usb_add_hcd()
2826 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); in usb_add_hcd()
2830 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; in usb_add_hcd()
2834 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; in usb_add_hcd()
2840 hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; in usb_add_hcd()
2844 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in usb_add_hcd()
2847 set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags); in usb_add_hcd()
2849 /* HC is in reset state, but accessible. Now do the one-time init, in usb_add_hcd()
2855 dev_dbg(hcd->self.sysdev, "pool alloc failed\n"); in usb_add_hcd()
2859 retval = usb_register_bus(&hcd->self); in usb_add_hcd()
2863 rhdev = usb_alloc_dev(NULL, &hcd->self, 0); in usb_add_hcd()
2865 dev_err(hcd->self.sysdev, "unable to allocate root hub\n"); in usb_add_hcd()
2866 retval = -ENOMEM; in usb_add_hcd()
2870 hcd->self.root_hub = rhdev; in usb_add_hcd()
2873 rhdev->rx_lanes = 1; in usb_add_hcd()
2874 rhdev->tx_lanes = 1; in usb_add_hcd()
2875 rhdev->ssp_rate = USB_SSP_GEN_UNKNOWN; in usb_add_hcd()
2877 switch (hcd->speed) { in usb_add_hcd()
2879 rhdev->speed = USB_SPEED_FULL; in usb_add_hcd()
2882 rhdev->speed = USB_SPEED_HIGH; in usb_add_hcd()
2885 rhdev->speed = USB_SPEED_SUPER; in usb_add_hcd()
2888 rhdev->rx_lanes = 2; in usb_add_hcd()
2889 rhdev->tx_lanes = 2; in usb_add_hcd()
2890 rhdev->ssp_rate = USB_SSP_GEN_2x2; in usb_add_hcd()
2891 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2894 rhdev->ssp_rate = USB_SSP_GEN_2x1; in usb_add_hcd()
2895 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2898 retval = -EINVAL; in usb_add_hcd()
2906 device_set_wakeup_capable(&rhdev->dev, 1); in usb_add_hcd()
2912 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_add_hcd()
2914 /* "reset" is misnamed; its role is now one-time init. the controller in usb_add_hcd()
2917 if (hcd->driver->reset) { in usb_add_hcd()
2918 retval = hcd->driver->reset(hcd); in usb_add_hcd()
2920 dev_err(hcd->self.controller, "can't setup: %d\n", in usb_add_hcd()
2925 hcd->rh_pollable = 1; in usb_add_hcd()
2927 retval = usb_phy_roothub_calibrate(hcd->phy_roothub); in usb_add_hcd()
2932 if (device_can_wakeup(hcd->self.controller) in usb_add_hcd()
2933 && device_can_wakeup(&hcd->self.root_hub->dev)) in usb_add_hcd()
2934 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); in usb_add_hcd()
2937 init_giveback_urb_bh(&hcd->high_prio_bh); in usb_add_hcd()
2938 hcd->high_prio_bh.high_prio = true; in usb_add_hcd()
2939 init_giveback_urb_bh(&hcd->low_prio_bh); in usb_add_hcd()
2950 hcd->state = HC_STATE_RUNNING; in usb_add_hcd()
2951 retval = hcd->driver->start(hcd); in usb_add_hcd()
2953 dev_err(hcd->self.controller, "startup error %d\n", retval); in usb_add_hcd()
2958 shared_hcd = hcd->shared_hcd; in usb_add_hcd()
2964 if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd)) in usb_add_hcd()
2974 if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) in usb_add_hcd()
2983 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) in usb_add_hcd()
2990 usb_deregister_bus(&hcd->self); in usb_add_hcd()
2994 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_add_hcd()
2996 usb_phy_roothub_exit(hcd->phy_roothub); in usb_add_hcd()
3003 * usb_remove_hcd - shutdown processing for generic HCDs
3020 rhdev = hcd->self.root_hub; in usb_remove_hcd()
3022 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); in usb_remove_hcd()
3025 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_remove_hcd()
3026 if (HC_IS_RUNNING (hcd->state)) in usb_remove_hcd()
3027 hcd->state = HC_STATE_QUIESCING; in usb_remove_hcd()
3029 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); in usb_remove_hcd()
3031 rh_registered = hcd->rh_registered; in usb_remove_hcd()
3032 hcd->rh_registered = 0; in usb_remove_hcd()
3036 cancel_work_sync(&hcd->wakeup_work); in usb_remove_hcd()
3038 cancel_work_sync(&hcd->died_work); in usb_remove_hcd()
3047 * - driver's disconnect() called from usb_disconnect() should in usb_remove_hcd()
3051 * - it is too late to run complete() here since driver may have in usb_remove_hcd()
3055 /* Prevent any more root-hub status calls from the timer. in usb_remove_hcd()
3063 if (hcd->irq > 0) in usb_remove_hcd()
3064 free_irq(hcd->irq, hcd); in usb_remove_hcd()
3067 usb_deregister_bus(&hcd->self); in usb_remove_hcd()
3070 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_remove_hcd()
3071 usb_phy_roothub_exit(hcd->phy_roothub); in usb_remove_hcd()
3074 hcd->flags = 0; in usb_remove_hcd()
3084 pm_runtime_get_sync(&dev->dev); in usb_hcd_platform_shutdown()
3086 if (hcd->driver->shutdown) in usb_hcd_platform_shutdown()
3087 hcd->driver->shutdown(hcd); in usb_hcd_platform_shutdown()
3097 hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4, in usb_hcd_setup_local_mem()
3098 dev_to_node(hcd->self.sysdev), in usb_hcd_setup_local_mem()
3099 dev_name(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3100 if (IS_ERR(hcd->localmem_pool)) in usb_hcd_setup_local_mem()
3101 return PTR_ERR(hcd->localmem_pool); in usb_hcd_setup_local_mem()
3108 local_mem = devm_memremap(hcd->self.sysdev, phys_addr, in usb_hcd_setup_local_mem()
3111 local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma, in usb_hcd_setup_local_mem()
3117 return -ENOMEM; in usb_hcd_setup_local_mem()
3127 err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem, in usb_hcd_setup_local_mem()
3128 dma, size, dev_to_node(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3130 dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n", in usb_hcd_setup_local_mem()
3139 /*-------------------------------------------------------------------------*/
3149 * Notice that the code is minimally error-proof. Because usbmon needs
3157 return -EBUSY; in usb_mon_register()