Lines Matching refs:xhci
17 #include "xhci.h"
18 #include "xhci-trace.h"
19 #include "xhci-debugfs.h"
28 static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
36 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
42 seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma);
52 dma_pool_free(xhci->segment_pool, seg->trbs, dma);
68 static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg)
71 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma);
78 static void xhci_free_segments_for_ring(struct xhci_hcd *xhci,
86 xhci_segment_free(xhci, seg);
89 xhci_segment_free(xhci, first);
126 static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
137 chain_links = !!(xhci_link_trb_quirk(xhci) ||
139 (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,
439 ret = xhci_alloc_segments_for_ring(xhci, &first, &last,
452 xhci_segment_free(xhci, first);
460 xhci_link_rings(xhci, ring, first, last, num_segs);
462 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion,
469 struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
473 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
483 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024;
485 ctx->size += CTX_SIZE(xhci->hcc_params);
487 ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma);
495 void xhci_free_container_ctx(struct xhci_hcd *xhci,
500 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma);
513 struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci,
520 (ctx->bytes + CTX_SIZE(xhci->hcc_params));
523 struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
533 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params)));
539 static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
543 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
550 return dma_pool_free(xhci->small_streams_pool,
553 return dma_pool_free(xhci->medium_streams_pool,
567 static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
571 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
578 return dma_pool_alloc(xhci->small_streams_pool,
581 return dma_pool_alloc(xhci->medium_streams_pool,
621 struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
631 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
633 xhci_dbg(xhci, "Allocating %u streams and %u "
636 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) {
637 xhci_dbg(xhci, "Command ring has no reserved TRBs available\n");
640 xhci->cmd_ring_reserved_trbs++;
658 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci,
668 xhci_alloc_command_with_ctx(xhci, true, mem_flags);
681 xhci_ring_alloc(xhci, 2, 1, TYPE_STREAM, max_packet,
694 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n",
699 xhci_ring_free(xhci, cur_ring);
717 xhci_ring_free(xhci, cur_ring);
721 xhci_free_command(xhci, stream_info->free_streams_command);
723 xhci_free_stream_ctx(xhci,
732 xhci->cmd_ring_reserved_trbs--;
739 void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
749 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
776 void xhci_free_stream_info(struct xhci_hcd *xhci,
789 xhci_ring_free(xhci, cur_ring);
793 xhci_free_command(xhci, stream_info->free_streams_command);
794 xhci->cmd_ring_reserved_trbs--;
796 xhci_free_stream_ctx(xhci,
808 static void xhci_init_endpoint_timer(struct xhci_hcd *xhci,
813 ep->xhci = xhci;
816 static void xhci_free_tt_info(struct xhci_hcd *xhci,
828 virt_dev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) {
829 xhci_dbg(xhci, "Bad real port.\n");
833 tt_list_head = &(xhci->rh_bw[virt_dev->real_port - 1].tts);
846 int xhci_alloc_tt_info(struct xhci_hcd *xhci,
854 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
870 &xhci->rh_bw[virt_dev->real_port - 1].tts);
881 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id);
887 * Should be called with xhci->lock held if there is any chance the TT lists
891 void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
898 if (slot_id == 0 || !xhci->devs[slot_id])
901 dev = xhci->devs[slot_id];
903 xhci->dcbaa->dev_context_ptrs[slot_id] = 0;
914 xhci_ring_free(xhci, dev->eps[i].ring);
916 xhci_free_stream_info(xhci,
928 xhci_dbg(xhci, "Slot %u endpoint %u not removed from BW list!\n",
933 xhci_free_tt_info(xhci, dev, slot_id);
935 xhci_update_tt_active_eps(xhci, dev, old_active_eps);
938 xhci_free_container_ctx(xhci, dev->in_ctx);
940 xhci_free_container_ctx(xhci, dev->out_ctx);
944 kfree(xhci->devs[slot_id]);
945 xhci->devs[slot_id] = NULL;
954 static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
961 vdev = xhci->devs[slot_id];
966 vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) {
967 xhci_dbg(xhci, "Bad vdev->real_port.\n");
971 tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
976 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
977 vdev = xhci->devs[i];
980 xhci, i);
986 xhci_debugfs_remove_slot(xhci, slot_id);
987 xhci_free_virt_device(xhci, slot_id);
990 int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
997 if (slot_id == 0 || xhci->devs[slot_id]) {
998 xhci_warn(xhci, "Bad Slot ID %d\n", slot_id);
1009 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags);
1013 xhci_dbg(xhci, "Slot %d output ctx = 0x%llx (dma)\n", slot_id,
1017 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags);
1021 xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id,
1028 xhci_init_endpoint_timer(xhci, &dev->eps[i]);
1034 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, 1, TYPE_CTRL, 0, flags);
1041 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma);
1042 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n",
1044 &xhci->dcbaa->dev_context_ptrs[slot_id],
1045 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id]));
1049 xhci->devs[slot_id] = dev;
1055 xhci_free_container_ctx(xhci, dev->in_ctx);
1057 xhci_free_container_ctx(xhci, dev->out_ctx);
1063 void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
1070 virt_dev = xhci->devs[udev->slot_id];
1071 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0);
1095 static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
1102 hcd = xhci->shared_hcd;
1104 hcd = xhci->main_hcd;
1114 int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev)
1123 dev = xhci->devs[udev->slot_id];
1126 xhci_warn(xhci, "Slot ID %d is not assigned to this device\n",
1130 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0);
1131 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx);
1158 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
1166 port_num = xhci_find_real_port_number(xhci, udev);
1176 xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num);
1177 xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->fake_port);
1186 dev->bw_table = &xhci->rh_bw[port_num - 1].bw_table;
1191 rh_bw = &xhci->rh_bw[port_num - 1];
1206 xhci_warn(xhci, "WARN: Didn't find a matching TT\n");
1216 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt);
1217 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport);
1443 int xhci_endpoint_init(struct xhci_hcd *xhci,
1463 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
1483 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) &&
1510 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100)
1512 /* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */
1513 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2))
1518 xhci_ring_alloc(xhci, 2, 1, ring_type, max_packet, mem_flags);
1542 void xhci_endpoint_zero(struct xhci_hcd *xhci,
1550 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
1571 void xhci_update_bw_info(struct xhci_hcd *xhci,
1596 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, i);
1629 void xhci_endpoint_copy(struct xhci_hcd *xhci,
1637 out_ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
1638 in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
1644 if (xhci->quirks & XHCI_MTK_HOST) {
1655 void xhci_slot_copy(struct xhci_hcd *xhci,
1662 in_slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1663 out_slot_ctx = xhci_get_slot_ctx(xhci, out_ctx);
1672 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
1675 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1676 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
1678 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1684 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags,
1686 if (!xhci->scratchpad)
1689 xhci->scratchpad->sp_array = dma_alloc_coherent(dev,
1691 &xhci->scratchpad->sp_dma, flags);
1692 if (!xhci->scratchpad->sp_array)
1695 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *),
1697 if (!xhci->scratchpad->sp_buffers)
1700 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma);
1703 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma,
1708 xhci->scratchpad->sp_array[i] = dma;
1709 xhci->scratchpad->sp_buffers[i] = buf;
1716 dma_free_coherent(dev, xhci->page_size,
1717 xhci->scratchpad->sp_buffers[i],
1718 xhci->scratchpad->sp_array[i]);
1721 kfree(xhci->scratchpad->sp_buffers);
1725 xhci->scratchpad->sp_array,
1726 xhci->scratchpad->sp_dma);
1729 kfree(xhci->scratchpad);
1730 xhci->scratchpad = NULL;
1736 static void scratchpad_free(struct xhci_hcd *xhci)
1740 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1742 if (!xhci->scratchpad)
1745 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
1748 dma_free_coherent(dev, xhci->page_size,
1749 xhci->scratchpad->sp_buffers[i],
1750 xhci->scratchpad->sp_array[i]);
1752 kfree(xhci->scratchpad->sp_buffers);
1754 xhci->scratchpad->sp_array,
1755 xhci->scratchpad->sp_dma);
1756 kfree(xhci->scratchpad);
1757 xhci->scratchpad = NULL;
1760 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1764 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1786 struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci,
1791 command = xhci_alloc_command(xhci, allocate_completion, mem_flags);
1795 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT,
1810 void xhci_free_command(struct xhci_hcd *xhci,
1813 xhci_free_container_ctx(xhci,
1819 int xhci_alloc_erst(struct xhci_hcd *xhci,
1830 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
1849 void xhci_free_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
1852 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1862 void xhci_mem_cleanup(struct xhci_hcd *xhci)
1864 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
1867 cancel_delayed_work_sync(&xhci->cmd_timer);
1869 xhci_free_erst(xhci, &xhci->erst);
1871 if (xhci->event_ring)
1872 xhci_ring_free(xhci, xhci->event_ring);
1873 xhci->event_ring = NULL;
1874 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed event ring");
1876 if (xhci->lpm_command)
1877 xhci_free_command(xhci, xhci->lpm_command);
1878 xhci->lpm_command = NULL;
1879 if (xhci->cmd_ring)
1880 xhci_ring_free(xhci, xhci->cmd_ring);
1881 xhci->cmd_ring = NULL;
1882 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring");
1883 xhci_cleanup_command_queue(xhci);
1885 num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1886 for (i = 0; i < num_ports && xhci->rh_bw; i++) {
1887 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table;
1895 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--)
1896 xhci_free_virt_devices_depth_first(xhci, i);
1898 dma_pool_destroy(xhci->segment_pool);
1899 xhci->segment_pool = NULL;
1900 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed segment pool");
1902 dma_pool_destroy(xhci->device_pool);
1903 xhci->device_pool = NULL;
1904 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed device context pool");
1906 dma_pool_destroy(xhci->small_streams_pool);
1907 xhci->small_streams_pool = NULL;
1908 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1911 dma_pool_destroy(xhci->medium_streams_pool);
1912 xhci->medium_streams_pool = NULL;
1913 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
1916 if (xhci->dcbaa)
1917 dma_free_coherent(dev, sizeof(*xhci->dcbaa),
1918 xhci->dcbaa, xhci->dcbaa->dma);
1919 xhci->dcbaa = NULL;
1921 scratchpad_free(xhci);
1923 if (!xhci->rh_bw)
1928 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) {
1935 xhci->cmd_ring_reserved_trbs = 0;
1936 xhci->usb2_rhub.num_ports = 0;
1937 xhci->usb3_rhub.num_ports = 0;
1938 xhci->num_active_eps = 0;
1939 kfree(xhci->usb2_rhub.ports);
1940 kfree(xhci->usb3_rhub.ports);
1941 kfree(xhci->hw_ports);
1942 kfree(xhci->rh_bw);
1943 kfree(xhci->ext_caps);
1944 for (i = 0; i < xhci->num_port_caps; i++)
1945 kfree(xhci->port_caps[i].psi);
1946 kfree(xhci->port_caps);
1947 xhci->num_port_caps = 0;
1949 xhci->usb2_rhub.ports = NULL;
1950 xhci->usb3_rhub.ports = NULL;
1951 xhci->hw_ports = NULL;
1952 xhci->rh_bw = NULL;
1953 xhci->ext_caps = NULL;
1954 xhci->port_caps = NULL;
1956 xhci->page_size = 0;
1957 xhci->page_shift = 0;
1958 xhci->usb2_rhub.bus_state.bus_suspended = 0;
1959 xhci->usb3_rhub.bus_state.bus_suspended = 0;
1962 static int xhci_test_trb_in_td(struct xhci_hcd *xhci,
1977 seg = trb_in_td(xhci, input_seg, start_trb, end_trb, input_dma, false);
1979 xhci_warn(xhci, "WARN: %s TRB math test %d failed!\n",
1981 xhci_warn(xhci, "Tested TRB math w/ seg %p and "
1985 xhci_warn(xhci, "starting TRB %p (0x%llx DMA), "
1989 xhci_warn(xhci, "Expected seg %p, got seg %p\n",
1991 trb_in_td(xhci, input_seg, start_trb, end_trb, input_dma,
1999 static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci)
2008 { xhci->event_ring->first_seg->dma - 16, NULL },
2010 { xhci->event_ring->first_seg->dma - 1, NULL },
2012 { xhci->event_ring->first_seg->dma, xhci->event_ring->first_seg },
2014 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 1)*16,
2015 xhci->event_ring->first_seg },
2017 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 1)*16 + 1, NULL },
2019 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT)*16, NULL },
2031 { .input_seg = xhci->event_ring->first_seg,
2032 .start_trb = xhci->event_ring->first_seg->trbs,
2033 .end_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
2034 .input_dma = xhci->cmd_ring->first_seg->dma,
2038 { .input_seg = xhci->event_ring->first_seg,
2039 .start_trb = xhci->event_ring->first_seg->trbs,
2040 .end_trb = &xhci->cmd_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
2041 .input_dma = xhci->cmd_ring->first_seg->dma,
2045 { .input_seg = xhci->event_ring->first_seg,
2046 .start_trb = xhci->cmd_ring->first_seg->trbs,
2047 .end_trb = &xhci->cmd_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
2048 .input_dma = xhci->cmd_ring->first_seg->dma,
2052 { .input_seg = xhci->event_ring->first_seg,
2053 .start_trb = &xhci->event_ring->first_seg->trbs[0],
2054 .end_trb = &xhci->event_ring->first_seg->trbs[3],
2055 .input_dma = xhci->event_ring->first_seg->dma + 4*16,
2059 { .input_seg = xhci->event_ring->first_seg,
2060 .start_trb = &xhci->event_ring->first_seg->trbs[3],
2061 .end_trb = &xhci->event_ring->first_seg->trbs[6],
2062 .input_dma = xhci->event_ring->first_seg->dma + 2*16,
2066 { .input_seg = xhci->event_ring->first_seg,
2067 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3],
2068 .end_trb = &xhci->event_ring->first_seg->trbs[1],
2069 .input_dma = xhci->event_ring->first_seg->dma + 2*16,
2073 { .input_seg = xhci->event_ring->first_seg,
2074 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3],
2075 .end_trb = &xhci->event_ring->first_seg->trbs[1],
2076 .input_dma = xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 4)*16,
2080 { .input_seg = xhci->event_ring->first_seg,
2081 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3],
2082 .end_trb = &xhci->event_ring->first_seg->trbs[1],
2083 .input_dma = xhci->cmd_ring->first_seg->dma + 2*16,
2093 ret = xhci_test_trb_in_td(xhci,
2094 xhci->event_ring->first_seg,
2095 xhci->event_ring->first_seg->trbs,
2096 &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
2106 ret = xhci_test_trb_in_td(xhci,
2116 xhci_dbg(xhci, "TRB math tests passed.\n");
2120 static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
2125 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
2126 xhci->event_ring->dequeue);
2128 xhci_warn(xhci, "WARN something wrong with SW event ring "
2131 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2137 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2140 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
2141 &xhci->ir_set->erst_dequeue);
2144 static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
2151 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2159 rhub = &xhci->usb3_rhub;
2173 if (xhci->quirks & XHCI_ZHAOXIN_HOST) {
2179 rhub = &xhci->usb2_rhub;
2181 xhci_warn(xhci, "Ignoring unknown port speed, "
2192 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2201 port_cap = &xhci->port_caps[xhci->num_port_caps++];
2202 if (xhci->num_port_caps > max_caps)
2225 if (xhci->quirks & XHCI_ZHAOXIN_HOST &&
2230 xhci_dbg(xhci, "PSIV:%d PSIE:%d PLT:%d PFD:%d LP:%d PSIM:%d\n",
2249 if (major_revision < 0x03 && xhci->num_ext_caps < max_caps)
2250 xhci->ext_caps[xhci->num_ext_caps++] = temp;
2252 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) &&
2254 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2256 xhci->hw_lpm_support = 1;
2261 struct xhci_port *hw_port = &xhci->hw_ports[i];
2264 xhci_warn(xhci, "Duplicate port entry, Ext Cap %p,"
2266 xhci_warn(xhci, "Port was marked as USB %u, "
2286 static void xhci_create_rhub_port_array(struct xhci_hcd *xhci,
2291 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2300 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
2301 if (xhci->hw_ports[i].rhub != rhub ||
2302 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY)
2304 xhci->hw_ports[i].hcd_portnum = port_index;
2305 rhub->ports[port_index] = &xhci->hw_ports[i];
2319 static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
2327 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2329 num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
2330 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports),
2332 if (!xhci->hw_ports)
2336 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base +
2338 xhci->hw_ports[i].hw_portnum = i;
2340 init_completion(&xhci->hw_ports[i].rexit_done);
2341 init_completion(&xhci->hw_ports[i].u3exit_done);
2344 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags,
2346 if (!xhci->rh_bw)
2351 INIT_LIST_HEAD(&xhci->rh_bw[i].tts);
2352 bw_table = &xhci->rh_bw[i].bw_table;
2356 base = &xhci->cap_regs->hc_capbase;
2360 xhci_err(xhci, "No Extended Capability registers, unable to set up roothub\n");
2372 xhci->ext_caps = kcalloc_node(cap_count, sizeof(*xhci->ext_caps),
2374 if (!xhci->ext_caps)
2377 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps),
2379 if (!xhci->port_caps)
2385 xhci_add_in_port(xhci, num_ports, base + offset, cap_count);
2386 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports ==
2392 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) {
2393 xhci_warn(xhci, "No ports on the roothubs?\n");
2396 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2398 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports);
2403 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) {
2404 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2407 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS;
2409 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) {
2410 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2413 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN;
2421 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags);
2422 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags);
2427 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2430 struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
2436 INIT_LIST_HEAD(&xhci->cmd_list);
2439 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout);
2440 init_completion(&xhci->cmd_ring_stop_completion);
2442 page_size = readl(&xhci->op_regs->page_size);
2443 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2451 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2454 xhci_warn(xhci, "WARN: no supported page size\n");
2456 xhci->page_shift = 12;
2457 xhci->page_size = 1 << xhci->page_shift;
2458 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2459 "HCD page size set to %iK", xhci->page_size / 1024);
2465 val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1));
2466 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2468 val2 = readl(&xhci->op_regs->config_reg);
2470 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2472 writel(val, &xhci->op_regs->config_reg);
2478 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma,
2480 if (!xhci->dcbaa)
2482 xhci->dcbaa->dma = dma;
2483 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2485 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa);
2486 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr);
2495 if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH)
2496 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
2497 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2);
2499 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
2500 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size);
2503 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev,
2504 2112, 64, xhci->page_size);
2505 if (!xhci->segment_pool || !xhci->device_pool)
2511 xhci->small_streams_pool =
2514 xhci->medium_streams_pool =
2521 if (!xhci->small_streams_pool || !xhci->medium_streams_pool)
2525 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, 0, flags);
2526 if (!xhci->cmd_ring)
2528 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2529 "Allocated command ring at %p", xhci->cmd_ring);
2530 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%llx",
2531 (unsigned long long)xhci->cmd_ring->first_seg->dma);
2534 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
2536 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) |
2537 xhci->cmd_ring->cycle_state;
2538 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2540 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2542 xhci->lpm_command = xhci_alloc_command_with_ctx(xhci, true, flags);
2543 if (!xhci->lpm_command)
2550 xhci->cmd_ring_reserved_trbs++;
2552 val = readl(&xhci->cap_regs->db_off);
2554 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2557 xhci->dba = (void __iomem *) xhci->cap_regs + val;
2559 xhci->ir_set = &xhci->run_regs->ir_set[0];
2565 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Allocating event ring");
2566 xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, 1, TYPE_EVENT,
2568 if (!xhci->event_ring)
2570 if (xhci_check_trb_in_td_math(xhci) < 0)
2573 ret = xhci_alloc_erst(xhci, xhci->event_ring, &xhci->erst, flags);
2578 val = readl(&xhci->ir_set->erst_size);
2581 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2584 writel(val, &xhci->ir_set->erst_size);
2586 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2589 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2591 (unsigned long long)xhci->erst.erst_dma_addr);
2592 val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base);
2594 val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK);
2595 xhci_write_64(xhci, val_64, &xhci->ir_set->erst_base);
2598 xhci_set_hc_event_deq(xhci);
2599 xhci_dbg_trace(xhci, trace_xhci_dbg_init,
2608 xhci->devs[i] = NULL;
2610 if (scratchpad_alloc(xhci, flags))
2612 if (xhci_setup_port_arrays(xhci, flags))
2619 temp = readl(&xhci->op_regs->dev_notification);
2622 writel(temp, &xhci->op_regs->dev_notification);
2627 xhci_halt(xhci);
2628 xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
2629 xhci_mem_cleanup(xhci);