Lines Matching +full:usb +full:- +full:hub
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>
37 #include <linux/usb.h>
38 #include <linux/usb/hcd.h>
39 #include <linux/usb/otg.h>
41 #include "usb.h"
45 /*-------------------------------------------------------------------------*/
48 * USB Host Controller Driver framework
51 * HCD-specific behaviors/bugs.
55 * hardware differences. That includes root hub registers, i/o queues,
58 * Shared code includes most of the "root hub" code (these are emulated,
64 * Happens the USB 2.0 spec says this would be invisible inside the "USBD",
66 * only by the hub driver ... and that neither should be seen or used by
67 * usb client device drivers.
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 /*-------------------------------------------------------------------------*/
110 * Sharable chunks of root hub code.
113 /*-------------------------------------------------------------------------*/
117 /* usb 3.1 root hub device descriptor */
125 0x03, /* __u8 bDeviceProtocol; USB 3 hub */
138 /* usb 3.0 root hub device descriptor */
146 0x03, /* __u8 bDeviceProtocol; USB 3.0 hub */
159 /* usb 2.5 (wireless USB 1.0) root hub device descriptor */
167 0x00, /* __u8 bDeviceProtocol; [ usb 2.0 no TT ] */
180 /* usb 2.0 root hub device descriptor */
188 0x00, /* __u8 bDeviceProtocol; [ usb 2.0 no TT ] */
201 /* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
203 /* usb 1.1 root hub device descriptor */
225 /*-------------------------------------------------------------------------*/
240 6: Self-powered,
245 /* USB 1.1:
246 * USB 2.0, single TT organization (mandatory):
249 * USB 2.0, multiple TT organization (optional):
273 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */
287 6: Self-powered,
292 /* USB 1.1:
293 * USB 2.0, single TT organization (mandatory):
296 * USB 2.0, multiple TT organization (optional):
320 * see hub.c:hub_configure() for details. */
322 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
335 6: Self-powered,
357 * see hub.c:hub_configure() for details. */
359 0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
371 * -1 is authorized for all devices except wireless (old behaviour)
376 #define USB_AUTHORIZE_WIRED -1
384 "Default USB device authorization: 0 is not authorized, 1 is "
385 "authorized, 2 is authorized for internal devices, -1 is "
386 "authorized except for wireless USB (default, old behaviour)");
387 /*-------------------------------------------------------------------------*/
390 * ascii2desc() - Helper routine for producing UTF-16LE string descriptors
391 * @s: Null-terminated ASCII (actually ISO-8859-1) string
392 * @buf: Buffer for USB string descriptor (header + UTF-16LE)
399 * USB String descriptors can contain at most 126 characters; input
415 while (n--) { in ascii2desc()
417 if (!n--) in ascii2desc()
426 * rh_string() - provides string descriptors for root hub
428 * @hcd: the host controller for this root hub
433 * virtual root hub device.
448 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ in rh_string()
449 /* See http://www.usb.org/developers/docs/USB_LANGIDs.pdf */ in rh_string()
456 s = hcd->self.bus_name; in rh_string()
460 s = hcd->product_desc; in rh_string()
464 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, in rh_string()
465 init_utsname()->release, hcd->driver->description); in rh_string()
477 /* Root hub control transfers execute synchronously */
482 u8 *ubuf = urb->transfer_buffer; in rh_call_control()
498 urb->hcpriv = hcd; /* Indicate it's queued */ in rh_call_control()
500 cmd = (struct usb_ctrlrequest *) urb->setup_packet; in rh_call_control()
501 typeReq = (cmd->bRequestType << 8) | cmd->bRequest; in rh_call_control()
502 wValue = le16_to_cpu (cmd->wValue); in rh_call_control()
503 wIndex = le16_to_cpu (cmd->wIndex); in rh_call_control()
504 wLength = le16_to_cpu (cmd->wLength); in rh_call_control()
506 if (wLength > urb->transfer_buffer_length) in rh_call_control()
511 * USB hub descriptor. in rh_call_control()
516 status = -ENOMEM; in rh_call_control()
523 urb->actual_length = 0; in rh_call_control()
528 /* The root hub's remote wakeup enable bit is implemented using in rh_call_control()
530 * through USB, userspace may change the default "allow wakeup" in rh_call_control()
534 * runtime power management (disabling USB clocks and reducing in rh_call_control()
540 * to wake up the whole system. So don't assume root hub and in rh_call_control()
545 tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
553 device_set_wakeup_enable(&hcd->self.root_hub->dev, 0); in rh_call_control()
558 if (device_can_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
560 device_set_wakeup_enable(&hcd->self.root_hub->dev, 1); in rh_call_control()
573 switch (hcd->speed) { in rh_call_control()
594 if (hcd->has_tt) in rh_call_control()
598 switch (hcd->speed) { in rh_call_control()
617 if (device_can_wakeup(&hcd->self.root_hub->dev)) in rh_call_control()
622 urb->actual_length = rh_string(wValue & 0xff, in rh_call_control()
624 else /* unsupported IDs --> "protocol stall" */ in rh_call_control()
640 /* wValue == urb->dev->devaddr */ in rh_call_control()
641 dev_dbg (hcd->self.controller, "root hub device address %d\n", in rh_call_control()
657 dev_dbg (hcd->self.controller, "no endpoint features yet\n"); in rh_call_control()
664 /* non-generic request */ in rh_call_control()
683 status = hcd->driver->hub_control (hcd, in rh_call_control()
688 usb_hub_adjust_deviceremovable(hcd->self.root_hub, in rh_call_control()
693 status = -EPIPE; in rh_call_control()
698 if (status != -EPIPE) { in rh_call_control()
699 dev_dbg (hcd->self.controller, in rh_call_control()
711 if (urb->transfer_buffer_length < len) in rh_call_control()
712 len = urb->transfer_buffer_length; in rh_call_control()
713 urb->actual_length = len; in rh_call_control()
721 ((struct usb_config_descriptor *)ubuf)->bmAttributes in rh_call_control()
728 ((struct usb_device_descriptor *) ubuf)-> in rh_call_control()
743 /*-------------------------------------------------------------------------*/
746 * Root Hub interrupt transfers are polled using a timer if the
760 if (unlikely(!hcd->rh_pollable)) in usb_hcd_poll_rh_status()
762 if (!hcd->uses_new_polling && !hcd->status_urb) in usb_hcd_poll_rh_status()
765 length = hcd->driver->hub_status_data(hcd, buffer); in usb_hcd_poll_rh_status()
770 urb = hcd->status_urb; in usb_hcd_poll_rh_status()
772 clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
773 hcd->status_urb = NULL; in usb_hcd_poll_rh_status()
774 if (urb->transfer_buffer_length >= length) { in usb_hcd_poll_rh_status()
777 status = -EOVERFLOW; in usb_hcd_poll_rh_status()
778 length = urb->transfer_buffer_length; in usb_hcd_poll_rh_status()
780 urb->actual_length = length; in usb_hcd_poll_rh_status()
781 memcpy(urb->transfer_buffer, buffer, length); in usb_hcd_poll_rh_status()
787 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
792 /* The USB 2.0 spec says 256 ms. This is close enough and won't in usb_hcd_poll_rh_status()
794 * maybe expected, this is to make sure that all timers for USB devices in usb_hcd_poll_rh_status()
796 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : in usb_hcd_poll_rh_status()
797 (length == 0 && hcd->status_urb != NULL)) in usb_hcd_poll_rh_status()
798 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in usb_hcd_poll_rh_status()
810 /*-------------------------------------------------------------------------*/
816 unsigned len = 1 + (urb->dev->maxchild / 8); in rh_queue_status()
819 if (hcd->status_urb || urb->transfer_buffer_length < len) { in rh_queue_status()
820 dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); in rh_queue_status()
821 retval = -EINVAL; in rh_queue_status()
829 hcd->status_urb = urb; in rh_queue_status()
830 urb->hcpriv = hcd; /* indicate it's queued */ in rh_queue_status()
831 if (!hcd->uses_new_polling) in rh_queue_status()
832 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in rh_queue_status()
836 mod_timer(&hcd->rh_timer, jiffies); in rh_queue_status()
845 if (usb_endpoint_xfer_int(&urb->ep->desc)) in rh_urb_enqueue()
847 if (usb_endpoint_xfer_control(&urb->ep->desc)) in rh_urb_enqueue()
849 return -EINVAL; in rh_urb_enqueue()
852 /*-------------------------------------------------------------------------*/
854 /* Unlinks of root-hub control URBs are legal, but they don't do anything
867 if (usb_endpoint_num(&urb->ep->desc) == 0) { /* Control URB */ in usb_rh_urb_dequeue()
871 if (!hcd->uses_new_polling) in usb_rh_urb_dequeue()
872 del_timer (&hcd->rh_timer); in usb_rh_urb_dequeue()
873 if (urb == hcd->status_urb) { in usb_rh_urb_dequeue()
874 hcd->status_urb = NULL; in usb_rh_urb_dequeue()
885 /*-------------------------------------------------------------------------*/
888 * usb_bus_init - shared initialization code
896 memset (&bus->devmap, 0, sizeof(struct usb_devmap)); in usb_bus_init()
898 bus->devnum_next = 1; in usb_bus_init()
900 bus->root_hub = NULL; in usb_bus_init()
901 bus->busnum = -1; in usb_bus_init()
902 bus->bandwidth_allocated = 0; in usb_bus_init()
903 bus->bandwidth_int_reqs = 0; in usb_bus_init()
904 bus->bandwidth_isoc_reqs = 0; in usb_bus_init()
905 mutex_init(&bus->devnum_next_mutex); in usb_bus_init()
908 /*-------------------------------------------------------------------------*/
911 * usb_register_bus - registers the USB host controller with the usb core
923 int result = -E2BIG; in usb_register_bus()
932 bus->busnum = busnum; in usb_register_bus()
937 dev_info (bus->controller, "new USB bus registered, assigned bus " in usb_register_bus()
938 "number %d\n", bus->busnum); in usb_register_bus()
947 * usb_deregister_bus - deregisters the USB host controller
957 dev_info (bus->controller, "USB bus %d deregistered\n", bus->busnum); in usb_deregister_bus()
965 idr_remove(&usb_bus_idr, bus->busnum); in usb_deregister_bus()
972 * register_root_hub - called by usb_add_hcd() to register a root hub
973 * @hcd: host controller for this root hub
975 * This function registers the root hub with the USB subsystem. It sets up
977 * to register the usb device. It also assigns the root hub's USB address
984 struct device *parent_dev = hcd->self.controller; in register_root_hub()
985 struct usb_device *usb_dev = hcd->self.root_hub; in register_root_hub()
989 usb_dev->devnum = devnum; in register_root_hub()
990 usb_dev->bus->devnum_next = devnum + 1; in register_root_hub()
991 set_bit (devnum, usb_dev->bus->devmap.devicemap); in register_root_hub()
996 usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64); in register_root_hub()
998 if (retval != sizeof usb_dev->descriptor) { in register_root_hub()
1001 dev_name(&usb_dev->dev), retval); in register_root_hub()
1002 return (retval < 0) ? retval : -EMSGSIZE; in register_root_hub()
1005 if (le16_to_cpu(usb_dev->descriptor.bcdUSB) >= 0x0201) { in register_root_hub()
1008 usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev); in register_root_hub()
1009 } else if (usb_dev->speed >= USB_SPEED_SUPER) { in register_root_hub()
1012 dev_name(&usb_dev->dev), retval); in register_root_hub()
1019 dev_err (parent_dev, "can't register root hub for %s, %d\n", in register_root_hub()
1020 dev_name(&usb_dev->dev), retval); in register_root_hub()
1023 hcd->rh_registered = 1; in register_root_hub()
1026 /* Did the HC die before the root hub was registered? */ in register_root_hub()
1036 * usb_hcd_start_port_resume - a root-hub port is sending a resume signal
1037 * @bus: the bus which the root hub belongs to
1041 * being sent to a root-hub port. The root hub will be prevented from
1050 if (!(bus->resuming_ports & bit)) { in usb_hcd_start_port_resume()
1051 bus->resuming_ports |= bit; in usb_hcd_start_port_resume()
1052 pm_runtime_get_noresume(&bus->root_hub->dev); in usb_hcd_start_port_resume()
1058 * usb_hcd_end_port_resume - a root-hub port has stopped sending a resume signal
1059 * @bus: the bus which the root hub belongs to
1063 * stopped being sent to a root-hub port. The root hub will be allowed to
1072 if (bus->resuming_ports & bit) { in usb_hcd_end_port_resume()
1073 bus->resuming_ports &= ~bit; in usb_hcd_end_port_resume()
1074 pm_runtime_put_noidle(&bus->root_hub->dev); in usb_hcd_end_port_resume()
1079 /*-------------------------------------------------------------------------*/
1082 * usb_calc_bus_time - approximate periodic transaction time in nanoseconds
1083 * @speed: from dev->speed; USB_SPEED_{LOW,FULL,HIGH}
1091 * See USB 2.0 spec section 5.11.3; only periodic transfers need to be
1124 return -1; in usb_calc_bus_time()
1130 /*-------------------------------------------------------------------------*/
1136 /*-------------------------------------------------------------------------*/
1139 * usb_hcd_link_urb_to_ep - add an URB to its endpoint queue
1160 if (unlikely(atomic_read(&urb->reject))) { in usb_hcd_link_urb_to_ep()
1161 rc = -EPERM; in usb_hcd_link_urb_to_ep()
1165 if (unlikely(!urb->ep->enabled)) { in usb_hcd_link_urb_to_ep()
1166 rc = -ENOENT; in usb_hcd_link_urb_to_ep()
1170 if (unlikely(!urb->dev->can_submit)) { in usb_hcd_link_urb_to_ep()
1171 rc = -EHOSTUNREACH; in usb_hcd_link_urb_to_ep()
1180 urb->unlinked = 0; in usb_hcd_link_urb_to_ep()
1181 list_add_tail(&urb->urb_list, &urb->ep->urb_list); in usb_hcd_link_urb_to_ep()
1183 rc = -ESHUTDOWN; in usb_hcd_link_urb_to_ep()
1193 * usb_hcd_check_unlink_urb - check whether an URB may be unlinked
1206 * -EIDRM: @urb was not submitted or has already completed.
1209 * -EBUSY: @urb has already been unlinked.
1217 list_for_each(tmp, &urb->ep->urb_list) { in usb_hcd_check_unlink_urb()
1218 if (tmp == &urb->urb_list) in usb_hcd_check_unlink_urb()
1221 if (tmp != &urb->urb_list) in usb_hcd_check_unlink_urb()
1222 return -EIDRM; in usb_hcd_check_unlink_urb()
1224 /* Any status except -EINPROGRESS means something already started to in usb_hcd_check_unlink_urb()
1227 if (urb->unlinked) in usb_hcd_check_unlink_urb()
1228 return -EBUSY; in usb_hcd_check_unlink_urb()
1229 urb->unlinked = status; in usb_hcd_check_unlink_urb()
1235 * usb_hcd_unlink_urb_from_ep - remove an URB from its endpoint queue
1248 list_del_init(&urb->urb_list); in usb_hcd_unlink_urb_from_ep()
1254 * Some usb host controllers can only perform dma using a small SRAM area,
1256 * The usb core itself is however optimized for host controllers that can dma
1257 * using regular system memory - like pci devices doing bus mastering.
1261 * hcd->localmem_pool using usb_hcd_setup_local_mem().
1263 * The initialized hcd->localmem_pool then tells the usb code to allocate all
1268 * - We need "local" memory, canonical example being
1274 * - So we use that, even though the primary requirement
1289 return -EFAULT; in hcd_alloc_coherent()
1295 return -ENOMEM; in hcd_alloc_coherent()
1335 (urb->transfer_flags & URB_SETUP_MAP_SINGLE)) in usb_hcd_unmap_urb_setup_for_dma()
1336 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_setup_for_dma()
1337 urb->setup_dma, in usb_hcd_unmap_urb_setup_for_dma()
1340 else if (urb->transfer_flags & URB_SETUP_MAP_LOCAL) in usb_hcd_unmap_urb_setup_for_dma()
1341 hcd_free_coherent(urb->dev->bus, in usb_hcd_unmap_urb_setup_for_dma()
1342 &urb->setup_dma, in usb_hcd_unmap_urb_setup_for_dma()
1343 (void **) &urb->setup_packet, in usb_hcd_unmap_urb_setup_for_dma()
1348 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); in usb_hcd_unmap_urb_setup_for_dma()
1354 if (hcd->driver->unmap_urb_for_dma) in unmap_urb_for_dma()
1355 hcd->driver->unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1368 (urb->transfer_flags & URB_DMA_MAP_SG)) in usb_hcd_unmap_urb_for_dma()
1369 dma_unmap_sg(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1370 urb->sg, in usb_hcd_unmap_urb_for_dma()
1371 urb->num_sgs, in usb_hcd_unmap_urb_for_dma()
1374 (urb->transfer_flags & URB_DMA_MAP_PAGE)) in usb_hcd_unmap_urb_for_dma()
1375 dma_unmap_page(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1376 urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1377 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1380 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in usb_hcd_unmap_urb_for_dma()
1381 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1382 urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1383 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1385 else if (urb->transfer_flags & URB_MAP_LOCAL) in usb_hcd_unmap_urb_for_dma()
1386 hcd_free_coherent(urb->dev->bus, in usb_hcd_unmap_urb_for_dma()
1387 &urb->transfer_dma, in usb_hcd_unmap_urb_for_dma()
1388 &urb->transfer_buffer, in usb_hcd_unmap_urb_for_dma()
1389 urb->transfer_buffer_length, in usb_hcd_unmap_urb_for_dma()
1393 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | in usb_hcd_unmap_urb_for_dma()
1401 if (hcd->driver->map_urb_for_dma) in map_urb_for_dma()
1402 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1419 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1420 if (hcd->self.uses_pio_for_control) in usb_hcd_map_urb_for_dma()
1422 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1424 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1425 &urb->setup_dma, in usb_hcd_map_urb_for_dma()
1426 (void **)&urb->setup_packet, in usb_hcd_map_urb_for_dma()
1431 urb->transfer_flags |= URB_SETUP_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1433 if (object_is_on_stack(urb->setup_packet)) { in usb_hcd_map_urb_for_dma()
1435 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1438 urb->setup_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1439 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1440 urb->setup_packet, in usb_hcd_map_urb_for_dma()
1443 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1444 urb->setup_dma)) in usb_hcd_map_urb_for_dma()
1445 return -EAGAIN; in usb_hcd_map_urb_for_dma()
1446 urb->transfer_flags |= URB_SETUP_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1451 if (urb->transfer_buffer_length != 0 in usb_hcd_map_urb_for_dma()
1452 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in usb_hcd_map_urb_for_dma()
1453 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1455 urb->dev->bus, mem_flags, in usb_hcd_map_urb_for_dma()
1456 &urb->transfer_dma, in usb_hcd_map_urb_for_dma()
1457 &urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1458 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1461 urb->transfer_flags |= URB_MAP_LOCAL; in usb_hcd_map_urb_for_dma()
1463 if (urb->num_sgs) { in usb_hcd_map_urb_for_dma()
1467 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) { in usb_hcd_map_urb_for_dma()
1469 return -EINVAL; in usb_hcd_map_urb_for_dma()
1473 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1474 urb->sg, in usb_hcd_map_urb_for_dma()
1475 urb->num_sgs, in usb_hcd_map_urb_for_dma()
1478 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1480 urb->transfer_flags |= URB_DMA_MAP_SG; in usb_hcd_map_urb_for_dma()
1481 urb->num_mapped_sgs = n; in usb_hcd_map_urb_for_dma()
1482 if (n != urb->num_sgs) in usb_hcd_map_urb_for_dma()
1483 urb->transfer_flags |= in usb_hcd_map_urb_for_dma()
1485 } else if (urb->sg) { in usb_hcd_map_urb_for_dma()
1486 struct scatterlist *sg = urb->sg; in usb_hcd_map_urb_for_dma()
1487 urb->transfer_dma = dma_map_page( in usb_hcd_map_urb_for_dma()
1488 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1490 sg->offset, in usb_hcd_map_urb_for_dma()
1491 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1493 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1494 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1495 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1497 urb->transfer_flags |= URB_DMA_MAP_PAGE; in usb_hcd_map_urb_for_dma()
1498 } else if (object_is_on_stack(urb->transfer_buffer)) { in usb_hcd_map_urb_for_dma()
1500 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1502 urb->transfer_dma = dma_map_single( in usb_hcd_map_urb_for_dma()
1503 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1504 urb->transfer_buffer, in usb_hcd_map_urb_for_dma()
1505 urb->transfer_buffer_length, in usb_hcd_map_urb_for_dma()
1507 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1508 urb->transfer_dma)) in usb_hcd_map_urb_for_dma()
1509 ret = -EAGAIN; in usb_hcd_map_urb_for_dma()
1511 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in usb_hcd_map_urb_for_dma()
1514 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | in usb_hcd_map_urb_for_dma()
1522 /*-------------------------------------------------------------------------*/
1524 /* may be called in any context with a valid urb->dev usecount
1532 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_submit_urb()
1539 atomic_inc(&urb->use_count); in usb_hcd_submit_urb()
1540 atomic_inc(&urb->dev->urbnum); in usb_hcd_submit_urb()
1541 usbmon_urb_submit(&hcd->self, urb); in usb_hcd_submit_urb()
1543 /* NOTE requirements on root-hub callers (usbfs and the hub in usb_hcd_submit_urb()
1544 * driver, for now): URBs' urb->transfer_buffer must be in usb_hcd_submit_urb()
1546 * they could clobber root hub response data. Also, control in usb_hcd_submit_urb()
1551 if (is_root_hub(urb->dev)) { in usb_hcd_submit_urb()
1556 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1563 usbmon_urb_submit_error(&hcd->self, urb, status); in usb_hcd_submit_urb()
1564 urb->hcpriv = NULL; in usb_hcd_submit_urb()
1565 INIT_LIST_HEAD(&urb->urb_list); in usb_hcd_submit_urb()
1566 atomic_dec(&urb->use_count); in usb_hcd_submit_urb()
1568 * Order the write of urb->use_count above before the read in usb_hcd_submit_urb()
1569 * of urb->reject below. Pairs with the memory barriers in in usb_hcd_submit_urb()
1574 atomic_dec(&urb->dev->urbnum); in usb_hcd_submit_urb()
1575 if (atomic_read(&urb->reject)) in usb_hcd_submit_urb()
1582 /*-------------------------------------------------------------------------*/
1593 if (is_root_hub(urb->dev)) in unlink1()
1600 value = hcd->driver->urb_dequeue(hcd, urb, status); in unlink1()
1614 struct usb_device *udev = urb->dev; in usb_hcd_unlink_urb()
1615 int retval = -EIDRM; in usb_hcd_unlink_urb()
1620 * then urb->use_count must be 0, since disconnected in usb_hcd_unlink_urb()
1624 if (atomic_read(&urb->use_count) > 0) { in usb_hcd_unlink_urb()
1630 hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_unlink_urb()
1633 retval = -EINPROGRESS; in usb_hcd_unlink_urb()
1634 else if (retval != -EIDRM && retval != -EBUSY) in usb_hcd_unlink_urb()
1635 dev_dbg(&udev->dev, "hcd_unlink_urb %pK fail %d\n", in usb_hcd_unlink_urb()
1642 /*-------------------------------------------------------------------------*/
1646 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in __usb_hcd_giveback_urb()
1647 struct usb_anchor *anchor = urb->anchor; in __usb_hcd_giveback_urb()
1648 int status = urb->unlinked; in __usb_hcd_giveback_urb()
1650 urb->hcpriv = NULL; in __usb_hcd_giveback_urb()
1651 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && in __usb_hcd_giveback_urb()
1652 urb->actual_length < urb->transfer_buffer_length && in __usb_hcd_giveback_urb()
1654 status = -EREMOTEIO; in __usb_hcd_giveback_urb()
1657 usbmon_urb_complete(&hcd->self, urb, status); in __usb_hcd_giveback_urb()
1664 urb->status = status; in __usb_hcd_giveback_urb()
1670 kcov_remote_start_usb_softirq((u64)urb->dev->bus->busnum); in __usb_hcd_giveback_urb()
1671 urb->complete(urb); in __usb_hcd_giveback_urb()
1675 atomic_dec(&urb->use_count); in __usb_hcd_giveback_urb()
1677 * Order the write of urb->use_count above before the read in __usb_hcd_giveback_urb()
1678 * of urb->reject below. Pairs with the memory barriers in in __usb_hcd_giveback_urb()
1683 if (unlikely(atomic_read(&urb->reject))) in __usb_hcd_giveback_urb()
1693 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1694 bh->running = true; in usb_giveback_urb_bh()
1695 list_replace_init(&bh->head, &local_list); in usb_giveback_urb_bh()
1696 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1702 list_del_init(&urb->urb_list); in usb_giveback_urb_bh()
1703 bh->completing_ep = urb->ep; in usb_giveback_urb_bh()
1705 bh->completing_ep = NULL; in usb_giveback_urb_bh()
1712 spin_lock_irq(&bh->lock); in usb_giveback_urb_bh()
1713 if (!list_empty(&bh->head)) { in usb_giveback_urb_bh()
1714 if (bh->high_prio) in usb_giveback_urb_bh()
1715 tasklet_hi_schedule(&bh->bh); in usb_giveback_urb_bh()
1717 tasklet_schedule(&bh->bh); in usb_giveback_urb_bh()
1719 bh->running = false; in usb_giveback_urb_bh()
1720 spin_unlock_irq(&bh->lock); in usb_giveback_urb_bh()
1724 * usb_hcd_giveback_urb - return URB from HCD to device driver
1726 * @urb: urb being returned to the USB device driver.
1731 * context (except for URBs submitted to the root hub which always complete in
1734 * This hands the URB from HCD to its USB device driver, using its
1735 * completion function. The HCD has freed all per-urb resources
1736 * (and is done using urb->hcpriv). It also released all HCD locks;
1741 * @urb->unlinked. Erroneous short transfers are detected in case
1750 if (likely(!urb->unlinked)) in usb_hcd_giveback_urb()
1751 urb->unlinked = status; in usb_hcd_giveback_urb()
1753 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) { in usb_hcd_giveback_urb()
1758 if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) in usb_hcd_giveback_urb()
1759 bh = &hcd->high_prio_bh; in usb_hcd_giveback_urb()
1761 bh = &hcd->low_prio_bh; in usb_hcd_giveback_urb()
1763 spin_lock(&bh->lock); in usb_hcd_giveback_urb()
1764 list_add_tail(&urb->urb_list, &bh->head); in usb_hcd_giveback_urb()
1765 running = bh->running; in usb_hcd_giveback_urb()
1766 spin_unlock(&bh->lock); in usb_hcd_giveback_urb()
1770 else if (bh->high_prio) in usb_hcd_giveback_urb()
1771 tasklet_hi_schedule(&bh->bh); in usb_hcd_giveback_urb()
1773 tasklet_schedule(&bh->bh); in usb_hcd_giveback_urb()
1777 /*-------------------------------------------------------------------------*/
1792 hcd = bus_to_hcd(udev->bus); in usb_hcd_flush_endpoint()
1797 list_for_each_entry_reverse(urb, &ep->urb_list, urb_list) { in usb_hcd_flush_endpoint()
1800 if (urb->unlinked) in usb_hcd_flush_endpoint()
1807 unlink1(hcd, urb, -ESHUTDOWN); in usb_hcd_flush_endpoint()
1808 dev_dbg (hcd->self.controller, in usb_hcd_flush_endpoint()
1809 "shutdown urb %pK ep%d%s-%s\n", in usb_hcd_flush_endpoint()
1810 urb, usb_endpoint_num(&ep->desc), in usb_hcd_flush_endpoint()
1812 usb_ep_type_string(usb_endpoint_type(&ep->desc))); in usb_hcd_flush_endpoint()
1822 while (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1827 if (!list_empty (&ep->urb_list)) { in usb_hcd_flush_endpoint()
1828 urb = list_entry (ep->urb_list.prev, struct urb, in usb_hcd_flush_endpoint()
1842 * usb_hcd_alloc_bandwidth - check whether a new bandwidth setting exceeds
1873 hcd = bus_to_hcd(udev->bus); in usb_hcd_alloc_bandwidth()
1874 if (!hcd->driver->check_bandwidth) in usb_hcd_alloc_bandwidth()
1877 /* Configuration is being removed - set configuration 0 */ in usb_hcd_alloc_bandwidth()
1880 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1882 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1883 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1885 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1887 hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1896 num_intfs = new_config->desc.bNumInterfaces; in usb_hcd_alloc_bandwidth()
1901 ep = udev->ep_out[i]; in usb_hcd_alloc_bandwidth()
1903 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1907 ep = udev->ep_in[i]; in usb_hcd_alloc_bandwidth()
1909 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1918 first_alt = &new_config->intf_cache[i]->altsetting[0]; in usb_hcd_alloc_bandwidth()
1919 iface_num = first_alt->desc.bInterfaceNumber; in usb_hcd_alloc_bandwidth()
1926 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in usb_hcd_alloc_bandwidth()
1927 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); in usb_hcd_alloc_bandwidth()
1935 cur_alt->desc.bInterfaceNumber); in usb_hcd_alloc_bandwidth()
1938 return -EINVAL; in usb_hcd_alloc_bandwidth()
1939 if (iface->resetting_device) { in usb_hcd_alloc_bandwidth()
1941 * The USB core just reset the device, so the xHCI host in usb_hcd_alloc_bandwidth()
1943 * However, the USB core will pass in the alternate in usb_hcd_alloc_bandwidth()
1951 cur_alt = &iface->altsetting[0]; in usb_hcd_alloc_bandwidth()
1955 for (i = 0; i < cur_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1956 ret = hcd->driver->drop_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1957 &cur_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1962 for (i = 0; i < new_alt->desc.bNumEndpoints; i++) { in usb_hcd_alloc_bandwidth()
1963 ret = hcd->driver->add_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1964 &new_alt->endpoint[i]); in usb_hcd_alloc_bandwidth()
1969 ret = hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1972 hcd->driver->reset_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1981 * example: a qh stored in ep->hcpriv, holding state related to endpoint
1990 hcd = bus_to_hcd(udev->bus); in usb_hcd_disable_endpoint()
1991 if (hcd->driver->endpoint_disable) in usb_hcd_disable_endpoint()
1992 hcd->driver->endpoint_disable(hcd, ep); in usb_hcd_disable_endpoint()
1996 * usb_hcd_reset_endpoint - reset host endpoint state
1997 * @udev: USB device.
2006 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_reset_endpoint()
2008 if (hcd->driver->endpoint_reset) in usb_hcd_reset_endpoint()
2009 hcd->driver->endpoint_reset(hcd, ep); in usb_hcd_reset_endpoint()
2011 int epnum = usb_endpoint_num(&ep->desc); in usb_hcd_reset_endpoint()
2012 int is_out = usb_endpoint_dir_out(&ep->desc); in usb_hcd_reset_endpoint()
2013 int is_control = usb_endpoint_xfer_control(&ep->desc); in usb_hcd_reset_endpoint()
2022 * usb_alloc_streams - allocate bulk endpoint stream IDs.
2045 hcd = bus_to_hcd(dev->bus); in usb_alloc_streams()
2046 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams) in usb_alloc_streams()
2047 return -EINVAL; in usb_alloc_streams()
2048 if (dev->speed < USB_SPEED_SUPER) in usb_alloc_streams()
2049 return -EINVAL; in usb_alloc_streams()
2050 if (dev->state < USB_STATE_CONFIGURED) in usb_alloc_streams()
2051 return -ENODEV; in usb_alloc_streams()
2055 if (!usb_endpoint_xfer_bulk(&eps[i]->desc)) in usb_alloc_streams()
2056 return -EINVAL; in usb_alloc_streams()
2057 /* Re-alloc is not allowed */ in usb_alloc_streams()
2058 if (eps[i]->streams) in usb_alloc_streams()
2059 return -EINVAL; in usb_alloc_streams()
2062 ret = hcd->driver->alloc_streams(hcd, dev, eps, num_eps, in usb_alloc_streams()
2068 eps[i]->streams = ret; in usb_alloc_streams()
2075 * usb_free_streams - free bulk endpoint stream IDs.
2095 hcd = bus_to_hcd(dev->bus); in usb_free_streams()
2096 if (dev->speed < USB_SPEED_SUPER) in usb_free_streams()
2097 return -EINVAL; in usb_free_streams()
2099 /* Double-free is not allowed */ in usb_free_streams()
2101 if (!eps[i] || !eps[i]->streams) in usb_free_streams()
2102 return -EINVAL; in usb_free_streams()
2104 ret = hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); in usb_free_streams()
2109 eps[i]->streams = 0; in usb_free_streams()
2126 /*-------------------------------------------------------------------------*/
2131 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_get_frame_number()
2134 return -ESHUTDOWN; in usb_hcd_get_frame_number()
2135 return hcd->driver->get_frame_number (hcd); in usb_hcd_get_frame_number()
2138 /*-------------------------------------------------------------------------*/
2143 struct completion *done = urb->context; in usb_ehset_completion()
2160 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in request_single_step_set_feature_urb()
2166 urb->pipe = usb_rcvctrlpipe(udev, 0); in request_single_step_set_feature_urb()
2168 urb->ep = &udev->ep0; in request_single_step_set_feature_urb()
2169 urb->dev = udev; in request_single_step_set_feature_urb()
2170 urb->setup_packet = (void *)dr; in request_single_step_set_feature_urb()
2171 urb->transfer_buffer = buf; in request_single_step_set_feature_urb()
2172 urb->transfer_buffer_length = USB_DT_DEVICE_SIZE; in request_single_step_set_feature_urb()
2173 urb->complete = usb_ehset_completion; in request_single_step_set_feature_urb()
2174 urb->status = -EINPROGRESS; in request_single_step_set_feature_urb()
2175 urb->actual_length = 0; in request_single_step_set_feature_urb()
2176 urb->transfer_flags = URB_DIR_IN; in request_single_step_set_feature_urb()
2178 atomic_inc(&urb->use_count); in request_single_step_set_feature_urb()
2179 atomic_inc(&urb->dev->urbnum); in request_single_step_set_feature_urb()
2186 urb->context = done; in request_single_step_set_feature_urb()
2192 int retval = -ENOMEM; in ehset_single_step_set_feature()
2200 udev = usb_hub_find_child(hcd->self.root_hub, port); in ehset_single_step_set_feature()
2202 dev_err(hcd->self.controller, "No device attached to the RootHub\n"); in ehset_single_step_set_feature()
2203 return -ENODEV; in ehset_single_step_set_feature()
2207 return -ENOMEM; in ehset_single_step_set_feature()
2212 return -ENOMEM; in ehset_single_step_set_feature()
2216 dr->bRequestType = USB_DIR_IN; in ehset_single_step_set_feature()
2217 dr->bRequest = USB_REQ_GET_DESCRIPTOR; in ehset_single_step_set_feature()
2218 dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8); in ehset_single_step_set_feature()
2219 dr->wIndex = 0; in ehset_single_step_set_feature()
2220 dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE); in ehset_single_step_set_feature()
2226 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 1); in ehset_single_step_set_feature()
2231 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2232 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2239 urb->status = -EINPROGRESS; in ehset_single_step_set_feature()
2241 atomic_inc(&urb->use_count); in ehset_single_step_set_feature()
2242 atomic_inc(&urb->dev->urbnum); in ehset_single_step_set_feature()
2243 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0); in ehset_single_step_set_feature()
2247 retval = -ETIMEDOUT; in ehset_single_step_set_feature()
2248 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2261 /*-------------------------------------------------------------------------*/
2267 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_suspend()
2269 int old_state = hcd->state; in hcd_bus_suspend()
2271 dev_dbg(&rhdev->dev, "bus %ssuspend, wakeup %d\n", in hcd_bus_suspend()
2272 (PMSG_IS_AUTO(msg) ? "auto-" : ""), in hcd_bus_suspend()
2273 rhdev->do_remote_wakeup); in hcd_bus_suspend()
2275 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend"); in hcd_bus_suspend()
2279 if (!hcd->driver->bus_suspend) { in hcd_bus_suspend()
2280 status = -ENOENT; in hcd_bus_suspend()
2282 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2283 hcd->state = HC_STATE_QUIESCING; in hcd_bus_suspend()
2284 status = hcd->driver->bus_suspend(hcd); in hcd_bus_suspend()
2288 hcd->state = HC_STATE_SUSPENDED; in hcd_bus_suspend()
2291 usb_phy_roothub_suspend(hcd->self.sysdev, in hcd_bus_suspend()
2292 hcd->phy_roothub); in hcd_bus_suspend()
2294 /* Did we race with a root-hub wakeup event? */ in hcd_bus_suspend()
2295 if (rhdev->do_remote_wakeup) { in hcd_bus_suspend()
2298 status = hcd->driver->hub_status_data(hcd, buffer); in hcd_bus_suspend()
2300 dev_dbg(&rhdev->dev, "suspend raced with wakeup event\n"); in hcd_bus_suspend()
2302 status = -EBUSY; in hcd_bus_suspend()
2308 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2309 hcd->state = old_state; in hcd_bus_suspend()
2312 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_suspend()
2320 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_resume()
2322 int old_state = hcd->state; in hcd_bus_resume()
2324 dev_dbg(&rhdev->dev, "usb %sresume\n", in hcd_bus_resume()
2325 (PMSG_IS_AUTO(msg) ? "auto-" : "")); in hcd_bus_resume()
2327 dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); in hcd_bus_resume()
2332 status = usb_phy_roothub_resume(hcd->self.sysdev, in hcd_bus_resume()
2333 hcd->phy_roothub); in hcd_bus_resume()
2338 if (!hcd->driver->bus_resume) in hcd_bus_resume()
2339 return -ENOENT; in hcd_bus_resume()
2343 hcd->state = HC_STATE_RESUMING; in hcd_bus_resume()
2344 status = hcd->driver->bus_resume(hcd); in hcd_bus_resume()
2345 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in hcd_bus_resume()
2347 status = usb_phy_roothub_calibrate(hcd->phy_roothub); in hcd_bus_resume()
2355 usb_set_device_state(rhdev, rhdev->actconfig in hcd_bus_resume()
2358 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_resume()
2359 hcd->state = HC_STATE_RUNNING; in hcd_bus_resume()
2364 * Check whether any of the enabled ports on the root hub are in hcd_bus_resume()
2366 * (this is what the USB-2 spec calls a "global resume"). in hcd_bus_resume()
2370 if (udev->state != USB_STATE_NOTATTACHED && in hcd_bus_resume()
2371 !udev->port_is_suspended) { in hcd_bus_resume()
2377 hcd->state = old_state; in hcd_bus_resume()
2378 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); in hcd_bus_resume()
2379 dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", in hcd_bus_resume()
2381 if (status != -ESHUTDOWN) in hcd_bus_resume()
2387 /* Workqueue routine for root-hub remote wakeup */
2391 struct usb_device *udev = hcd->self.root_hub; in hcd_resume_work()
2397 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2398 * @hcd: host controller for this root hub
2400 * The USB host controller calls this function when its root hub is
2403 * to resume the root hub (that is, manage its downstream ports again).
2410 if (hcd->rh_registered) { in usb_hcd_resume_root_hub()
2411 pm_wakeup_event(&hcd->self.root_hub->dev, 0); in usb_hcd_resume_root_hub()
2412 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in usb_hcd_resume_root_hub()
2413 queue_work(pm_wq, &hcd->wakeup_work); in usb_hcd_resume_root_hub()
2421 /*-------------------------------------------------------------------------*/
2426 * usb_bus_start_enum - start immediate enumeration (for OTG)
2428 * @port_num: 1-based number of port; usually bus->otg_port
2441 int status = -EOPNOTSUPP; in usb_bus_start_enum()
2448 if (port_num && hcd->driver->start_port_reset) in usb_bus_start_enum()
2449 status = hcd->driver->start_port_reset(hcd, port_num); in usb_bus_start_enum()
2455 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); in usb_bus_start_enum()
2462 /*-------------------------------------------------------------------------*/
2465 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
2481 else if (hcd->driver->irq(hcd) == IRQ_NONE) in usb_hcd_irq()
2490 /*-------------------------------------------------------------------------*/
2492 /* Workqueue routine for when the root-hub has died. */
2502 kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env); in hcd_died_work()
2506 * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
2509 * This is called by bus glue to report a USB host controller that died
2511 * by the PCI glue, so only glue for non-PCI busses should need to call it.
2519 dev_err (hcd->self.controller, "HC died; cleaning up\n"); in usb_hc_died()
2522 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2523 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2524 if (hcd->rh_registered) { in usb_hc_died()
2525 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2528 usb_set_device_state (hcd->self.root_hub, in usb_hc_died()
2530 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2532 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { in usb_hc_died()
2533 hcd = hcd->shared_hcd; in usb_hc_died()
2534 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2535 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2536 if (hcd->rh_registered) { in usb_hc_died()
2537 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2540 usb_set_device_state(hcd->self.root_hub, in usb_hc_died()
2542 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2548 schedule_work(&hcd->died_work); in usb_hc_died()
2550 schedule_work(&hcd->primary_hcd->died_work); in usb_hc_died()
2557 /*-------------------------------------------------------------------------*/
2562 spin_lock_init(&bh->lock); in init_giveback_urb_bh()
2563 INIT_LIST_HEAD(&bh->head); in init_giveback_urb_bh()
2564 tasklet_setup(&bh->bh, usb_giveback_urb_bh); in init_giveback_urb_bh()
2573 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); in __usb_create_hcd()
2577 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), in __usb_create_hcd()
2579 if (!hcd->address0_mutex) { in __usb_create_hcd()
2584 mutex_init(hcd->address0_mutex); in __usb_create_hcd()
2585 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), in __usb_create_hcd()
2587 if (!hcd->bandwidth_mutex) { in __usb_create_hcd()
2588 kfree(hcd->address0_mutex); in __usb_create_hcd()
2593 mutex_init(hcd->bandwidth_mutex); in __usb_create_hcd()
2597 hcd->address0_mutex = primary_hcd->address0_mutex; in __usb_create_hcd()
2598 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; in __usb_create_hcd()
2599 hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2600 primary_hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2601 hcd->shared_hcd = primary_hcd; in __usb_create_hcd()
2602 primary_hcd->shared_hcd = hcd; in __usb_create_hcd()
2606 kref_init(&hcd->kref); in __usb_create_hcd()
2608 usb_bus_init(&hcd->self); in __usb_create_hcd()
2609 hcd->self.controller = dev; in __usb_create_hcd()
2610 hcd->self.sysdev = sysdev; in __usb_create_hcd()
2611 hcd->self.bus_name = bus_name; in __usb_create_hcd()
2613 timer_setup(&hcd->rh_timer, rh_timer_func, 0); in __usb_create_hcd()
2615 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); in __usb_create_hcd()
2618 INIT_WORK(&hcd->died_work, hcd_died_work); in __usb_create_hcd()
2620 hcd->driver = driver; in __usb_create_hcd()
2621 hcd->speed = driver->flags & HCD_MASK; in __usb_create_hcd()
2622 hcd->product_desc = (driver->product_desc) ? driver->product_desc : in __usb_create_hcd()
2623 "USB Host Controller"; in __usb_create_hcd()
2629 * usb_create_shared_hcd - create and initialize an HCD structure
2631 * @dev: device for this HC, stored in hcd->self.controller
2632 * @bus_name: value to store in hcd->self.bus_name
2654 * usb_create_hcd - create and initialize an HCD structure
2656 * @dev: device for this HC, stored in hcd->self.controller
2657 * @bus_name: value to store in hcd->self.bus_name
2682 * invalidate the peer's ->shared_hcd and ->primary_hcd pointers.
2689 if (hcd->shared_hcd) { in hcd_release()
2690 struct usb_hcd *peer = hcd->shared_hcd; in hcd_release()
2692 peer->shared_hcd = NULL; in hcd_release()
2693 peer->primary_hcd = NULL; in hcd_release()
2695 kfree(hcd->address0_mutex); in hcd_release()
2696 kfree(hcd->bandwidth_mutex); in hcd_release()
2705 kref_get (&hcd->kref); in usb_get_hcd()
2713 kref_put (&hcd->kref, hcd_release); in usb_put_hcd()
2719 if (!hcd->primary_hcd) in usb_hcd_is_primary_hcd()
2721 return hcd == hcd->primary_hcd; in usb_hcd_is_primary_hcd()
2727 if (!hcd->driver->find_raw_port_number) in usb_hcd_find_raw_port_number()
2730 return hcd->driver->find_raw_port_number(hcd, port1); in usb_hcd_find_raw_port_number()
2738 if (hcd->driver->irq) { in usb_hcd_request_irqs()
2740 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in usb_hcd_request_irqs()
2741 hcd->driver->description, hcd->self.busnum); in usb_hcd_request_irqs()
2743 hcd->irq_descr, hcd); in usb_hcd_request_irqs()
2745 dev_err(hcd->self.controller, in usb_hcd_request_irqs()
2750 hcd->irq = irqnum; in usb_hcd_request_irqs()
2751 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, in usb_hcd_request_irqs()
2752 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2754 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2756 hcd->irq = 0; in usb_hcd_request_irqs()
2757 if (hcd->rsrc_start) in usb_hcd_request_irqs()
2758 dev_info(hcd->self.controller, "%s 0x%08llx\n", in usb_hcd_request_irqs()
2759 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2761 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2767 * Before we free this root hub, flush in-flight peering attempts
2775 rhdev = hcd->self.root_hub; in usb_put_invalidate_rhdev()
2776 hcd->self.root_hub = NULL; in usb_put_invalidate_rhdev()
2782 * usb_stop_hcd - Halt the HCD
2785 * Stop the root-hub polling timer and invoke the HCD's ->stop callback.
2789 hcd->rh_pollable = 0; in usb_stop_hcd()
2790 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2791 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2793 hcd->driver->stop(hcd); in usb_stop_hcd()
2794 hcd->state = HC_STATE_HALT; in usb_stop_hcd()
2797 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2798 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2802 * usb_add_hcd - finish generic HCD structure initialization and register
2818 if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { in usb_add_hcd()
2819 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); in usb_add_hcd()
2820 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2821 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2823 retval = usb_phy_roothub_init(hcd->phy_roothub); in usb_add_hcd()
2827 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2830 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2835 retval = usb_phy_roothub_power_on(hcd->phy_roothub); in usb_add_hcd()
2840 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); in usb_add_hcd()
2844 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; in usb_add_hcd()
2848 hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; in usb_add_hcd()
2852 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; in usb_add_hcd()
2857 hcd->dev_policy = hcd->wireless ? in usb_add_hcd()
2862 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in usb_add_hcd()
2865 set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags); in usb_add_hcd()
2867 /* HC is in reset state, but accessible. Now do the one-time init, in usb_add_hcd()
2873 dev_dbg(hcd->self.sysdev, "pool alloc failed\n"); in usb_add_hcd()
2877 retval = usb_register_bus(&hcd->self); in usb_add_hcd()
2881 rhdev = usb_alloc_dev(NULL, &hcd->self, 0); in usb_add_hcd()
2883 dev_err(hcd->self.sysdev, "unable to allocate root hub\n"); in usb_add_hcd()
2884 retval = -ENOMEM; in usb_add_hcd()
2888 hcd->self.root_hub = rhdev; in usb_add_hcd()
2891 rhdev->rx_lanes = 1; in usb_add_hcd()
2892 rhdev->tx_lanes = 1; in usb_add_hcd()
2893 rhdev->ssp_rate = USB_SSP_GEN_UNKNOWN; in usb_add_hcd()
2895 switch (hcd->speed) { in usb_add_hcd()
2897 rhdev->speed = USB_SPEED_FULL; in usb_add_hcd()
2900 rhdev->speed = USB_SPEED_HIGH; in usb_add_hcd()
2903 rhdev->speed = USB_SPEED_WIRELESS; in usb_add_hcd()
2906 rhdev->speed = USB_SPEED_SUPER; in usb_add_hcd()
2909 rhdev->rx_lanes = 2; in usb_add_hcd()
2910 rhdev->tx_lanes = 2; in usb_add_hcd()
2911 rhdev->ssp_rate = USB_SSP_GEN_2x2; in usb_add_hcd()
2912 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2915 rhdev->ssp_rate = USB_SSP_GEN_2x1; in usb_add_hcd()
2916 rhdev->speed = USB_SPEED_SUPER_PLUS; in usb_add_hcd()
2919 retval = -EINVAL; in usb_add_hcd()
2927 device_set_wakeup_capable(&rhdev->dev, 1); in usb_add_hcd()
2929 /* HCD_FLAG_RH_RUNNING doesn't matter until the root hub is in usb_add_hcd()
2933 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_add_hcd()
2935 /* "reset" is misnamed; its role is now one-time init. the controller in usb_add_hcd()
2938 if (hcd->driver->reset) { in usb_add_hcd()
2939 retval = hcd->driver->reset(hcd); in usb_add_hcd()
2941 dev_err(hcd->self.controller, "can't setup: %d\n", in usb_add_hcd()
2946 hcd->rh_pollable = 1; in usb_add_hcd()
2948 retval = usb_phy_roothub_calibrate(hcd->phy_roothub); in usb_add_hcd()
2952 /* NOTE: root hub and controller capabilities may not be the same */ in usb_add_hcd()
2953 if (device_can_wakeup(hcd->self.controller) in usb_add_hcd()
2954 && device_can_wakeup(&hcd->self.root_hub->dev)) in usb_add_hcd()
2955 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); in usb_add_hcd()
2958 init_giveback_urb_bh(&hcd->high_prio_bh); in usb_add_hcd()
2959 hcd->high_prio_bh.high_prio = true; in usb_add_hcd()
2960 init_giveback_urb_bh(&hcd->low_prio_bh); in usb_add_hcd()
2971 hcd->state = HC_STATE_RUNNING; in usb_add_hcd()
2972 retval = hcd->driver->start(hcd); in usb_add_hcd()
2974 dev_err(hcd->self.controller, "startup error %d\n", retval); in usb_add_hcd()
2979 shared_hcd = hcd->shared_hcd; in usb_add_hcd()
2985 if (shared_hcd->uses_new_polling && HCD_POLL_RH(shared_hcd)) in usb_add_hcd()
2989 /* starting here, usbcore will pay attention to this root hub */ in usb_add_hcd()
2995 if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) in usb_add_hcd()
3004 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) in usb_add_hcd()
3011 usb_deregister_bus(&hcd->self); in usb_add_hcd()
3015 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_add_hcd()
3017 usb_phy_roothub_exit(hcd->phy_roothub); in usb_add_hcd()
3024 * usb_remove_hcd - shutdown processing for generic HCDs
3029 * Disconnects the root hub, then reverses the effects of usb_add_hcd(),
3041 rhdev = hcd->self.root_hub; in usb_remove_hcd()
3043 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); in usb_remove_hcd()
3046 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_remove_hcd()
3047 if (HC_IS_RUNNING (hcd->state)) in usb_remove_hcd()
3048 hcd->state = HC_STATE_QUIESCING; in usb_remove_hcd()
3050 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); in usb_remove_hcd()
3052 rh_registered = hcd->rh_registered; in usb_remove_hcd()
3053 hcd->rh_registered = 0; in usb_remove_hcd()
3057 cancel_work_sync(&hcd->wakeup_work); in usb_remove_hcd()
3059 cancel_work_sync(&hcd->died_work); in usb_remove_hcd()
3068 * - driver's disconnect() called from usb_disconnect() should in usb_remove_hcd()
3072 * - it is too late to run complete() here since driver may have in usb_remove_hcd()
3076 /* Prevent any more root-hub status calls from the timer. in usb_remove_hcd()
3084 if (hcd->irq > 0) in usb_remove_hcd()
3085 free_irq(hcd->irq, hcd); in usb_remove_hcd()
3088 usb_deregister_bus(&hcd->self); in usb_remove_hcd()
3091 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_remove_hcd()
3092 usb_phy_roothub_exit(hcd->phy_roothub); in usb_remove_hcd()
3095 hcd->flags = 0; in usb_remove_hcd()
3105 pm_runtime_get_sync(&dev->dev); in usb_hcd_platform_shutdown()
3107 if (hcd->driver->shutdown) in usb_hcd_platform_shutdown()
3108 hcd->driver->shutdown(hcd); in usb_hcd_platform_shutdown()
3118 hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4, in usb_hcd_setup_local_mem()
3119 dev_to_node(hcd->self.sysdev), in usb_hcd_setup_local_mem()
3120 dev_name(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3121 if (IS_ERR(hcd->localmem_pool)) in usb_hcd_setup_local_mem()
3122 return PTR_ERR(hcd->localmem_pool); in usb_hcd_setup_local_mem()
3129 local_mem = devm_memremap(hcd->self.sysdev, phys_addr, in usb_hcd_setup_local_mem()
3132 local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma, in usb_hcd_setup_local_mem()
3144 err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem, in usb_hcd_setup_local_mem()
3145 dma, size, dev_to_node(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3147 dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n", in usb_hcd_setup_local_mem()
3156 /*-------------------------------------------------------------------------*/
3166 * Notice that the code is minimally error-proof. Because usbmon needs
3174 return -EBUSY; in usb_mon_register()
3186 printk(KERN_ERR "USB: monitor was not registered\n"); in usb_mon_deregister()