Lines Matching refs:xhci
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,
37 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
43 seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma);
53 dma_pool_free(xhci->segment_pool, seg->trbs, dma);
69 static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg)
72 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma);
79 static void xhci_free_segments_for_ring(struct xhci_hcd *xhci,
87 xhci_segment_free(xhci, seg);
90 xhci_segment_free(xhci, first);
127 static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
138 chain_links = !!(xhci_link_trb_quirk(xhci) ||
140 (xhci->quirks & XHCI_AMD_0x96_HOST)));
280 void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
290 xhci_free_segments_for_ring(xhci, ring->first_seg);
321 static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
330 chain_links = !!(xhci_link_trb_quirk(xhci) ||
332 (xhci->quirks & XHCI_AMD_0x96_HOST)));
334 prev = xhci_segment_alloc(xhci, cycle_state, max_packet, flags);
343 next = xhci_segment_alloc(xhci, cycle_state, max_packet, flags);
348 xhci_segment_free(xhci, prev);
371 struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
377 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
390 ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg,
411 void xhci_free_endpoint_ring(struct xhci_hcd *xhci,
415 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring);
423 int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
430 ret = xhci_alloc_segments_for_ring(xhci, &first, &last,
443 xhci_segment_free(xhci, first);
451 xhci_link_rings(xhci, ring, first, last, num_new_segs);
453 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion,
460 struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
464 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
474 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024;
476 ctx->size += CTX_SIZE(xhci->hcc_params);
478 ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma);
486 void xhci_free_container_ctx(struct xhci_hcd *xhci,
491 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma);
504 struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci,
511 (ctx->bytes + CTX_SIZE(xhci->hcc_params));
514 struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
524 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params)));
530 static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
534 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
540 dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma);
542 dma_pool_free(xhci->small_streams_pool, stream_ctx, dma);
555 static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
559 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
565 return dma_pool_zalloc(xhci->medium_streams_pool, mem_flags, dma);
567 return dma_pool_zalloc(xhci->small_streams_pool, mem_flags, dma);
589 struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
599 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
601 xhci_dbg(xhci, "Allocating %u streams and %u stream context array entries.\n",
603 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) {
604 xhci_dbg(xhci, "Command ring has no reserved TRBs available\n");
607 xhci->cmd_ring_reserved_trbs++;
625 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci,
633 xhci_alloc_command_with_ctx(xhci, true, mem_flags);
646 xhci_ring_alloc(xhci, 2, 1, TYPE_STREAM, max_packet,
659 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", cur_stream, addr);
663 xhci_ring_free(xhci, cur_ring);
681 xhci_ring_free(xhci, cur_ring);
685 xhci_free_command(xhci, stream_info->free_streams_command);
687 xhci_free_stream_ctx(xhci,
696 xhci->cmd_ring_reserved_trbs--;
703 void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
713 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
740 void xhci_free_stream_info(struct xhci_hcd *xhci,
753 xhci_ring_free(xhci, cur_ring);
757 xhci_free_command(xhci, stream_info->free_streams_command);
758 xhci->cmd_ring_reserved_trbs--;
760 xhci_free_stream_ctx(xhci,
772 static void xhci_free_tt_info(struct xhci_hcd *xhci,
784 virt_dev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) {
785 xhci_dbg(xhci, "Bad real port.\n");
789 tt_list_head = &(xhci->rh_bw[virt_dev->real_port - 1].tts);
802 int xhci_alloc_tt_info(struct xhci_hcd *xhci,
810 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
826 &xhci->rh_bw[virt_dev->real_port - 1].tts);
837 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id);
843 * Should be called with xhci->lock held if there is any chance the TT lists
847 void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
854 if (slot_id == 0 || !xhci->devs[slot_id])
857 dev = xhci->devs[slot_id];
859 xhci->dcbaa->dev_context_ptrs[slot_id] = 0;
870 xhci_ring_free(xhci, dev->eps[i].ring);
872 xhci_free_stream_info(xhci,
884 xhci_dbg(xhci, "Slot %u endpoint %u not removed from BW list!\n",
889 xhci_free_tt_info(xhci, dev, slot_id);
891 xhci_update_tt_active_eps(xhci, dev, old_active_eps);
894 xhci_free_container_ctx(xhci, dev->in_ctx);
896 xhci_free_container_ctx(xhci, dev->out_ctx);
900 kfree(xhci->devs[slot_id]);
901 xhci->devs[slot_id] = NULL;
910 static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
917 vdev = xhci->devs[slot_id];
922 vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) {
923 xhci_dbg(xhci, "Bad vdev->real_port.\n");
927 tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
932 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
933 vdev = xhci->devs[i];
936 xhci, i);
942 xhci_debugfs_remove_slot(xhci, slot_id);
943 xhci_free_virt_device(xhci, slot_id);
946 int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
953 if (slot_id == 0 || xhci->devs[slot_id]) {
954 xhci_warn(xhci, "Bad Slot ID %d\n", slot_id);
965 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags);
969 xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma);
972 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags);
976 xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma);
982 dev->eps[i].xhci = xhci;
988 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, 1, TYPE_CTRL, 0, flags);
995 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma);
996 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n",
998 &xhci->dcbaa->dev_context_ptrs[slot_id],
999 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id]));
1003 xhci->devs[slot_id] = dev;
1009 xhci_free_container_ctx(xhci, dev->in_ctx);
1011 xhci_free_container_ctx(xhci, dev->out_ctx);
1017 void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
1024 virt_dev = xhci->devs[udev->slot_id];
1025 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0);
1049 static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
1056 hcd = xhci_get_usb3_hcd(xhci);
1058 hcd = xhci->main_hcd;
1068 int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev)
1077 dev = xhci->devs[udev->slot_id];
1080 xhci_warn(xhci, "Slot ID %d is not assigned to this device\n",
1084 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0);
1085 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx);
1116 port_num = xhci_find_real_port_number(xhci, udev);
1126 xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num);
1127 xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->fake_port);
1136 dev->bw_table = &xhci->rh_bw[port_num - 1].bw_table;
1141 rh_bw = &xhci->rh_bw[port_num - 1];
1156 xhci_warn(xhci, "WARN: Didn't find a matching TT\n");
1166 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt);
1167 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport);
1394 int xhci_endpoint_init(struct xhci_hcd *xhci,
1414 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
1434 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) &&
1461 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100)
1463 /* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */
1464 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2))
1469 xhci_ring_alloc(xhci, 2, 1, ring_type, max_packet, mem_flags);
1493 void xhci_endpoint_zero(struct xhci_hcd *xhci,
1501 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
1522 void xhci_update_bw_info(struct xhci_hcd *xhci,
1547 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, i);
1580 void xhci_endpoint_copy(struct xhci_hcd *xhci,
1588 out_ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
1589 in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
1595 if (xhci->quirks & XHCI_MTK_HOST) {
1606 void xhci_slot_copy(struct xhci_hcd *xhci,
1613 in_slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1614 out_slot_ctx = xhci_get_slot_ctx(xhci, out_ctx);
1623 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
1626 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1627 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
1629 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1635 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags,
1637 if (!xhci->scratchpad)
1640 xhci->scratchpad->sp_array = dma_alloc_coherent(dev,
1642 &xhci->scratchpad->sp_dma, flags);
1643 if (!xhci->scratchpad->sp_array)
1646 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *),
1648 if (!xhci->scratchpad->sp_buffers)
1651 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma);
1654 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma,
1659 xhci->scratchpad->sp_array[i] = dma;
1660 xhci->scratchpad->sp_buffers[i] = buf;
1667 dma_free_coherent(dev, xhci->page_size,
1668 xhci->scratchpad->sp_buffers[i],
1669 xhci->scratchpad->sp_array[i]);
1671 kfree(xhci->scratchpad->sp_buffers);
1675 xhci->scratchpad->sp_array,
1676 xhci->scratchpad->sp_dma);
1679 kfree(xhci->scratchpad);
1680 xhci->scratchpad = NULL;
1686 static void scratchpad_free(struct xhci_hcd *xhci)
1690 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1692 if (!xhci->scratchpad)
1695 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
1698 dma_free_coherent(dev, xhci->page_size,
1699 xhci->scratchpad->sp_buffers[i],
1700 xhci->scratchpad->sp_array[i]);
1702 kfree(xhci->scratchpad->sp_buffers);
1704 xhci->scratchpad->sp_array,
1705 xhci->scratchpad->sp_dma);
1706 kfree(xhci->scratchpad);
1707 xhci->scratchpad = NULL;
1710 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1714 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1736 struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci,
1741 command = xhci_alloc_command(xhci, allocate_completion, mem_flags);
1745 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT,
1760 void xhci_free_command(struct xhci_hcd *xhci,
1763 xhci_free_container_ctx(xhci,
1769 int xhci_alloc_erst(struct xhci_hcd *xhci,
1780 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
1800 xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
1802 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1827 tmp64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue);
1829 xhci_write_64(xhci, tmp64, &ir->ir_set->erst_dequeue);
1834 xhci_ring_free(xhci, ir->event_ring);
1840 void xhci_mem_cleanup(struct xhci_hcd *xhci)
1842 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1845 cancel_delayed_work_sync(&xhci->cmd_timer);
1847 xhci_free_interrupter(xhci, xhci->interrupter);
1848 xhci->interrupter = NULL;
1849 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed primary event ring");
1851 if (xhci->cmd_ring)
1852 xhci_ring_free(xhci, xhci->cmd_ring);
1853 xhci->cmd_ring = NULL;
1854 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring");
1855 xhci_cleanup_command_queue(xhci);
1857 num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1858 for (i = 0; i < num_ports && xhci->rh_bw; i++) {
1859 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table;
1867 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--)
1868 xhci_free_virt_devices_depth_first(xhci, i);
1870 dma_pool_destroy(xhci->segment_pool);
1871 xhci->segment_pool = NULL;
1872 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed segment pool");
1874 dma_pool_destroy(xhci->device_pool);
1875 xhci->device_pool = NULL;
1876 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed device context pool");
1878 dma_pool_destroy(xhci->small_streams_pool);
1879 xhci->small_streams_pool = NULL;
1880 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1883 dma_pool_destroy(xhci->medium_streams_pool);
1884 xhci->medium_streams_pool = NULL;
1885 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1888 if (xhci->dcbaa)
1889 dma_free_coherent(dev, sizeof(*xhci->dcbaa),
1890 xhci->dcbaa, xhci->dcbaa->dma);
1891 xhci->dcbaa = NULL;
1893 scratchpad_free(xhci);
1895 if (!xhci->rh_bw)
1900 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) {
1907 xhci->cmd_ring_reserved_trbs = 0;
1908 xhci->usb2_rhub.num_ports = 0;
1909 xhci->usb3_rhub.num_ports = 0;
1910 xhci->num_active_eps = 0;
1911 kfree(xhci->usb2_rhub.ports);
1912 kfree(xhci->usb3_rhub.ports);
1913 kfree(xhci->hw_ports);
1914 kfree(xhci->rh_bw);
1915 kfree(xhci->ext_caps);
1916 for (i = 0; i < xhci->num_port_caps; i++)
1917 kfree(xhci->port_caps[i].psi);
1918 kfree(xhci->port_caps);
1919 xhci->num_port_caps = 0;
1921 xhci->usb2_rhub.ports = NULL;
1922 xhci->usb3_rhub.ports = NULL;
1923 xhci->hw_ports = NULL;
1924 xhci->rh_bw = NULL;
1925 xhci->ext_caps = NULL;
1926 xhci->port_caps = NULL;
1928 xhci->page_size = 0;
1929 xhci->page_shift = 0;
1930 xhci->usb2_rhub.bus_state.bus_suspended = 0;
1931 xhci->usb3_rhub.bus_state.bus_suspended = 0;
1934 static void xhci_set_hc_event_deq(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
1942 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr.\n");
1944 temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue);
1950 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1952 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
1956 static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
1963 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1971 rhub = &xhci->usb3_rhub;
1985 if (xhci->quirks & XHCI_ZHAOXIN_HOST) {
1991 rhub = &xhci->usb2_rhub;
1993 xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n",
2003 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2011 port_cap = &xhci->port_caps[xhci->num_port_caps++];
2012 if (xhci->num_port_caps > max_caps)
2035 if (xhci->quirks & XHCI_ZHAOXIN_HOST &&
2040 xhci_dbg(xhci, "PSIV:%d PSIE:%d PLT:%d PFD:%d LP:%d PSIM:%d\n",
2059 if (major_revision < 0x03 && xhci->num_ext_caps < max_caps)
2060 xhci->ext_caps[xhci->num_ext_caps++] = temp;
2062 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) &&
2064 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2066 xhci->hw_lpm_support = 1;
2071 struct xhci_port *hw_port = &xhci->hw_ports[i];
2074 xhci_warn(xhci, "Duplicate port entry, Ext Cap %p, port %u\n", addr, i);
2075 xhci_warn(xhci, "Port was marked as USB %u, duplicated as USB %u\n",
2094 static void xhci_create_rhub_port_array(struct xhci_hcd *xhci,
2099 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2108 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
2109 if (xhci->hw_ports[i].rhub != rhub ||
2110 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY)
2112 xhci->hw_ports[i].hcd_portnum = port_index;
2113 rhub->ports[port_index] = &xhci->hw_ports[i];
2127 static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
2135 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2137 num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
2138 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports),
2140 if (!xhci->hw_ports)
2144 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base +
2146 xhci->hw_ports[i].hw_portnum = i;
2148 init_completion(&xhci->hw_ports[i].rexit_done);
2149 init_completion(&xhci->hw_ports[i].u3exit_done);
2152 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags,
2154 if (!xhci->rh_bw)
2159 INIT_LIST_HEAD(&xhci->rh_bw[i].tts);
2160 bw_table = &xhci->rh_bw[i].bw_table;
2164 base = &xhci->cap_regs->hc_capbase;
2168 xhci_err(xhci, "No Extended Capability registers, unable to set up roothub\n");
2180 xhci->ext_caps = kcalloc_node(cap_count, sizeof(*xhci->ext_caps),
2182 if (!xhci->ext_caps)
2185 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps),
2187 if (!xhci->port_caps)
2193 xhci_add_in_port(xhci, num_ports, base + offset, cap_count);
2194 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports ==
2200 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) {
2201 xhci_warn(xhci, "No ports on the roothubs?\n");
2204 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2206 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports);
2211 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) {
2212 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2215 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS;
2217 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) {
2218 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2221 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN;
2224 if (!xhci->usb2_rhub.num_ports)
2225 xhci_info(xhci, "USB2 root hub has no ports\n");
2227 if (!xhci->usb3_rhub.num_ports)
2228 xhci_info(xhci, "USB3 root hub has no ports\n");
2230 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags);
2231 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags);
2237 xhci_alloc_interrupter(struct xhci_hcd *xhci, gfp_t flags)
2239 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2247 ir->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, 1, TYPE_EVENT,
2250 xhci_warn(xhci, "Failed to allocate interrupter event ring\n");
2255 ret = xhci_alloc_erst(xhci, ir->event_ring, &ir->erst, flags);
2257 xhci_warn(xhci, "Failed to allocate interrupter erst\n");
2258 xhci_ring_free(xhci, ir->event_ring);
2267 xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir,
2273 if (intr_num > xhci->max_interrupters) {
2274 xhci_warn(xhci, "Can't add interrupter %d, max interrupters %d\n",
2275 intr_num, xhci->max_interrupters);
2279 ir->ir_set = &xhci->run_regs->ir_set[intr_num];
2287 erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base);
2290 xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base);
2293 xhci_set_hc_event_deq(xhci, ir);
2298 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2301 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2307 INIT_LIST_HEAD(&xhci->cmd_list);
2310 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout);
2311 init_completion(&xhci->cmd_ring_stop_completion);
2313 page_size = readl(&xhci->op_regs->page_size);
2314 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2318 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2321 xhci_warn(xhci, "WARN: no supported page size\n");
2323 xhci->page_shift = 12;
2324 xhci->page_size = 1 << xhci->page_shift;
2325 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2326 "HCD page size set to %iK", xhci->page_size / 1024);
2332 val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1));
2333 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2335 val2 = readl(&xhci->op_regs->config_reg);
2337 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2339 writel(val, &xhci->op_regs->config_reg);
2345 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma,
2347 if (!xhci->dcbaa)
2349 xhci->dcbaa->dma = dma;
2350 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2352 &xhci->dcbaa->dma, xhci->dcbaa);
2353 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr);
2362 if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH)
2363 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
2364 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2);
2366 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
2367 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size);
2370 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev,
2371 2112, 64, xhci->page_size);
2372 if (!xhci->segment_pool || !xhci->device_pool)
2378 xhci->small_streams_pool =
2381 xhci->medium_streams_pool =
2388 if (!xhci->small_streams_pool || !xhci->medium_streams_pool)
2392 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, 0, flags);
2393 if (!xhci->cmd_ring)
2395 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2396 "Allocated command ring at %p", xhci->cmd_ring);
2397 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad",
2398 &xhci->cmd_ring->first_seg->dma);
2401 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
2403 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) |
2404 xhci->cmd_ring->cycle_state;
2405 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2407 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2413 xhci->cmd_ring_reserved_trbs++;
2415 val = readl(&xhci->cap_regs->db_off);
2417 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2420 xhci->dba = (void __iomem *) xhci->cap_regs + val;
2423 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2425 xhci->interrupter = xhci_alloc_interrupter(xhci, flags);
2426 if (!xhci->interrupter)
2429 if (xhci_add_interrupter(xhci, xhci->interrupter, 0))
2432 xhci->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX;
2440 xhci->devs[i] = NULL;
2442 if (scratchpad_alloc(xhci, flags))
2444 if (xhci_setup_port_arrays(xhci, flags))
2451 temp = readl(&xhci->op_regs->dev_notification);
2454 writel(temp, &xhci->op_regs->dev_notification);
2459 xhci_halt(xhci);
2460 xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
2461 xhci_mem_cleanup(xhci);