Lines Matching +full:self +full:- +full:powered

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 /*-------------------------------------------------------------------------*/
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
364 "authorized, 2 is authorized for internal devices, -1 is "
366 /*-------------------------------------------------------------------------*/
369 * ascii2desc() - Helper routine for producing UTF-16LE string descriptors
370 * @s: Null-terminated ASCII (actually ISO-8859-1) string
371 * @buf: Buffer for USB string descriptor (header + UTF-16LE)
394 while (n--) { in ascii2desc()
396 if (!n--) in ascii2desc()
405 * rh_string() - provides string descriptors for root hub
427 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ in rh_string()
435 s = hcd->self.bus_name; in rh_string()
439 s = hcd->product_desc; in rh_string()
443 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, in rh_string()
444 init_utsname()->release, hcd->driver->description); in rh_string()
461 u8 *ubuf = urb->transfer_buffer; in rh_call_control()
477 urb->hcpriv = hcd; /* Indicate it's queued */ in rh_call_control()
479 cmd = (struct usb_ctrlrequest *) urb->setup_packet; in rh_call_control()
480 typeReq = (cmd->bRequestType << 8) | cmd->bRequest; in rh_call_control()
481 wValue = le16_to_cpu (cmd->wValue); in rh_call_control()
482 wIndex = le16_to_cpu (cmd->wIndex); in rh_call_control()
483 wLength = le16_to_cpu (cmd->wLength); in rh_call_control()
485 if (wLength > urb->transfer_buffer_length) in rh_call_control()
495 status = -ENOMEM; in rh_call_control()
502 urb->actual_length = 0; in rh_call_control()
524 tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
532 device_set_wakeup_enable(&hcd->self.root_hub->dev, 0); in rh_call_control()
537 if (device_can_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
539 device_set_wakeup_enable(&hcd->self.root_hub->dev, 1); in rh_call_control()
552 switch (hcd->speed) { in rh_call_control()
570 if (hcd->has_tt) in rh_call_control()
574 switch (hcd->speed) { in rh_call_control()
592 if (device_can_wakeup(&hcd->self.root_hub->dev)) in rh_call_control()
597 urb->actual_length = rh_string(wValue & 0xff, in rh_call_control()
599 else /* unsupported IDs --> "protocol stall" */ in rh_call_control()
615 /* wValue == urb->dev->devaddr */ in rh_call_control()
616 dev_dbg (hcd->self.controller, "root hub device address %d\n", in rh_call_control()
632 dev_dbg (hcd->self.controller, "no endpoint features yet\n"); in rh_call_control()
639 /* non-generic request */ in rh_call_control()
658 status = hcd->driver->hub_control (hcd, in rh_call_control()
663 usb_hub_adjust_deviceremovable(hcd->self.root_hub, in rh_call_control()
668 status = -EPIPE; in rh_call_control()
673 if (status != -EPIPE) { in rh_call_control()
674 dev_dbg (hcd->self.controller, in rh_call_control()
686 if (urb->transfer_buffer_length < len) in rh_call_control()
687 len = urb->transfer_buffer_length; in rh_call_control()
688 urb->actual_length = len; in rh_call_control()
696 ((struct usb_config_descriptor *)ubuf)->bmAttributes in rh_call_control()
703 ((struct usb_device_descriptor *) ubuf)-> in rh_call_control()
718 /*-------------------------------------------------------------------------*/
735 if (unlikely(!hcd->rh_pollable)) in usb_hcd_poll_rh_status()
737 if (!hcd->uses_new_polling && !hcd->status_urb) in usb_hcd_poll_rh_status()
740 length = hcd->driver->hub_status_data(hcd, buffer); in usb_hcd_poll_rh_status()
745 urb = hcd->status_urb; in usb_hcd_poll_rh_status()
747 clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
748 hcd->status_urb = NULL; in usb_hcd_poll_rh_status()
749 if (urb->transfer_buffer_length >= length) { in usb_hcd_poll_rh_status()
752 status = -EOVERFLOW; in usb_hcd_poll_rh_status()
753 length = urb->transfer_buffer_length; in usb_hcd_poll_rh_status()
755 urb->actual_length = length; in usb_hcd_poll_rh_status()
756 memcpy(urb->transfer_buffer, buffer, length); in usb_hcd_poll_rh_status()
762 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
771 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : in usb_hcd_poll_rh_status()
772 (length == 0 && hcd->status_urb != NULL)) in usb_hcd_poll_rh_status()
773 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in usb_hcd_poll_rh_status()
785 /*-------------------------------------------------------------------------*/
791 unsigned len = 1 + (urb->dev->maxchild / 8); in rh_queue_status()
794 if (hcd->status_urb || urb->transfer_buffer_length < len) { in rh_queue_status()
795 dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); in rh_queue_status()
796 retval = -EINVAL; in rh_queue_status()
804 hcd->status_urb = urb; in rh_queue_status()
805 urb->hcpriv = hcd; /* indicate it's queued */ in rh_queue_status()
806 if (!hcd->uses_new_polling) in rh_queue_status()
807 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in rh_queue_status()
811 mod_timer(&hcd->rh_timer, jiffies); in rh_queue_status()
820 if (usb_endpoint_xfer_int(&urb->ep->desc)) in rh_urb_enqueue()
822 if (usb_endpoint_xfer_control(&urb->ep->desc)) in rh_urb_enqueue()
824 return -EINVAL; in rh_urb_enqueue()
827 /*-------------------------------------------------------------------------*/
829 /* Unlinks of root-hub control URBs are legal, but they don't do anything
842 if (usb_endpoint_num(&urb->ep->desc) == 0) { /* Control URB */ in usb_rh_urb_dequeue()
846 if (!hcd->uses_new_polling) in usb_rh_urb_dequeue()
847 del_timer (&hcd->rh_timer); in usb_rh_urb_dequeue()
848 if (urb == hcd->status_urb) { in usb_rh_urb_dequeue()
849 hcd->status_urb = NULL; in usb_rh_urb_dequeue()
860 /*-------------------------------------------------------------------------*/
863 * usb_bus_init - shared initialization code
871 memset (&bus->devmap, 0, sizeof(struct usb_devmap)); in usb_bus_init()
873 bus->devnum_next = 1; in usb_bus_init()
875 bus->root_hub = NULL; in usb_bus_init()
876 bus->busnum = -1; in usb_bus_init()
877 bus->bandwidth_allocated = 0; in usb_bus_init()
878 bus->bandwidth_int_reqs = 0; in usb_bus_init()
879 bus->bandwidth_isoc_reqs = 0; in usb_bus_init()
880 mutex_init(&bus->devnum_next_mutex); in usb_bus_init()
883 /*-------------------------------------------------------------------------*/
886 * usb_register_bus - registers the USB host controller with the usb core
898 int result = -E2BIG; in usb_register_bus()
907 bus->busnum = busnum; in usb_register_bus()
912 dev_info (bus->controller, "new USB bus registered, assigned bus " in usb_register_bus()
913 "number %d\n", bus->busnum); in usb_register_bus()
922 * usb_deregister_bus - deregisters the USB host controller
932 dev_info (bus->controller, "USB bus %d deregistered\n", bus->busnum); in usb_deregister_bus()
940 idr_remove(&usb_bus_idr, bus->busnum); in usb_deregister_bus()
947 * register_root_hub - called by usb_add_hcd() to register a root hub
959 struct device *parent_dev = hcd->self.controller; in register_root_hub()
960 struct usb_device *usb_dev = hcd->self.root_hub; in register_root_hub()
965 usb_dev->devnum = devnum; in register_root_hub()
966 usb_dev->bus->devnum_next = devnum + 1; in register_root_hub()
967 set_bit (devnum, usb_dev->bus->devmap.devicemap); in register_root_hub()
972 usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in register_root_hub()
978 dev_name(&usb_dev->dev), retval); in register_root_hub()
981 usb_dev->descriptor = *descr; in register_root_hub()
984 if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) { in register_root_hub()
987 usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev); in register_root_hub()
988 } else if (usb_dev->speed >= USB_SPEED_SUPER) { in register_root_hub()
991 dev_name(&usb_dev->dev), retval); in register_root_hub()
999 dev_name(&usb_dev->dev), retval); in register_root_hub()
1002 hcd->rh_registered = 1; in register_root_hub()
1015 * usb_hcd_start_port_resume - a root-hub port is sending a resume signal
1020 * being sent to a root-hub port. The root hub will be prevented from
1029 if (!(bus->resuming_ports & bit)) { in usb_hcd_start_port_resume()
1030 bus->resuming_ports |= bit; in usb_hcd_start_port_resume()
1031 pm_runtime_get_noresume(&bus->root_hub->dev); in usb_hcd_start_port_resume()
1037 * usb_hcd_end_port_resume - a root-hub port has stopped sending a resume signal
1042 * stopped being sent to a root-hub port. The root hub will be allowed to
1051 if (bus->resuming_ports & bit) { in usb_hcd_end_port_resume()
1052 bus->resuming_ports &= ~bit; in usb_hcd_end_port_resume()
1053 pm_runtime_put_noidle(&bus->root_hub->dev); in usb_hcd_end_port_resume()
1058 /*-------------------------------------------------------------------------*/
1061 * usb_calc_bus_time - approximate periodic transaction time in nanoseconds
1062 * @speed: from dev->speed; USB_SPEED_{LOW,FULL,HIGH}
1103 return -1; in usb_calc_bus_time()
1109 /*-------------------------------------------------------------------------*/
1115 /*-------------------------------------------------------------------------*/
1118 * usb_hcd_link_urb_to_ep - add an URB to its endpoint queue
1139 if (unlikely(atomic_read(&urb->reject))) { in usb_hcd_link_urb_to_ep()
1140 rc = -EPERM; in usb_hcd_link_urb_to_ep()
1144 if (unlikely(!urb->ep->enabled)) { in usb_hcd_link_urb_to_ep()
1145 rc = -ENOENT; in usb_hcd_link_urb_to_ep()
1149 if (unlikely(!urb->dev->can_submit)) { in usb_hcd_link_urb_to_ep()
1150 rc = -EHOSTUNREACH; in usb_hcd_link_urb_to_ep()
1159 urb->unlinked = 0; in usb_hcd_link_urb_to_ep()
1160 list_add_tail(&urb->urb_list, &urb->ep->urb_list); in usb_hcd_link_urb_to_ep()
1162 rc = -ESHUTDOWN; in usb_hcd_link_urb_to_ep()
1172 * usb_hcd_check_unlink_urb - check whether an URB may be unlinked
1185 * -EIDRM: @urb was not submitted or has already completed.
1188 * -EBUSY: @urb has already been unlinked.
1196 list_for_each(tmp, &urb->ep->urb_list) { in usb_hcd_check_unlink_urb()
1197 if (tmp == &urb->urb_list) in usb_hcd_check_unlink_urb()
1200 if (tmp != &urb->urb_list) in usb_hcd_check_unlink_urb()
1201 return -EIDRM; in usb_hcd_check_unlink_urb()
1203 /* Any status except -EINPROGRESS means something already started to in usb_hcd_check_unlink_urb()
1206 if (urb->unlinked) in usb_hcd_check_unlink_urb()
1207 return -EBUSY; in usb_hcd_check_unlink_urb()
1208 urb->unlinked = status; in usb_hcd_check_unlink_urb()
1214 * usb_hcd_unlink_urb_from_ep - remove an URB from its endpoint queue
1227 list_del_init(&urb->urb_list); in usb_hcd_unlink_urb_from_ep()
1236 * using regular system memory - like pci devices doing bus mastering.
1240 * hcd->localmem_pool using usb_hcd_setup_local_mem().
1242 * The initialized hcd->localmem_pool then tells the usb code to allocate all
1247 * - We need "local" memory, canonical example being
1253 * - So we use that, even though the primary requirement
1268 return -EFAULT; in hcd_alloc_coherent()
1274 return -ENOMEM; in hcd_alloc_coherent()
1314 (urb->transfer_flags & URB_SETUP_MAP_SINGLE)) in usb_hcd_unmap_urb_setup_for_dma()
1315 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_setup_for_dma()
1316 urb->setup_dma, in usb_hcd_unmap_urb_setup_for_dma()
1319 else if (urb->transfer_flags & URB_SETUP_MAP_LOCAL) in usb_hcd_unmap_urb_setup_for_dma()
1320 hcd_free_coherent(urb->dev->bus, in usb_hcd_unmap_urb_setup_for_dma()
1321 &urb->setup_dma, in usb_hcd_unmap_urb_setup_for_dma()
1322 (void **) &urb->setup_packet, in usb_hcd_unmap_urb_setup_for_dma()
1327 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); in usb_hcd_unmap_urb_setup_for_dma()
1333 if (hcd->driver->unmap_urb_for_dma) in unmap_urb_for_dma()
1334 hcd->driver->unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1347 (urb->transfer_flags & URB_DMA_MAP_SG)) in usb_hcd_unmap_urb_for_dma()
1348 dma_unmap_sg(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1349 urb->sg, in usb_hcd_unmap_urb_for_dma()
1350 urb->num_sgs, in usb_hcd_unmap_urb_for_dma()
1353 (urb->transfer_flags & URB_DMA_MAP_PAGE)) in usb_hcd_unmap_urb_for_dma()
1354 dma_unmap_page(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1355 urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1356 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1359 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in usb_hcd_unmap_urb_for_dma()
1360 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1361 urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1362 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1364 else if (urb->transfer_flags & URB_MAP_LOCAL) in usb_hcd_unmap_urb_for_dma()
1365 hcd_free_coherent(urb->dev->bus, in usb_hcd_unmap_urb_for_dma()
1366 &urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1367 &urb->transfer_buffer, in usb_hcd_unmap_urb_for_dma()
1368 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1372 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | in usb_hcd_unmap_urb_for_dma()
1380 if (hcd->driver->map_urb_for_dma) in map_urb_for_dma()
1381 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1398 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1399 if (hcd->self.uses_pio_for_control) in usb_hcd_map_urb_for_dma()
1401 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1403 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1404 &urb->setup_dma, in usb_hcd_map_urb_for_dma()
1405 (void **)&urb->setup_packet, in usb_hcd_map_urb_for_dma()
1410 urb->transfer_flags |= URB_SETUP_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1412 if (object_is_on_stack(urb->setup_packet)) { in usb_hcd_map_urb_for_dma()
1414 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1417 urb->setup_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1418 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1419 urb->setup_packet, in usb_hcd_map_urb_for_dma()
1422 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1423 urb->setup_dma)) in usb_hcd_map_urb_for_dma()
1424 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1425 urb->transfer_flags |= URB_SETUP_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1430 if (urb->transfer_buffer_length != 0 in usb_hcd_map_urb_for_dma()
1431 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in usb_hcd_map_urb_for_dma()
1432 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1434 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1435 &urb->transfer_dma, in usb_hcd_map_urb_for_dma()
1436 &urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1437 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1440 urb->transfer_flags |= URB_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1442 if (urb->num_sgs) { in usb_hcd_map_urb_for_dma()
1446 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1448 return -EINVAL; in usb_hcd_map_urb_for_dma()
1452 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1453 urb->sg, in usb_hcd_map_urb_for_dma()
1454 urb->num_sgs, in usb_hcd_map_urb_for_dma()
1457 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1459 urb->transfer_flags |= URB_DMA_MAP_SG; in usb_hcd_map_urb_for_dma()
1460 urb->num_mapped_sgs = n; in usb_hcd_map_urb_for_dma()
1461 if (n != urb->num_sgs) in usb_hcd_map_urb_for_dma()
1462 urb->transfer_flags |= in usb_hcd_map_urb_for_dma()
1464 } else if (urb->sg) { in usb_hcd_map_urb_for_dma()
1465 struct scatterlist *sg = urb->sg; in usb_hcd_map_urb_for_dma()
1466 urb->transfer_dma = dma_map_page( in usb_hcd_map_urb_for_dma()
1467 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1469 sg->offset, in usb_hcd_map_urb_for_dma()
1470 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1472 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1473 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1474 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1476 urb->transfer_flags |= URB_DMA_MAP_PAGE; in usb_hcd_map_urb_for_dma()
1477 } else if (object_is_on_stack(urb->transfer_buffer)) { in usb_hcd_map_urb_for_dma()
1479 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1481 urb->transfer_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1482 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1483 urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1484 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1486 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1487 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1488 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1490 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1493 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | in usb_hcd_map_urb_for_dma()
1501 /*-------------------------------------------------------------------------*/
1503 /* may be called in any context with a valid urb->dev usecount
1511 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_submit_urb()
1518 atomic_inc(&urb->use_count); in usb_hcd_submit_urb()
1519 atomic_inc(&urb->dev->urbnum); in usb_hcd_submit_urb()
1520 usbmon_urb_submit(&hcd->self, urb); in usb_hcd_submit_urb()
1522 /* NOTE requirements on root-hub callers (usbfs and the hub in usb_hcd_submit_urb()
1523 * driver, for now): URBs' urb->transfer_buffer must be in usb_hcd_submit_urb()
1530 if (is_root_hub(urb->dev)) { in usb_hcd_submit_urb()
1535 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1542 usbmon_urb_submit_error(&hcd->self, urb, status); in usb_hcd_submit_urb()
1543 urb->hcpriv = NULL; in usb_hcd_submit_urb()
1544 INIT_LIST_HEAD(&urb->urb_list); in usb_hcd_submit_urb()
1545 atomic_dec(&urb->use_count); in usb_hcd_submit_urb()
1547 * Order the write of urb->use_count above before the read in usb_hcd_submit_urb()
1548 * of urb->reject below. Pairs with the memory barriers in in usb_hcd_submit_urb()
1553 atomic_dec(&urb->dev->urbnum); in usb_hcd_submit_urb()
1554 if (atomic_read(&urb->reject)) in usb_hcd_submit_urb()
1561 /*-------------------------------------------------------------------------*/
1572 if (is_root_hub(urb->dev)) in unlink1()
1579 value = hcd->driver->urb_dequeue(hcd, urb, status); in unlink1()
1593 struct usb_device *udev = urb->dev; in usb_hcd_unlink_urb()
1594 int retval = -EIDRM; in usb_hcd_unlink_urb()
1599 * then urb->use_count must be 0, since disconnected in usb_hcd_unlink_urb()
1603 if (atomic_read(&urb->use_count) > 0) { in usb_hcd_unlink_urb()
1609 hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_unlink_urb()
1612 retval = -EINPROGRESS; in usb_hcd_unlink_urb()
1613 else if (retval != -EIDRM && retval != -EBUSY) in usb_hcd_unlink_urb()
1614 dev_dbg(&udev->dev, "hcd_unlink_urb %pK fail %d\n", in usb_hcd_unlink_urb()
1621 /*-------------------------------------------------------------------------*/
1625 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in __usb_hcd_giveback_urb()
1626 struct usb_anchor *anchor = urb->anchor; in __usb_hcd_giveback_urb()
1627 int status = urb->unlinked; in __usb_hcd_giveback_urb()
1629 urb->hcpriv = NULL; in __usb_hcd_giveback_urb()
1630 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && in __usb_hcd_giveback_urb()
1631 urb->actual_length < urb->transfer_buffer_length && in __usb_hcd_giveback_urb()
1633 status = -EREMOTEIO; in __usb_hcd_giveback_urb()
1636 usbmon_urb_complete(&hcd->self, urb, status); in __usb_hcd_giveback_urb()
1643 urb->status = status; in __usb_hcd_giveback_urb()
1649 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()
1672 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1673 bh->running = true; in usb_giveback_urb_bh()
1674 list_replace_init(&bh->head, &local_list); in usb_giveback_urb_bh()
1675 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1681 list_del_init(&urb->urb_list); in usb_giveback_urb_bh()
1682 bh->completing_ep = urb->ep; in usb_giveback_urb_bh()
1684 bh->completing_ep = NULL; in usb_giveback_urb_bh()
1691 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1692 if (!list_empty(&bh->head)) { in usb_giveback_urb_bh()
1693 if (bh->high_prio) in usb_giveback_urb_bh()
1694 tasklet_hi_schedule(&bh->bh); in usb_giveback_urb_bh()
1696 tasklet_schedule(&bh->bh); in usb_giveback_urb_bh()
1698 bh->running = false; in usb_giveback_urb_bh()
1699 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1703 * usb_hcd_giveback_urb - return URB from HCD to device driver
1714 * completion function. The HCD has freed all per-urb resources
1715 * (and is done using urb->hcpriv). It also released all HCD locks;
1720 * @urb->unlinked. Erroneous short transfers are detected in case
1729 if (likely(!urb->unlinked)) in usb_hcd_giveback_urb()
1730 urb->unlinked = status; in usb_hcd_giveback_urb()
1732 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) { in usb_hcd_giveback_urb()
1737 if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) in usb_hcd_giveback_urb()
1738 bh = &hcd->high_prio_bh; in usb_hcd_giveback_urb()
1740 bh = &hcd->low_prio_bh; in usb_hcd_giveback_urb()
1742 spin_lock(&bh->lock); in usb_hcd_giveback_urb()
1743 list_add_tail(&urb->urb_list, &bh->head); in usb_hcd_giveback_urb()
1744 running = bh->running; in usb_hcd_giveback_urb()
1745 spin_unlock(&bh->lock); in usb_hcd_giveback_urb()
1749 else if (bh->high_prio) in usb_hcd_giveback_urb()
1750 tasklet_hi_schedule(&bh->bh); in usb_hcd_giveback_urb()
1752 tasklet_schedule(&bh->bh); in usb_hcd_giveback_urb()
1756 /*-------------------------------------------------------------------------*/
1771 hcd = bus_to_hcd(udev->bus); in usb_hcd_flush_endpoint()
1776 list_for_each_entry_reverse(urb, &ep->urb_list, urb_list) { in usb_hcd_flush_endpoint()
1779 if (urb->unlinked) in usb_hcd_flush_endpoint()
1786 unlink1(hcd, urb, -ESHUTDOWN); in usb_hcd_flush_endpoint()
1787 dev_dbg (hcd->self.controller, in usb_hcd_flush_endpoint()
1788 "shutdown urb %pK ep%d%s-%s\n", in usb_hcd_flush_endpoint()
1789 urb, usb_endpoint_num(&ep->desc), in usb_hcd_flush_endpoint()
1791 usb_ep_type_string(usb_endpoint_type(&ep->desc))); in usb_hcd_flush_endpoint()
1801 while (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1806 if (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1807 urb = list_entry (ep->urb_list.prev, struct urb, in usb_hcd_flush_endpoint()
1821 * usb_hcd_alloc_bandwidth - check whether a new bandwidth setting exceeds
1852 hcd = bus_to_hcd(udev->bus); in usb_hcd_alloc_bandwidth()
1853 if (!hcd->driver->check_bandwidth) in usb_hcd_alloc_bandwidth()
1856 /* Configuration is being removed - set configuration 0 */ in usb_hcd_alloc_bandwidth()
1859 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1861 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1862 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1864 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1866 hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1875 num_intfs = new_config->desc.bNumInterfaces; in usb_hcd_alloc_bandwidth()
1880 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1882 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1886 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1888 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1897 first_alt = &new_config->intf_cache[i]->altsetting[0]; in usb_hcd_alloc_bandwidth()
1898 iface_num = first_alt->desc.bInterfaceNumber; in usb_hcd_alloc_bandwidth()
1905 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in usb_hcd_alloc_bandwidth()
1906 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); in usb_hcd_alloc_bandwidth()
1914 cur_alt->desc.bInterfaceNumber); in usb_hcd_alloc_bandwidth()
1917 return -EINVAL; in usb_hcd_alloc_bandwidth()
1918 if (iface->resetting_device) { in usb_hcd_alloc_bandwidth()
1930 cur_alt = &iface->altsetting[0]; in usb_hcd_alloc_bandwidth()
1934 for (i = 0; i < cur_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1935 ret = hcd->driver->drop_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1936 &cur_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1941 for (i = 0; i < new_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1942 ret = hcd->driver->add_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1943 &new_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1948 ret = hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1951 hcd->driver->reset_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1960 * example: a qh stored in ep->hcpriv, holding state related to endpoint
1969 hcd = bus_to_hcd(udev->bus); in usb_hcd_disable_endpoint()
1970 if (hcd->driver->endpoint_disable) in usb_hcd_disable_endpoint()
1971 hcd->driver->endpoint_disable(hcd, ep); in usb_hcd_disable_endpoint()
1975 * usb_hcd_reset_endpoint - reset host endpoint state
1985 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_reset_endpoint()
1987 if (hcd->driver->endpoint_reset) in usb_hcd_reset_endpoint()
1988 hcd->driver->endpoint_reset(hcd, ep); in usb_hcd_reset_endpoint()
1990 int epnum = usb_endpoint_num(&ep->desc); in usb_hcd_reset_endpoint()
1991 int is_out = usb_endpoint_dir_out(&ep->desc); in usb_hcd_reset_endpoint()
1992 int is_control = usb_endpoint_xfer_control(&ep->desc); in usb_hcd_reset_endpoint()
2001 * usb_alloc_streams - allocate bulk endpoint stream IDs.
2024 hcd = bus_to_hcd(dev->bus); in usb_alloc_streams()
2025 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams) in usb_alloc_streams()
2026 return -EINVAL; in usb_alloc_streams()
2027 if (dev->speed < USB_SPEED_SUPER) in usb_alloc_streams()
2028 return -EINVAL; in usb_alloc_streams()
2029 if (dev->state < USB_STATE_CONFIGURED) in usb_alloc_streams()
2030 return -ENODEV; in usb_alloc_streams()
2034 if (!usb_endpoint_xfer_bulk(&eps[i]->desc)) in usb_alloc_streams()
2035 return -EINVAL; in usb_alloc_streams()
2036 /* Re-alloc is not allowed */ in usb_alloc_streams()
2037 if (eps[i]->streams) in usb_alloc_streams()
2038 return -EINVAL; in usb_alloc_streams()
2041 ret = hcd->driver->alloc_streams(hcd, dev, eps, num_eps, in usb_alloc_streams()
2047 eps[i]->streams = ret; in usb_alloc_streams()
2054 * usb_free_streams - free bulk endpoint stream IDs.
2074 hcd = bus_to_hcd(dev->bus); in usb_free_streams()
2075 if (dev->speed < USB_SPEED_SUPER) in usb_free_streams()
2076 return -EINVAL; in usb_free_streams()
2078 /* Double-free is not allowed */ in usb_free_streams()
2080 if (!eps[i] || !eps[i]->streams) in usb_free_streams()
2081 return -EINVAL; in usb_free_streams()
2083 ret = hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); in usb_free_streams()
2088 eps[i]->streams = 0; in usb_free_streams()
2105 /*-------------------------------------------------------------------------*/
2110 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_get_frame_number()
2113 return -ESHUTDOWN; in usb_hcd_get_frame_number()
2114 return hcd->driver->get_frame_number (hcd); in usb_hcd_get_frame_number()
2117 /*-------------------------------------------------------------------------*/
2122 struct completion *done = urb->context; in usb_ehset_completion()
2139 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in request_single_step_set_feature_urb()
2145 urb->pipe = usb_rcvctrlpipe(udev, 0); in request_single_step_set_feature_urb()
2147 urb->ep = &udev->ep0; in request_single_step_set_feature_urb()
2148 urb->dev = udev; in request_single_step_set_feature_urb()
2149 urb->setup_packet = (void *)dr; in request_single_step_set_feature_urb()
2150 urb->transfer_buffer = buf; in request_single_step_set_feature_urb()
2151 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE; in request_single_step_set_feature_urb()
2152 urb->complete = usb_ehset_completion; in request_single_step_set_feature_urb()
2153 urb->status = -EINPROGRESS; in request_single_step_set_feature_urb()
2154 urb->actual_length = 0; in request_single_step_set_feature_urb()
2155 urb->transfer_flags = URB_DIR_IN; in request_single_step_set_feature_urb()
2157 atomic_inc(&urb->use_count); in request_single_step_set_feature_urb()
2158 atomic_inc(&urb->dev->urbnum); in request_single_step_set_feature_urb()
2165 urb->context = done; in request_single_step_set_feature_urb()
2171 int retval = -ENOMEM; in ehset_single_step_set_feature()
2179 udev = usb_hub_find_child(hcd->self.root_hub, port); in ehset_single_step_set_feature()
2181 dev_err(hcd->self.controller, "No device attached to the RootHub\n"); in ehset_single_step_set_feature()
2182 return -ENODEV; in ehset_single_step_set_feature()
2186 return -ENOMEM; in ehset_single_step_set_feature()
2191 return -ENOMEM; in ehset_single_step_set_feature()
2195 dr->bRequestType = USB_DIR_IN; in ehset_single_step_set_feature()
2196 dr->bRequest = USB_REQ_GET_DESCRIPTOR; in ehset_single_step_set_feature()
2197 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8); in ehset_single_step_set_feature()
2198 dr->wIndex = 0; in ehset_single_step_set_feature()
2199 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE); in ehset_single_step_set_feature()
2205 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 1); in ehset_single_step_set_feature()
2210 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2211 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2218 urb->status = -EINPROGRESS; in ehset_single_step_set_feature()
2220 atomic_inc(&urb->use_count); in ehset_single_step_set_feature()
2221 atomic_inc(&urb->dev->urbnum); in ehset_single_step_set_feature()
2222 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0); in ehset_single_step_set_feature()
2226 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2227 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2240 /*-------------------------------------------------------------------------*/
2246 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_suspend()
2248 int old_state = hcd->state; in hcd_bus_suspend()
2250 dev_dbg(&rhdev->dev, "bus %ssuspend, wakeup %d\n", in hcd_bus_suspend()
2251 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in hcd_bus_suspend()
2252 rhdev->do_remote_wakeup); in hcd_bus_suspend()
2254 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend"); in hcd_bus_suspend()
2258 if (!hcd->driver->bus_suspend) { in hcd_bus_suspend()
2259 status = -ENOENT; in hcd_bus_suspend()
2261 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2262 hcd->state = HC_STATE_QUIESCING; in hcd_bus_suspend()
2263 status = hcd->driver->bus_suspend(hcd); in hcd_bus_suspend()
2267 hcd->state = HC_STATE_SUSPENDED; in hcd_bus_suspend()
2270 usb_phy_roothub_suspend(hcd->self.sysdev, in hcd_bus_suspend()
2271 hcd->phy_roothub); in hcd_bus_suspend()
2273 /* Did we race with a root-hub wakeup event? */ in hcd_bus_suspend()
2274 if (rhdev->do_remote_wakeup) { in hcd_bus_suspend()
2277 status = hcd->driver->hub_status_data(hcd, buffer); in hcd_bus_suspend()
2279 dev_dbg(&rhdev->dev, "suspend raced with wakeup event\n"); in hcd_bus_suspend()
2281 status = -EBUSY; in hcd_bus_suspend()
2287 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2288 hcd->state = old_state; in hcd_bus_suspend()
2291 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_suspend()
2299 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_resume()
2301 int old_state = hcd->state; in hcd_bus_resume()
2303 dev_dbg(&rhdev->dev, "usb %sresume\n", in hcd_bus_resume()
2304 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in hcd_bus_resume()
2306 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); in hcd_bus_resume()
2311 status = usb_phy_roothub_resume(hcd->self.sysdev, in hcd_bus_resume()
2312 hcd->phy_roothub); in hcd_bus_resume()
2317 if (!hcd->driver->bus_resume) in hcd_bus_resume()
2318 return -ENOENT; in hcd_bus_resume()
2322 hcd->state = HC_STATE_RESUMING; in hcd_bus_resume()
2323 status = hcd->driver->bus_resume(hcd); in hcd_bus_resume()
2324 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in hcd_bus_resume()
2326 status = usb_phy_roothub_calibrate(hcd->phy_roothub); in hcd_bus_resume()
2334 usb_set_device_state(rhdev, rhdev->actconfig in hcd_bus_resume()
2337 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_resume()
2338 hcd->state = HC_STATE_RUNNING; in hcd_bus_resume()
2345 * (this is what the USB-2 spec calls a "global resume"). in hcd_bus_resume()
2349 if (udev->state != USB_STATE_NOTATTACHED && in hcd_bus_resume()
2350 !udev->port_is_suspended) { in hcd_bus_resume()
2356 hcd->state = old_state; in hcd_bus_resume()
2357 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); in hcd_bus_resume()
2358 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_resume()
2360 if (status != -ESHUTDOWN) in hcd_bus_resume()
2366 /* Workqueue routine for root-hub remote wakeup */
2370 struct usb_device *udev = hcd->self.root_hub; in hcd_resume_work()
2376 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2389 if (hcd->rh_registered) { in usb_hcd_resume_root_hub()
2390 pm_wakeup_event(&hcd->self.root_hub->dev, 0); in usb_hcd_resume_root_hub()
2391 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in usb_hcd_resume_root_hub()
2392 queue_work(pm_wq, &hcd->wakeup_work); in usb_hcd_resume_root_hub()
2400 /*-------------------------------------------------------------------------*/
2405 * usb_bus_start_enum - start immediate enumeration (for OTG)
2407 * @port_num: 1-based number of port; usually bus->otg_port
2420 int status = -EOPNOTSUPP; in usb_bus_start_enum()
2427 if (port_num && hcd->driver->start_port_reset) in usb_bus_start_enum()
2428 status = hcd->driver->start_port_reset(hcd, port_num); in usb_bus_start_enum()
2434 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); in usb_bus_start_enum()
2441 /*-------------------------------------------------------------------------*/
2444 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
2460 else if (hcd->driver->irq(hcd) == IRQ_NONE) in usb_hcd_irq()
2469 /*-------------------------------------------------------------------------*/
2471 /* Workqueue routine for when the root-hub has died. */
2481 kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env); in hcd_died_work()
2485 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
2490 * by the PCI glue, so only glue for non-PCI busses should need to call it.
2498 dev_err (hcd->self.controller, "HC died; cleaning up\n"); in usb_hc_died()
2501 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2502 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2503 if (hcd->rh_registered) { in usb_hc_died()
2504 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2507 usb_set_device_state (hcd->self.root_hub, in usb_hc_died()
2509 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2511 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { in usb_hc_died()
2512 hcd = hcd->shared_hcd; in usb_hc_died()
2513 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2514 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2515 if (hcd->rh_registered) { in usb_hc_died()
2516 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2519 usb_set_device_state(hcd->self.root_hub, in usb_hc_died()
2521 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2527 schedule_work(&hcd->died_work); in usb_hc_died()
2529 schedule_work(&hcd->primary_hcd->died_work); in usb_hc_died()
2536 /*-------------------------------------------------------------------------*/
2541 spin_lock_init(&bh->lock); in init_giveback_urb_bh()
2542 INIT_LIST_HEAD(&bh->head); in init_giveback_urb_bh()
2543 tasklet_setup(&bh->bh, usb_giveback_urb_bh); in init_giveback_urb_bh()
2552 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); in __usb_create_hcd()
2556 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), in __usb_create_hcd()
2558 if (!hcd->address0_mutex) { in __usb_create_hcd()
2563 mutex_init(hcd->address0_mutex); in __usb_create_hcd()
2564 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), in __usb_create_hcd()
2566 if (!hcd->bandwidth_mutex) { in __usb_create_hcd()
2567 kfree(hcd->address0_mutex); in __usb_create_hcd()
2572 mutex_init(hcd->bandwidth_mutex); in __usb_create_hcd()
2576 hcd->address0_mutex = primary_hcd->address0_mutex; in __usb_create_hcd()
2577 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; in __usb_create_hcd()
2578 hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2579 primary_hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2580 hcd->shared_hcd = primary_hcd; in __usb_create_hcd()
2581 primary_hcd->shared_hcd = hcd; in __usb_create_hcd()
2585 kref_init(&hcd->kref); in __usb_create_hcd()
2587 usb_bus_init(&hcd->self); in __usb_create_hcd()
2588 hcd->self.controller = dev; in __usb_create_hcd()
2589 hcd->self.sysdev = sysdev; in __usb_create_hcd()
2590 hcd->self.bus_name = bus_name; in __usb_create_hcd()
2592 timer_setup(&hcd->rh_timer, rh_timer_func, 0); in __usb_create_hcd()
2594 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); in __usb_create_hcd()
2597 INIT_WORK(&hcd->died_work, hcd_died_work); in __usb_create_hcd()
2599 hcd->driver = driver; in __usb_create_hcd()
2600 hcd->speed = driver->flags & HCD_MASK; in __usb_create_hcd()
2601 hcd->product_desc = (driver->product_desc) ? driver->product_desc : in __usb_create_hcd()
2608 * usb_create_shared_hcd - create and initialize an HCD structure
2610 * @dev: device for this HC, stored in hcd->self.controller
2611 * @bus_name: value to store in hcd->self.bus_name
2633 * usb_create_hcd - create and initialize an HCD structure
2635 * @dev: device for this HC, stored in hcd->self.controller
2636 * @bus_name: value to store in hcd->self.bus_name
2661 * invalidate the peer's ->shared_hcd and ->primary_hcd pointers.
2668 if (hcd->shared_hcd) { in hcd_release()
2669 struct usb_hcd *peer = hcd->shared_hcd; in hcd_release()
2671 peer->shared_hcd = NULL; in hcd_release()
2672 peer->primary_hcd = NULL; in hcd_release()
2674 kfree(hcd->address0_mutex); in hcd_release()
2675 kfree(hcd->bandwidth_mutex); in hcd_release()
2684 kref_get (&hcd->kref); in usb_get_hcd()
2692 kref_put (&hcd->kref, hcd_release); in usb_put_hcd()
2698 if (!hcd->primary_hcd) in usb_hcd_is_primary_hcd()
2700 return hcd == hcd->primary_hcd; in usb_hcd_is_primary_hcd()
2706 if (!hcd->driver->find_raw_port_number) in usb_hcd_find_raw_port_number()
2709 return hcd->driver->find_raw_port_number(hcd, port1); in usb_hcd_find_raw_port_number()
2717 if (hcd->driver->irq) { in usb_hcd_request_irqs()
2719 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in usb_hcd_request_irqs()
2720 hcd->driver->description, hcd->self.busnum); in usb_hcd_request_irqs()
2722 hcd->irq_descr, hcd); in usb_hcd_request_irqs()
2724 dev_err(hcd->self.controller, in usb_hcd_request_irqs()
2729 hcd->irq = irqnum; in usb_hcd_request_irqs()
2730 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, in usb_hcd_request_irqs()
2731 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2733 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2735 hcd->irq = 0; in usb_hcd_request_irqs()
2736 if (hcd->rsrc_start) in usb_hcd_request_irqs()
2737 dev_info(hcd->self.controller, "%s 0x%08llx\n", in usb_hcd_request_irqs()
2738 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2740 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2746 * Before we free this root hub, flush in-flight peering attempts
2754 rhdev = hcd->self.root_hub; in usb_put_invalidate_rhdev()
2755 hcd->self.root_hub = NULL; in usb_put_invalidate_rhdev()
2761 * usb_stop_hcd - Halt the HCD
2764 * Stop the root-hub polling timer and invoke the HCD's ->stop callback.
2768 hcd->rh_pollable = 0; in usb_stop_hcd()
2769 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2770 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2772 hcd->driver->stop(hcd); in usb_stop_hcd()
2773 hcd->state = HC_STATE_HALT; in usb_stop_hcd()
2776 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2777 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2781 * usb_add_hcd - finish generic HCD structure initialization and register
2797 if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { in usb_add_hcd()
2798 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); in usb_add_hcd()
2799 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2800 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2802 retval = usb_phy_roothub_init(hcd->phy_roothub); in usb_add_hcd()
2806 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2809 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2814 retval = usb_phy_roothub_power_on(hcd->phy_roothub); in usb_add_hcd()
2819 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); in usb_add_hcd()
2823 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; in usb_add_hcd()
2827 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; in usb_add_hcd()
2833 hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; in usb_add_hcd()
2837 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in usb_add_hcd()
2840 set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags); in usb_add_hcd()
2842 /* HC is in reset state, but accessible. Now do the one-time init, in usb_add_hcd()
2848 dev_dbg(hcd->self.sysdev, "pool alloc failed\n"); in usb_add_hcd()
2852 retval = usb_register_bus(&hcd->self); in usb_add_hcd()
2856 rhdev = usb_alloc_dev(NULL, &hcd->self, 0); in usb_add_hcd()
2858 dev_err(hcd->self.sysdev, "unable to allocate root hub\n"); in usb_add_hcd()
2859 retval = -ENOMEM; in usb_add_hcd()
2863 hcd->self.root_hub = rhdev; in usb_add_hcd()
2866 rhdev->rx_lanes = 1; in usb_add_hcd()
2867 rhdev->tx_lanes = 1; in usb_add_hcd()
2868 rhdev->ssp_rate = USB_SSP_GEN_UNKNOWN; in usb_add_hcd()
2870 switch (hcd->speed) { in usb_add_hcd()
2872 rhdev->speed = USB_SPEED_FULL; in usb_add_hcd()
2875 rhdev->speed = USB_SPEED_HIGH; in usb_add_hcd()
2878 rhdev->speed = USB_SPEED_SUPER; in usb_add_hcd()
2881 rhdev->rx_lanes = 2; in usb_add_hcd()
2882 rhdev->tx_lanes = 2; in usb_add_hcd()
2883 rhdev->ssp_rate = USB_SSP_GEN_2x2; in usb_add_hcd()
2884 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2887 rhdev->ssp_rate = USB_SSP_GEN_2x1; in usb_add_hcd()
2888 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2891 retval = -EINVAL; in usb_add_hcd()
2899 device_set_wakeup_capable(&rhdev->dev, 1); in usb_add_hcd()
2905 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_add_hcd()
2907 /* "reset" is misnamed; its role is now one-time init. the controller in usb_add_hcd()
2910 if (hcd->driver->reset) { in usb_add_hcd()
2911 retval = hcd->driver->reset(hcd); in usb_add_hcd()
2913 dev_err(hcd->self.controller, "can't setup: %d\n", in usb_add_hcd()
2918 hcd->rh_pollable = 1; in usb_add_hcd()
2920 retval = usb_phy_roothub_calibrate(hcd->phy_roothub); in usb_add_hcd()
2925 if (device_can_wakeup(hcd->self.controller) in usb_add_hcd()
2926 && device_can_wakeup(&hcd->self.root_hub->dev)) in usb_add_hcd()
2927 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); in usb_add_hcd()
2930 init_giveback_urb_bh(&hcd->high_prio_bh); in usb_add_hcd()
2931 hcd->high_prio_bh.high_prio = true; in usb_add_hcd()
2932 init_giveback_urb_bh(&hcd->low_prio_bh); in usb_add_hcd()
2943 hcd->state = HC_STATE_RUNNING; in usb_add_hcd()
2944 retval = hcd->driver->start(hcd); in usb_add_hcd()
2946 dev_err(hcd->self.controller, "startup error %d\n", retval); in usb_add_hcd()
2951 shared_hcd = hcd->shared_hcd; in usb_add_hcd()
2957 if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd)) in usb_add_hcd()
2967 if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) in usb_add_hcd()
2976 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) in usb_add_hcd()
2983 usb_deregister_bus(&hcd->self); in usb_add_hcd()
2987 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_add_hcd()
2989 usb_phy_roothub_exit(hcd->phy_roothub); in usb_add_hcd()
2996 * usb_remove_hcd - shutdown processing for generic HCDs
3013 rhdev = hcd->self.root_hub; in usb_remove_hcd()
3015 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); in usb_remove_hcd()
3018 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_remove_hcd()
3019 if (HC_IS_RUNNING (hcd->state)) in usb_remove_hcd()
3020 hcd->state = HC_STATE_QUIESCING; in usb_remove_hcd()
3022 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); in usb_remove_hcd()
3024 rh_registered = hcd->rh_registered; in usb_remove_hcd()
3025 hcd->rh_registered = 0; in usb_remove_hcd()
3029 cancel_work_sync(&hcd->wakeup_work); in usb_remove_hcd()
3031 cancel_work_sync(&hcd->died_work); in usb_remove_hcd()
3040 * - driver's disconnect() called from usb_disconnect() should in usb_remove_hcd()
3044 * - it is too late to run complete() here since driver may have in usb_remove_hcd()
3048 /* Prevent any more root-hub status calls from the timer. in usb_remove_hcd()
3056 if (hcd->irq > 0) in usb_remove_hcd()
3057 free_irq(hcd->irq, hcd); in usb_remove_hcd()
3060 usb_deregister_bus(&hcd->self); in usb_remove_hcd()
3063 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_remove_hcd()
3064 usb_phy_roothub_exit(hcd->phy_roothub); in usb_remove_hcd()
3067 hcd->flags = 0; in usb_remove_hcd()
3077 pm_runtime_get_sync(&dev->dev); in usb_hcd_platform_shutdown()
3079 if (hcd->driver->shutdown) in usb_hcd_platform_shutdown()
3080 hcd->driver->shutdown(hcd); in usb_hcd_platform_shutdown()
3090 hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4, in usb_hcd_setup_local_mem()
3091 dev_to_node(hcd->self.sysdev), in usb_hcd_setup_local_mem()
3092 dev_name(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3093 if (IS_ERR(hcd->localmem_pool)) in usb_hcd_setup_local_mem()
3094 return PTR_ERR(hcd->localmem_pool); in usb_hcd_setup_local_mem()
3101 local_mem = devm_memremap(hcd->self.sysdev, phys_addr, in usb_hcd_setup_local_mem()
3104 local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma, in usb_hcd_setup_local_mem()
3110 return -ENOMEM; in usb_hcd_setup_local_mem()
3120 err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem, in usb_hcd_setup_local_mem()
3121 dma, size, dev_to_node(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3123 dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n", in usb_hcd_setup_local_mem()
3132 /*-------------------------------------------------------------------------*/
3142 * Notice that the code is minimally error-proof. Because usbmon needs
3150 return -EBUSY; in usb_mon_register()