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
405 * @hcd: the host controller for this root hub
416 rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len) in rh_string() argument
433 s = hcd->self.bus_name; in rh_string()
437 s = hcd->product_desc; in rh_string()
442 init_utsname()->release, hcd->driver->description); in rh_string()
455 static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) in rh_call_control() argument
471 status = usb_hcd_link_urb_to_ep(hcd, urb); in rh_call_control()
475 urb->hcpriv = hcd; /* Indicate it's queued */ in rh_call_control()
522 tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
530 device_set_wakeup_enable(&hcd->self.root_hub->dev, 0); in rh_call_control()
535 if (device_can_wakeup(&hcd->self.root_hub->dev) in rh_call_control()
537 device_set_wakeup_enable(&hcd->self.root_hub->dev, 1); in rh_call_control()
550 switch (hcd->speed) { in rh_call_control()
568 if (hcd->has_tt) in rh_call_control()
572 switch (hcd->speed) { in rh_call_control()
590 if (device_can_wakeup(&hcd->self.root_hub->dev)) in rh_call_control()
596 hcd, ubuf, wLength); in rh_call_control()
614 dev_dbg (hcd->self.controller, "root hub device address %d\n", in rh_call_control()
630 dev_dbg (hcd->self.controller, "no endpoint features yet\n"); in rh_call_control()
656 status = hcd->driver->hub_control (hcd, in rh_call_control()
661 usb_hub_adjust_deviceremovable(hcd->self.root_hub, in rh_call_control()
672 dev_dbg (hcd->self.controller, in rh_call_control()
710 usb_hcd_unlink_urb_from_ep(hcd, urb); in rh_call_control()
711 usb_hcd_giveback_urb(hcd, urb, status); in rh_call_control()
725 void usb_hcd_poll_rh_status(struct usb_hcd *hcd) in usb_hcd_poll_rh_status() argument
733 if (unlikely(!hcd->rh_pollable)) in usb_hcd_poll_rh_status()
735 if (!hcd->uses_new_polling && !hcd->status_urb) in usb_hcd_poll_rh_status()
738 length = hcd->driver->hub_status_data(hcd, buffer); in usb_hcd_poll_rh_status()
743 urb = hcd->status_urb; in usb_hcd_poll_rh_status()
745 clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
746 hcd->status_urb = NULL; in usb_hcd_poll_rh_status()
756 usb_hcd_unlink_urb_from_ep(hcd, urb); in usb_hcd_poll_rh_status()
757 usb_hcd_giveback_urb(hcd, urb, status); in usb_hcd_poll_rh_status()
760 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); in usb_hcd_poll_rh_status()
769 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : in usb_hcd_poll_rh_status()
770 (length == 0 && hcd->status_urb != NULL)) in usb_hcd_poll_rh_status()
771 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in usb_hcd_poll_rh_status()
785 static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb) in rh_queue_status() argument
792 if (hcd->status_urb || urb->transfer_buffer_length < len) { in rh_queue_status()
793 dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); in rh_queue_status()
798 retval = usb_hcd_link_urb_to_ep(hcd, urb); in rh_queue_status()
802 hcd->status_urb = urb; in rh_queue_status()
803 urb->hcpriv = hcd; /* indicate it's queued */ in rh_queue_status()
804 if (!hcd->uses_new_polling) in rh_queue_status()
805 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); in rh_queue_status()
808 else if (HCD_POLL_PENDING(hcd)) in rh_queue_status()
809 mod_timer(&hcd->rh_timer, jiffies); in rh_queue_status()
816 static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb) in rh_urb_enqueue() argument
819 return rh_queue_status (hcd, urb); in rh_urb_enqueue()
821 return rh_call_control (hcd, urb); in rh_urb_enqueue()
830 static int usb_rh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) in usb_rh_urb_dequeue() argument
836 rc = usb_hcd_check_unlink_urb(hcd, urb, status); in usb_rh_urb_dequeue()
844 if (!hcd->uses_new_polling) in usb_rh_urb_dequeue()
845 del_timer (&hcd->rh_timer); in usb_rh_urb_dequeue()
846 if (urb == hcd->status_urb) { in usb_rh_urb_dequeue()
847 hcd->status_urb = NULL; in usb_rh_urb_dequeue()
848 usb_hcd_unlink_urb_from_ep(hcd, urb); in usb_rh_urb_dequeue()
849 usb_hcd_giveback_urb(hcd, urb, status); in usb_rh_urb_dequeue()
946 * @hcd: host controller for this root hub
955 static int register_root_hub(struct usb_hcd *hcd) in register_root_hub() argument
957 struct device *parent_dev = hcd->self.controller; in register_root_hub()
958 struct usb_device *usb_dev = hcd->self.root_hub; in register_root_hub()
1000 hcd->rh_registered = 1; in register_root_hub()
1004 if (HCD_DEAD(hcd)) in register_root_hub()
1005 usb_hc_died (hcd); /* This time clean up */ in register_root_hub()
1117 * @hcd: host controller to which @urb was submitted
1121 * method. The HCD's private spinlock must be held and interrupts must
1130 int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_link_urb_to_ep() argument
1156 if (HCD_RH_RUNNING(hcd)) { in usb_hcd_link_urb_to_ep()
1171 * @hcd: host controller to which @urb was submitted
1176 * method. The HCD's private spinlock must be held and interrupts must
1188 int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, in usb_hcd_check_unlink_urb() argument
1213 * @hcd: host controller to which @urb was submitted
1217 * usb_hcd_giveback_urb(). The HCD's private spinlock must be held and
1221 void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unlink_urb_from_ep() argument
1223 /* clear all state linking urb to this dev (and hcd) */ in usb_hcd_unlink_urb_from_ep()
1238 * hcd->localmem_pool using usb_hcd_setup_local_mem().
1240 * The initialized hcd->localmem_pool then tells the usb code to allocate all
1309 void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unmap_urb_setup_for_dma() argument
1313 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_setup_for_dma()
1329 static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) in unmap_urb_for_dma() argument
1331 if (hcd->driver->unmap_urb_for_dma) in unmap_urb_for_dma()
1332 hcd->driver->unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1334 usb_hcd_unmap_urb_for_dma(hcd, urb); in unmap_urb_for_dma()
1337 void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) in usb_hcd_unmap_urb_for_dma() argument
1341 usb_hcd_unmap_urb_setup_for_dma(hcd, urb); in usb_hcd_unmap_urb_for_dma()
1346 dma_unmap_sg(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1352 dma_unmap_page(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1358 dma_unmap_single(hcd->self.sysdev, in usb_hcd_unmap_urb_for_dma()
1375 static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, in map_urb_for_dma() argument
1378 if (hcd->driver->map_urb_for_dma) in map_urb_for_dma()
1379 return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1381 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); in map_urb_for_dma()
1384 int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, in usb_hcd_map_urb_for_dma() argument
1391 * Lower level HCD code should use *_dma exclusively, in usb_hcd_map_urb_for_dma()
1397 if (hcd->self.uses_pio_for_control) in usb_hcd_map_urb_for_dma()
1399 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1409 } else if (hcd_uses_dma(hcd)) { in usb_hcd_map_urb_for_dma()
1416 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1420 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1430 if (hcd->localmem_pool) { in usb_hcd_map_urb_for_dma()
1439 } else if (hcd_uses_dma(hcd)) { in usb_hcd_map_urb_for_dma()
1450 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1465 hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1470 if (dma_mapping_error(hcd->self.sysdev, in usb_hcd_map_urb_for_dma()
1480 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()
1493 usb_hcd_unmap_urb_for_dma(hcd, urb); in usb_hcd_map_urb_for_dma()
1509 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_submit_urb() local
1511 /* increment urb's reference count as part of giving it to the HCD in usb_hcd_submit_urb()
1512 * (which will control it). HCD guarantees that it either returns in usb_hcd_submit_urb()
1518 usbmon_urb_submit(&hcd->self, urb); in usb_hcd_submit_urb()
1529 status = rh_urb_enqueue(hcd, urb); in usb_hcd_submit_urb()
1531 status = map_urb_for_dma(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1533 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); in usb_hcd_submit_urb()
1535 unmap_urb_for_dma(hcd, urb); in usb_hcd_submit_urb()
1540 usbmon_urb_submit_error(&hcd->self, urb, status); in usb_hcd_submit_urb()
1561 /* this makes the hcd giveback() the urb more quickly, by kicking it
1566 static int unlink1(struct usb_hcd *hcd, struct urb *urb, int status) in unlink1() argument
1571 value = usb_rh_urb_dequeue(hcd, urb, status); in unlink1()
1574 /* The only reason an HCD might fail this call is if in unlink1()
1577 value = hcd->driver->urb_dequeue(hcd, urb, status); in unlink1()
1590 struct usb_hcd *hcd; in usb_hcd_unlink_urb() local
1607 hcd = bus_to_hcd(urb->dev->bus); in usb_hcd_unlink_urb()
1608 retval = unlink1(hcd, urb, status); in usb_hcd_unlink_urb()
1623 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in __usb_hcd_giveback_urb() local
1634 unmap_urb_for_dma(hcd, urb); in __usb_hcd_giveback_urb()
1635 usbmon_urb_complete(&hcd->self, urb, status); in __usb_hcd_giveback_urb()
1704 * usb_hcd_giveback_urb - return URB from HCD to device driver
1705 * @hcd: host controller returning the URB
1714 * This hands the URB from HCD to its USB device driver, using its
1715 * completion function. The HCD has freed all per-urb resources
1716 * (and is done using urb->hcpriv). It also released all HCD locks;
1722 * the HCD hasn't checked for them.
1724 void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status) in usb_hcd_giveback_urb() argument
1733 if (!hcd_giveback_urb_in_bh(hcd) && !is_root_hub(urb->dev)) { in usb_hcd_giveback_urb()
1739 bh = &hcd->high_prio_bh; in usb_hcd_giveback_urb()
1741 bh = &hcd->low_prio_bh; in usb_hcd_giveback_urb()
1766 struct usb_hcd *hcd; in usb_hcd_flush_endpoint() local
1772 hcd = bus_to_hcd(udev->bus); in usb_hcd_flush_endpoint()
1786 /* kick hcd */ in usb_hcd_flush_endpoint()
1787 unlink1(hcd, urb, -ESHUTDOWN); in usb_hcd_flush_endpoint()
1788 dev_dbg (hcd->self.controller, in usb_hcd_flush_endpoint()
1850 struct usb_hcd *hcd; in usb_hcd_alloc_bandwidth() local
1853 hcd = bus_to_hcd(udev->bus); in usb_hcd_alloc_bandwidth()
1854 if (!hcd->driver->check_bandwidth) in usb_hcd_alloc_bandwidth()
1862 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1865 hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1867 hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1870 /* Check if the HCD says there's enough bandwidth. Enable all endpoints in usb_hcd_alloc_bandwidth()
1871 * each interface's alt setting 0 and ask the HCD to check the bandwidth in usb_hcd_alloc_bandwidth()
1883 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1889 ret = hcd->driver->drop_endpoint(hcd, udev, ep); in usb_hcd_alloc_bandwidth()
1907 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); in usb_hcd_alloc_bandwidth()
1936 ret = hcd->driver->drop_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1943 ret = hcd->driver->add_endpoint(hcd, udev, in usb_hcd_alloc_bandwidth()
1949 ret = hcd->driver->check_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1952 hcd->driver->reset_bandwidth(hcd, udev); in usb_hcd_alloc_bandwidth()
1956 /* Disables the endpoint: synchronizes with the hcd to make sure all
1967 struct usb_hcd *hcd; in usb_hcd_disable_endpoint() local
1970 hcd = bus_to_hcd(udev->bus); in usb_hcd_disable_endpoint()
1971 if (hcd->driver->endpoint_disable) in usb_hcd_disable_endpoint()
1972 hcd->driver->endpoint_disable(hcd, ep); in usb_hcd_disable_endpoint()
1986 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_reset_endpoint() local
1988 if (hcd->driver->endpoint_reset) in usb_hcd_reset_endpoint()
1989 hcd->driver->endpoint_reset(hcd, ep); in usb_hcd_reset_endpoint()
2007 * @mem_flags: flags hcd should use to allocate memory.
2020 struct usb_hcd *hcd; in usb_alloc_streams() local
2025 hcd = bus_to_hcd(dev->bus); in usb_alloc_streams()
2026 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams) in usb_alloc_streams()
2042 ret = hcd->driver->alloc_streams(hcd, dev, eps, num_eps, in usb_alloc_streams()
2059 * @mem_flags: flags hcd should use to allocate memory.
2062 * Can fail if we are given bad arguments, or HCD is broken.
2070 struct usb_hcd *hcd; in usb_free_streams() local
2075 hcd = bus_to_hcd(dev->bus); in usb_free_streams()
2084 ret = hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); in usb_free_streams()
2111 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in usb_hcd_get_frame_number() local
2113 if (!HCD_RH_RUNNING(hcd)) in usb_hcd_get_frame_number()
2115 return hcd->driver->get_frame_number (hcd); in usb_hcd_get_frame_number()
2140 struct usb_hcd *hcd = bus_to_hcd(udev->bus); in request_single_step_set_feature_urb() local
2160 if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) { in request_single_step_set_feature_urb()
2170 int ehset_single_step_set_feature(struct usb_hcd *hcd, int port) in ehset_single_step_set_feature() argument
2180 udev = usb_hub_find_child(hcd->self.root_hub, port); in ehset_single_step_set_feature()
2182 dev_err(hcd->self.controller, "No device attached to the RootHub\n"); in ehset_single_step_set_feature()
2206 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 1); in ehset_single_step_set_feature()
2212 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2223 retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0); in ehset_single_step_set_feature()
2228 dev_err(hcd->self.controller, in ehset_single_step_set_feature()
2247 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_suspend() local
2249 int old_state = hcd->state; in hcd_bus_suspend()
2254 if (HCD_DEAD(hcd)) { in hcd_bus_suspend()
2259 if (!hcd->driver->bus_suspend) { in hcd_bus_suspend()
2262 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2263 hcd->state = HC_STATE_QUIESCING; in hcd_bus_suspend()
2264 status = hcd->driver->bus_suspend(hcd); in hcd_bus_suspend()
2268 hcd->state = HC_STATE_SUSPENDED; in hcd_bus_suspend()
2271 usb_phy_roothub_suspend(hcd->self.sysdev, in hcd_bus_suspend()
2272 hcd->phy_roothub); in hcd_bus_suspend()
2278 status = hcd->driver->hub_status_data(hcd, buffer); in hcd_bus_suspend()
2287 if (!HCD_DEAD(hcd)) { in hcd_bus_suspend()
2288 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_suspend()
2289 hcd->state = old_state; in hcd_bus_suspend()
2300 struct usb_hcd *hcd = bus_to_hcd(rhdev->bus); in hcd_bus_resume() local
2302 int old_state = hcd->state; in hcd_bus_resume()
2306 if (HCD_DEAD(hcd)) { in hcd_bus_resume()
2312 status = usb_phy_roothub_resume(hcd->self.sysdev, in hcd_bus_resume()
2313 hcd->phy_roothub); in hcd_bus_resume()
2318 if (!hcd->driver->bus_resume) in hcd_bus_resume()
2320 if (HCD_RH_RUNNING(hcd)) in hcd_bus_resume()
2323 hcd->state = HC_STATE_RESUMING; in hcd_bus_resume()
2324 status = hcd->driver->bus_resume(hcd); in hcd_bus_resume()
2325 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in hcd_bus_resume()
2327 status = usb_phy_roothub_calibrate(hcd->phy_roothub); in hcd_bus_resume()
2334 if (!HCD_DEAD(hcd)) { in hcd_bus_resume()
2338 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in hcd_bus_resume()
2339 hcd->state = HC_STATE_RUNNING; in hcd_bus_resume()
2357 hcd->state = old_state; in hcd_bus_resume()
2358 usb_phy_roothub_suspend(hcd->self.sysdev, hcd->phy_roothub); in hcd_bus_resume()
2362 usb_hc_died(hcd); in hcd_bus_resume()
2370 struct usb_hcd *hcd = container_of(work, struct usb_hcd, wakeup_work); in hcd_resume_work() local
2371 struct usb_device *udev = hcd->self.root_hub; in hcd_resume_work()
2377 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2378 * @hcd: host controller for this root hub
2385 void usb_hcd_resume_root_hub (struct usb_hcd *hcd) in usb_hcd_resume_root_hub() argument
2390 if (hcd->rh_registered) { in usb_hcd_resume_root_hub()
2391 pm_wakeup_event(&hcd->self.root_hub->dev, 0); in usb_hcd_resume_root_hub()
2392 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); in usb_hcd_resume_root_hub()
2393 queue_work(pm_wq, &hcd->wakeup_work); in usb_hcd_resume_root_hub()
2407 * @bus: the bus (must use hcd framework)
2420 struct usb_hcd *hcd; in usb_bus_start_enum() local
2427 hcd = bus_to_hcd(bus); in usb_bus_start_enum()
2428 if (port_num && hcd->driver->start_port_reset) in usb_bus_start_enum()
2429 status = hcd->driver->start_port_reset(hcd, port_num); in usb_bus_start_enum()
2435 mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10)); in usb_bus_start_enum()
2445 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
2447 * @__hcd: pointer to the HCD whose IRQ is being signaled
2456 struct usb_hcd *hcd = __hcd; in usb_hcd_irq() local
2459 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) in usb_hcd_irq()
2461 else if (hcd->driver->irq(hcd) == IRQ_NONE) in usb_hcd_irq()
2475 struct usb_hcd *hcd = container_of(work, struct usb_hcd, died_work); in hcd_died_work() local
2482 kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_OFFLINE, env); in hcd_died_work()
2487 * @hcd: pointer to the HCD representing the controller
2493 * Only call this function with the primary HCD.
2495 void usb_hc_died (struct usb_hcd *hcd) in usb_hc_died() argument
2499 dev_err (hcd->self.controller, "HC died; cleaning up\n"); in usb_hc_died()
2502 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2503 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2504 if (hcd->rh_registered) { in usb_hc_died()
2505 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2508 usb_set_device_state (hcd->self.root_hub, in usb_hc_died()
2510 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2512 if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { in usb_hc_died()
2513 hcd = hcd->shared_hcd; in usb_hc_died()
2514 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_hc_died()
2515 set_bit(HCD_FLAG_DEAD, &hcd->flags); in usb_hc_died()
2516 if (hcd->rh_registered) { in usb_hc_died()
2517 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_hc_died()
2520 usb_set_device_state(hcd->self.root_hub, in usb_hc_died()
2522 usb_kick_hub_wq(hcd->self.root_hub); in usb_hc_died()
2526 /* Handle the case where this function gets called with a shared HCD */ in usb_hc_died()
2527 if (usb_hcd_is_primary_hcd(hcd)) in usb_hc_died()
2528 schedule_work(&hcd->died_work); in usb_hc_died()
2530 schedule_work(&hcd->primary_hcd->died_work); in usb_hc_died()
2551 struct usb_hcd *hcd; in __usb_create_hcd() local
2553 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); in __usb_create_hcd()
2554 if (!hcd) in __usb_create_hcd()
2557 hcd->address0_mutex = kmalloc(sizeof(*hcd->address0_mutex), in __usb_create_hcd()
2559 if (!hcd->address0_mutex) { in __usb_create_hcd()
2560 kfree(hcd); in __usb_create_hcd()
2561 dev_dbg(dev, "hcd address0 mutex alloc failed\n"); in __usb_create_hcd()
2564 mutex_init(hcd->address0_mutex); in __usb_create_hcd()
2565 hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), in __usb_create_hcd()
2567 if (!hcd->bandwidth_mutex) { in __usb_create_hcd()
2568 kfree(hcd->address0_mutex); in __usb_create_hcd()
2569 kfree(hcd); in __usb_create_hcd()
2570 dev_dbg(dev, "hcd bandwidth mutex alloc failed\n"); in __usb_create_hcd()
2573 mutex_init(hcd->bandwidth_mutex); in __usb_create_hcd()
2574 dev_set_drvdata(dev, hcd); in __usb_create_hcd()
2577 hcd->address0_mutex = primary_hcd->address0_mutex; in __usb_create_hcd()
2578 hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; in __usb_create_hcd()
2579 hcd->primary_hcd = primary_hcd; in __usb_create_hcd()
2581 hcd->shared_hcd = primary_hcd; in __usb_create_hcd()
2582 primary_hcd->shared_hcd = hcd; in __usb_create_hcd()
2586 kref_init(&hcd->kref); in __usb_create_hcd()
2588 usb_bus_init(&hcd->self); in __usb_create_hcd()
2589 hcd->self.controller = dev; in __usb_create_hcd()
2590 hcd->self.sysdev = sysdev; in __usb_create_hcd()
2591 hcd->self.bus_name = bus_name; in __usb_create_hcd()
2593 timer_setup(&hcd->rh_timer, rh_timer_func, 0); in __usb_create_hcd()
2595 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); in __usb_create_hcd()
2598 INIT_WORK(&hcd->died_work, hcd_died_work); in __usb_create_hcd()
2600 hcd->driver = driver; in __usb_create_hcd()
2601 hcd->speed = driver->flags & HCD_MASK; in __usb_create_hcd()
2602 hcd->product_desc = (driver->product_desc) ? driver->product_desc : in __usb_create_hcd()
2604 return hcd; in __usb_create_hcd()
2609 * usb_create_shared_hcd - create and initialize an HCD structure
2610 * @driver: HC driver that will use this hcd
2611 * @dev: device for this HC, stored in hcd->self.controller
2612 * @bus_name: value to store in hcd->self.bus_name
2614 * PCI device. Only allocate certain resources for the primary HCD
2620 * hcd structure.
2622 * Return: On success, a pointer to the created and initialized HCD structure.
2634 * usb_create_hcd - create and initialize an HCD structure
2635 * @driver: HC driver that will use this hcd
2636 * @dev: device for this HC, stored in hcd->self.controller
2637 * @bus_name: value to store in hcd->self.bus_name
2643 * hcd structure.
2645 * Return: On success, a pointer to the created and initialized HCD
2660 * Make sure to deallocate the bandwidth_mutex only when the last HCD is
2661 * freed. When hcd_release() is called for either hcd in a peer set,
2666 struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); in hcd_release() local
2669 if (hcd->shared_hcd) { in hcd_release()
2670 struct usb_hcd *peer = hcd->shared_hcd; in hcd_release()
2675 kfree(hcd->address0_mutex); in hcd_release()
2676 kfree(hcd->bandwidth_mutex); in hcd_release()
2679 kfree(hcd); in hcd_release()
2682 struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd) in usb_get_hcd() argument
2684 if (hcd) in usb_get_hcd()
2685 kref_get (&hcd->kref); in usb_get_hcd()
2686 return hcd; in usb_get_hcd()
2690 void usb_put_hcd (struct usb_hcd *hcd) in usb_put_hcd() argument
2692 if (hcd) in usb_put_hcd()
2693 kref_put (&hcd->kref, hcd_release); in usb_put_hcd()
2697 int usb_hcd_is_primary_hcd(struct usb_hcd *hcd) in usb_hcd_is_primary_hcd() argument
2699 if (!hcd->primary_hcd) in usb_hcd_is_primary_hcd()
2701 return hcd == hcd->primary_hcd; in usb_hcd_is_primary_hcd()
2705 int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1) in usb_hcd_find_raw_port_number() argument
2707 if (!hcd->driver->find_raw_port_number) in usb_hcd_find_raw_port_number()
2710 return hcd->driver->find_raw_port_number(hcd, port1); in usb_hcd_find_raw_port_number()
2713 static int usb_hcd_request_irqs(struct usb_hcd *hcd, in usb_hcd_request_irqs() argument
2718 if (hcd->driver->irq) { in usb_hcd_request_irqs()
2720 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in usb_hcd_request_irqs()
2721 hcd->driver->description, hcd->self.busnum); in usb_hcd_request_irqs()
2723 hcd->irq_descr, hcd); in usb_hcd_request_irqs()
2725 dev_err(hcd->self.controller, in usb_hcd_request_irqs()
2730 hcd->irq = irqnum; in usb_hcd_request_irqs()
2731 dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, in usb_hcd_request_irqs()
2732 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2734 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2736 hcd->irq = 0; in usb_hcd_request_irqs()
2737 if (hcd->rsrc_start) in usb_hcd_request_irqs()
2738 dev_info(hcd->self.controller, "%s 0x%08llx\n", in usb_hcd_request_irqs()
2739 (hcd->driver->flags & HCD_MEMORY) ? in usb_hcd_request_irqs()
2741 (unsigned long long)hcd->rsrc_start); in usb_hcd_request_irqs()
2750 static void usb_put_invalidate_rhdev(struct usb_hcd *hcd) in usb_put_invalidate_rhdev() argument
2755 rhdev = hcd->self.root_hub; in usb_put_invalidate_rhdev()
2756 hcd->self.root_hub = NULL; in usb_put_invalidate_rhdev()
2762 * usb_stop_hcd - Halt the HCD
2763 * @hcd: the usb_hcd that has to be halted
2765 * Stop the root-hub polling timer and invoke the HCD's ->stop callback.
2767 static void usb_stop_hcd(struct usb_hcd *hcd) in usb_stop_hcd() argument
2769 hcd->rh_pollable = 0; in usb_stop_hcd()
2770 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2771 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2773 hcd->driver->stop(hcd); in usb_stop_hcd()
2774 hcd->state = HC_STATE_HALT; in usb_stop_hcd()
2776 /* In case the HCD restarted the timer, stop it again. */ in usb_stop_hcd()
2777 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in usb_stop_hcd()
2778 del_timer_sync(&hcd->rh_timer); in usb_stop_hcd()
2782 * usb_add_hcd - finish generic HCD structure initialization and register
2783 * @hcd: the usb_hcd structure to initialize
2787 * Finish the remaining parts of generic HCD initialization: allocate the
2791 int usb_add_hcd(struct usb_hcd *hcd, in usb_add_hcd() argument
2799 if (usb_hcd_is_primary_hcd(hcd)) in usb_add_hcd()
2800 skip_phy_initialization = hcd->skip_phy_initialization; in usb_add_hcd()
2802 skip_phy_initialization = hcd->primary_hcd->skip_phy_initialization; in usb_add_hcd()
2805 if (usb_hcd_is_primary_hcd(hcd)) { in usb_add_hcd()
2806 hcd->phy_roothub = usb_phy_roothub_alloc(hcd->self.sysdev); in usb_add_hcd()
2807 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2808 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2810 hcd->phy_roothub = usb_phy_roothub_alloc_usb3_phy(hcd->self.sysdev); in usb_add_hcd()
2811 if (IS_ERR(hcd->phy_roothub)) in usb_add_hcd()
2812 return PTR_ERR(hcd->phy_roothub); in usb_add_hcd()
2815 retval = usb_phy_roothub_init(hcd->phy_roothub); in usb_add_hcd()
2819 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2822 retval = usb_phy_roothub_set_mode(hcd->phy_roothub, in usb_add_hcd()
2827 retval = usb_phy_roothub_power_on(hcd->phy_roothub); in usb_add_hcd()
2832 dev_info(hcd->self.controller, "%s\n", hcd->product_desc); in usb_add_hcd()
2836 hcd->dev_policy = USB_DEVICE_AUTHORIZE_NONE; in usb_add_hcd()
2840 hcd->dev_policy = USB_DEVICE_AUTHORIZE_INTERNAL; in usb_add_hcd()
2846 hcd->dev_policy = USB_DEVICE_AUTHORIZE_ALL; in usb_add_hcd()
2850 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in usb_add_hcd()
2853 set_bit(HCD_FLAG_INTF_AUTHORIZED, &hcd->flags); in usb_add_hcd()
2859 retval = hcd_buffer_create(hcd); in usb_add_hcd()
2861 dev_dbg(hcd->self.sysdev, "pool alloc failed\n"); in usb_add_hcd()
2865 retval = usb_register_bus(&hcd->self); in usb_add_hcd()
2869 rhdev = usb_alloc_dev(NULL, &hcd->self, 0); in usb_add_hcd()
2871 dev_err(hcd->self.sysdev, "unable to allocate root hub\n"); in usb_add_hcd()
2876 hcd->self.root_hub = rhdev; in usb_add_hcd()
2883 switch (hcd->speed) { in usb_add_hcd()
2918 set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_add_hcd()
2923 if (hcd->driver->reset) { in usb_add_hcd()
2924 retval = hcd->driver->reset(hcd); in usb_add_hcd()
2926 dev_err(hcd->self.controller, "can't setup: %d\n", in usb_add_hcd()
2931 hcd->rh_pollable = 1; in usb_add_hcd()
2933 retval = usb_phy_roothub_calibrate(hcd->phy_roothub); in usb_add_hcd()
2938 if (device_can_wakeup(hcd->self.controller) in usb_add_hcd()
2939 && device_can_wakeup(&hcd->self.root_hub->dev)) in usb_add_hcd()
2940 dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); in usb_add_hcd()
2943 init_giveback_urb_bh(&hcd->high_prio_bh); in usb_add_hcd()
2944 hcd->high_prio_bh.high_prio = true; in usb_add_hcd()
2945 init_giveback_urb_bh(&hcd->low_prio_bh); in usb_add_hcd()
2950 if (usb_hcd_is_primary_hcd(hcd) && irqnum) { in usb_add_hcd()
2951 retval = usb_hcd_request_irqs(hcd, irqnum, irqflags); in usb_add_hcd()
2956 hcd->state = HC_STATE_RUNNING; in usb_add_hcd()
2957 retval = hcd->driver->start(hcd); in usb_add_hcd()
2959 dev_err(hcd->self.controller, "startup error %d\n", retval); in usb_add_hcd()
2963 /* starting here, usbcore will pay attention to the shared HCD roothub */ in usb_add_hcd()
2964 shared_hcd = hcd->shared_hcd; in usb_add_hcd()
2965 if (!usb_hcd_is_primary_hcd(hcd) && shared_hcd && HCD_DEFER_RH_REGISTER(shared_hcd)) { in usb_add_hcd()
2975 if (!HCD_DEFER_RH_REGISTER(hcd)) { in usb_add_hcd()
2976 retval = register_root_hub(hcd); in usb_add_hcd()
2980 if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) in usb_add_hcd()
2981 usb_hcd_poll_rh_status(hcd); in usb_add_hcd()
2987 usb_stop_hcd(hcd); in usb_add_hcd()
2989 if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0) in usb_add_hcd()
2990 free_irq(irqnum, hcd); in usb_add_hcd()
2994 usb_put_invalidate_rhdev(hcd); in usb_add_hcd()
2996 usb_deregister_bus(&hcd->self); in usb_add_hcd()
2998 hcd_buffer_destroy(hcd); in usb_add_hcd()
3000 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_add_hcd()
3002 usb_phy_roothub_exit(hcd->phy_roothub); in usb_add_hcd()
3010 * @hcd: the usb_hcd structure to remove
3015 * invoking the HCD's stop() method.
3017 void usb_remove_hcd(struct usb_hcd *hcd) in usb_remove_hcd() argument
3022 if (!hcd) { in usb_remove_hcd()
3023 pr_debug("%s: hcd is NULL\n", __func__); in usb_remove_hcd()
3026 rhdev = hcd->self.root_hub; in usb_remove_hcd()
3028 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); in usb_remove_hcd()
3031 clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); in usb_remove_hcd()
3032 if (HC_IS_RUNNING (hcd->state)) in usb_remove_hcd()
3033 hcd->state = HC_STATE_QUIESCING; in usb_remove_hcd()
3035 dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); in usb_remove_hcd()
3037 rh_registered = hcd->rh_registered; in usb_remove_hcd()
3038 hcd->rh_registered = 0; in usb_remove_hcd()
3042 cancel_work_sync(&hcd->wakeup_work); in usb_remove_hcd()
3044 cancel_work_sync(&hcd->died_work); in usb_remove_hcd()
3062 * The HCD might still restart the timer (if a port status change in usb_remove_hcd()
3066 usb_stop_hcd(hcd); in usb_remove_hcd()
3068 if (usb_hcd_is_primary_hcd(hcd)) { in usb_remove_hcd()
3069 if (hcd->irq > 0) in usb_remove_hcd()
3070 free_irq(hcd->irq, hcd); in usb_remove_hcd()
3073 usb_deregister_bus(&hcd->self); in usb_remove_hcd()
3074 hcd_buffer_destroy(hcd); in usb_remove_hcd()
3076 usb_phy_roothub_power_off(hcd->phy_roothub); in usb_remove_hcd()
3077 usb_phy_roothub_exit(hcd->phy_roothub); in usb_remove_hcd()
3079 usb_put_invalidate_rhdev(hcd); in usb_remove_hcd()
3080 hcd->flags = 0; in usb_remove_hcd()
3087 struct usb_hcd *hcd = platform_get_drvdata(dev); in usb_hcd_platform_shutdown() local
3092 if (hcd->driver->shutdown) in usb_hcd_platform_shutdown()
3093 hcd->driver->shutdown(hcd); in usb_hcd_platform_shutdown()
3097 int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr, in usb_hcd_setup_local_mem() argument
3103 hcd->localmem_pool = devm_gen_pool_create(hcd->self.sysdev, 4, in usb_hcd_setup_local_mem()
3104 dev_to_node(hcd->self.sysdev), in usb_hcd_setup_local_mem()
3105 dev_name(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3106 if (IS_ERR(hcd->localmem_pool)) in usb_hcd_setup_local_mem()
3107 return PTR_ERR(hcd->localmem_pool); in usb_hcd_setup_local_mem()
3114 local_mem = devm_memremap(hcd->self.sysdev, phys_addr, in usb_hcd_setup_local_mem()
3117 local_mem = dmam_alloc_attrs(hcd->self.sysdev, size, &dma, in usb_hcd_setup_local_mem()
3133 err = gen_pool_add_virt(hcd->localmem_pool, (unsigned long)local_mem, in usb_hcd_setup_local_mem()
3134 dma, size, dev_to_node(hcd->self.sysdev)); in usb_hcd_setup_local_mem()
3136 dev_err(hcd->self.sysdev, "gen_pool_add_virt failed with %d\n", in usb_hcd_setup_local_mem()