Lines Matching full:xhci
3 * xHCI host controller driver
18 #include "xhci.h"
19 #include "xhci-trace.h"
20 #include "xhci-debugfs.h"
29 static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci, in xhci_segment_alloc() argument
36 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_segment_alloc()
42 seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma); in xhci_segment_alloc()
52 dma_pool_free(xhci->segment_pool, seg->trbs, dma); in xhci_segment_alloc()
64 static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg) in xhci_segment_free() argument
67 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma); in xhci_segment_free()
74 static void xhci_ring_segments_free(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_ring_segments_free() argument
83 xhci_segment_free(xhci, seg); in xhci_ring_segments_free()
116 static void xhci_initialize_ring_segments(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_initialize_ring_segments() argument
124 chain_links = xhci_link_chain_quirk(xhci, ring->type); in xhci_initialize_ring_segments()
136 static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *src, struct xhci_ring *dst) in xhci_link_rings() argument
155 chain_links = xhci_link_chain_quirk(xhci, dst->type); in xhci_link_rings()
289 void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_ring_free() argument
299 xhci_ring_segments_free(xhci, ring); in xhci_ring_free()
330 static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, struct xhci_ring *ring, gfp_t flags) in xhci_alloc_segments_for_ring() argument
335 prev = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags); in xhci_alloc_segments_for_ring()
344 next = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags); in xhci_alloc_segments_for_ring()
359 xhci_ring_segments_free(xhci, ring); in xhci_alloc_segments_for_ring()
370 struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, unsigned int num_segs, in xhci_ring_alloc() argument
375 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_ring_alloc()
388 ret = xhci_alloc_segments_for_ring(xhci, ring, flags); in xhci_ring_alloc()
392 xhci_initialize_ring_segments(xhci, ring); in xhci_ring_alloc()
402 void xhci_free_endpoint_ring(struct xhci_hcd *xhci, in xhci_free_endpoint_ring() argument
406 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring); in xhci_free_endpoint_ring()
414 int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, in xhci_ring_expansion() argument
426 ret = xhci_alloc_segments_for_ring(xhci, &new_ring, flags); in xhci_ring_expansion()
430 xhci_initialize_ring_segments(xhci, &new_ring); in xhci_ring_expansion()
439 xhci_link_rings(xhci, &new_ring, ring); in xhci_ring_expansion()
441 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, in xhci_ring_expansion()
448 xhci_ring_segments_free(xhci, &new_ring); in xhci_ring_expansion()
452 struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, in xhci_alloc_container_ctx() argument
456 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_container_ctx()
466 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024; in xhci_alloc_container_ctx()
468 ctx->size += CTX_SIZE(xhci->hcc_params); in xhci_alloc_container_ctx()
470 ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma); in xhci_alloc_container_ctx()
478 void xhci_free_container_ctx(struct xhci_hcd *xhci, in xhci_free_container_ctx() argument
483 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma); in xhci_free_container_ctx()
496 struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, in xhci_get_slot_ctx() argument
503 (ctx->bytes + CTX_SIZE(xhci->hcc_params)); in xhci_get_slot_ctx()
506 struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, in xhci_get_ep_ctx() argument
516 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); in xhci_get_ep_ctx()
522 static void xhci_free_stream_ctx(struct xhci_hcd *xhci, in xhci_free_stream_ctx() argument
526 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_stream_ctx()
532 dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
534 dma_pool_free(xhci->small_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
547 static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, in xhci_alloc_stream_ctx() argument
551 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_ctx()
557 return dma_pool_zalloc(xhci->medium_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
559 return dma_pool_zalloc(xhci->small_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
581 struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, in xhci_alloc_stream_info() argument
591 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_info()
593 xhci_dbg(xhci, "Allocating %u streams and %u stream context array entries.\n", in xhci_alloc_stream_info()
595 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) { in xhci_alloc_stream_info()
596 xhci_dbg(xhci, "Command ring has no reserved TRBs available\n"); in xhci_alloc_stream_info()
599 xhci->cmd_ring_reserved_trbs++; in xhci_alloc_stream_info()
617 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci, in xhci_alloc_stream_info()
625 xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_alloc_stream_info()
638 xhci_ring_alloc(xhci, 2, TYPE_STREAM, max_packet, mem_flags); in xhci_alloc_stream_info()
650 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", cur_stream, addr); in xhci_alloc_stream_info()
656 xhci_ring_free(xhci, cur_ring); in xhci_alloc_stream_info()
674 xhci_ring_free(xhci, cur_ring); in xhci_alloc_stream_info()
678 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_alloc_stream_info()
680 xhci_free_stream_ctx(xhci, in xhci_alloc_stream_info()
689 xhci->cmd_ring_reserved_trbs--; in xhci_alloc_stream_info()
696 void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci, in xhci_setup_streams_ep_input_ctx() argument
706 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_setup_streams_ep_input_ctx()
733 void xhci_free_stream_info(struct xhci_hcd *xhci, in xhci_free_stream_info() argument
746 xhci_ring_free(xhci, cur_ring); in xhci_free_stream_info()
750 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_free_stream_info()
751 xhci->cmd_ring_reserved_trbs--; in xhci_free_stream_info()
753 xhci_free_stream_ctx(xhci, in xhci_free_stream_info()
765 static void xhci_free_tt_info(struct xhci_hcd *xhci, in xhci_free_tt_info() argument
777 xhci_dbg(xhci, "Bad rhub port.\n"); in xhci_free_tt_info()
781 tt_list_head = &(xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_free_tt_info()
794 int xhci_alloc_tt_info(struct xhci_hcd *xhci, in xhci_alloc_tt_info() argument
802 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_tt_info()
818 &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_alloc_tt_info()
829 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id); in xhci_alloc_tt_info()
835 * Should be called with xhci->lock held if there is any chance the TT lists
839 void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) in xhci_free_virt_device() argument
846 if (slot_id == 0 || !xhci->devs[slot_id]) in xhci_free_virt_device()
849 dev = xhci->devs[slot_id]; in xhci_free_virt_device()
851 xhci->dcbaa->dev_context_ptrs[slot_id] = 0; in xhci_free_virt_device()
862 xhci_ring_free(xhci, dev->eps[i].ring); in xhci_free_virt_device()
864 xhci_free_stream_info(xhci, in xhci_free_virt_device()
876 xhci_dbg(xhci, "Slot %u endpoint %u not removed from BW list!\n", in xhci_free_virt_device()
881 xhci_free_tt_info(xhci, dev, slot_id); in xhci_free_virt_device()
883 xhci_update_tt_active_eps(xhci, dev, old_active_eps); in xhci_free_virt_device()
886 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_free_virt_device()
888 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_free_virt_device()
894 kfree(xhci->devs[slot_id]); in xhci_free_virt_device()
895 xhci->devs[slot_id] = NULL; in xhci_free_virt_device()
904 static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id) in xhci_free_virt_devices_depth_first() argument
911 vdev = xhci->devs[slot_id]; in xhci_free_virt_devices_depth_first()
916 xhci_dbg(xhci, "Bad rhub port.\n"); in xhci_free_virt_devices_depth_first()
920 tt_list_head = &(xhci->rh_bw[vdev->rhub_port->hw_portnum].tts); in xhci_free_virt_devices_depth_first()
925 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_free_virt_devices_depth_first()
926 vdev = xhci->devs[i]; in xhci_free_virt_devices_depth_first()
929 xhci, i); in xhci_free_virt_devices_depth_first()
935 xhci_debugfs_remove_slot(xhci, slot_id); in xhci_free_virt_devices_depth_first()
936 xhci_free_virt_device(xhci, slot_id); in xhci_free_virt_devices_depth_first()
939 int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, in xhci_alloc_virt_device() argument
946 if (slot_id == 0 || xhci->devs[slot_id]) { in xhci_alloc_virt_device()
947 xhci_warn(xhci, "Bad Slot ID %d\n", slot_id); in xhci_alloc_virt_device()
958 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); in xhci_alloc_virt_device()
962 xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma); in xhci_alloc_virt_device()
965 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags); in xhci_alloc_virt_device()
969 xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma); in xhci_alloc_virt_device()
975 dev->eps[i].xhci = xhci; in xhci_alloc_virt_device()
981 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, TYPE_CTRL, 0, flags); in xhci_alloc_virt_device()
988 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma); in xhci_alloc_virt_device()
989 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n", in xhci_alloc_virt_device()
991 &xhci->dcbaa->dev_context_ptrs[slot_id], in xhci_alloc_virt_device()
992 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id])); in xhci_alloc_virt_device()
996 xhci->devs[slot_id] = dev; in xhci_alloc_virt_device()
1002 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_alloc_virt_device()
1004 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_alloc_virt_device()
1010 void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci, in xhci_copy_ep0_dequeue_into_input_ctx() argument
1017 virt_dev = xhci->devs[udev->slot_id]; in xhci_copy_ep0_dequeue_into_input_ctx()
1018 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0); in xhci_copy_ep0_dequeue_into_input_ctx()
1033 * The xHCI roothub may have ports of differing speeds in any order in the port
1036 * The xHCI hardware wants to know the roothub port that the USB device
1042 static struct xhci_port *xhci_find_rhub_port(struct xhci_hcd *xhci, struct usb_device *udev) in xhci_find_rhub_port() argument
1049 hcd = xhci_get_usb3_hcd(xhci); in xhci_find_rhub_port()
1051 hcd = xhci->main_hcd; in xhci_find_rhub_port()
1061 /* Setup an xHCI virtual device for a Set Address command */
1062 int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) in xhci_setup_addressable_virt_dev() argument
1069 dev = xhci->devs[udev->slot_id]; in xhci_setup_addressable_virt_dev()
1072 xhci_warn(xhci, "Slot ID %d is not assigned to this device\n", in xhci_setup_addressable_virt_dev()
1076 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); in xhci_setup_addressable_virt_dev()
1077 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); in xhci_setup_addressable_virt_dev()
1108 dev->rhub_port = xhci_find_rhub_port(xhci, udev); in xhci_setup_addressable_virt_dev()
1115 xhci_dbg(xhci, "Slot ID %d: HW portnum %d, hcd portnum %d\n", in xhci_setup_addressable_virt_dev()
1125 dev->bw_table = &xhci->rh_bw[dev->rhub_port->hw_portnum].bw_table; in xhci_setup_addressable_virt_dev()
1130 rh_bw = &xhci->rh_bw[dev->rhub_port->hw_portnum]; in xhci_setup_addressable_virt_dev()
1145 xhci_warn(xhci, "WARN: Didn't find a matching TT\n"); in xhci_setup_addressable_virt_dev()
1155 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); in xhci_setup_addressable_virt_dev()
1156 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); in xhci_setup_addressable_virt_dev()
1247 * The polling interval is expressed in "microframes". If xHCI's Interval field
1383 int xhci_endpoint_init(struct xhci_hcd *xhci, in xhci_endpoint_init() argument
1403 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_init()
1415 * set it to max available. See xHCI 1.1 spec 4.14.1.1 for details. in xhci_endpoint_init()
1423 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) && in xhci_endpoint_init()
1449 /* xHCI 1.0 and 1.1 indicates that ctrl ep avg TRB Length should be 8 */ in xhci_endpoint_init()
1450 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) in xhci_endpoint_init()
1452 /* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */ in xhci_endpoint_init()
1453 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) in xhci_endpoint_init()
1458 xhci_ring_alloc(xhci, 2, ring_type, max_packet, mem_flags); in xhci_endpoint_init()
1482 void xhci_endpoint_zero(struct xhci_hcd *xhci, in xhci_endpoint_zero() argument
1490 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_zero()
1511 void xhci_update_bw_info(struct xhci_hcd *xhci, in xhci_update_bw_info() argument
1536 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, i); in xhci_update_bw_info()
1569 void xhci_endpoint_copy(struct xhci_hcd *xhci, in xhci_endpoint_copy() argument
1577 out_ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_endpoint_copy()
1578 in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); in xhci_endpoint_copy()
1584 if (xhci->quirks & XHCI_MTK_HOST) { in xhci_endpoint_copy()
1595 void xhci_slot_copy(struct xhci_hcd *xhci, in xhci_slot_copy() argument
1602 in_slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); in xhci_slot_copy()
1603 out_slot_ctx = xhci_get_slot_ctx(xhci, out_ctx); in xhci_slot_copy()
1612 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) in scratchpad_alloc() argument
1615 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_alloc()
1616 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_alloc()
1618 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in scratchpad_alloc()
1624 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags, in scratchpad_alloc()
1626 if (!xhci->scratchpad) in scratchpad_alloc()
1629 xhci->scratchpad->sp_array = dma_alloc_coherent(dev, in scratchpad_alloc()
1631 &xhci->scratchpad->sp_dma, flags); in scratchpad_alloc()
1632 if (!xhci->scratchpad->sp_array) in scratchpad_alloc()
1635 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *), in scratchpad_alloc()
1637 if (!xhci->scratchpad->sp_buffers) in scratchpad_alloc()
1640 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); in scratchpad_alloc()
1643 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma, in scratchpad_alloc()
1648 xhci->scratchpad->sp_array[i] = dma; in scratchpad_alloc()
1649 xhci->scratchpad->sp_buffers[i] = buf; in scratchpad_alloc()
1656 dma_free_coherent(dev, xhci->page_size, in scratchpad_alloc()
1657 xhci->scratchpad->sp_buffers[i], in scratchpad_alloc()
1658 xhci->scratchpad->sp_array[i]); in scratchpad_alloc()
1660 kfree(xhci->scratchpad->sp_buffers); in scratchpad_alloc()
1664 xhci->scratchpad->sp_array, in scratchpad_alloc()
1665 xhci->scratchpad->sp_dma); in scratchpad_alloc()
1668 kfree(xhci->scratchpad); in scratchpad_alloc()
1669 xhci->scratchpad = NULL; in scratchpad_alloc()
1675 static void scratchpad_free(struct xhci_hcd *xhci) in scratchpad_free() argument
1679 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_free()
1681 if (!xhci->scratchpad) in scratchpad_free()
1684 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_free()
1687 dma_free_coherent(dev, xhci->page_size, in scratchpad_free()
1688 xhci->scratchpad->sp_buffers[i], in scratchpad_free()
1689 xhci->scratchpad->sp_array[i]); in scratchpad_free()
1691 kfree(xhci->scratchpad->sp_buffers); in scratchpad_free()
1693 xhci->scratchpad->sp_array, in scratchpad_free()
1694 xhci->scratchpad->sp_dma); in scratchpad_free()
1695 kfree(xhci->scratchpad); in scratchpad_free()
1696 xhci->scratchpad = NULL; in scratchpad_free()
1699 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, in xhci_alloc_command() argument
1703 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_command()
1727 struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci, in xhci_alloc_command_with_ctx() argument
1732 command = xhci_alloc_command(xhci, allocate_completion, mem_flags); in xhci_alloc_command_with_ctx()
1736 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, in xhci_alloc_command_with_ctx()
1751 void xhci_free_command(struct xhci_hcd *xhci, in xhci_free_command() argument
1754 xhci_free_container_ctx(xhci, in xhci_free_command()
1760 static int xhci_alloc_erst(struct xhci_hcd *xhci, in xhci_alloc_erst() argument
1771 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev, in xhci_alloc_erst()
1791 xhci_remove_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_remove_interrupter() argument
1808 xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue); in xhci_remove_interrupter()
1813 xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_free_interrupter() argument
1815 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_interrupter()
1830 xhci_ring_free(xhci, ir->event_ring); in xhci_free_interrupter()
1839 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_remove_secondary_interrupter() local
1842 spin_lock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1845 if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) { in xhci_remove_secondary_interrupter()
1846 xhci_dbg(xhci, "Invalid secondary interrupter, can't remove\n"); in xhci_remove_secondary_interrupter()
1847 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1853 xhci_remove_interrupter(xhci, ir); in xhci_remove_secondary_interrupter()
1854 xhci->interrupters[intr_num] = NULL; in xhci_remove_secondary_interrupter()
1856 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1858 xhci_free_interrupter(xhci, ir); in xhci_remove_secondary_interrupter()
1862 void xhci_mem_cleanup(struct xhci_hcd *xhci) in xhci_mem_cleanup() argument
1864 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_cleanup()
1867 cancel_delayed_work_sync(&xhci->cmd_timer); in xhci_mem_cleanup()
1869 for (i = 0; xhci->interrupters && i < xhci->max_interrupters; i++) { in xhci_mem_cleanup()
1870 if (xhci->interrupters[i]) { in xhci_mem_cleanup()
1871 xhci_remove_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1872 xhci_free_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1873 xhci->interrupters[i] = NULL; in xhci_mem_cleanup()
1876 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed interrupters"); in xhci_mem_cleanup()
1878 if (xhci->cmd_ring) in xhci_mem_cleanup()
1879 xhci_ring_free(xhci, xhci->cmd_ring); in xhci_mem_cleanup()
1880 xhci->cmd_ring = NULL; in xhci_mem_cleanup()
1881 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring"); in xhci_mem_cleanup()
1882 xhci_cleanup_command_queue(xhci); in xhci_mem_cleanup()
1884 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_mem_cleanup()
1885 for (i = 0; i < num_ports && xhci->rh_bw; i++) { in xhci_mem_cleanup()
1886 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table; in xhci_mem_cleanup()
1894 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--) in xhci_mem_cleanup()
1895 xhci_free_virt_devices_depth_first(xhci, i); in xhci_mem_cleanup()
1897 dma_pool_destroy(xhci->segment_pool); in xhci_mem_cleanup()
1898 xhci->segment_pool = NULL; in xhci_mem_cleanup()
1899 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed segment pool"); in xhci_mem_cleanup()
1901 dma_pool_destroy(xhci->device_pool); in xhci_mem_cleanup()
1902 xhci->device_pool = NULL; in xhci_mem_cleanup()
1903 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed device context pool"); in xhci_mem_cleanup()
1905 dma_pool_destroy(xhci->small_streams_pool); in xhci_mem_cleanup()
1906 xhci->small_streams_pool = NULL; in xhci_mem_cleanup()
1907 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_cleanup()
1910 dma_pool_destroy(xhci->medium_streams_pool); in xhci_mem_cleanup()
1911 xhci->medium_streams_pool = NULL; in xhci_mem_cleanup()
1912 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_cleanup()
1915 if (xhci->dcbaa) in xhci_mem_cleanup()
1916 dma_free_coherent(dev, sizeof(*xhci->dcbaa), in xhci_mem_cleanup()
1917 xhci->dcbaa, xhci->dcbaa->dma); in xhci_mem_cleanup()
1918 xhci->dcbaa = NULL; in xhci_mem_cleanup()
1920 scratchpad_free(xhci); in xhci_mem_cleanup()
1922 if (!xhci->rh_bw) in xhci_mem_cleanup()
1927 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) { in xhci_mem_cleanup()
1934 xhci->cmd_ring_reserved_trbs = 0; in xhci_mem_cleanup()
1935 xhci->usb2_rhub.num_ports = 0; in xhci_mem_cleanup()
1936 xhci->usb3_rhub.num_ports = 0; in xhci_mem_cleanup()
1937 xhci->num_active_eps = 0; in xhci_mem_cleanup()
1938 kfree(xhci->usb2_rhub.ports); in xhci_mem_cleanup()
1939 kfree(xhci->usb3_rhub.ports); in xhci_mem_cleanup()
1940 kfree(xhci->hw_ports); in xhci_mem_cleanup()
1941 kfree(xhci->rh_bw); in xhci_mem_cleanup()
1942 for (i = 0; i < xhci->num_port_caps; i++) in xhci_mem_cleanup()
1943 kfree(xhci->port_caps[i].psi); in xhci_mem_cleanup()
1944 kfree(xhci->port_caps); in xhci_mem_cleanup()
1945 kfree(xhci->interrupters); in xhci_mem_cleanup()
1946 xhci->num_port_caps = 0; in xhci_mem_cleanup()
1948 xhci->usb2_rhub.ports = NULL; in xhci_mem_cleanup()
1949 xhci->usb3_rhub.ports = NULL; in xhci_mem_cleanup()
1950 xhci->hw_ports = NULL; in xhci_mem_cleanup()
1951 xhci->rh_bw = NULL; in xhci_mem_cleanup()
1952 xhci->port_caps = NULL; in xhci_mem_cleanup()
1953 xhci->interrupters = NULL; in xhci_mem_cleanup()
1955 xhci->page_size = 0; in xhci_mem_cleanup()
1956 xhci->page_shift = 0; in xhci_mem_cleanup()
1957 xhci->usb2_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1958 xhci->usb3_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1961 static void xhci_set_hc_event_deq(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_set_hc_event_deq() argument
1968 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr.\n"); in xhci_set_hc_event_deq()
1973 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_set_hc_event_deq()
1975 xhci_write_64(xhci, deq & ERST_PTR_MASK, &ir->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
1978 static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, in xhci_add_in_port() argument
1985 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_add_in_port()
1993 rhub = &xhci->usb3_rhub; in xhci_add_in_port()
2004 * Some zhaoxin's xHCI controller that follow usb3.1 spec in xhci_add_in_port()
2007 if (xhci->quirks & XHCI_ZHAOXIN_HOST) { in xhci_add_in_port()
2013 rhub = &xhci->usb2_rhub; in xhci_add_in_port()
2015 xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n", in xhci_add_in_port()
2025 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_add_in_port()
2033 port_cap = &xhci->port_caps[xhci->num_port_caps++]; in xhci_add_in_port()
2034 if (xhci->num_port_caps > max_caps) in xhci_add_in_port()
2057 if (xhci->quirks & XHCI_ZHAOXIN_HOST && in xhci_add_in_port()
2062 xhci_dbg(xhci, "PSIV:%d PSIE:%d PLT:%d PFD:%d LP:%d PSIM:%d\n", in xhci_add_in_port()
2081 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) && in xhci_add_in_port()
2083 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_add_in_port()
2084 "xHCI 1.0: support USB2 hardware lpm"); in xhci_add_in_port()
2085 xhci->hw_lpm_support = 1; in xhci_add_in_port()
2090 struct xhci_port *hw_port = &xhci->hw_ports[i]; in xhci_add_in_port()
2093 xhci_warn(xhci, "Duplicate port entry, Ext Cap %p, port %u\n", addr, i); in xhci_add_in_port()
2094 xhci_warn(xhci, "Port was marked as USB %u, duplicated as USB %u\n", in xhci_add_in_port()
2113 static void xhci_create_rhub_port_array(struct xhci_hcd *xhci, in xhci_create_rhub_port_array() argument
2118 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_create_rhub_port_array()
2127 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { in xhci_create_rhub_port_array()
2128 if (xhci->hw_ports[i].rhub != rhub || in xhci_create_rhub_port_array()
2129 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY) in xhci_create_rhub_port_array()
2131 xhci->hw_ports[i].hcd_portnum = port_index; in xhci_create_rhub_port_array()
2132 rhub->ports[port_index] = &xhci->hw_ports[i]; in xhci_create_rhub_port_array()
2146 static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) in xhci_setup_port_arrays() argument
2154 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_setup_port_arrays()
2156 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_setup_port_arrays()
2157 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports), in xhci_setup_port_arrays()
2159 if (!xhci->hw_ports) in xhci_setup_port_arrays()
2163 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base + in xhci_setup_port_arrays()
2165 xhci->hw_ports[i].hw_portnum = i; in xhci_setup_port_arrays()
2167 init_completion(&xhci->hw_ports[i].rexit_done); in xhci_setup_port_arrays()
2168 init_completion(&xhci->hw_ports[i].u3exit_done); in xhci_setup_port_arrays()
2171 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags, in xhci_setup_port_arrays()
2173 if (!xhci->rh_bw) in xhci_setup_port_arrays()
2178 INIT_LIST_HEAD(&xhci->rh_bw[i].tts); in xhci_setup_port_arrays()
2179 bw_table = &xhci->rh_bw[i].bw_table; in xhci_setup_port_arrays()
2183 base = &xhci->cap_regs->hc_capbase; in xhci_setup_port_arrays()
2187 xhci_err(xhci, "No Extended Capability registers, unable to set up roothub\n"); in xhci_setup_port_arrays()
2199 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps), in xhci_setup_port_arrays()
2201 if (!xhci->port_caps) in xhci_setup_port_arrays()
2207 xhci_add_in_port(xhci, num_ports, base + offset, cap_count); in xhci_setup_port_arrays()
2208 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports == in xhci_setup_port_arrays()
2214 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) { in xhci_setup_port_arrays()
2215 xhci_warn(xhci, "No ports on the roothubs?\n"); in xhci_setup_port_arrays()
2218 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_setup_port_arrays()
2220 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports); in xhci_setup_port_arrays()
2225 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) { in xhci_setup_port_arrays()
2226 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_setup_port_arrays()
2229 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS; in xhci_setup_port_arrays()
2231 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) { in xhci_setup_port_arrays()
2232 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_setup_port_arrays()
2235 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN; in xhci_setup_port_arrays()
2238 if (!xhci->usb2_rhub.num_ports) in xhci_setup_port_arrays()
2239 xhci_info(xhci, "USB2 root hub has no ports\n"); in xhci_setup_port_arrays()
2241 if (!xhci->usb3_rhub.num_ports) in xhci_setup_port_arrays()
2242 xhci_info(xhci, "USB3 root hub has no ports\n"); in xhci_setup_port_arrays()
2244 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags); in xhci_setup_port_arrays()
2245 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags); in xhci_setup_port_arrays()
2251 xhci_alloc_interrupter(struct xhci_hcd *xhci, unsigned int segs, gfp_t flags) in xhci_alloc_interrupter() argument
2253 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_interrupter()
2261 max_segs = BIT(HCS_ERST_MAX(xhci->hcs_params2)); in xhci_alloc_interrupter()
2268 ir->event_ring = xhci_ring_alloc(xhci, segs, TYPE_EVENT, 0, flags); in xhci_alloc_interrupter()
2270 xhci_warn(xhci, "Failed to allocate interrupter event ring\n"); in xhci_alloc_interrupter()
2275 ret = xhci_alloc_erst(xhci, ir->event_ring, &ir->erst, flags); in xhci_alloc_interrupter()
2277 xhci_warn(xhci, "Failed to allocate interrupter erst\n"); in xhci_alloc_interrupter()
2278 xhci_ring_free(xhci, ir->event_ring); in xhci_alloc_interrupter()
2287 xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, in xhci_add_interrupter() argument
2293 if (intr_num >= xhci->max_interrupters) { in xhci_add_interrupter()
2294 xhci_warn(xhci, "Can't add interrupter %d, max interrupters %d\n", in xhci_add_interrupter()
2295 intr_num, xhci->max_interrupters); in xhci_add_interrupter()
2299 if (xhci->interrupters[intr_num]) { in xhci_add_interrupter()
2300 xhci_warn(xhci, "Interrupter %d\n already set up", intr_num); in xhci_add_interrupter()
2304 xhci->interrupters[intr_num] = ir; in xhci_add_interrupter()
2306 ir->ir_set = &xhci->run_regs->ir_set[intr_num]; in xhci_add_interrupter()
2314 erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_add_interrupter()
2317 if (xhci->quirks & XHCI_WRITE_64_HI_LO) in xhci_add_interrupter()
2320 xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2323 xhci_set_hc_event_deq(xhci, ir); in xhci_add_interrupter()
2332 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_create_secondary_interrupter() local
2337 if (!xhci->interrupters || xhci->max_interrupters <= 1) in xhci_create_secondary_interrupter()
2340 ir = xhci_alloc_interrupter(xhci, segs, GFP_KERNEL); in xhci_create_secondary_interrupter()
2344 spin_lock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2347 for (i = 1; i < xhci->max_interrupters; i++) { in xhci_create_secondary_interrupter()
2348 if (xhci->interrupters[i] == NULL) { in xhci_create_secondary_interrupter()
2349 err = xhci_add_interrupter(xhci, ir, i); in xhci_create_secondary_interrupter()
2354 spin_unlock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2357 xhci_warn(xhci, "Failed to add secondary interrupter, max interrupters %d\n", in xhci_create_secondary_interrupter()
2358 xhci->max_interrupters); in xhci_create_secondary_interrupter()
2359 xhci_free_interrupter(xhci, ir); in xhci_create_secondary_interrupter()
2365 xhci_warn(xhci, "Failed to set interrupter %d moderation to %uns\n", in xhci_create_secondary_interrupter()
2368 xhci_dbg(xhci, "Add secondary interrupter %d, max interrupters %d\n", in xhci_create_secondary_interrupter()
2369 i, xhci->max_interrupters); in xhci_create_secondary_interrupter()
2375 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) in xhci_mem_init() argument
2378 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_init()
2385 INIT_LIST_HEAD(&xhci->cmd_list); in xhci_mem_init()
2388 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); in xhci_mem_init()
2389 init_completion(&xhci->cmd_ring_stop_completion); in xhci_mem_init()
2391 page_size = readl(&xhci->op_regs->page_size); in xhci_mem_init()
2392 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2396 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2399 xhci_warn(xhci, "WARN: no supported page size\n"); in xhci_mem_init()
2401 xhci->page_shift = 12; in xhci_mem_init()
2402 xhci->page_size = 1 << xhci->page_shift; in xhci_mem_init()
2403 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2404 "HCD page size set to %iK", xhci->page_size / 1024); in xhci_mem_init()
2410 val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1)); in xhci_mem_init()
2411 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2413 val2 = readl(&xhci->op_regs->config_reg); in xhci_mem_init()
2415 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2417 writel(val, &xhci->op_regs->config_reg); in xhci_mem_init()
2420 * xHCI section 5.4.6 - Device Context array must be in xhci_mem_init()
2423 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, in xhci_mem_init()
2425 if (!xhci->dcbaa) in xhci_mem_init()
2427 xhci->dcbaa->dma = dma; in xhci_mem_init()
2428 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2430 &xhci->dcbaa->dma, xhci->dcbaa); in xhci_mem_init()
2431 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); in xhci_mem_init()
2440 if (xhci->quirks & XHCI_TRB_OVERFETCH) in xhci_mem_init()
2442 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2443 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2); in xhci_mem_init()
2445 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2446 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); in xhci_mem_init()
2449 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, in xhci_mem_init()
2450 2112, 64, xhci->page_size); in xhci_mem_init()
2451 if (!xhci->segment_pool || !xhci->device_pool) in xhci_mem_init()
2457 xhci->small_streams_pool = in xhci_mem_init()
2458 dma_pool_create("xHCI 256 byte stream ctx arrays", in xhci_mem_init()
2460 xhci->medium_streams_pool = in xhci_mem_init()
2461 dma_pool_create("xHCI 1KB stream ctx arrays", in xhci_mem_init()
2467 if (!xhci->small_streams_pool || !xhci->medium_streams_pool) in xhci_mem_init()
2471 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, TYPE_COMMAND, 0, flags); in xhci_mem_init()
2472 if (!xhci->cmd_ring) in xhci_mem_init()
2474 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2475 "Allocated command ring at %p", xhci->cmd_ring); in xhci_mem_init()
2476 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad", in xhci_mem_init()
2477 &xhci->cmd_ring->first_seg->dma); in xhci_mem_init()
2480 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2482 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | in xhci_mem_init()
2483 xhci->cmd_ring->cycle_state; in xhci_mem_init()
2484 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2486 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2492 xhci->cmd_ring_reserved_trbs++; in xhci_mem_init()
2494 val = readl(&xhci->cap_regs->db_off); in xhci_mem_init()
2496 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2499 xhci->dba = (void __iomem *) xhci->cap_regs + val; in xhci_mem_init()
2502 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2504 xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), in xhci_mem_init()
2507 ir = xhci_alloc_interrupter(xhci, 0, flags); in xhci_mem_init()
2511 if (xhci_add_interrupter(xhci, ir, 0)) in xhci_mem_init()
2517 xhci->devs[i] = NULL; in xhci_mem_init()
2519 if (scratchpad_alloc(xhci, flags)) in xhci_mem_init()
2521 if (xhci_setup_port_arrays(xhci, flags)) in xhci_mem_init()
2528 temp = readl(&xhci->op_regs->dev_notification); in xhci_mem_init()
2531 writel(temp, &xhci->op_regs->dev_notification); in xhci_mem_init()
2536 xhci_halt(xhci); in xhci_mem_init()
2537 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_mem_init()
2538 xhci_mem_cleanup(xhci); in xhci_mem_init()