26 #include <linux/module.h>
27 #include <linux/version.h>
28 #include <linux/kernel.h>
29 #include <linux/slab.h>
31 #include <linux/utsname.h>
34 #include <linux/device.h>
38 #include <asm/byteorder.h>
39 #include <asm/unaligned.h>
115 static inline int is_root_hub(
struct usb_device *
udev)
117 return (udev->parent ==
NULL);
127 #define KERNEL_REL bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff))
128 #define KERNEL_VER bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))
131 static const u8 usb3_rh_dev_descriptor[18] = {
152 static const u8 usb2_rh_dev_descriptor [18] = {
175 static const u8 usb11_rh_dev_descriptor [18] = {
200 static const u8 fs_rh_config_descriptor [] = {
247 static const u8 hs_rh_config_descriptor [] = {
292 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
296 static const u8 ss_rh_config_descriptor[] = {
329 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
345 static int authorized_default = -1;
348 "Default USB device authorization: 0 is not authorized, 1 is "
349 "authorized, -1 is authorized except for wireless USB (default, "
366 ascii2desc(
char const *
s,
u8 *
buf,
unsigned len)
383 t = (
unsigned char)*s++;
401 rh_string(
int id,
struct usb_hcd
const *hcd,
u8 *
data,
unsigned len)
405 static char const langids[4] = {4,
USB_DT_STRING, 0x09, 0x04};
414 memcpy(data, langids, len);
418 s = hcd->self.bus_name;
422 s = hcd->product_desc;
426 snprintf (buf,
sizeof buf,
"%s %s %s", init_utsname()->sysname,
427 init_utsname()->
release, hcd->driver->description);
435 return ascii2desc(s, data, len);
440 static int rh_call_control (
struct usb_hcd *hcd,
struct urb *
urb)
444 u8 *ubuf = urb->transfer_buffer;
451 const u8 *bufp = tbuf;
455 u8 patch_protocol = 0;
459 spin_lock_irq(&hcd_root_hub_lock);
461 spin_unlock_irq(&hcd_root_hub_lock);
472 if (wLength > urb->transfer_buffer_length)
475 urb->actual_length = 0;
497 tbuf [0] = (device_may_wakeup(&hcd->self.root_hub->dev)
510 if (device_can_wakeup(&hcd->self.root_hub->dev)
523 switch (wValue & 0xff00) {
525 switch (hcd->speed) {
527 bufp = usb3_rh_dev_descriptor;
530 bufp = usb2_rh_dev_descriptor;
533 bufp = usb11_rh_dev_descriptor;
543 switch (hcd->speed) {
545 bufp = ss_rh_config_descriptor;
546 len =
sizeof ss_rh_config_descriptor;
549 bufp = hs_rh_config_descriptor;
550 len =
sizeof hs_rh_config_descriptor;
553 bufp = fs_rh_config_descriptor;
554 len =
sizeof fs_rh_config_descriptor;
559 if (device_can_wakeup(&hcd->self.root_hub->dev))
563 if ((wValue & 0xff) < 4)
564 urb->actual_length = rh_string(wValue & 0xff,
583 dev_dbg (hcd->self.controller,
"root hub device address %d\n",
599 dev_dbg (hcd->self.controller,
"no endpoint features yet\n");
612 case GetHubDescriptor:
619 status = hcd->driver->hub_control (hcd,
620 typeReq, wValue, wIndex,
630 if (status != -
EPIPE) {
632 "CTRL: TypeReq=0x%x val=0x%x "
633 "idx=0x%x len=%d ==> %d\n",
634 typeReq, wValue, wIndex,
637 }
else if (status > 0) {
643 if (urb->transfer_buffer_length < len)
644 len = urb->transfer_buffer_length;
645 urb->actual_length = len;
657 if (patch_protocol &&
665 spin_lock_irq(&hcd_root_hub_lock);
672 spin_unlock(&hcd_root_hub_lock);
674 spin_lock(&hcd_root_hub_lock);
676 spin_unlock_irq(&hcd_root_hub_lock);
699 if (!hcd->uses_new_polling && !hcd->status_urb)
702 length = hcd->driver->hub_status_data(hcd, buffer);
707 urb = hcd->status_urb;
709 clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
710 hcd->status_urb =
NULL;
711 urb->actual_length =
length;
712 memcpy(urb->transfer_buffer, buffer, length);
715 spin_unlock(&hcd_root_hub_lock);
717 spin_lock(&hcd_root_hub_lock);
720 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
722 spin_unlock_irqrestore(&hcd_root_hub_lock, flags);
729 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) :
730 (length == 0 && hcd->status_urb !=
NULL))
736 static void rh_timer_func (
unsigned long _hcd)
743 static int rh_queue_status (
struct usb_hcd *hcd,
struct urb *urb)
747 unsigned len = 1 + (urb->dev->maxchild / 8);
750 if (hcd->status_urb || urb->transfer_buffer_length < len) {
751 dev_dbg (hcd->self.controller,
"not queuing rh status urb\n");
760 hcd->status_urb =
urb;
762 if (!hcd->uses_new_polling)
766 else if (HCD_POLL_PENDING(hcd))
770 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
774 static int rh_urb_enqueue (
struct usb_hcd *hcd,
struct urb *urb)
776 if (usb_endpoint_xfer_int(&urb->ep->desc))
777 return rh_queue_status (hcd, urb);
778 if (usb_endpoint_xfer_control(&urb->ep->desc))
779 return rh_call_control (hcd, urb);
788 static int usb_rh_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
798 if (usb_endpoint_num(&urb->ep->desc) == 0) {
802 if (!hcd->uses_new_polling)
804 if (urb == hcd->status_urb) {
805 hcd->status_urb =
NULL;
808 spin_unlock(&hcd_root_hub_lock);
810 spin_lock(&hcd_root_hub_lock);
814 spin_unlock_irqrestore(&hcd_root_hub_lock, flags);
827 struct usb_device *rh_usb_dev = to_usb_device(dev);
828 struct usb_bus *usb_bus = rh_usb_dev->bus;
829 struct usb_hcd *usb_hcd;
833 usb_hcd = bus_to_hcd(usb_bus);
837 static ssize_t usb_host_authorized_default_store(
struct device *dev,
839 const char *buf,
size_t size)
843 struct usb_device *rh_usb_dev = to_usb_device(dev);
844 struct usb_bus *usb_bus = rh_usb_dev->bus;
845 struct usb_hcd *usb_hcd;
849 usb_hcd = bus_to_hcd(usb_bus);
850 result =
sscanf(buf,
"%u\n", &val);
852 usb_hcd->authorized_default = val? 1 : 0;
861 usb_host_authorized_default_show,
862 usb_host_authorized_default_store);
866 static struct attribute *usb_bus_attrs[] = {
867 &dev_attr_authorized_default.attr,
873 .attrs = usb_bus_attrs,
887 static void usb_bus_init (
struct usb_bus *
bus)
889 memset (&bus->devmap, 0,
sizeof(
struct usb_devmap));
891 bus->devnum_next = 1;
893 bus->root_hub =
NULL;
895 bus->bandwidth_allocated = 0;
896 bus->bandwidth_int_reqs = 0;
897 bus->bandwidth_isoc_reqs = 0;
899 INIT_LIST_HEAD (&bus->bus_list);
912 static int usb_register_bus(
struct usb_bus *
bus)
921 goto error_find_busnum;
923 set_bit (busnum, busmap.busmap);
927 list_add (&bus->bus_list, &usb_bus_list);
932 dev_info (bus->controller,
"new USB bus registered, assigned bus "
933 "number %d\n", bus->busnum);
949 static void usb_deregister_bus (
struct usb_bus *bus)
951 dev_info (bus->controller,
"USB bus %d deregistered\n", bus->busnum);
976 static int register_root_hub(
struct usb_hcd *hcd)
978 struct device *parent_dev = hcd->self.controller;
979 struct usb_device *usb_dev = hcd->self.root_hub;
984 usb_dev->bus->devnum_next = devnum + 1;
985 memset (&usb_dev->bus->devmap.devicemap, 0,
986 sizeof usb_dev->bus->devmap.devicemap);
987 set_bit (devnum, usb_dev->bus->devmap.devicemap);
992 usb_dev->ep0.desc.wMaxPacketSize =
cpu_to_le16(64);
994 if (retval !=
sizeof usb_dev->descriptor) {
996 dev_dbg (parent_dev,
"can't read %s device descriptor %d\n",
997 dev_name(&usb_dev->dev), retval);
998 return (retval < 0) ? retval : -
EMSGSIZE;
1004 dev_dbg(parent_dev,
"can't read %s bos descriptor %d\n",
1005 dev_name(&usb_dev->dev), retval);
1012 dev_err (parent_dev,
"can't register root hub for %s, %d\n",
1013 dev_name(&usb_dev->dev), retval);
1015 spin_lock_irq (&hcd_root_hub_lock);
1016 hcd->rh_registered = 1;
1017 spin_unlock_irq (&hcd_root_hub_lock);
1049 tmp = (67667
L * (31
L + 10
L * BitTime (bytecount))) / 1000
L;
1050 return (64060
L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY +
tmp);
1052 tmp = (66700
L * (31
L + 10
L * BitTime (bytecount))) / 1000
L;
1053 return (64107
L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY +
tmp);
1057 tmp = (8354
L * (31
L + 10
L * BitTime (bytecount))) / 1000
L;
1058 return (((is_input) ? 7268
L : 6265
L) + BW_HOST_DELAY + tmp);
1060 tmp = (8354
L * (31
L + 10
L * BitTime (bytecount))) / 1000
L;
1061 return (9107
L + BW_HOST_DELAY + tmp);
1066 tmp = HS_NSECS_ISO (bytecount);
1068 tmp = HS_NSECS (bytecount);
1105 spin_lock(&hcd_urb_list_lock);
1118 if (
unlikely(!urb->dev->can_submit)) {
1127 if (HCD_RH_RUNNING(hcd)) {
1135 spin_unlock(&hcd_urb_list_lock);
1166 if (tmp == &urb->urb_list)
1169 if (tmp != &urb->urb_list)
1195 spin_lock(&hcd_urb_list_lock);
1196 list_del_init(&urb->urb_list);
1197 spin_unlock(&hcd_urb_list_lock);
1233 static int hcd_alloc_coherent(
struct usb_bus *bus,
1235 void **vaddr_handle,
size_t size,
1238 unsigned char *
vaddr;
1240 if (*vaddr_handle ==
NULL) {
1246 mem_flags, dma_handle);
1259 (
unsigned long *)(vaddr + size));
1262 memcpy(vaddr, *vaddr_handle, size);
1264 *vaddr_handle =
vaddr;
1268 static void hcd_free_coherent(
struct usb_bus *bus,
dma_addr_t *dma_handle,
1269 void **vaddr_handle,
size_t size,
1272 unsigned char *vaddr = *vaddr_handle;
1277 memcpy(vaddr, *vaddr_handle, size);
1279 hcd_buffer_free(bus, size +
sizeof(vaddr), *vaddr_handle, *dma_handle);
1281 *vaddr_handle =
vaddr;
1287 if (urb->transfer_flags & URB_SETUP_MAP_SINGLE)
1292 else if (urb->transfer_flags & URB_SETUP_MAP_LOCAL)
1293 hcd_free_coherent(urb->dev->bus,
1295 (
void **) &urb->setup_packet,
1300 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL);
1304 static void unmap_urb_for_dma(
struct usb_hcd *hcd,
struct urb *urb)
1306 if (hcd->driver->unmap_urb_for_dma)
1307 hcd->driver->unmap_urb_for_dma(hcd, urb);
1319 if (urb->transfer_flags & URB_DMA_MAP_SG)
1324 else if (urb->transfer_flags & URB_DMA_MAP_PAGE)
1327 urb->transfer_buffer_length,
1329 else if (urb->transfer_flags & URB_DMA_MAP_SINGLE)
1332 urb->transfer_buffer_length,
1334 else if (urb->transfer_flags & URB_MAP_LOCAL)
1335 hcd_free_coherent(urb->dev->bus,
1337 &urb->transfer_buffer,
1338 urb->transfer_buffer_length,
1342 urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
1343 URB_DMA_MAP_SINGLE | URB_MAP_LOCAL);
1347 static int map_urb_for_dma(
struct usb_hcd *hcd,
struct urb *urb,
1350 if (hcd->driver->map_urb_for_dma)
1351 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags);
1368 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
1369 if (hcd->self.uses_pio_for_control)
1371 if (hcd->self.uses_dma) {
1373 hcd->self.controller,
1380 urb->transfer_flags |= URB_SETUP_MAP_SINGLE;
1381 }
else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1382 ret = hcd_alloc_coherent(
1383 urb->dev->bus, mem_flags,
1385 (
void **)&urb->setup_packet,
1390 urb->transfer_flags |= URB_SETUP_MAP_LOCAL;
1395 if (urb->transfer_buffer_length != 0
1396 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1397 if (hcd->self.uses_dma) {
1402 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) {
1408 hcd->self.controller,
1415 urb->transfer_flags |= URB_DMA_MAP_SG;
1416 urb->num_mapped_sgs =
n;
1417 if (n != urb->num_sgs)
1418 urb->transfer_flags |=
1419 URB_DMA_SG_COMBINED;
1420 }
else if (urb->sg) {
1423 hcd->self.controller,
1426 urb->transfer_buffer_length,
1432 urb->transfer_flags |= URB_DMA_MAP_PAGE;
1435 hcd->self.controller,
1436 urb->transfer_buffer,
1437 urb->transfer_buffer_length,
1443 urb->transfer_flags |= URB_DMA_MAP_SINGLE;
1445 }
else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1446 ret = hcd_alloc_coherent(
1447 urb->dev->bus, mem_flags,
1449 &urb->transfer_buffer,
1450 urb->transfer_buffer_length,
1453 urb->transfer_flags |= URB_MAP_LOCAL;
1455 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
1456 URB_SETUP_MAP_LOCAL)))
1473 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
1482 usbmon_urb_submit(&hcd->self, urb);
1492 if (is_root_hub(urb->dev)) {
1493 status = rh_urb_enqueue(hcd, urb);
1495 status = map_urb_for_dma(hcd, urb, mem_flags);
1496 if (
likely(status == 0)) {
1497 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags);
1499 unmap_urb_for_dma(hcd, urb);
1504 usbmon_urb_submit_error(&hcd->self, urb, status);
1506 INIT_LIST_HEAD(&urb->urb_list);
1523 static int unlink1(
struct usb_hcd *hcd,
struct urb *urb,
int status)
1527 if (is_root_hub(urb->dev))
1528 value = usb_rh_urb_dequeue(hcd, urb, status);
1534 value = hcd->driver->urb_dequeue(hcd, urb, status);
1547 struct usb_hcd *hcd;
1548 int retval = -
EIDRM;
1549 unsigned long flags;
1561 spin_unlock_irqrestore(&hcd_urb_unlink_lock, flags);
1563 hcd = bus_to_hcd(urb->dev->bus);
1564 retval = unlink1(hcd, urb, status);
1570 else if (retval != -
EIDRM && retval != -
EBUSY)
1571 dev_dbg(&urb->dev->dev,
"hcd_unlink_urb %p fail %d\n",
1599 status = urb->unlinked;
1600 else if (
unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
1601 urb->actual_length < urb->transfer_buffer_length &&
1605 unmap_urb_for_dma(hcd, urb);
1606 usbmon_urb_complete(&hcd->self, urb, status);
1611 urb->complete (urb);
1614 wake_up (&usb_kill_urb_queue);
1626 struct usb_host_endpoint *ep)
1628 struct usb_hcd *hcd;
1634 hcd = bus_to_hcd(udev->bus);
1637 spin_lock_irq(&hcd_urb_list_lock);
1645 is_in = usb_urb_dir_in(urb);
1646 spin_unlock(&hcd_urb_list_lock);
1650 dev_dbg (hcd->self.controller,
1651 "shutdown urb %p ep%d%s%s\n",
1652 urb, usb_endpoint_num(&ep->desc),
1653 is_in ?
"in" :
"out",
1656 switch (usb_endpoint_type(&ep->desc)) {
1671 spin_lock(&hcd_urb_list_lock);
1674 spin_unlock_irq(&hcd_urb_list_lock);
1677 while (!list_empty (&ep->urb_list)) {
1678 spin_lock_irq(&hcd_urb_list_lock);
1682 if (!list_empty (&ep->urb_list)) {
1683 urb =
list_entry (ep->urb_list.prev,
struct urb,
1687 spin_unlock_irq(&hcd_urb_list_lock);
1718 struct usb_host_config *new_config,
1719 struct usb_host_interface *cur_alt,
1720 struct usb_host_interface *new_alt)
1722 int num_intfs,
i,
j;
1723 struct usb_host_interface *alt =
NULL;
1725 struct usb_hcd *hcd;
1726 struct usb_host_endpoint *ep;
1728 hcd = bus_to_hcd(udev->bus);
1729 if (!hcd->driver->check_bandwidth)
1733 if (!new_config && !cur_alt) {
1734 for (i = 1; i < 16; ++
i) {
1735 ep = udev->ep_out[
i];
1737 hcd->driver->drop_endpoint(hcd, udev, ep);
1738 ep = udev->ep_in[
i];
1740 hcd->driver->drop_endpoint(hcd, udev, ep);
1742 hcd->driver->check_bandwidth(hcd, udev);
1751 num_intfs = new_config->desc.bNumInterfaces;
1755 for (i = 1; i < 16; ++
i) {
1756 ep = udev->ep_out[
i];
1758 ret = hcd->driver->drop_endpoint(hcd, udev, ep);
1762 ep = udev->ep_in[
i];
1764 ret = hcd->driver->drop_endpoint(hcd, udev, ep);
1769 for (i = 0; i < num_intfs; ++
i) {
1770 struct usb_host_interface *first_alt;
1773 first_alt = &new_config->intf_cache[
i]->altsetting[0];
1774 iface_num = first_alt->desc.bInterfaceNumber;
1781 for (j = 0; j < alt->desc.bNumEndpoints; j++) {
1782 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]);
1788 if (cur_alt && new_alt) {
1790 cur_alt->desc.bInterfaceNumber);
1794 if (iface->resetting_device) {
1806 cur_alt = &iface->altsetting[0];
1810 for (i = 0; i < cur_alt->desc.bNumEndpoints; i++) {
1811 ret = hcd->driver->drop_endpoint(hcd, udev,
1812 &cur_alt->endpoint[i]);
1817 for (i = 0; i < new_alt->desc.bNumEndpoints; i++) {
1818 ret = hcd->driver->add_endpoint(hcd, udev,
1819 &new_alt->endpoint[i]);
1824 ret = hcd->driver->check_bandwidth(hcd, udev);
1827 hcd->driver->reset_bandwidth(hcd, udev);
1840 struct usb_host_endpoint *ep)
1842 struct usb_hcd *hcd;
1845 hcd = bus_to_hcd(udev->bus);
1846 if (hcd->driver->endpoint_disable)
1847 hcd->driver->endpoint_disable(hcd, ep);
1859 struct usb_host_endpoint *ep)
1861 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1863 if (hcd->driver->endpoint_reset)
1864 hcd->driver->endpoint_reset(hcd, ep);
1866 int epnum = usb_endpoint_num(&ep->desc);
1867 int is_out = usb_endpoint_dir_out(&ep->desc);
1868 int is_control = usb_endpoint_xfer_control(&ep->desc);
1870 usb_settoggle(udev, epnum, is_out, 0);
1872 usb_settoggle(udev, epnum, !is_out, 0);
1889 struct usb_host_endpoint **eps,
unsigned int num_eps,
1890 unsigned int num_streams,
gfp_t mem_flags)
1892 struct usb_hcd *hcd;
1893 struct usb_device *
dev;
1896 dev = interface_to_usbdev(interface);
1897 hcd = bus_to_hcd(dev->bus);
1898 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams)
1904 for (i = 0; i < num_eps; i++)
1905 if (!usb_endpoint_xfer_bulk(&eps[i]->
desc))
1908 return hcd->driver->alloc_streams(hcd, dev, eps, num_eps,
1909 num_streams, mem_flags);
1924 struct usb_host_endpoint **eps,
unsigned int num_eps,
1927 struct usb_hcd *hcd;
1928 struct usb_device *
dev;
1931 dev = interface_to_usbdev(interface);
1932 hcd = bus_to_hcd(dev->bus);
1937 for (i = 0; i < num_eps; i++)
1938 if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->
desc))
1941 hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags);
1952 spin_lock_irq(&hcd_urb_unlink_lock);
1953 spin_unlock_irq(&hcd_urb_unlink_lock);
1961 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1963 if (!HCD_RH_RUNNING(hcd))
1965 return hcd->driver->get_frame_number (hcd);
1974 struct usb_hcd *hcd =
container_of(rhdev->bus,
struct usb_hcd,
self);
1976 int old_state = hcd->state;
1978 dev_dbg(&rhdev->dev,
"bus %ssuspend, wakeup %d\n",
1980 rhdev->do_remote_wakeup);
1981 if (HCD_DEAD(hcd)) {
1982 dev_dbg(&rhdev->dev,
"skipped %s of dead bus\n",
"suspend");
1986 if (!hcd->driver->bus_suspend) {
1989 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
1990 hcd->state = HC_STATE_QUIESCING;
1991 status = hcd->driver->bus_suspend(hcd);
1995 hcd->state = HC_STATE_SUSPENDED;
1998 if (rhdev->do_remote_wakeup) {
2001 status = hcd->driver->hub_status_data(hcd, buffer);
2003 dev_dbg(&rhdev->dev,
"suspend raced with wakeup event\n");
2009 spin_lock_irq(&hcd_root_hub_lock);
2010 if (!HCD_DEAD(hcd)) {
2011 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2012 hcd->state = old_state;
2014 spin_unlock_irq(&hcd_root_hub_lock);
2015 dev_dbg(&rhdev->dev,
"bus %s fail, err %d\n",
2021 int hcd_bus_resume(
struct usb_device *rhdev,
pm_message_t msg)
2023 struct usb_hcd *hcd =
container_of(rhdev->bus,
struct usb_hcd,
self);
2025 int old_state = hcd->state;
2027 dev_dbg(&rhdev->dev,
"usb %sresume\n",
2029 if (HCD_DEAD(hcd)) {
2030 dev_dbg(&rhdev->dev,
"skipped %s of dead bus\n",
"resume");
2033 if (!hcd->driver->bus_resume)
2035 if (HCD_RH_RUNNING(hcd))
2038 hcd->state = HC_STATE_RESUMING;
2039 status = hcd->driver->bus_resume(hcd);
2040 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
2044 spin_lock_irq(&hcd_root_hub_lock);
2045 if (!HCD_DEAD(hcd)) {
2049 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2050 hcd->state = HC_STATE_RUNNING;
2052 spin_unlock_irq(&hcd_root_hub_lock);
2054 hcd->state = old_state;
2055 dev_dbg(&rhdev->dev,
"bus %s fail, err %d\n",
2065 #ifdef CONFIG_USB_SUSPEND
2070 struct usb_hcd *hcd =
container_of(work,
struct usb_hcd, wakeup_work);
2071 struct usb_device *udev = hcd->self.root_hub;
2073 usb_lock_device(udev);
2074 usb_remote_wakeup(udev);
2075 usb_unlock_device(udev);
2087 void usb_hcd_resume_root_hub (
struct usb_hcd *hcd)
2089 unsigned long flags;
2092 if (hcd->rh_registered) {
2093 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
2096 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
2104 #ifdef CONFIG_USB_OTG
2119 struct usb_hcd *hcd;
2127 if (port_num && hcd->driver->start_port_reset)
2128 status = hcd->driver->start_port_reset(hcd, port_num);
2153 struct usb_hcd *hcd = __hcd;
2154 unsigned long flags;
2163 if (
unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd)))
2165 else if (hcd->driver->irq(hcd) ==
IRQ_NONE)
2189 unsigned long flags;
2191 dev_err (hcd->self.controller,
"HC died; cleaning up\n");
2194 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2195 set_bit(HCD_FLAG_DEAD, &hcd->flags);
2196 if (hcd->rh_registered) {
2197 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2205 hcd = hcd->shared_hcd;
2206 if (hcd->rh_registered) {
2207 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2215 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
2238 struct device *dev,
const char *bus_name,
2239 struct usb_hcd *primary_hcd)
2241 struct usb_hcd *hcd;
2243 hcd = kzalloc(
sizeof(*hcd) + driver->hcd_priv_size,
GFP_KERNEL);
2245 dev_dbg (dev,
"hcd alloc failed\n");
2248 if (primary_hcd ==
NULL) {
2249 hcd->bandwidth_mutex =
kmalloc(
sizeof(*hcd->bandwidth_mutex),
2251 if (!hcd->bandwidth_mutex) {
2253 dev_dbg(dev,
"hcd bandwidth mutex alloc failed\n");
2259 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex;
2260 hcd->primary_hcd = primary_hcd;
2261 primary_hcd->primary_hcd = primary_hcd;
2262 hcd->shared_hcd = primary_hcd;
2263 primary_hcd->shared_hcd = hcd;
2266 kref_init(&hcd->kref);
2268 usb_bus_init(&hcd->self);
2269 hcd->self.controller =
dev;
2270 hcd->self.bus_name = bus_name;
2274 hcd->rh_timer.function = rh_timer_func;
2275 hcd->rh_timer.data = (
unsigned long) hcd;
2276 #ifdef CONFIG_USB_SUSPEND
2277 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2281 hcd->speed = driver->flags & HCD_MASK;
2282 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
2283 "USB Host Controller";
2302 struct device *dev,
const char *bus_name)
2318 static void hcd_release (
struct kref *
kref)
2320 struct usb_hcd *hcd =
container_of (kref,
struct usb_hcd, kref);
2323 kfree(hcd->bandwidth_mutex);
2325 hcd->shared_hcd->shared_hcd =
NULL;
2332 kref_get (&hcd->kref);
2340 kref_put (&hcd->kref, hcd_release);
2346 if (!hcd->primary_hcd)
2348 return hcd == hcd->primary_hcd;
2352 static int usb_hcd_request_irqs(
struct usb_hcd *hcd,
2353 unsigned int irqnum,
unsigned long irqflags)
2357 if (hcd->driver->irq) {
2366 snprintf(hcd->irq_descr,
sizeof(hcd->irq_descr),
"%s:usb%d",
2367 hcd->driver->description, hcd->self.busnum);
2369 hcd->irq_descr, hcd);
2372 "request interrupt %d failed\n",
2377 dev_info(hcd->self.controller,
"irq %d, %s 0x%08llx\n", irqnum,
2378 (hcd->driver->flags & HCD_MEMORY) ?
2379 "io mem" :
"io base",
2380 (
unsigned long long)hcd->rsrc_start);
2383 if (hcd->rsrc_start)
2384 dev_info(hcd->self.controller,
"%s 0x%08llx\n",
2385 (hcd->driver->flags & HCD_MEMORY) ?
2386 "io mem" :
"io base",
2387 (
unsigned long long)hcd->rsrc_start);
2403 unsigned int irqnum,
unsigned long irqflags)
2406 struct usb_device *rhdev;
2408 dev_info(hcd->self.controller,
"%s\n", hcd->product_desc);
2411 if (authorized_default < 0 || authorized_default > 1)
2412 hcd->authorized_default = hcd->wireless? 0 : 1;
2414 hcd->authorized_default = authorized_default;
2415 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
2422 dev_dbg(hcd->self.controller,
"pool alloc failed\n");
2426 if ((retval = usb_register_bus(&hcd->self)) < 0)
2427 goto err_register_bus;
2430 dev_err(hcd->self.controller,
"unable to allocate root hub\n");
2432 goto err_allocate_root_hub;
2434 hcd->self.root_hub = rhdev;
2436 switch (hcd->speed) {
2448 goto err_set_rh_speed;
2461 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2466 if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
2467 dev_err(hcd->self.controller,
"can't setup\n");
2468 goto err_hcd_driver_setup;
2470 hcd->rh_pollable = 1;
2473 if (device_can_wakeup(hcd->self.controller)
2474 && device_can_wakeup(&hcd->self.root_hub->dev))
2475 dev_dbg(hcd->self.controller,
"supports USB remote wakeup\n");
2481 retval = usb_hcd_request_irqs(hcd, irqnum, irqflags);
2483 goto err_request_irq;
2486 hcd->state = HC_STATE_RUNNING;
2487 retval = hcd->driver->start(hcd);
2489 dev_err(hcd->self.controller,
"startup error %d\n", retval);
2490 goto err_hcd_driver_start;
2494 rhdev->bus_mA =
min(500
u, hcd->power_budget);
2495 if ((retval = register_root_hub(hcd)) != 0)
2496 goto err_register_root_hub;
2500 printk(
KERN_ERR "Cannot register USB bus sysfs attributes: %d\n",
2502 goto error_create_attr_group;
2504 if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
2515 error_create_attr_group:
2516 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2517 if (HC_IS_RUNNING(hcd->state))
2518 hcd->state = HC_STATE_QUIESCING;
2519 spin_lock_irq(&hcd_root_hub_lock);
2520 hcd->rh_registered = 0;
2521 spin_unlock_irq(&hcd_root_hub_lock);
2523 #ifdef CONFIG_USB_SUSPEND
2529 err_register_root_hub:
2530 hcd->rh_pollable = 0;
2531 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2533 hcd->driver->stop(hcd);
2534 hcd->state = HC_STATE_HALT;
2535 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2537 err_hcd_driver_start:
2541 err_hcd_driver_setup:
2544 err_allocate_root_hub:
2545 usb_deregister_bus(&hcd->self);
2562 struct usb_device *rhdev = hcd->self.root_hub;
2564 dev_info(hcd->self.controller,
"remove, state %x\n", hcd->state);
2569 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
2570 if (HC_IS_RUNNING (hcd->state))
2571 hcd->state = HC_STATE_QUIESCING;
2573 dev_dbg(hcd->self.controller,
"roothub graceful disconnect\n");
2574 spin_lock_irq (&hcd_root_hub_lock);
2575 hcd->rh_registered = 0;
2576 spin_unlock_irq (&hcd_root_hub_lock);
2578 #ifdef CONFIG_USB_SUSPEND
2591 hcd->rh_pollable = 0;
2592 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2595 hcd->driver->stop(hcd);
2596 hcd->state = HC_STATE_HALT;
2599 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2608 usb_deregister_bus(&hcd->self);
2616 struct usb_hcd *hcd = platform_get_drvdata(dev);
2618 if (hcd->driver->shutdown)
2619 hcd->driver->shutdown(hcd);
2625 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
2627 struct usb_mon_operations *mon_ops;
2637 int usb_mon_register (
struct usb_mon_operations *ops)
2649 void usb_mon_deregister (
void)
2652 if (mon_ops ==
NULL) {