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
407 * @hcd: the host controller for this root hub
418 rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len) in rh_string() argument
435 s = hcd->self.bus_name; in rh_string()
439 s = hcd->product_desc; in rh_string()
444 init_utsname()->release, hcd->driver->description); in rh_string()
457 static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) in rh_call_control() argument
473 status = usb_hcd_link_urb_to_ep(hcd, urb); in rh_call_control()
477 urb->hcpriv = hcd; /* Indicate it's queued */ in rh_call_control()
524 tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
532 device_set_wakeup_enable(&hcd->self.root_hub->dev, 0); in rh_call_control()
537 if (device_can_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
539 device_set_wakeup_enable(&hcd->self.root_hub->dev, 1); in rh_call_control()
552 switch (hcd->speed) { in rh_call_control()
570 if (hcd->has_tt) in rh_call_control()
574 switch (hcd->speed) { in rh_call_control()
592 if (device_can_wakeup(&hcd->self.root_hub->dev)) in rh_call_control()
598 hcd, ubuf, wLength); in rh_call_control()
616 dev_dbg (hcd->self.controller, "root hub device address %d\n", in rh_call_control()
632 dev_dbg (hcd->self.controller, "no endpoint features yet\n"); in rh_call_control()
658 status = hcd->driver->hub_control (hcd, in rh_call_control()
663 usb_hub_adjust_deviceremovable(hcd->self.root_hub, in rh_call_control()
674 dev_dbg (hcd->self.controller, in rh_call_control()
712 usb_hcd_unlink_urb_from_ep(hcd, urb); in rh_call_control()
713 usb_hcd_giveback_urb(hcd, urb, status); in rh_call_control()
727 void usb_hcd_poll_rh_status(struct usb_hcd *hcd) in usb_hcd_poll_rh_status() argument
735 if (unlikely(!hcd->rh_pollable)) in usb_hcd_poll_rh_status()
737 if (!hcd->uses_new_polling && !hcd->status_urb) in usb_hcd_poll_rh_status()
740 length = hcd->driver->hub_status_data(hcd, buffer); in usb_hcd_poll_rh_status()
745 urb = hcd->status_urb; in usb_hcd_poll_rh_status()
747 clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
748 hcd->status_urb = NULL; in usb_hcd_poll_rh_status()
758 usb_hcd_unlink_urb_from_ep(hcd, urb); in usb_hcd_poll_rh_status()
759 usb_hcd_giveback_urb(hcd, urb, status); in usb_hcd_poll_rh_status()
762 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
771 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : in usb_hcd_poll_rh_status()
772 (length == 0 && hcd->status_urb != NULL)) in usb_hcd_poll_rh_status()
773 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in usb_hcd_poll_rh_status()
787 static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb) in rh_queue_status() argument
794 if (hcd->status_urb || urb->transfer_buffer_length < len) { in rh_queue_status()
795 dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); in rh_queue_status()
800 retval = usb_hcd_link_urb_to_ep(hcd, urb); in rh_queue_status()
804 hcd->status_urb = urb; in rh_queue_status()
805 urb->hcpriv = hcd; /* indicate it's queued */ in rh_queue_status()
806 if (!hcd->uses_new_polling) in rh_queue_status()
807 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in rh_queue_status()
810 else if (HCD_POLL_PENDING(hcd)) in rh_queue_status()
811 mod_timer(&hcd->rh_timer, jiffies); in rh_queue_status()
818 static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb) in rh_urb_enqueue() argument
821 return rh_queue_status (hcd, urb); in rh_urb_enqueue()
823 return rh_call_control (hcd, urb); in rh_urb_enqueue()
832 static int usb_rh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) in usb_rh_urb_dequeue() argument
838 rc = usb_hcd_check_unlink_urb(hcd, urb, status); in usb_rh_urb_dequeue()
846 if (!hcd->uses_new_polling) in usb_rh_urb_dequeue()
847 del_timer (&hcd->rh_timer); in usb_rh_urb_dequeue()
848 if (urb == hcd->status_urb) { in usb_rh_urb_dequeue()
849 hcd->status_urb = NULL; in usb_rh_urb_dequeue()
850 usb_hcd_unlink_urb_from_ep(hcd, urb); in usb_rh_urb_dequeue()
851 usb_hcd_giveback_urb(hcd, urb, status); in usb_rh_urb_dequeue()
948 * @hcd: host controller for this root hub
957 static int register_root_hub(struct usb_hcd *hcd) in register_root_hub() argument
959 struct device *parent_dev = hcd->self.controller; in register_root_hub()
960 struct usb_device *usb_dev = hcd->self.root_hub; in register_root_hub()
1002 hcd->rh_registered = 1; in register_root_hub()
1006 if (HCD_DEAD(hcd)) in register_root_hub()
1007 usb_hc_died (hcd); /* This time clean up */ in register_root_hub()
1119 * @hcd: host controller to which @urb was submitted
1123 * method. The HCD's private spinlock must be held and interrupts must
1132 int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_link_urb_to_ep() argument
1158 if (HCD_RH_RUNNING(hcd)) { in usb_hcd_link_urb_to_ep()
1173 * @hcd: host controller to which @urb was submitted
1178 * method. The HCD's private spinlock must be held and interrupts must
1190 int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, in usb_hcd_check_unlink_urb() argument
1215 * @hcd: host controller to which @urb was submitted
1219 * usb_hcd_giveback_urb(). The HCD's private spinlock must be held and
1223 void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unlink_urb_from_ep() argument
1225 /* clear all state linking urb to this dev (and hcd) */ in usb_hcd_unlink_urb_from_ep()
1240 * hcd->localmem_pool using usb_hcd_setup_local_mem().
1242 * The initialized hcd->localmem_pool then tells the usb code to allocate all
1311 void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unmap_urb_setup_for_dma() argument
1315 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_setup_for_dma()
1331 static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) in unmap_urb_for_dma() argument
1333 if (hcd->driver->unmap_urb_for_dma) in unmap_urb_for_dma()
1334 hcd->driver->unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1336 usb_hcd_unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1339 void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unmap_urb_for_dma() argument
1343 usb_hcd_unmap_urb_setup_for_dma(hcd, urb); in usb_hcd_unmap_urb_for_dma()
1348 dma_unmap_sg(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1354 dma_unmap_page(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1360 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1377 static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, in map_urb_for_dma() argument
1380 if (hcd->driver->map_urb_for_dma) in map_urb_for_dma()
1381 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1383 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1386 int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, in usb_hcd_map_urb_for_dma() argument
1393 * Lower level HCD code should use *_dma exclusively, in usb_hcd_map_urb_for_dma()
1399 if (hcd->self.uses_pio_for_control) in usb_hcd_map_urb_for_dma()
1401 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1411 } else if (hcd_uses_dma(hcd)) { in usb_hcd_map_urb_for_dma()
1418 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1422 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1432 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1441 } else if (hcd_uses_dma(hcd)) { in usb_hcd_map_urb_for_dma()
1452 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1467 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1472 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1482 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1486 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1495 usb_hcd_unmap_urb_for_dma(hcd, urb); in usb_hcd_map_urb_for_dma()
1511 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_submit_urb() local
1513 /* increment urb's reference count as part of giving it to the HCD in usb_hcd_submit_urb()
1514 * (which will control it). HCD guarantees that it either returns in usb_hcd_submit_urb()
1520 usbmon_urb_submit(&hcd->self, urb); in usb_hcd_submit_urb()
1531 status = rh_urb_enqueue(hcd, urb); in usb_hcd_submit_urb()
1533 status = map_urb_for_dma(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1535 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1537 unmap_urb_for_dma(hcd, urb); in usb_hcd_submit_urb()
1542 usbmon_urb_submit_error(&hcd->self, urb, status); in usb_hcd_submit_urb()
1563 /* this makes the hcd giveback() the urb more quickly, by kicking it
1568 static int unlink1(struct usb_hcd *hcd, struct urb *urb, int status) in unlink1() argument
1573 value = usb_rh_urb_dequeue(hcd, urb, status); in unlink1()
1576 /* The only reason an HCD might fail this call is if in unlink1()
1579 value = hcd->driver->urb_dequeue(hcd, urb, status); in unlink1()
1592 struct usb_hcd *hcd; in usb_hcd_unlink_urb() local
1609 hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_unlink_urb()
1610 retval = unlink1(hcd, urb, status); in usb_hcd_unlink_urb()
1625 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in __usb_hcd_giveback_urb() local
1635 unmap_urb_for_dma(hcd, urb); in __usb_hcd_giveback_urb()
1636 usbmon_urb_complete(&hcd->self, urb, status); in __usb_hcd_giveback_urb()
1703 * usb_hcd_giveback_urb - return URB from HCD to device driver
1704 * @hcd: host controller returning the URB
1713 * This hands the URB from HCD to its USB device driver, using its
1714 * completion function. The HCD has freed all per-urb resources
1715 * (and is done using urb->hcpriv). It also released all HCD locks;
1721 * the HCD hasn't checked for them.
1723 void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) in usb_hcd_giveback_urb() argument
1732 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) { in usb_hcd_giveback_urb()
1738 bh = &hcd->high_prio_bh; in usb_hcd_giveback_urb()
1740 bh = &hcd->low_prio_bh; in usb_hcd_giveback_urb()
1765 struct usb_hcd *hcd; in usb_hcd_flush_endpoint() local
1771 hcd = bus_to_hcd(udev->bus); in usb_hcd_flush_endpoint()
1785 /* kick hcd */ in usb_hcd_flush_endpoint()
1786 unlink1(hcd, urb, -ESHUTDOWN); in usb_hcd_flush_endpoint()
1787 dev_dbg (hcd->self.controller, in usb_hcd_flush_endpoint()
1849 struct usb_hcd *hcd; in usb_hcd_alloc_bandwidth() local
1852 hcd = bus_to_hcd(udev->bus); in usb_hcd_alloc_bandwidth()
1853 if (!hcd->driver->check_bandwidth) in usb_hcd_alloc_bandwidth()
1861 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1864 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1866 hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1869 /* Check if the HCD says there's enough bandwidth. Enable all endpoints in usb_hcd_alloc_bandwidth()
1870 * each interface's alt setting 0 and ask the HCD to check the bandwidth in usb_hcd_alloc_bandwidth()
1882 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1888 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1906 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); in usb_hcd_alloc_bandwidth()
1935 ret = hcd->driver->drop_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1942 ret = hcd->driver->add_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1948 ret = hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1951 hcd->driver->reset_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1955 /* Disables the endpoint: synchronizes with the hcd to make sure all
1966 struct usb_hcd *hcd; in usb_hcd_disable_endpoint() local
1969 hcd = bus_to_hcd(udev->bus); in usb_hcd_disable_endpoint()
1970 if (hcd->driver->endpoint_disable) in usb_hcd_disable_endpoint()
1971 hcd->driver->endpoint_disable(hcd, ep); in usb_hcd_disable_endpoint()
1985 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_reset_endpoint() local
1987 if (hcd->driver->endpoint_reset) in usb_hcd_reset_endpoint()
1988 hcd->driver->endpoint_reset(hcd, ep); in usb_hcd_reset_endpoint()
2006 * @mem_flags: flags hcd should use to allocate memory.
2019 struct usb_hcd *hcd; in usb_alloc_streams() local
2024 hcd = bus_to_hcd(dev->bus); in usb_alloc_streams()
2025 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams) in usb_alloc_streams()
2041 ret = hcd->driver->alloc_streams(hcd, dev, eps, num_eps, in usb_alloc_streams()
2058 * @mem_flags: flags hcd should use to allocate memory.
2061 * Can fail if we are given bad arguments, or HCD is broken.
2069 struct usb_hcd *hcd; in usb_free_streams() local
2074 hcd = bus_to_hcd(dev->bus); in usb_free_streams()
2083 ret = hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); in usb_free_streams()
2110 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_get_frame_number() local
2112 if (!HCD_RH_RUNNING(hcd)) in usb_hcd_get_frame_number()
2114 return hcd->driver->get_frame_number (hcd); in usb_hcd_get_frame_number()
2139 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in request_single_step_set_feature_urb() local
2159 if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) { in request_single_step_set_feature_urb()
2169 int ehset_single_step_set_feature(struct usb_hcd *hcd, int port) in ehset_single_step_set_feature() argument
2179 udev = usb_hub_find_child(hcd->self.root_hub, port); in ehset_single_step_set_feature()
2181 dev_err(hcd->self.controller, "No device attached to the RootHub\n"); in ehset_single_step_set_feature()
2205 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 1); in ehset_single_step_set_feature()
2211 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2222 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0); in ehset_single_step_set_feature()
2227 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2246 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_suspend() local
2248 int old_state = hcd->state; in hcd_bus_suspend()
2253 if (HCD_DEAD(hcd)) { in hcd_bus_suspend()
2258 if (!hcd->driver->bus_suspend) { in hcd_bus_suspend()
2261 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2262 hcd->state = HC_STATE_QUIESCING; in hcd_bus_suspend()
2263 status = hcd->driver->bus_suspend(hcd); in hcd_bus_suspend()
2267 hcd->state = HC_STATE_SUSPENDED; in hcd_bus_suspend()
2270 usb_phy_roothub_suspend(hcd->self.sysdev, in hcd_bus_suspend()
2271 hcd->phy_roothub); in hcd_bus_suspend()
2277 status = hcd->driver->hub_status_data(hcd, buffer); in hcd_bus_suspend()
2286 if (!HCD_DEAD(hcd)) { in hcd_bus_suspend()
2287 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2288 hcd->state = old_state; in hcd_bus_suspend()
2299 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_resume() local
2301 int old_state = hcd->state; in hcd_bus_resume()
2305 if (HCD_DEAD(hcd)) { in hcd_bus_resume()
2311 status = usb_phy_roothub_resume(hcd->self.sysdev, in hcd_bus_resume()
2312 hcd->phy_roothub); in hcd_bus_resume()
2317 if (!hcd->driver->bus_resume) in hcd_bus_resume()
2319 if (HCD_RH_RUNNING(hcd)) in hcd_bus_resume()
2322 hcd->state = HC_STATE_RESUMING; in hcd_bus_resume()
2323 status = hcd->driver->bus_resume(hcd); in hcd_bus_resume()
2324 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in hcd_bus_resume()
2326 status = usb_phy_roothub_calibrate(hcd->phy_roothub); in hcd_bus_resume()
2333 if (!HCD_DEAD(hcd)) { in hcd_bus_resume()
2337 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_resume()
2338 hcd->state = HC_STATE_RUNNING; in hcd_bus_resume()
2356 hcd->state = old_state; in hcd_bus_resume()
2357 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); in hcd_bus_resume()
2361 usb_hc_died(hcd); in hcd_bus_resume()
2369 struct usb_hcd *hcd = container_of(work, struct usb_hcd, wakeup_work); in hcd_resume_work() local
2370 struct usb_device *udev = hcd->self.root_hub; in hcd_resume_work()
2376 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2377 * @hcd: host controller for this root hub
2384 void usb_hcd_resume_root_hub (struct usb_hcd *hcd) in usb_hcd_resume_root_hub() argument
2389 if (hcd->rh_registered) { in usb_hcd_resume_root_hub()
2390 pm_wakeup_event(&hcd->self.root_hub->dev, 0); in usb_hcd_resume_root_hub()
2391 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in usb_hcd_resume_root_hub()
2392 queue_work(pm_wq, &hcd->wakeup_work); in usb_hcd_resume_root_hub()
2406 * @bus: the bus (must use hcd framework)
2419 struct usb_hcd *hcd; in usb_bus_start_enum() local
2426 hcd = bus_to_hcd(bus); in usb_bus_start_enum()
2427 if (port_num && hcd->driver->start_port_reset) in usb_bus_start_enum()
2428 status = hcd->driver->start_port_reset(hcd, port_num); in usb_bus_start_enum()
2434 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); in usb_bus_start_enum()
2444 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
2446 * @__hcd: pointer to the HCD whose IRQ is being signaled
2455 struct usb_hcd *hcd = __hcd; in usb_hcd_irq() local
2458 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) in usb_hcd_irq()
2460 else if (hcd->driver->irq(hcd) == IRQ_NONE) in usb_hcd_irq()
2474 struct usb_hcd *hcd = container_of(work, struct usb_hcd, died_work); in hcd_died_work() local
2481 kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env); in hcd_died_work()
2486 * @hcd: pointer to the HCD representing the controller
2492 * Only call this function with the primary HCD.
2494 void usb_hc_died (struct usb_hcd *hcd) in usb_hc_died() argument
2498 dev_err (hcd->self.controller, "HC died; cleaning up\n"); in usb_hc_died()
2501 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2502 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2503 if (hcd->rh_registered) { in usb_hc_died()
2504 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2507 usb_set_device_state (hcd->self.root_hub, in usb_hc_died()
2509 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2511 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { in usb_hc_died()
2512 hcd = hcd->shared_hcd; in usb_hc_died()
2513 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2514 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2515 if (hcd->rh_registered) { in usb_hc_died()
2516 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2519 usb_set_device_state(hcd->self.root_hub, in usb_hc_died()
2521 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2525 /* Handle the case where this function gets called with a shared HCD */ in usb_hc_died()
2526 if (usb_hcd_is_primary_hcd(hcd)) in usb_hc_died()
2527 schedule_work(&hcd->died_work); in usb_hc_died()
2529 schedule_work(&hcd->primary_hcd->died_work); in usb_hc_died()
2550 struct usb_hcd *hcd; in __usb_create_hcd() local
2552 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); in __usb_create_hcd()
2553 if (!hcd) in __usb_create_hcd()
2556 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), in __usb_create_hcd()
2558 if (!hcd->address0_mutex) { in __usb_create_hcd()
2559 kfree(hcd); in __usb_create_hcd()
2560 dev_dbg(dev, "hcd address0 mutex alloc failed\n"); in __usb_create_hcd()
2563 mutex_init(hcd->address0_mutex); in __usb_create_hcd()
2564 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), in __usb_create_hcd()
2566 if (!hcd->bandwidth_mutex) { in __usb_create_hcd()
2567 kfree(hcd->address0_mutex); in __usb_create_hcd()
2568 kfree(hcd); in __usb_create_hcd()
2569 dev_dbg(dev, "hcd bandwidth mutex alloc failed\n"); in __usb_create_hcd()
2572 mutex_init(hcd->bandwidth_mutex); in __usb_create_hcd()
2573 dev_set_drvdata(dev, hcd); in __usb_create_hcd()
2576 hcd->address0_mutex = primary_hcd->address0_mutex; in __usb_create_hcd()
2577 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; in __usb_create_hcd()
2578 hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2580 hcd->shared_hcd = primary_hcd; in __usb_create_hcd()
2581 primary_hcd->shared_hcd = hcd; in __usb_create_hcd()
2585 kref_init(&hcd->kref); in __usb_create_hcd()
2587 usb_bus_init(&hcd->self); in __usb_create_hcd()
2588 hcd->self.controller = dev; in __usb_create_hcd()
2589 hcd->self.sysdev = sysdev; in __usb_create_hcd()
2590 hcd->self.bus_name = bus_name; in __usb_create_hcd()
2592 timer_setup(&hcd->rh_timer, rh_timer_func, 0); in __usb_create_hcd()
2594 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); in __usb_create_hcd()
2597 INIT_WORK(&hcd->died_work, hcd_died_work); in __usb_create_hcd()
2599 hcd->driver = driver; in __usb_create_hcd()
2600 hcd->speed = driver->flags & HCD_MASK; in __usb_create_hcd()
2601 hcd->product_desc = (driver->product_desc) ? driver->product_desc : in __usb_create_hcd()
2603 return hcd; in __usb_create_hcd()
2608 * usb_create_shared_hcd - create and initialize an HCD structure
2609 * @driver: HC driver that will use this hcd
2610 * @dev: device for this HC, stored in hcd->self.controller
2611 * @bus_name: value to store in hcd->self.bus_name
2613 * PCI device. Only allocate certain resources for the primary HCD
2619 * hcd structure.
2621 * Return: On success, a pointer to the created and initialized HCD structure.
2633 * usb_create_hcd - create and initialize an HCD structure
2634 * @driver: HC driver that will use this hcd
2635 * @dev: device for this HC, stored in hcd->self.controller
2636 * @bus_name: value to store in hcd->self.bus_name
2642 * hcd structure.
2644 * Return: On success, a pointer to the created and initialized HCD
2659 * Make sure to deallocate the bandwidth_mutex only when the last HCD is
2660 * freed. When hcd_release() is called for either hcd in a peer set,
2665 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); in hcd_release() local
2668 if (hcd->shared_hcd) { in hcd_release()
2669 struct usb_hcd *peer = hcd->shared_hcd; in hcd_release()
2674 kfree(hcd->address0_mutex); in hcd_release()
2675 kfree(hcd->bandwidth_mutex); in hcd_release()
2678 kfree(hcd); in hcd_release()
2681 struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd) in usb_get_hcd() argument
2683 if (hcd) in usb_get_hcd()
2684 kref_get (&hcd->kref); in usb_get_hcd()
2685 return hcd; in usb_get_hcd()
2689 void usb_put_hcd (struct usb_hcd *hcd) in usb_put_hcd() argument
2691 if (hcd) in usb_put_hcd()
2692 kref_put (&hcd->kref, hcd_release); in usb_put_hcd()
2696 int usb_hcd_is_primary_hcd(struct usb_hcd *hcd) in usb_hcd_is_primary_hcd() argument
2698 if (!hcd->primary_hcd) in usb_hcd_is_primary_hcd()
2700 return hcd == hcd->primary_hcd; in usb_hcd_is_primary_hcd()
2704 int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1) in usb_hcd_find_raw_port_number() argument
2706 if (!hcd->driver->find_raw_port_number) in usb_hcd_find_raw_port_number()
2709 return hcd->driver->find_raw_port_number(hcd, port1); in usb_hcd_find_raw_port_number()
2712 static int usb_hcd_request_irqs(struct usb_hcd *hcd, in usb_hcd_request_irqs() argument
2717 if (hcd->driver->irq) { in usb_hcd_request_irqs()
2719 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in usb_hcd_request_irqs()
2720 hcd->driver->description, hcd->self.busnum); in usb_hcd_request_irqs()
2722 hcd->irq_descr, hcd); in usb_hcd_request_irqs()
2724 dev_err(hcd->self.controller, in usb_hcd_request_irqs()
2729 hcd->irq = irqnum; in usb_hcd_request_irqs()
2730 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, in usb_hcd_request_irqs()
2731 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2733 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2735 hcd->irq = 0; in usb_hcd_request_irqs()
2736 if (hcd->rsrc_start) in usb_hcd_request_irqs()
2737 dev_info(hcd->self.controller, "%s 0x%08llx\n", in usb_hcd_request_irqs()
2738 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2740 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2749 static void usb_put_invalidate_rhdev(struct usb_hcd *hcd) in usb_put_invalidate_rhdev() argument
2754 rhdev = hcd->self.root_hub; in usb_put_invalidate_rhdev()
2755 hcd->self.root_hub = NULL; in usb_put_invalidate_rhdev()
2761 * usb_stop_hcd - Halt the HCD
2762 * @hcd: the usb_hcd that has to be halted
2764 * Stop the root-hub polling timer and invoke the HCD's ->stop callback.
2766 static void usb_stop_hcd(struct usb_hcd *hcd) in usb_stop_hcd() argument
2768 hcd->rh_pollable = 0; in usb_stop_hcd()
2769 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2770 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2772 hcd->driver->stop(hcd); in usb_stop_hcd()
2773 hcd->state = HC_STATE_HALT; in usb_stop_hcd()
2775 /* In case the HCD restarted the timer, stop it again. */ in usb_stop_hcd()
2776 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2777 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2781 * usb_add_hcd - finish generic HCD structure initialization and register
2782 * @hcd: the usb_hcd structure to initialize
2786 * Finish the remaining parts of generic HCD initialization: allocate the
2790 int usb_add_hcd(struct usb_hcd *hcd, in usb_add_hcd() argument
2797 if (!hcd->skip_phy_initialization && usb_hcd_is_primary_hcd(hcd)) { in usb_add_hcd()
2798 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); in usb_add_hcd()
2799 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2800 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2802 retval = usb_phy_roothub_init(hcd->phy_roothub); in usb_add_hcd()
2806 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2809 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2814 retval = usb_phy_roothub_power_on(hcd->phy_roothub); in usb_add_hcd()
2819 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); in usb_add_hcd()
2823 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; in usb_add_hcd()
2827 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; in usb_add_hcd()
2833 hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; in usb_add_hcd()
2837 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in usb_add_hcd()
2840 set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags); in usb_add_hcd()
2846 retval = hcd_buffer_create(hcd); in usb_add_hcd()
2848 dev_dbg(hcd->self.sysdev, "pool alloc failed\n"); in usb_add_hcd()
2852 retval = usb_register_bus(&hcd->self); in usb_add_hcd()
2856 rhdev = usb_alloc_dev(NULL, &hcd->self, 0); in usb_add_hcd()
2858 dev_err(hcd->self.sysdev, "unable to allocate root hub\n"); in usb_add_hcd()
2863 hcd->self.root_hub = rhdev; in usb_add_hcd()
2870 switch (hcd->speed) { in usb_add_hcd()
2905 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_add_hcd()
2910 if (hcd->driver->reset) { in usb_add_hcd()
2911 retval = hcd->driver->reset(hcd); in usb_add_hcd()
2913 dev_err(hcd->self.controller, "can't setup: %d\n", in usb_add_hcd()
2918 hcd->rh_pollable = 1; in usb_add_hcd()
2920 retval = usb_phy_roothub_calibrate(hcd->phy_roothub); in usb_add_hcd()
2925 if (device_can_wakeup(hcd->self.controller) in usb_add_hcd()
2926 && device_can_wakeup(&hcd->self.root_hub->dev)) in usb_add_hcd()
2927 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); in usb_add_hcd()
2930 init_giveback_urb_bh(&hcd->high_prio_bh); in usb_add_hcd()
2931 hcd->high_prio_bh.high_prio = true; in usb_add_hcd()
2932 init_giveback_urb_bh(&hcd->low_prio_bh); in usb_add_hcd()
2937 if (usb_hcd_is_primary_hcd(hcd) && irqnum) { in usb_add_hcd()
2938 retval = usb_hcd_request_irqs(hcd, irqnum, irqflags); in usb_add_hcd()
2943 hcd->state = HC_STATE_RUNNING; in usb_add_hcd()
2944 retval = hcd->driver->start(hcd); in usb_add_hcd()
2946 dev_err(hcd->self.controller, "startup error %d\n", retval); in usb_add_hcd()
2950 /* starting here, usbcore will pay attention to the shared HCD roothub */ in usb_add_hcd()
2951 shared_hcd = hcd->shared_hcd; in usb_add_hcd()
2952 if (!usb_hcd_is_primary_hcd(hcd) && shared_hcd && HCD_DEFER_RH_REGISTER(shared_hcd)) { in usb_add_hcd()
2962 if (!HCD_DEFER_RH_REGISTER(hcd)) { in usb_add_hcd()
2963 retval = register_root_hub(hcd); in usb_add_hcd()
2967 if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) in usb_add_hcd()
2968 usb_hcd_poll_rh_status(hcd); in usb_add_hcd()
2974 usb_stop_hcd(hcd); in usb_add_hcd()
2976 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) in usb_add_hcd()
2977 free_irq(irqnum, hcd); in usb_add_hcd()
2981 usb_put_invalidate_rhdev(hcd); in usb_add_hcd()
2983 usb_deregister_bus(&hcd->self); in usb_add_hcd()
2985 hcd_buffer_destroy(hcd); in usb_add_hcd()
2987 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_add_hcd()
2989 usb_phy_roothub_exit(hcd->phy_roothub); in usb_add_hcd()
2997 * @hcd: the usb_hcd structure to remove
3002 * invoking the HCD's stop() method.
3004 void usb_remove_hcd(struct usb_hcd *hcd) in usb_remove_hcd() argument
3009 if (!hcd) { in usb_remove_hcd()
3010 pr_debug("%s: hcd is NULL\n", __func__); in usb_remove_hcd()
3013 rhdev = hcd->self.root_hub; in usb_remove_hcd()
3015 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); in usb_remove_hcd()
3018 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_remove_hcd()
3019 if (HC_IS_RUNNING (hcd->state)) in usb_remove_hcd()
3020 hcd->state = HC_STATE_QUIESCING; in usb_remove_hcd()
3022 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); in usb_remove_hcd()
3024 rh_registered = hcd->rh_registered; in usb_remove_hcd()
3025 hcd->rh_registered = 0; in usb_remove_hcd()
3029 cancel_work_sync(&hcd->wakeup_work); in usb_remove_hcd()
3031 cancel_work_sync(&hcd->died_work); in usb_remove_hcd()
3049 * The HCD might still restart the timer (if a port status change in usb_remove_hcd()
3053 usb_stop_hcd(hcd); in usb_remove_hcd()
3055 if (usb_hcd_is_primary_hcd(hcd)) { in usb_remove_hcd()
3056 if (hcd->irq > 0) in usb_remove_hcd()
3057 free_irq(hcd->irq, hcd); in usb_remove_hcd()
3060 usb_deregister_bus(&hcd->self); in usb_remove_hcd()
3061 hcd_buffer_destroy(hcd); in usb_remove_hcd()
3063 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_remove_hcd()
3064 usb_phy_roothub_exit(hcd->phy_roothub); in usb_remove_hcd()
3066 usb_put_invalidate_rhdev(hcd); in usb_remove_hcd()
3067 hcd->flags = 0; in usb_remove_hcd()
3074 struct usb_hcd *hcd = platform_get_drvdata(dev); in usb_hcd_platform_shutdown() local
3079 if (hcd->driver->shutdown) in usb_hcd_platform_shutdown()
3080 hcd->driver->shutdown(hcd); in usb_hcd_platform_shutdown()
3084 int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr, in usb_hcd_setup_local_mem() argument
3090 hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4, in usb_hcd_setup_local_mem()
3091 dev_to_node(hcd->self.sysdev), in usb_hcd_setup_local_mem()
3092 dev_name(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3093 if (IS_ERR(hcd->localmem_pool)) in usb_hcd_setup_local_mem()
3094 return PTR_ERR(hcd->localmem_pool); in usb_hcd_setup_local_mem()
3101 local_mem = devm_memremap(hcd->self.sysdev, phys_addr, in usb_hcd_setup_local_mem()
3104 local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma, in usb_hcd_setup_local_mem()
3120 err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem, in usb_hcd_setup_local_mem()
3121 dma, size, dev_to_node(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3123 dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n", in usb_hcd_setup_local_mem()