Lines Matching full:hcd
38 #include <linux/usb/hcd.h>
51 * HCD-specific behaviors/bugs.
60 * tracking overhead. The HCD code should only block on spinlocks or on
65 * and includes mostly a "HCDI" (HCD Interface) along with some APIs used
428 * @hcd: the host controller for this root hub
439 rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len) in rh_string() argument
456 s = hcd->self.bus_name; in rh_string()
460 s = hcd->product_desc; in rh_string()
465 init_utsname()->release, hcd->driver->description); in rh_string()
478 static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) in rh_call_control() argument
494 status = usb_hcd_link_urb_to_ep(hcd, urb); in rh_call_control()
498 urb->hcpriv = hcd; /* Indicate it's queued */ 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()
623 hcd, ubuf, wLength); 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()
683 status = hcd->driver->hub_control (hcd, in rh_call_control()
688 usb_hub_adjust_deviceremovable(hcd->self.root_hub, in rh_call_control()
699 dev_dbg (hcd->self.controller, in rh_call_control()
737 usb_hcd_unlink_urb_from_ep(hcd, urb); in rh_call_control()
738 usb_hcd_giveback_urb(hcd, urb, status); in rh_call_control()
753 void usb_hcd_poll_rh_status(struct usb_hcd *hcd) in usb_hcd_poll_rh_status() argument
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()
777 usb_hcd_unlink_urb_from_ep(hcd, urb); in usb_hcd_poll_rh_status()
778 usb_hcd_giveback_urb(hcd, urb, 0); in usb_hcd_poll_rh_status()
781 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
790 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : in usb_hcd_poll_rh_status()
791 (length == 0 && hcd->status_urb != NULL)) in usb_hcd_poll_rh_status()
792 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in usb_hcd_poll_rh_status()
806 static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb) in rh_queue_status() argument
813 if (hcd->status_urb || urb->transfer_buffer_length < len) { in rh_queue_status()
814 dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); in rh_queue_status()
819 retval = usb_hcd_link_urb_to_ep(hcd, urb); in rh_queue_status()
823 hcd->status_urb = urb; in rh_queue_status()
824 urb->hcpriv = hcd; /* indicate it's queued */ in rh_queue_status()
825 if (!hcd->uses_new_polling) in rh_queue_status()
826 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in rh_queue_status()
829 else if (HCD_POLL_PENDING(hcd)) in rh_queue_status()
830 mod_timer(&hcd->rh_timer, jiffies); in rh_queue_status()
837 static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb) in rh_urb_enqueue() argument
840 return rh_queue_status (hcd, urb); in rh_urb_enqueue()
842 return rh_call_control (hcd, urb); in rh_urb_enqueue()
851 static int usb_rh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) in usb_rh_urb_dequeue() argument
857 rc = usb_hcd_check_unlink_urb(hcd, urb, status); in usb_rh_urb_dequeue()
865 if (!hcd->uses_new_polling) in usb_rh_urb_dequeue()
866 del_timer (&hcd->rh_timer); in usb_rh_urb_dequeue()
867 if (urb == hcd->status_urb) { in usb_rh_urb_dequeue()
868 hcd->status_urb = NULL; in usb_rh_urb_dequeue()
869 usb_hcd_unlink_urb_from_ep(hcd, urb); in usb_rh_urb_dequeue()
870 usb_hcd_giveback_urb(hcd, urb, status); in usb_rh_urb_dequeue()
965 * @hcd: host controller for this root hub
974 static int register_root_hub(struct usb_hcd *hcd) in register_root_hub() argument
976 struct device *parent_dev = hcd->self.controller; in register_root_hub()
977 struct usb_device *usb_dev = hcd->self.root_hub; in register_root_hub()
1015 hcd->rh_registered = 1; in register_root_hub()
1019 if (HCD_DEAD(hcd)) in register_root_hub()
1020 usb_hc_died (hcd); /* This time clean up */ in register_root_hub()
1132 * @hcd: host controller to which @urb was submitted
1136 * method. The HCD's private spinlock must be held and interrupts must
1145 int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_link_urb_to_ep() argument
1171 if (HCD_RH_RUNNING(hcd)) { in usb_hcd_link_urb_to_ep()
1186 * @hcd: host controller to which @urb was submitted
1191 * method. The HCD's private spinlock must be held and interrupts must
1203 int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, in usb_hcd_check_unlink_urb() argument
1228 * @hcd: host controller to which @urb was submitted
1232 * usb_hcd_giveback_urb(). The HCD's private spinlock must be held and
1236 void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unlink_urb_from_ep() argument
1238 /* clear all state linking urb to this dev (and hcd) */ in usb_hcd_unlink_urb_from_ep()
1252 * hcd->localmem_pool using usb_hcd_setup_local_mem().
1254 * The initialized hcd->localmem_pool then tells the usb code to allocate all
1323 void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unmap_urb_setup_for_dma() argument
1327 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_setup_for_dma()
1343 static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) in unmap_urb_for_dma() argument
1345 if (hcd->driver->unmap_urb_for_dma) in unmap_urb_for_dma()
1346 hcd->driver->unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1348 usb_hcd_unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1351 void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unmap_urb_for_dma() argument
1355 usb_hcd_unmap_urb_setup_for_dma(hcd, urb); in usb_hcd_unmap_urb_for_dma()
1360 dma_unmap_sg(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1366 dma_unmap_page(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1372 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1389 static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, in map_urb_for_dma() argument
1392 if (hcd->driver->map_urb_for_dma) in map_urb_for_dma()
1393 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1395 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1398 int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, in usb_hcd_map_urb_for_dma() argument
1405 * Lower level HCD code should use *_dma exclusively, in usb_hcd_map_urb_for_dma()
1411 if (hcd->self.uses_pio_for_control) in usb_hcd_map_urb_for_dma()
1413 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1423 } else if (hcd_uses_dma(hcd)) { in usb_hcd_map_urb_for_dma()
1430 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1434 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1444 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1453 } else if (hcd_uses_dma(hcd)) { in usb_hcd_map_urb_for_dma()
1464 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1479 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1484 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1494 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1498 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1507 usb_hcd_unmap_urb_for_dma(hcd, urb); in usb_hcd_map_urb_for_dma()
1523 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_submit_urb() local
1525 /* increment urb's reference count as part of giving it to the HCD in usb_hcd_submit_urb()
1526 * (which will control it). HCD guarantees that it either returns in usb_hcd_submit_urb()
1532 usbmon_urb_submit(&hcd->self, urb); in usb_hcd_submit_urb()
1543 status = rh_urb_enqueue(hcd, urb); in usb_hcd_submit_urb()
1545 status = map_urb_for_dma(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1547 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1549 unmap_urb_for_dma(hcd, urb); in usb_hcd_submit_urb()
1554 usbmon_urb_submit_error(&hcd->self, urb, status); in usb_hcd_submit_urb()
1568 /* this makes the hcd giveback() the urb more quickly, by kicking it
1573 static int unlink1(struct usb_hcd *hcd, struct urb *urb, int status) in unlink1() argument
1578 value = usb_rh_urb_dequeue(hcd, urb, status); in unlink1()
1581 /* The only reason an HCD might fail this call is if in unlink1()
1584 value = hcd->driver->urb_dequeue(hcd, urb, status); in unlink1()
1597 struct usb_hcd *hcd; in usb_hcd_unlink_urb() local
1614 hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_unlink_urb()
1615 retval = unlink1(hcd, urb, status); in usb_hcd_unlink_urb()
1630 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in __usb_hcd_giveback_urb() local
1640 unmap_urb_for_dma(hcd, urb); in __usb_hcd_giveback_urb()
1641 usbmon_urb_complete(&hcd->self, urb, status); in __usb_hcd_giveback_urb()
1690 * usb_hcd_giveback_urb - return URB from HCD to device driver
1691 * @hcd: host controller returning the URB
1696 * This hands the URB from HCD to its USB device driver, using its
1697 * completion function. The HCD has freed all per-urb resources
1698 * (and is done using urb->hcpriv). It also released all HCD locks;
1704 * the HCD hasn't checked for them.
1706 void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) in usb_hcd_giveback_urb() argument
1715 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) { in usb_hcd_giveback_urb()
1721 bh = &hcd->high_prio_bh; in usb_hcd_giveback_urb()
1724 bh = &hcd->low_prio_bh; in usb_hcd_giveback_urb()
1751 struct usb_hcd *hcd; in usb_hcd_flush_endpoint() local
1757 hcd = bus_to_hcd(udev->bus); in usb_hcd_flush_endpoint()
1771 /* kick hcd */ in usb_hcd_flush_endpoint()
1772 unlink1(hcd, urb, -ESHUTDOWN); in usb_hcd_flush_endpoint()
1773 dev_dbg (hcd->self.controller, in usb_hcd_flush_endpoint()
1835 struct usb_hcd *hcd; in usb_hcd_alloc_bandwidth() local
1838 hcd = bus_to_hcd(udev->bus); in usb_hcd_alloc_bandwidth()
1839 if (!hcd->driver->check_bandwidth) in usb_hcd_alloc_bandwidth()
1847 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1850 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1852 hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1855 /* Check if the HCD says there's enough bandwidth. Enable all endpoints in usb_hcd_alloc_bandwidth()
1856 * each interface's alt setting 0 and ask the HCD to check the bandwidth in usb_hcd_alloc_bandwidth()
1868 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1874 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1892 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); in usb_hcd_alloc_bandwidth()
1921 ret = hcd->driver->drop_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1928 ret = hcd->driver->add_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1934 ret = hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1937 hcd->driver->reset_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1941 /* Disables the endpoint: synchronizes with the hcd to make sure all
1952 struct usb_hcd *hcd; in usb_hcd_disable_endpoint() local
1955 hcd = bus_to_hcd(udev->bus); in usb_hcd_disable_endpoint()
1956 if (hcd->driver->endpoint_disable) in usb_hcd_disable_endpoint()
1957 hcd->driver->endpoint_disable(hcd, ep); in usb_hcd_disable_endpoint()
1971 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_reset_endpoint() local
1973 if (hcd->driver->endpoint_reset) in usb_hcd_reset_endpoint()
1974 hcd->driver->endpoint_reset(hcd, ep); in usb_hcd_reset_endpoint()
1992 * @mem_flags: flags hcd should use to allocate memory.
2005 struct usb_hcd *hcd; in usb_alloc_streams() local
2010 hcd = bus_to_hcd(dev->bus); in usb_alloc_streams()
2011 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams) in usb_alloc_streams()
2027 ret = hcd->driver->alloc_streams(hcd, dev, eps, num_eps, in usb_alloc_streams()
2044 * @mem_flags: flags hcd should use to allocate memory.
2047 * Can fail if we are given bad arguments, or HCD is broken.
2055 struct usb_hcd *hcd; in usb_free_streams() local
2060 hcd = bus_to_hcd(dev->bus); in usb_free_streams()
2069 ret = hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); in usb_free_streams()
2096 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_get_frame_number() local
2098 if (!HCD_RH_RUNNING(hcd)) in usb_hcd_get_frame_number()
2100 return hcd->driver->get_frame_number (hcd); in usb_hcd_get_frame_number()
2109 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_suspend() local
2111 int old_state = hcd->state; in hcd_bus_suspend()
2116 if (HCD_DEAD(hcd)) { in hcd_bus_suspend()
2121 if (!hcd->driver->bus_suspend) { in hcd_bus_suspend()
2124 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2125 hcd->state = HC_STATE_QUIESCING; in hcd_bus_suspend()
2126 status = hcd->driver->bus_suspend(hcd); in hcd_bus_suspend()
2130 hcd->state = HC_STATE_SUSPENDED; in hcd_bus_suspend()
2133 usb_phy_roothub_suspend(hcd->self.sysdev, in hcd_bus_suspend()
2134 hcd->phy_roothub); in hcd_bus_suspend()
2140 status = hcd->driver->hub_status_data(hcd, buffer); in hcd_bus_suspend()
2149 if (!HCD_DEAD(hcd)) { in hcd_bus_suspend()
2150 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2151 hcd->state = old_state; in hcd_bus_suspend()
2162 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_resume() local
2164 int old_state = hcd->state; in hcd_bus_resume()
2168 if (HCD_DEAD(hcd)) { in hcd_bus_resume()
2174 status = usb_phy_roothub_resume(hcd->self.sysdev, in hcd_bus_resume()
2175 hcd->phy_roothub); in hcd_bus_resume()
2180 if (!hcd->driver->bus_resume) in hcd_bus_resume()
2182 if (HCD_RH_RUNNING(hcd)) in hcd_bus_resume()
2185 hcd->state = HC_STATE_RESUMING; in hcd_bus_resume()
2186 status = hcd->driver->bus_resume(hcd); in hcd_bus_resume()
2187 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in hcd_bus_resume()
2189 status = usb_phy_roothub_calibrate(hcd->phy_roothub); in hcd_bus_resume()
2196 if (!HCD_DEAD(hcd)) { in hcd_bus_resume()
2200 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_resume()
2201 hcd->state = HC_STATE_RUNNING; in hcd_bus_resume()
2219 hcd->state = old_state; in hcd_bus_resume()
2220 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); in hcd_bus_resume()
2224 usb_hc_died(hcd); in hcd_bus_resume()
2232 struct usb_hcd *hcd = container_of(work, struct usb_hcd, wakeup_work); in hcd_resume_work() local
2233 struct usb_device *udev = hcd->self.root_hub; in hcd_resume_work()
2239 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2240 * @hcd: host controller for this root hub
2247 void usb_hcd_resume_root_hub (struct usb_hcd *hcd) in usb_hcd_resume_root_hub() argument
2252 if (hcd->rh_registered) { in usb_hcd_resume_root_hub()
2253 pm_wakeup_event(&hcd->self.root_hub->dev, 0); in usb_hcd_resume_root_hub()
2254 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in usb_hcd_resume_root_hub()
2255 queue_work(pm_wq, &hcd->wakeup_work); in usb_hcd_resume_root_hub()
2269 * @bus: the bus (must use hcd framework)
2282 struct usb_hcd *hcd; in usb_bus_start_enum() local
2289 hcd = bus_to_hcd(bus); in usb_bus_start_enum()
2290 if (port_num && hcd->driver->start_port_reset) in usb_bus_start_enum()
2291 status = hcd->driver->start_port_reset(hcd, port_num); in usb_bus_start_enum()
2297 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); in usb_bus_start_enum()
2307 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
2309 * @__hcd: pointer to the HCD whose IRQ is being signaled
2318 struct usb_hcd *hcd = __hcd; in usb_hcd_irq() local
2321 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) in usb_hcd_irq()
2323 else if (hcd->driver->irq(hcd) == IRQ_NONE) in usb_hcd_irq()
2337 struct usb_hcd *hcd = container_of(work, struct usb_hcd, died_work); in hcd_died_work() local
2344 kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env); in hcd_died_work()
2349 * @hcd: pointer to the HCD representing the controller
2355 * Only call this function with the primary HCD.
2357 void usb_hc_died (struct usb_hcd *hcd) in usb_hc_died() argument
2361 dev_err (hcd->self.controller, "HC died; cleaning up\n"); in usb_hc_died()
2364 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2365 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2366 if (hcd->rh_registered) { in usb_hc_died()
2367 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2370 usb_set_device_state (hcd->self.root_hub, in usb_hc_died()
2372 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2374 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { in usb_hc_died()
2375 hcd = hcd->shared_hcd; in usb_hc_died()
2376 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2377 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2378 if (hcd->rh_registered) { in usb_hc_died()
2379 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2382 usb_set_device_state(hcd->self.root_hub, in usb_hc_died()
2384 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2388 /* Handle the case where this function gets called with a shared HCD */ in usb_hc_died()
2389 if (usb_hcd_is_primary_hcd(hcd)) in usb_hc_died()
2390 schedule_work(&hcd->died_work); in usb_hc_died()
2392 schedule_work(&hcd->primary_hcd->died_work); in usb_hc_died()
2413 struct usb_hcd *hcd; in __usb_create_hcd() local
2415 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); in __usb_create_hcd()
2416 if (!hcd) in __usb_create_hcd()
2419 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), in __usb_create_hcd()
2421 if (!hcd->address0_mutex) { in __usb_create_hcd()
2422 kfree(hcd); in __usb_create_hcd()
2423 dev_dbg(dev, "hcd address0 mutex alloc failed\n"); in __usb_create_hcd()
2426 mutex_init(hcd->address0_mutex); in __usb_create_hcd()
2427 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), in __usb_create_hcd()
2429 if (!hcd->bandwidth_mutex) { in __usb_create_hcd()
2430 kfree(hcd->address0_mutex); in __usb_create_hcd()
2431 kfree(hcd); in __usb_create_hcd()
2432 dev_dbg(dev, "hcd bandwidth mutex alloc failed\n"); in __usb_create_hcd()
2435 mutex_init(hcd->bandwidth_mutex); in __usb_create_hcd()
2436 dev_set_drvdata(dev, hcd); in __usb_create_hcd()
2439 hcd->address0_mutex = primary_hcd->address0_mutex; in __usb_create_hcd()
2440 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; in __usb_create_hcd()
2441 hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2443 hcd->shared_hcd = primary_hcd; in __usb_create_hcd()
2444 primary_hcd->shared_hcd = hcd; in __usb_create_hcd()
2448 kref_init(&hcd->kref); in __usb_create_hcd()
2450 usb_bus_init(&hcd->self); in __usb_create_hcd()
2451 hcd->self.controller = dev; in __usb_create_hcd()
2452 hcd->self.sysdev = sysdev; in __usb_create_hcd()
2453 hcd->self.bus_name = bus_name; in __usb_create_hcd()
2455 timer_setup(&hcd->rh_timer, rh_timer_func, 0); in __usb_create_hcd()
2457 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); in __usb_create_hcd()
2460 INIT_WORK(&hcd->died_work, hcd_died_work); in __usb_create_hcd()
2462 hcd->driver = driver; in __usb_create_hcd()
2463 hcd->speed = driver->flags & HCD_MASK; in __usb_create_hcd()
2464 hcd->product_desc = (driver->product_desc) ? driver->product_desc : in __usb_create_hcd()
2466 return hcd; in __usb_create_hcd()
2471 * usb_create_shared_hcd - create and initialize an HCD structure
2472 * @driver: HC driver that will use this hcd
2473 * @dev: device for this HC, stored in hcd->self.controller
2474 * @bus_name: value to store in hcd->self.bus_name
2476 * PCI device. Only allocate certain resources for the primary HCD
2481 * hcd structure.
2483 * Return: On success, a pointer to the created and initialized HCD structure.
2495 * usb_create_hcd - create and initialize an HCD structure
2496 * @driver: HC driver that will use this hcd
2497 * @dev: device for this HC, stored in hcd->self.controller
2498 * @bus_name: value to store in hcd->self.bus_name
2503 * hcd structure.
2505 * Return: On success, a pointer to the created and initialized HCD
2520 * Make sure to deallocate the bandwidth_mutex only when the last HCD is
2521 * freed. When hcd_release() is called for either hcd in a peer set,
2526 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); in hcd_release() local
2529 if (hcd->shared_hcd) { in hcd_release()
2530 struct usb_hcd *peer = hcd->shared_hcd; in hcd_release()
2535 kfree(hcd->address0_mutex); in hcd_release()
2536 kfree(hcd->bandwidth_mutex); in hcd_release()
2539 kfree(hcd); in hcd_release()
2542 struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd) in usb_get_hcd() argument
2544 if (hcd) in usb_get_hcd()
2545 kref_get (&hcd->kref); in usb_get_hcd()
2546 return hcd; in usb_get_hcd()
2550 void usb_put_hcd (struct usb_hcd *hcd) in usb_put_hcd() argument
2552 if (hcd) in usb_put_hcd()
2553 kref_put (&hcd->kref, hcd_release); in usb_put_hcd()
2557 int usb_hcd_is_primary_hcd(struct usb_hcd *hcd) in usb_hcd_is_primary_hcd() argument
2559 if (!hcd->primary_hcd) in usb_hcd_is_primary_hcd()
2561 return hcd == hcd->primary_hcd; in usb_hcd_is_primary_hcd()
2565 int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1) in usb_hcd_find_raw_port_number() argument
2567 if (!hcd->driver->find_raw_port_number) in usb_hcd_find_raw_port_number()
2570 return hcd->driver->find_raw_port_number(hcd, port1); in usb_hcd_find_raw_port_number()
2573 static int usb_hcd_request_irqs(struct usb_hcd *hcd, in usb_hcd_request_irqs() argument
2578 if (hcd->driver->irq) { in usb_hcd_request_irqs()
2580 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in usb_hcd_request_irqs()
2581 hcd->driver->description, hcd->self.busnum); in usb_hcd_request_irqs()
2583 hcd->irq_descr, hcd); in usb_hcd_request_irqs()
2585 dev_err(hcd->self.controller, in usb_hcd_request_irqs()
2590 hcd->irq = irqnum; in usb_hcd_request_irqs()
2591 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, in usb_hcd_request_irqs()
2592 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2594 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2596 hcd->irq = 0; in usb_hcd_request_irqs()
2597 if (hcd->rsrc_start) in usb_hcd_request_irqs()
2598 dev_info(hcd->self.controller, "%s 0x%08llx\n", in usb_hcd_request_irqs()
2599 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2601 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2610 static void usb_put_invalidate_rhdev(struct usb_hcd *hcd) in usb_put_invalidate_rhdev() argument
2615 rhdev = hcd->self.root_hub; in usb_put_invalidate_rhdev()
2616 hcd->self.root_hub = NULL; in usb_put_invalidate_rhdev()
2622 * usb_add_hcd - finish generic HCD structure initialization and register
2623 * @hcd: the usb_hcd structure to initialize
2627 * Finish the remaining parts of generic HCD initialization: allocate the
2631 int usb_add_hcd(struct usb_hcd *hcd, in usb_add_hcd() argument
2637 if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { in usb_add_hcd()
2638 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); in usb_add_hcd()
2639 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2640 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2642 retval = usb_phy_roothub_init(hcd->phy_roothub); in usb_add_hcd()
2646 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2649 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2654 retval = usb_phy_roothub_power_on(hcd->phy_roothub); in usb_add_hcd()
2659 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); in usb_add_hcd()
2663 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; in usb_add_hcd()
2667 hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; in usb_add_hcd()
2671 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; in usb_add_hcd()
2676 hcd->dev_policy = hcd->wireless ? in usb_add_hcd()
2681 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in usb_add_hcd()
2684 set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags); in usb_add_hcd()
2690 retval = hcd_buffer_create(hcd); in usb_add_hcd()
2692 dev_dbg(hcd->self.sysdev, "pool alloc failed\n"); in usb_add_hcd()
2696 retval = usb_register_bus(&hcd->self); in usb_add_hcd()
2700 rhdev = usb_alloc_dev(NULL, &hcd->self, 0); in usb_add_hcd()
2702 dev_err(hcd->self.sysdev, "unable to allocate root hub\n"); in usb_add_hcd()
2707 hcd->self.root_hub = rhdev; in usb_add_hcd()
2713 switch (hcd->speed) { in usb_add_hcd()
2748 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_add_hcd()
2753 if (hcd->driver->reset) { in usb_add_hcd()
2754 retval = hcd->driver->reset(hcd); in usb_add_hcd()
2756 dev_err(hcd->self.controller, "can't setup: %d\n", in usb_add_hcd()
2761 hcd->rh_pollable = 1; in usb_add_hcd()
2763 retval = usb_phy_roothub_calibrate(hcd->phy_roothub); in usb_add_hcd()
2768 if (device_can_wakeup(hcd->self.controller) in usb_add_hcd()
2769 && device_can_wakeup(&hcd->self.root_hub->dev)) in usb_add_hcd()
2770 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); in usb_add_hcd()
2773 init_giveback_urb_bh(&hcd->high_prio_bh); in usb_add_hcd()
2774 init_giveback_urb_bh(&hcd->low_prio_bh); in usb_add_hcd()
2779 if (usb_hcd_is_primary_hcd(hcd) && irqnum) { in usb_add_hcd()
2780 retval = usb_hcd_request_irqs(hcd, irqnum, irqflags); in usb_add_hcd()
2785 hcd->state = HC_STATE_RUNNING; in usb_add_hcd()
2786 retval = hcd->driver->start(hcd); in usb_add_hcd()
2788 dev_err(hcd->self.controller, "startup error %d\n", retval); in usb_add_hcd()
2793 retval = register_root_hub(hcd); in usb_add_hcd()
2797 if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) in usb_add_hcd()
2798 usb_hcd_poll_rh_status(hcd); in usb_add_hcd()
2803 hcd->rh_pollable = 0; in usb_add_hcd()
2804 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_add_hcd()
2805 del_timer_sync(&hcd->rh_timer); in usb_add_hcd()
2806 hcd->driver->stop(hcd); in usb_add_hcd()
2807 hcd->state = HC_STATE_HALT; in usb_add_hcd()
2808 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_add_hcd()
2809 del_timer_sync(&hcd->rh_timer); in usb_add_hcd()
2811 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) in usb_add_hcd()
2812 free_irq(irqnum, hcd); in usb_add_hcd()
2816 usb_put_invalidate_rhdev(hcd); in usb_add_hcd()
2818 usb_deregister_bus(&hcd->self); in usb_add_hcd()
2820 hcd_buffer_destroy(hcd); in usb_add_hcd()
2822 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_add_hcd()
2824 usb_phy_roothub_exit(hcd->phy_roothub); in usb_add_hcd()
2832 * @hcd: the usb_hcd structure to remove
2836 * invoking the HCD's stop() method.
2838 void usb_remove_hcd(struct usb_hcd *hcd) in usb_remove_hcd() argument
2840 struct usb_device *rhdev = hcd->self.root_hub; in usb_remove_hcd()
2842 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); in usb_remove_hcd()
2845 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_remove_hcd()
2846 if (HC_IS_RUNNING (hcd->state)) in usb_remove_hcd()
2847 hcd->state = HC_STATE_QUIESCING; in usb_remove_hcd()
2849 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); in usb_remove_hcd()
2851 hcd->rh_registered = 0; in usb_remove_hcd()
2855 cancel_work_sync(&hcd->wakeup_work); in usb_remove_hcd()
2857 cancel_work_sync(&hcd->died_work); in usb_remove_hcd()
2874 * The HCD might still restart the timer (if a port status change in usb_remove_hcd()
2878 hcd->rh_pollable = 0; in usb_remove_hcd()
2879 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_remove_hcd()
2880 del_timer_sync(&hcd->rh_timer); in usb_remove_hcd()
2882 hcd->driver->stop(hcd); in usb_remove_hcd()
2883 hcd->state = HC_STATE_HALT; in usb_remove_hcd()
2885 /* In case the HCD restarted the timer, stop it again. */ in usb_remove_hcd()
2886 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_remove_hcd()
2887 del_timer_sync(&hcd->rh_timer); in usb_remove_hcd()
2889 if (usb_hcd_is_primary_hcd(hcd)) { in usb_remove_hcd()
2890 if (hcd->irq > 0) in usb_remove_hcd()
2891 free_irq(hcd->irq, hcd); in usb_remove_hcd()
2894 usb_deregister_bus(&hcd->self); in usb_remove_hcd()
2895 hcd_buffer_destroy(hcd); in usb_remove_hcd()
2897 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_remove_hcd()
2898 usb_phy_roothub_exit(hcd->phy_roothub); in usb_remove_hcd()
2900 usb_put_invalidate_rhdev(hcd); in usb_remove_hcd()
2901 hcd->flags = 0; in usb_remove_hcd()
2908 struct usb_hcd *hcd = platform_get_drvdata(dev); in usb_hcd_platform_shutdown() local
2913 if (hcd->driver->shutdown) in usb_hcd_platform_shutdown()
2914 hcd->driver->shutdown(hcd); in usb_hcd_platform_shutdown()
2918 int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr, in usb_hcd_setup_local_mem() argument
2924 hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4, in usb_hcd_setup_local_mem()
2925 dev_to_node(hcd->self.sysdev), in usb_hcd_setup_local_mem()
2926 dev_name(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
2927 if (IS_ERR(hcd->localmem_pool)) in usb_hcd_setup_local_mem()
2928 return PTR_ERR(hcd->localmem_pool); in usb_hcd_setup_local_mem()
2930 local_mem = devm_memremap(hcd->self.sysdev, phys_addr, in usb_hcd_setup_local_mem()
2940 err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem, in usb_hcd_setup_local_mem()
2941 dma, size, dev_to_node(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
2943 dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n", in usb_hcd_setup_local_mem()