Lines Matching +full:multi +full:- +full:tt

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/dma-mapping.h>
19 #include "xhci-trace.h"
20 #include "xhci-debugfs.h"
38 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_segment_alloc()
44 seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma); in xhci_segment_alloc()
45 if (!seg->trbs) { in xhci_segment_alloc()
51 seg->bounce_buf = kzalloc_node(max_packet, flags, in xhci_segment_alloc()
53 if (!seg->bounce_buf) { in xhci_segment_alloc()
54 dma_pool_free(xhci->segment_pool, seg->trbs, dma); in xhci_segment_alloc()
62 seg->trbs[i].link.control = cpu_to_le32(TRB_CYCLE); in xhci_segment_alloc()
64 seg->num = num; in xhci_segment_alloc()
65 seg->dma = dma; in xhci_segment_alloc()
66 seg->next = NULL; in xhci_segment_alloc()
73 if (seg->trbs) { in xhci_segment_free()
74 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma); in xhci_segment_free()
75 seg->trbs = NULL; in xhci_segment_free()
77 kfree(seg->bounce_buf); in xhci_segment_free()
86 seg = first->next; in xhci_free_segments_for_ring()
88 struct xhci_segment *next = seg->next; in xhci_free_segments_for_ring()
110 prev->next = next; in xhci_link_segments()
112 prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = in xhci_link_segments()
113 cpu_to_le64(next->dma); in xhci_link_segments()
116 val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control); in xhci_link_segments()
121 prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val); in xhci_link_segments()
139 chain_links = xhci_link_chain_quirk(xhci, ring->type); in xhci_link_rings()
141 next = ring->enq_seg->next; in xhci_link_rings()
142 xhci_link_segments(ring->enq_seg, first, ring->type, chain_links); in xhci_link_rings()
143 xhci_link_segments(last, next, ring->type, chain_links); in xhci_link_rings()
144 ring->num_segs += num_segs; in xhci_link_rings()
146 if (ring->enq_seg == ring->last_seg) { in xhci_link_rings()
147 if (ring->type != TYPE_EVENT) { in xhci_link_rings()
148 ring->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control in xhci_link_rings()
150 last->trbs[TRBS_PER_SEGMENT-1].link.control in xhci_link_rings()
153 ring->last_seg = last; in xhci_link_rings()
156 for (seg = ring->enq_seg; seg != ring->last_seg; seg = seg->next) in xhci_link_rings()
157 seg->next->num = seg->num + 1; in xhci_link_rings()
183 * The radix tree uses an unsigned long as a key pair. On 32-bit systems, an
184 * unsigned long will be 32-bits; on a 64-bit system an unsigned long will be
185 * 64-bits. Since we only request 32-bit DMA addresses, we can use that as the
186 * key on 32-bit or 64-bit systems (it would also be fine if we asked for 64-bit
187 * PCI DMA addresses on a 64-bit system). There might be a problem on 32-bit
188 * extended systems (where the DMA address can be bigger than 32-bits),
189 * if we allow the PCI dma mask to be bigger than 32-bits. So don't do that.
199 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in xhci_insert_segment_mapping()
218 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in xhci_remove_segment_mapping()
245 seg = seg->next; in xhci_update_stream_segment_mapping()
257 seg = seg->next; in xhci_update_stream_segment_mapping()
267 if (WARN_ON_ONCE(ring->trb_address_map == NULL)) in xhci_remove_stream_mapping()
270 seg = ring->first_seg; in xhci_remove_stream_mapping()
272 xhci_remove_segment_mapping(ring->trb_address_map, seg); in xhci_remove_stream_mapping()
273 seg = seg->next; in xhci_remove_stream_mapping()
274 } while (seg != ring->first_seg); in xhci_remove_stream_mapping()
279 return xhci_update_stream_segment_mapping(ring->trb_address_map, ring, in xhci_update_stream_mapping()
280 ring->first_seg, ring->last_seg, mem_flags); in xhci_update_stream_mapping()
291 if (ring->first_seg) { in xhci_ring_free()
292 if (ring->type == TYPE_STREAM) in xhci_ring_free()
294 xhci_free_segments_for_ring(xhci, ring->first_seg); in xhci_ring_free()
304 ring->enqueue = ring->first_seg->trbs; in xhci_initialize_ring_info()
305 ring->enq_seg = ring->first_seg; in xhci_initialize_ring_info()
306 ring->dequeue = ring->enqueue; in xhci_initialize_ring_info()
307 ring->deq_seg = ring->first_seg; in xhci_initialize_ring_info()
315 ring->cycle_state = cycle_state; in xhci_initialize_ring_info()
321 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in xhci_initialize_ring_info()
343 return -ENOMEM; in xhci_alloc_segments_for_ring()
366 return -ENOMEM; in xhci_alloc_segments_for_ring()
382 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_ring_alloc()
388 ring->num_segs = num_segs; in xhci_ring_alloc()
389 ring->bounce_buf_len = max_packet; in xhci_ring_alloc()
390 INIT_LIST_HEAD(&ring->td_list); in xhci_ring_alloc()
391 ring->type = type; in xhci_ring_alloc()
395 ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg, &ring->last_seg, num_segs, in xhci_ring_alloc()
403 ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= in xhci_ring_alloc()
419 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring); in xhci_free_endpoint_ring()
420 virt_dev->eps[ep_index].ring = NULL; in xhci_free_endpoint_ring()
434 ret = xhci_alloc_segments_for_ring(xhci, &first, &last, num_new_segs, ring->cycle_state, in xhci_ring_expansion()
435 ring->type, ring->bounce_buf_len, flags); in xhci_ring_expansion()
437 return -ENOMEM; in xhci_ring_expansion()
439 if (ring->type == TYPE_STREAM) { in xhci_ring_expansion()
440 ret = xhci_update_stream_segment_mapping(ring->trb_address_map, in xhci_ring_expansion()
450 ring->num_segs); in xhci_ring_expansion()
463 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_container_ctx()
472 ctx->type = type; in xhci_alloc_container_ctx()
473 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024; in xhci_alloc_container_ctx()
475 ctx->size += CTX_SIZE(xhci->hcc_params); in xhci_alloc_container_ctx()
477 ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma); in xhci_alloc_container_ctx()
478 if (!ctx->bytes) { in xhci_alloc_container_ctx()
490 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma); in xhci_free_container_ctx()
497 if (ctx->type != XHCI_CTX_TYPE_INPUT) in xhci_get_input_control_ctx()
500 return (struct xhci_input_control_ctx *)ctx->bytes; in xhci_get_input_control_ctx()
506 if (ctx->type == XHCI_CTX_TYPE_DEVICE) in xhci_get_slot_ctx()
507 return (struct xhci_slot_ctx *)ctx->bytes; in xhci_get_slot_ctx()
510 (ctx->bytes + CTX_SIZE(xhci->hcc_params)); in xhci_get_slot_ctx()
519 if (ctx->type == XHCI_CTX_TYPE_INPUT) in xhci_get_ep_ctx()
523 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); in xhci_get_ep_ctx()
533 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_stream_ctx()
539 dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
541 dma_pool_free(xhci->small_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
547 * - how many streams the endpoint supports,
548 * - the maximum primary stream array size the host controller supports,
549 * - and how many streams the device driver asks for.
558 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_ctx()
564 return dma_pool_zalloc(xhci->medium_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
566 return dma_pool_zalloc(xhci->small_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
573 if (ep->ep_state & EP_HAS_STREAMS) in xhci_dma_to_transfer_ring()
574 return radix_tree_lookup(&ep->stream_info->trb_address_map, in xhci_dma_to_transfer_ring()
576 return ep->ring; in xhci_dma_to_transfer_ring()
598 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_info()
602 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) { in xhci_alloc_stream_info()
606 xhci->cmd_ring_reserved_trbs++; in xhci_alloc_stream_info()
613 stream_info->num_streams = num_streams; in xhci_alloc_stream_info()
614 stream_info->num_stream_ctxs = num_stream_ctxs; in xhci_alloc_stream_info()
617 stream_info->stream_rings = kcalloc_node( in xhci_alloc_stream_info()
620 if (!stream_info->stream_rings) in xhci_alloc_stream_info()
624 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci, in xhci_alloc_stream_info()
625 num_stream_ctxs, &stream_info->ctx_array_dma, in xhci_alloc_stream_info()
627 if (!stream_info->stream_ctx_array) in xhci_alloc_stream_info()
631 stream_info->free_streams_command = in xhci_alloc_stream_info()
633 if (!stream_info->free_streams_command) in xhci_alloc_stream_info()
636 INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC); in xhci_alloc_stream_info()
644 stream_info->stream_rings[cur_stream] = in xhci_alloc_stream_info()
647 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
650 cur_ring->stream_id = cur_stream; in xhci_alloc_stream_info()
651 cur_ring->trb_address_map = &stream_info->trb_address_map; in xhci_alloc_stream_info()
653 addr = cur_ring->first_seg->dma | in xhci_alloc_stream_info()
655 cur_ring->cycle_state; in xhci_alloc_stream_info()
656 stream_info->stream_ctx_array[cur_stream].stream_ring = in xhci_alloc_stream_info()
663 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
678 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
681 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
684 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_alloc_stream_info()
687 stream_info->num_stream_ctxs, in xhci_alloc_stream_info()
688 stream_info->stream_ctx_array, in xhci_alloc_stream_info()
689 stream_info->ctx_array_dma); in xhci_alloc_stream_info()
691 kfree(stream_info->stream_rings); in xhci_alloc_stream_info()
695 xhci->cmd_ring_reserved_trbs--; in xhci_alloc_stream_info()
711 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; in xhci_setup_streams_ep_input_ctx()
715 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK); in xhci_setup_streams_ep_input_ctx()
716 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams) in xhci_setup_streams_ep_input_ctx()
718 ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma); in xhci_setup_streams_ep_input_ctx()
730 ep_ctx->ep_info &= cpu_to_le32(~(EP_MAXPSTREAMS_MASK | EP_HAS_LSA)); in xhci_setup_no_streams_ep_input_ctx()
731 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue); in xhci_setup_no_streams_ep_input_ctx()
732 ep_ctx->deq = cpu_to_le64(addr | ep->ring->cycle_state); in xhci_setup_no_streams_ep_input_ctx()
748 for (cur_stream = 1; cur_stream < stream_info->num_streams; in xhci_free_stream_info()
750 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_free_stream_info()
753 stream_info->stream_rings[cur_stream] = NULL; in xhci_free_stream_info()
756 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_free_stream_info()
757 xhci->cmd_ring_reserved_trbs--; in xhci_free_stream_info()
758 if (stream_info->stream_ctx_array) in xhci_free_stream_info()
760 stream_info->num_stream_ctxs, in xhci_free_stream_info()
761 stream_info->stream_ctx_array, in xhci_free_stream_info()
762 stream_info->ctx_array_dma); in xhci_free_stream_info()
764 kfree(stream_info->stream_rings); in xhci_free_stream_info()
782 if (!virt_dev->rhub_port) { in xhci_free_tt_info()
787 tt_list_head = &(xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_free_tt_info()
789 /* Multi-TT hubs will have more than one entry */ in xhci_free_tt_info()
790 if (tt_info->slot_id == slot_id) { in xhci_free_tt_info()
792 list_del(&tt_info->tt_list); in xhci_free_tt_info()
803 struct usb_tt *tt, gfp_t mem_flags) in xhci_alloc_tt_info() argument
808 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_tt_info()
810 if (!tt->multi) in xhci_alloc_tt_info()
813 num_ports = hdev->maxchild; in xhci_alloc_tt_info()
822 INIT_LIST_HEAD(&tt_info->tt_list); in xhci_alloc_tt_info()
823 list_add(&tt_info->tt_list, in xhci_alloc_tt_info()
824 &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_alloc_tt_info()
825 tt_info->slot_id = virt_dev->udev->slot_id; in xhci_alloc_tt_info()
826 if (tt->multi) in xhci_alloc_tt_info()
827 tt_info->ttport = i+1; in xhci_alloc_tt_info()
828 bw_table = &tt_info->bw_table; in xhci_alloc_tt_info()
830 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_alloc_tt_info()
835 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id); in xhci_alloc_tt_info()
836 return -ENOMEM; in xhci_alloc_tt_info()
841 * Should be called with xhci->lock held if there is any chance the TT lists
843 * hub functions while this function is removing the TT entries from the list.
852 if (slot_id == 0 || !xhci->devs[slot_id]) in xhci_free_virt_device()
855 dev = xhci->devs[slot_id]; in xhci_free_virt_device()
857 xhci->dcbaa->dev_context_ptrs[slot_id] = 0; in xhci_free_virt_device()
863 if (dev->tt_info) in xhci_free_virt_device()
864 old_active_eps = dev->tt_info->active_eps; in xhci_free_virt_device()
867 if (dev->eps[i].ring) in xhci_free_virt_device()
868 xhci_ring_free(xhci, dev->eps[i].ring); in xhci_free_virt_device()
869 if (dev->eps[i].stream_info) in xhci_free_virt_device()
871 dev->eps[i].stream_info); in xhci_free_virt_device()
880 if (!list_empty(&dev->eps[i].bw_endpoint_list)) { in xhci_free_virt_device()
881 list_del_init(&dev->eps[i].bw_endpoint_list); in xhci_free_virt_device()
886 /* If this is a hub, free the TT(s) from the TT list */ in xhci_free_virt_device()
891 if (dev->in_ctx) in xhci_free_virt_device()
892 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_free_virt_device()
893 if (dev->out_ctx) in xhci_free_virt_device()
894 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_free_virt_device()
896 if (dev->udev && dev->udev->slot_id) in xhci_free_virt_device()
897 dev->udev->slot_id = 0; in xhci_free_virt_device()
898 if (dev->rhub_port && dev->rhub_port->slot_id == slot_id) in xhci_free_virt_device()
899 dev->rhub_port->slot_id = 0; in xhci_free_virt_device()
900 kfree(xhci->devs[slot_id]); in xhci_free_virt_device()
901 xhci->devs[slot_id] = NULL; in xhci_free_virt_device()
908 * We can't rely on udev at this point to find child-parent relationships.
917 vdev = xhci->devs[slot_id]; in xhci_free_virt_devices_depth_first()
921 if (!vdev->rhub_port) { in xhci_free_virt_devices_depth_first()
926 tt_list_head = &(xhci->rh_bw[vdev->rhub_port->hw_portnum].tts); in xhci_free_virt_devices_depth_first()
929 if (tt_info->slot_id == slot_id) { in xhci_free_virt_devices_depth_first()
931 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_free_virt_devices_depth_first()
932 vdev = xhci->devs[i]; in xhci_free_virt_devices_depth_first()
933 if (vdev && (vdev->tt_info == tt_info)) in xhci_free_virt_devices_depth_first()
952 if (slot_id == 0 || xhci->devs[slot_id]) { in xhci_alloc_virt_device()
961 dev->slot_id = slot_id; in xhci_alloc_virt_device()
964 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); in xhci_alloc_virt_device()
965 if (!dev->out_ctx) in xhci_alloc_virt_device()
968 xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma); in xhci_alloc_virt_device()
971 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags); in xhci_alloc_virt_device()
972 if (!dev->in_ctx) in xhci_alloc_virt_device()
975 xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma); in xhci_alloc_virt_device()
979 dev->eps[i].ep_index = i; in xhci_alloc_virt_device()
980 dev->eps[i].vdev = dev; in xhci_alloc_virt_device()
981 dev->eps[i].xhci = xhci; in xhci_alloc_virt_device()
982 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); in xhci_alloc_virt_device()
983 INIT_LIST_HEAD(&dev->eps[i].bw_endpoint_list); in xhci_alloc_virt_device()
987 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, 1, TYPE_CTRL, 0, flags); in xhci_alloc_virt_device()
988 if (!dev->eps[0].ring) in xhci_alloc_virt_device()
991 dev->udev = udev; in xhci_alloc_virt_device()
994 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma); in xhci_alloc_virt_device()
997 &xhci->dcbaa->dev_context_ptrs[slot_id], in xhci_alloc_virt_device()
998 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id])); in xhci_alloc_virt_device()
1002 xhci->devs[slot_id] = dev; in xhci_alloc_virt_device()
1007 if (dev->in_ctx) in xhci_alloc_virt_device()
1008 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_alloc_virt_device()
1009 if (dev->out_ctx) in xhci_alloc_virt_device()
1010 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_alloc_virt_device()
1023 virt_dev = xhci->devs[udev->slot_id]; in xhci_copy_ep0_dequeue_into_input_ctx()
1024 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0); in xhci_copy_ep0_dequeue_into_input_ctx()
1025 ep_ring = virt_dev->eps[0].ring; in xhci_copy_ep0_dequeue_into_input_ctx()
1033 ep0_ctx->deq = cpu_to_le64(xhci_trb_virt_to_dma(ep_ring->enq_seg, in xhci_copy_ep0_dequeue_into_input_ctx()
1034 ep_ring->enqueue) in xhci_copy_ep0_dequeue_into_input_ctx()
1035 | ep_ring->cycle_state); in xhci_copy_ep0_dequeue_into_input_ctx()
1054 if (udev->speed >= USB_SPEED_SUPER) in xhci_find_rhub_port()
1057 hcd = xhci->main_hcd; in xhci_find_rhub_port()
1059 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; in xhci_find_rhub_port()
1060 top_dev = top_dev->parent) in xhci_find_rhub_port()
1064 return rhub->ports[top_dev->portnum - 1]; in xhci_find_rhub_port()
1075 dev = xhci->devs[udev->slot_id]; in xhci_setup_addressable_virt_dev()
1077 if (udev->slot_id == 0 || !dev) { in xhci_setup_addressable_virt_dev()
1079 udev->slot_id); in xhci_setup_addressable_virt_dev()
1080 return -EINVAL; in xhci_setup_addressable_virt_dev()
1082 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); in xhci_setup_addressable_virt_dev()
1083 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); in xhci_setup_addressable_virt_dev()
1085 /* 3) Only the control endpoint is valid - one endpoint context */ in xhci_setup_addressable_virt_dev()
1086 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); in xhci_setup_addressable_virt_dev()
1087 switch (udev->speed) { in xhci_setup_addressable_virt_dev()
1089 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SSP); in xhci_setup_addressable_virt_dev()
1093 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS); in xhci_setup_addressable_virt_dev()
1097 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS); in xhci_setup_addressable_virt_dev()
1100 /* USB core guesses at a 64-byte max packet first for FS devices */ in xhci_setup_addressable_virt_dev()
1102 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS); in xhci_setup_addressable_virt_dev()
1106 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS); in xhci_setup_addressable_virt_dev()
1111 return -EINVAL; in xhci_setup_addressable_virt_dev()
1114 dev->rhub_port = xhci_find_rhub_port(xhci, udev); in xhci_setup_addressable_virt_dev()
1115 if (!dev->rhub_port) in xhci_setup_addressable_virt_dev()
1116 return -EINVAL; in xhci_setup_addressable_virt_dev()
1118 if (!udev->parent->parent) in xhci_setup_addressable_virt_dev()
1119 dev->rhub_port->slot_id = udev->slot_id; in xhci_setup_addressable_virt_dev()
1120 slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(dev->rhub_port->hw_portnum + 1)); in xhci_setup_addressable_virt_dev()
1122 udev->slot_id, dev->rhub_port->hw_portnum, dev->rhub_port->hcd_portnum); in xhci_setup_addressable_virt_dev()
1127 * secondary bandwidth domain under a TT. An xhci_tt_info structure in xhci_setup_addressable_virt_dev()
1130 if (!udev->tt || !udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1131 dev->bw_table = &xhci->rh_bw[dev->rhub_port->hw_portnum].bw_table; in xhci_setup_addressable_virt_dev()
1136 rh_bw = &xhci->rh_bw[dev->rhub_port->hw_portnum]; in xhci_setup_addressable_virt_dev()
1137 /* Find the right TT. */ in xhci_setup_addressable_virt_dev()
1138 list_for_each_entry(tt_bw, &rh_bw->tts, tt_list) { in xhci_setup_addressable_virt_dev()
1139 if (tt_bw->slot_id != udev->tt->hub->slot_id) in xhci_setup_addressable_virt_dev()
1142 if (!dev->udev->tt->multi || in xhci_setup_addressable_virt_dev()
1143 (udev->tt->multi && in xhci_setup_addressable_virt_dev()
1144 tt_bw->ttport == dev->udev->ttport)) { in xhci_setup_addressable_virt_dev()
1145 dev->bw_table = &tt_bw->bw_table; in xhci_setup_addressable_virt_dev()
1146 dev->tt_info = tt_bw; in xhci_setup_addressable_virt_dev()
1150 if (!dev->tt_info) in xhci_setup_addressable_virt_dev()
1151 xhci_warn(xhci, "WARN: Didn't find a matching TT\n"); in xhci_setup_addressable_virt_dev()
1155 if (udev->tt && udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1156 slot_ctx->tt_info = cpu_to_le32(udev->tt->hub->slot_id | in xhci_setup_addressable_virt_dev()
1157 (udev->ttport << 8)); in xhci_setup_addressable_virt_dev()
1158 if (udev->tt->multi) in xhci_setup_addressable_virt_dev()
1159 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_setup_addressable_virt_dev()
1161 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); in xhci_setup_addressable_virt_dev()
1162 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); in xhci_setup_addressable_virt_dev()
1164 /* Step 4 - ring already allocated */ in xhci_setup_addressable_virt_dev()
1166 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP)); in xhci_setup_addressable_virt_dev()
1169 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) | in xhci_setup_addressable_virt_dev()
1172 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma | in xhci_setup_addressable_virt_dev()
1173 dev->eps[0].ring->cycle_state); in xhci_setup_addressable_virt_dev()
1183 * Convert interval expressed as 2^(bInterval - 1) == interval into
1192 interval = clamp_val(ep->desc.bInterval, 1, 16) - 1; in xhci_parse_exponent_interval()
1193 if (interval != ep->desc.bInterval - 1) in xhci_parse_exponent_interval()
1194 dev_warn(&udev->dev, in xhci_parse_exponent_interval()
1195 "ep %#x - rounding interval to %d %sframes\n", in xhci_parse_exponent_interval()
1196 ep->desc.bEndpointAddress, in xhci_parse_exponent_interval()
1198 udev->speed == USB_SPEED_FULL ? "" : "micro"); in xhci_parse_exponent_interval()
1200 if (udev->speed == USB_SPEED_FULL) { in xhci_parse_exponent_interval()
1213 * Convert bInterval expressed in microframes (in 1-255 range) to exponent of
1222 interval = fls(desc_interval) - 1; in xhci_microframes_to_exponent()
1225 dev_dbg(&udev->dev, in xhci_microframes_to_exponent()
1226 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n", in xhci_microframes_to_exponent()
1227 ep->desc.bEndpointAddress, in xhci_microframes_to_exponent()
1237 if (ep->desc.bInterval == 0) in xhci_parse_microframe_interval()
1240 ep->desc.bInterval, 0, 15); in xhci_parse_microframe_interval()
1248 ep->desc.bInterval * 8, 3, 10); in xhci_parse_frame_interval()
1264 switch (udev->speed) { in xhci_get_endpoint_interval()
1267 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_endpoint_interval()
1268 usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_get_endpoint_interval()
1276 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1277 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1283 if (usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1295 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1296 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1316 if (udev->speed < USB_SPEED_SUPER || in xhci_get_endpoint_mult()
1317 !usb_endpoint_xfer_isoc(&ep->desc)) in xhci_get_endpoint_mult()
1319 return ep->ss_ep_comp.bmAttributes; in xhci_get_endpoint_mult()
1326 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_endpoint_max_burst()
1327 return ep->ss_ep_comp.bMaxBurst; in xhci_get_endpoint_max_burst()
1329 if (udev->speed == USB_SPEED_HIGH && in xhci_get_endpoint_max_burst()
1330 (usb_endpoint_xfer_isoc(&ep->desc) || in xhci_get_endpoint_max_burst()
1331 usb_endpoint_xfer_int(&ep->desc))) in xhci_get_endpoint_max_burst()
1332 return usb_endpoint_maxp_mult(&ep->desc) - 1; in xhci_get_endpoint_max_burst()
1341 in = usb_endpoint_dir_in(&ep->desc); in xhci_get_endpoint_type()
1343 switch (usb_endpoint_type(&ep->desc)) { in xhci_get_endpoint_type()
1367 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_max_esit_payload()
1368 usb_endpoint_xfer_bulk(&ep->desc)) in xhci_get_max_esit_payload()
1372 if ((udev->speed >= USB_SPEED_SUPER_PLUS) && in xhci_get_max_esit_payload()
1373 USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) in xhci_get_max_esit_payload()
1374 return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); in xhci_get_max_esit_payload()
1377 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_max_esit_payload()
1378 return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); in xhci_get_max_esit_payload()
1380 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_get_max_esit_payload()
1381 max_burst = usb_endpoint_maxp_mult(&ep->desc); in xhci_get_max_esit_payload()
1408 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_init()
1409 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_init()
1413 return -EINVAL; in xhci_endpoint_init()
1415 ring_type = usb_endpoint_type(&ep->desc); in xhci_endpoint_init()
1427 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_endpoint_init()
1428 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_endpoint_init()
1429 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) && in xhci_endpoint_init()
1430 udev->speed >= USB_SPEED_HIGH && in xhci_endpoint_init()
1437 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_endpoint_init()
1444 if (!usb_endpoint_xfer_isoc(&ep->desc)) in xhci_endpoint_init()
1447 if (usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_endpoint_init()
1448 if (udev->speed == USB_SPEED_HIGH) in xhci_endpoint_init()
1450 if (udev->speed == USB_SPEED_FULL) { in xhci_endpoint_init()
1456 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) in xhci_endpoint_init()
1459 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) in xhci_endpoint_init()
1463 virt_dev->eps[ep_index].new_ring = in xhci_endpoint_init()
1465 if (!virt_dev->eps[ep_index].new_ring) in xhci_endpoint_init()
1466 return -ENOMEM; in xhci_endpoint_init()
1468 virt_dev->eps[ep_index].skip = false; in xhci_endpoint_init()
1469 ep_ring = virt_dev->eps[ep_index].new_ring; in xhci_endpoint_init()
1472 ep_ctx->ep_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) | in xhci_endpoint_init()
1475 ep_ctx->ep_info2 = cpu_to_le32(EP_TYPE(endpoint_type) | in xhci_endpoint_init()
1479 ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma | in xhci_endpoint_init()
1480 ep_ring->cycle_state); in xhci_endpoint_init()
1482 ep_ctx->tx_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) | in xhci_endpoint_init()
1495 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_zero()
1496 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_zero()
1498 ep_ctx->ep_info = 0; in xhci_endpoint_zero()
1499 ep_ctx->ep_info2 = 0; in xhci_endpoint_zero()
1500 ep_ctx->deq = 0; in xhci_endpoint_zero()
1501 ep_ctx->tx_info = 0; in xhci_endpoint_zero()
1509 bw_info->ep_interval = 0; in xhci_clear_endpoint_bw_info()
1510 bw_info->mult = 0; in xhci_clear_endpoint_bw_info()
1511 bw_info->num_packets = 0; in xhci_clear_endpoint_bw_info()
1512 bw_info->max_packet_size = 0; in xhci_clear_endpoint_bw_info()
1513 bw_info->type = 0; in xhci_clear_endpoint_bw_info()
1514 bw_info->max_esit_payload = 0; in xhci_clear_endpoint_bw_info()
1528 bw_info = &virt_dev->eps[i].bw_info; in xhci_update_bw_info()
1531 * unconditionally clearing the bandwidth info for non-periodic in xhci_update_bw_info()
1543 ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1545 /* Ignore non-periodic endpoints */ in xhci_update_bw_info()
1552 bw_info->ep_interval = CTX_TO_EP_INTERVAL( in xhci_update_bw_info()
1553 le32_to_cpu(ep_ctx->ep_info)); in xhci_update_bw_info()
1554 /* Number of packets and mult are zero-based in the in xhci_update_bw_info()
1555 * input context, but we want one-based for the in xhci_update_bw_info()
1558 bw_info->mult = CTX_TO_EP_MULT( in xhci_update_bw_info()
1559 le32_to_cpu(ep_ctx->ep_info)) + 1; in xhci_update_bw_info()
1560 bw_info->num_packets = CTX_TO_MAX_BURST( in xhci_update_bw_info()
1561 le32_to_cpu(ep_ctx->ep_info2)) + 1; in xhci_update_bw_info()
1562 bw_info->max_packet_size = MAX_PACKET_DECODED( in xhci_update_bw_info()
1563 le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1564 bw_info->type = ep_type; in xhci_update_bw_info()
1565 bw_info->max_esit_payload = CTX_TO_MAX_ESIT_PAYLOAD( in xhci_update_bw_info()
1566 le32_to_cpu(ep_ctx->tx_info)); in xhci_update_bw_info()
1586 in_ep_ctx->ep_info = out_ep_ctx->ep_info; in xhci_endpoint_copy()
1587 in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2; in xhci_endpoint_copy()
1588 in_ep_ctx->deq = out_ep_ctx->deq; in xhci_endpoint_copy()
1589 in_ep_ctx->tx_info = out_ep_ctx->tx_info; in xhci_endpoint_copy()
1590 if (xhci->quirks & XHCI_MTK_HOST) { in xhci_endpoint_copy()
1591 in_ep_ctx->reserved[0] = out_ep_ctx->reserved[0]; in xhci_endpoint_copy()
1592 in_ep_ctx->reserved[1] = out_ep_ctx->reserved[1]; in xhci_endpoint_copy()
1611 in_slot_ctx->dev_info = out_slot_ctx->dev_info; in xhci_slot_copy()
1612 in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2; in xhci_slot_copy()
1613 in_slot_ctx->tt_info = out_slot_ctx->tt_info; in xhci_slot_copy()
1614 in_slot_ctx->dev_state = out_slot_ctx->dev_state; in xhci_slot_copy()
1621 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_alloc()
1622 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_alloc()
1630 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags, in scratchpad_alloc()
1632 if (!xhci->scratchpad) in scratchpad_alloc()
1635 xhci->scratchpad->sp_array = dma_alloc_coherent(dev, in scratchpad_alloc()
1637 &xhci->scratchpad->sp_dma, flags); in scratchpad_alloc()
1638 if (!xhci->scratchpad->sp_array) in scratchpad_alloc()
1641 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *), in scratchpad_alloc()
1643 if (!xhci->scratchpad->sp_buffers) in scratchpad_alloc()
1646 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); in scratchpad_alloc()
1649 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma, in scratchpad_alloc()
1654 xhci->scratchpad->sp_array[i] = dma; in scratchpad_alloc()
1655 xhci->scratchpad->sp_buffers[i] = buf; in scratchpad_alloc()
1661 while (i--) in scratchpad_alloc()
1662 dma_free_coherent(dev, xhci->page_size, in scratchpad_alloc()
1663 xhci->scratchpad->sp_buffers[i], in scratchpad_alloc()
1664 xhci->scratchpad->sp_array[i]); in scratchpad_alloc()
1666 kfree(xhci->scratchpad->sp_buffers); in scratchpad_alloc()
1670 xhci->scratchpad->sp_array, in scratchpad_alloc()
1671 xhci->scratchpad->sp_dma); in scratchpad_alloc()
1674 kfree(xhci->scratchpad); in scratchpad_alloc()
1675 xhci->scratchpad = NULL; in scratchpad_alloc()
1678 return -ENOMEM; in scratchpad_alloc()
1685 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_free()
1687 if (!xhci->scratchpad) in scratchpad_free()
1690 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_free()
1693 dma_free_coherent(dev, xhci->page_size, in scratchpad_free()
1694 xhci->scratchpad->sp_buffers[i], in scratchpad_free()
1695 xhci->scratchpad->sp_array[i]); in scratchpad_free()
1697 kfree(xhci->scratchpad->sp_buffers); in scratchpad_free()
1699 xhci->scratchpad->sp_array, in scratchpad_free()
1700 xhci->scratchpad->sp_dma); in scratchpad_free()
1701 kfree(xhci->scratchpad); in scratchpad_free()
1702 xhci->scratchpad = NULL; in scratchpad_free()
1709 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_command()
1716 command->completion = in xhci_alloc_command()
1719 if (!command->completion) { in xhci_alloc_command()
1723 init_completion(command->completion); in xhci_alloc_command()
1726 command->status = 0; in xhci_alloc_command()
1728 command->timeout_ms = XHCI_CMD_DEFAULT_TIMEOUT; in xhci_alloc_command()
1729 INIT_LIST_HEAD(&command->cmd_list); in xhci_alloc_command()
1742 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, in xhci_alloc_command_with_ctx()
1744 if (!command->in_ctx) { in xhci_alloc_command_with_ctx()
1745 kfree(command->completion); in xhci_alloc_command_with_ctx()
1761 command->in_ctx); in xhci_free_command()
1762 kfree(command->completion); in xhci_free_command()
1776 size = array_size(sizeof(struct xhci_erst_entry), evt_ring->num_segs); in xhci_alloc_erst()
1777 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev, in xhci_alloc_erst()
1778 size, &erst->erst_dma_addr, flags); in xhci_alloc_erst()
1779 if (!erst->entries) in xhci_alloc_erst()
1780 return -ENOMEM; in xhci_alloc_erst()
1782 erst->num_entries = evt_ring->num_segs; in xhci_alloc_erst()
1784 seg = evt_ring->first_seg; in xhci_alloc_erst()
1785 for (val = 0; val < evt_ring->num_segs; val++) { in xhci_alloc_erst()
1786 entry = &erst->entries[val]; in xhci_alloc_erst()
1787 entry->seg_addr = cpu_to_le64(seg->dma); in xhci_alloc_erst()
1788 entry->seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in xhci_alloc_erst()
1789 entry->rsvd = 0; in xhci_alloc_erst()
1790 seg = seg->next; in xhci_alloc_erst()
1809 if (ir->ir_set) { in xhci_remove_interrupter()
1810 tmp = readl(&ir->ir_set->erst_size); in xhci_remove_interrupter()
1812 writel(tmp, &ir->ir_set->erst_size); in xhci_remove_interrupter()
1814 xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue); in xhci_remove_interrupter()
1821 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_interrupter()
1827 erst_size = array_size(sizeof(struct xhci_erst_entry), ir->erst.num_entries); in xhci_free_interrupter()
1828 if (ir->erst.entries) in xhci_free_interrupter()
1830 ir->erst.entries, in xhci_free_interrupter()
1831 ir->erst.erst_dma_addr); in xhci_free_interrupter()
1832 ir->erst.entries = NULL; in xhci_free_interrupter()
1835 if (ir->event_ring) in xhci_free_interrupter()
1836 xhci_ring_free(xhci, ir->event_ring); in xhci_free_interrupter()
1838 ir->event_ring = NULL; in xhci_free_interrupter()
1848 spin_lock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1851 if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) { in xhci_remove_secondary_interrupter()
1853 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1857 intr_num = ir->intr_num; in xhci_remove_secondary_interrupter()
1860 xhci->interrupters[intr_num] = NULL; in xhci_remove_secondary_interrupter()
1862 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1870 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_cleanup()
1873 cancel_delayed_work_sync(&xhci->cmd_timer); in xhci_mem_cleanup()
1875 for (i = 0; xhci->interrupters && i < xhci->max_interrupters; i++) { in xhci_mem_cleanup()
1876 if (xhci->interrupters[i]) { in xhci_mem_cleanup()
1877 xhci_remove_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1878 xhci_free_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1879 xhci->interrupters[i] = NULL; in xhci_mem_cleanup()
1884 if (xhci->cmd_ring) in xhci_mem_cleanup()
1885 xhci_ring_free(xhci, xhci->cmd_ring); in xhci_mem_cleanup()
1886 xhci->cmd_ring = NULL; in xhci_mem_cleanup()
1890 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_mem_cleanup()
1891 for (i = 0; i < num_ports && xhci->rh_bw; i++) { in xhci_mem_cleanup()
1892 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table; in xhci_mem_cleanup()
1894 struct list_head *ep = &bwt->interval_bw[j].endpoints; in xhci_mem_cleanup()
1896 list_del_init(ep->next); in xhci_mem_cleanup()
1900 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--) in xhci_mem_cleanup()
1903 dma_pool_destroy(xhci->segment_pool); in xhci_mem_cleanup()
1904 xhci->segment_pool = NULL; in xhci_mem_cleanup()
1907 dma_pool_destroy(xhci->device_pool); in xhci_mem_cleanup()
1908 xhci->device_pool = NULL; in xhci_mem_cleanup()
1911 dma_pool_destroy(xhci->small_streams_pool); in xhci_mem_cleanup()
1912 xhci->small_streams_pool = NULL; in xhci_mem_cleanup()
1916 dma_pool_destroy(xhci->medium_streams_pool); in xhci_mem_cleanup()
1917 xhci->medium_streams_pool = NULL; in xhci_mem_cleanup()
1921 if (xhci->dcbaa) in xhci_mem_cleanup()
1922 dma_free_coherent(dev, sizeof(*xhci->dcbaa), in xhci_mem_cleanup()
1923 xhci->dcbaa, xhci->dcbaa->dma); in xhci_mem_cleanup()
1924 xhci->dcbaa = NULL; in xhci_mem_cleanup()
1928 if (!xhci->rh_bw) in xhci_mem_cleanup()
1932 struct xhci_tt_bw_info *tt, *n; in xhci_mem_cleanup() local
1933 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) { in xhci_mem_cleanup()
1934 list_del(&tt->tt_list); in xhci_mem_cleanup()
1935 kfree(tt); in xhci_mem_cleanup()
1940 xhci->cmd_ring_reserved_trbs = 0; in xhci_mem_cleanup()
1941 xhci->usb2_rhub.num_ports = 0; in xhci_mem_cleanup()
1942 xhci->usb3_rhub.num_ports = 0; in xhci_mem_cleanup()
1943 xhci->num_active_eps = 0; in xhci_mem_cleanup()
1944 kfree(xhci->usb2_rhub.ports); in xhci_mem_cleanup()
1945 kfree(xhci->usb3_rhub.ports); in xhci_mem_cleanup()
1946 kfree(xhci->hw_ports); in xhci_mem_cleanup()
1947 kfree(xhci->rh_bw); in xhci_mem_cleanup()
1948 for (i = 0; i < xhci->num_port_caps; i++) in xhci_mem_cleanup()
1949 kfree(xhci->port_caps[i].psi); in xhci_mem_cleanup()
1950 kfree(xhci->port_caps); in xhci_mem_cleanup()
1951 kfree(xhci->interrupters); in xhci_mem_cleanup()
1952 xhci->num_port_caps = 0; in xhci_mem_cleanup()
1954 xhci->usb2_rhub.ports = NULL; in xhci_mem_cleanup()
1955 xhci->usb3_rhub.ports = NULL; in xhci_mem_cleanup()
1956 xhci->hw_ports = NULL; in xhci_mem_cleanup()
1957 xhci->rh_bw = NULL; in xhci_mem_cleanup()
1958 xhci->port_caps = NULL; in xhci_mem_cleanup()
1959 xhci->interrupters = NULL; in xhci_mem_cleanup()
1961 xhci->page_size = 0; in xhci_mem_cleanup()
1962 xhci->page_shift = 0; in xhci_mem_cleanup()
1963 xhci->usb2_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1964 xhci->usb3_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1971 deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, in xhci_set_hc_event_deq()
1972 ir->event_ring->dequeue); in xhci_set_hc_event_deq()
1981 xhci_write_64(xhci, deq & ERST_PTR_MASK, &ir->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
1991 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_add_in_port()
1999 rhub = &xhci->usb3_rhub; in xhci_add_in_port()
2001 * Some hosts incorrectly use sub-minor version for minor in xhci_add_in_port()
2013 if (xhci->quirks & XHCI_ZHAOXIN_HOST) { in xhci_add_in_port()
2019 rhub = &xhci->usb2_rhub; in xhci_add_in_port()
2035 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) in xhci_add_in_port()
2039 port_cap = &xhci->port_caps[xhci->num_port_caps++]; in xhci_add_in_port()
2040 if (xhci->num_port_caps > max_caps) in xhci_add_in_port()
2043 port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp); in xhci_add_in_port()
2045 if (port_cap->psi_count) { in xhci_add_in_port()
2046 port_cap->psi = kcalloc_node(port_cap->psi_count, in xhci_add_in_port()
2047 sizeof(*port_cap->psi), in xhci_add_in_port()
2049 if (!port_cap->psi) in xhci_add_in_port()
2050 port_cap->psi_count = 0; in xhci_add_in_port()
2052 port_cap->psi_uid_count++; in xhci_add_in_port()
2053 for (i = 0; i < port_cap->psi_count; i++) { in xhci_add_in_port()
2054 port_cap->psi[i] = readl(addr + 4 + i); in xhci_add_in_port()
2059 if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) != in xhci_add_in_port()
2060 XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1]))) in xhci_add_in_port()
2061 port_cap->psi_uid_count++; in xhci_add_in_port()
2063 if (xhci->quirks & XHCI_ZHAOXIN_HOST && in xhci_add_in_port()
2065 XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5) in xhci_add_in_port()
2069 XHCI_EXT_PORT_PSIV(port_cap->psi[i]), in xhci_add_in_port()
2070 XHCI_EXT_PORT_PSIE(port_cap->psi[i]), in xhci_add_in_port()
2071 XHCI_EXT_PORT_PLT(port_cap->psi[i]), in xhci_add_in_port()
2072 XHCI_EXT_PORT_PFD(port_cap->psi[i]), in xhci_add_in_port()
2073 XHCI_EXT_PORT_LP(port_cap->psi[i]), in xhci_add_in_port()
2074 XHCI_EXT_PORT_PSIM(port_cap->psi[i])); in xhci_add_in_port()
2078 rhub->maj_rev = major_revision; in xhci_add_in_port()
2080 if (rhub->min_rev < minor_revision) in xhci_add_in_port()
2081 rhub->min_rev = minor_revision; in xhci_add_in_port()
2083 port_cap->maj_rev = major_revision; in xhci_add_in_port()
2084 port_cap->min_rev = minor_revision; in xhci_add_in_port()
2085 port_cap->protocol_caps = temp; in xhci_add_in_port()
2087 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) && in xhci_add_in_port()
2091 xhci->hw_lpm_support = 1; in xhci_add_in_port()
2094 port_offset--; in xhci_add_in_port()
2096 struct xhci_port *hw_port = &xhci->hw_ports[i]; in xhci_add_in_port()
2098 if (hw_port->rhub) { in xhci_add_in_port()
2101 hw_port->rhub->maj_rev, major_revision); in xhci_add_in_port()
2105 if (hw_port->rhub != rhub && in xhci_add_in_port()
2106 hw_port->hcd_portnum != DUPLICATE_ENTRY) { in xhci_add_in_port()
2107 hw_port->rhub->num_ports--; in xhci_add_in_port()
2108 hw_port->hcd_portnum = DUPLICATE_ENTRY; in xhci_add_in_port()
2112 hw_port->rhub = rhub; in xhci_add_in_port()
2113 hw_port->port_cap = port_cap; in xhci_add_in_port()
2114 rhub->num_ports++; in xhci_add_in_port()
2124 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_create_rhub_port_array()
2126 if (!rhub->num_ports) in xhci_create_rhub_port_array()
2128 rhub->ports = kcalloc_node(rhub->num_ports, sizeof(*rhub->ports), in xhci_create_rhub_port_array()
2130 if (!rhub->ports) in xhci_create_rhub_port_array()
2133 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { in xhci_create_rhub_port_array()
2134 if (xhci->hw_ports[i].rhub != rhub || in xhci_create_rhub_port_array()
2135 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY) in xhci_create_rhub_port_array()
2137 xhci->hw_ports[i].hcd_portnum = port_index; in xhci_create_rhub_port_array()
2138 rhub->ports[port_index] = &xhci->hw_ports[i]; in xhci_create_rhub_port_array()
2140 if (port_index == rhub->num_ports) in xhci_create_rhub_port_array()
2160 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_setup_port_arrays()
2162 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_setup_port_arrays()
2163 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports), in xhci_setup_port_arrays()
2165 if (!xhci->hw_ports) in xhci_setup_port_arrays()
2166 return -ENOMEM; in xhci_setup_port_arrays()
2169 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base + in xhci_setup_port_arrays()
2171 xhci->hw_ports[i].hw_portnum = i; in xhci_setup_port_arrays()
2173 init_completion(&xhci->hw_ports[i].rexit_done); in xhci_setup_port_arrays()
2174 init_completion(&xhci->hw_ports[i].u3exit_done); in xhci_setup_port_arrays()
2177 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags, in xhci_setup_port_arrays()
2179 if (!xhci->rh_bw) in xhci_setup_port_arrays()
2180 return -ENOMEM; in xhci_setup_port_arrays()
2184 INIT_LIST_HEAD(&xhci->rh_bw[i].tts); in xhci_setup_port_arrays()
2185 bw_table = &xhci->rh_bw[i].bw_table; in xhci_setup_port_arrays()
2187 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_setup_port_arrays()
2189 base = &xhci->cap_regs->hc_capbase; in xhci_setup_port_arrays()
2194 return -ENODEV; in xhci_setup_port_arrays()
2205 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps), in xhci_setup_port_arrays()
2207 if (!xhci->port_caps) in xhci_setup_port_arrays()
2208 return -ENOMEM; in xhci_setup_port_arrays()
2214 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports == in xhci_setup_port_arrays()
2220 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) { in xhci_setup_port_arrays()
2222 return -ENODEV; in xhci_setup_port_arrays()
2226 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports); in xhci_setup_port_arrays()
2231 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) { in xhci_setup_port_arrays()
2235 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS; in xhci_setup_port_arrays()
2237 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) { in xhci_setup_port_arrays()
2241 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN; in xhci_setup_port_arrays()
2244 if (!xhci->usb2_rhub.num_ports) in xhci_setup_port_arrays()
2247 if (!xhci->usb3_rhub.num_ports) in xhci_setup_port_arrays()
2250 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags); in xhci_setup_port_arrays()
2251 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags); in xhci_setup_port_arrays()
2259 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_interrupter()
2267 max_segs = BIT(HCS_ERST_MAX(xhci->hcs_params2)); in xhci_alloc_interrupter()
2274 ir->event_ring = xhci_ring_alloc(xhci, segs, 1, TYPE_EVENT, 0, flags); in xhci_alloc_interrupter()
2275 if (!ir->event_ring) { in xhci_alloc_interrupter()
2281 ret = xhci_alloc_erst(xhci, ir->event_ring, &ir->erst, flags); in xhci_alloc_interrupter()
2284 xhci_ring_free(xhci, ir->event_ring); in xhci_alloc_interrupter()
2299 if (intr_num >= xhci->max_interrupters) { in xhci_add_interrupter()
2301 intr_num, xhci->max_interrupters); in xhci_add_interrupter()
2302 return -EINVAL; in xhci_add_interrupter()
2305 if (xhci->interrupters[intr_num]) { in xhci_add_interrupter()
2307 return -EINVAL; in xhci_add_interrupter()
2310 xhci->interrupters[intr_num] = ir; in xhci_add_interrupter()
2311 ir->intr_num = intr_num; in xhci_add_interrupter()
2312 ir->ir_set = &xhci->run_regs->ir_set[intr_num]; in xhci_add_interrupter()
2315 erst_size = readl(&ir->ir_set->erst_size); in xhci_add_interrupter()
2317 erst_size |= ir->event_ring->num_segs; in xhci_add_interrupter()
2318 writel(erst_size, &ir->ir_set->erst_size); in xhci_add_interrupter()
2320 erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_add_interrupter()
2322 erst_base |= ir->erst.erst_dma_addr & ~ERST_BASE_RSVDP; in xhci_add_interrupter()
2323 if (xhci->quirks & XHCI_WRITE_64_HI_LO) in xhci_add_interrupter()
2324 hi_lo_writeq(erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2326 xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2341 int err = -ENOSPC; in xhci_create_secondary_interrupter()
2343 if (!xhci->interrupters || xhci->max_interrupters <= 1) in xhci_create_secondary_interrupter()
2350 spin_lock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2353 for (i = 1; i < xhci->max_interrupters; i++) { in xhci_create_secondary_interrupter()
2354 if (xhci->interrupters[i] == NULL) { in xhci_create_secondary_interrupter()
2360 spin_unlock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2364 xhci->max_interrupters); in xhci_create_secondary_interrupter()
2375 i, xhci->max_interrupters); in xhci_create_secondary_interrupter()
2384 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_init()
2391 INIT_LIST_HEAD(&xhci->cmd_list); in xhci_mem_init()
2394 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); in xhci_mem_init()
2395 init_completion(&xhci->cmd_ring_stop_completion); in xhci_mem_init()
2397 page_size = readl(&xhci->op_regs->page_size); in xhci_mem_init()
2407 xhci->page_shift = 12; in xhci_mem_init()
2408 xhci->page_size = 1 << xhci->page_shift; in xhci_mem_init()
2410 "HCD page size set to %iK", xhci->page_size / 1024); in xhci_mem_init()
2416 val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1)); in xhci_mem_init()
2419 val2 = readl(&xhci->op_regs->config_reg); in xhci_mem_init()
2423 writel(val, &xhci->op_regs->config_reg); in xhci_mem_init()
2426 * xHCI section 5.4.6 - Device Context array must be in xhci_mem_init()
2427 * "physically contiguous and 64-byte (cache line) aligned". in xhci_mem_init()
2429 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, in xhci_mem_init()
2431 if (!xhci->dcbaa) in xhci_mem_init()
2433 xhci->dcbaa->dma = dma; in xhci_mem_init()
2436 &xhci->dcbaa->dma, xhci->dcbaa); in xhci_mem_init()
2437 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); in xhci_mem_init()
2442 * however, the command ring segment needs 64-byte aligned segments in xhci_mem_init()
2446 if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH) in xhci_mem_init()
2447 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2448 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2); in xhci_mem_init()
2450 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2451 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); in xhci_mem_init()
2454 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, in xhci_mem_init()
2455 2112, 64, xhci->page_size); in xhci_mem_init()
2456 if (!xhci->segment_pool || !xhci->device_pool) in xhci_mem_init()
2460 * and only need to be 16-byte aligned. in xhci_mem_init()
2462 xhci->small_streams_pool = in xhci_mem_init()
2465 xhci->medium_streams_pool = in xhci_mem_init()
2472 if (!xhci->small_streams_pool || !xhci->medium_streams_pool) in xhci_mem_init()
2476 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, 0, flags); in xhci_mem_init()
2477 if (!xhci->cmd_ring) in xhci_mem_init()
2480 "Allocated command ring at %p", xhci->cmd_ring); in xhci_mem_init()
2482 &xhci->cmd_ring->first_seg->dma); in xhci_mem_init()
2485 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2487 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | in xhci_mem_init()
2488 xhci->cmd_ring->cycle_state; in xhci_mem_init()
2491 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2497 xhci->cmd_ring_reserved_trbs++; in xhci_mem_init()
2499 val = readl(&xhci->cap_regs->db_off); in xhci_mem_init()
2504 xhci->dba = (void __iomem *) xhci->cap_regs + val; in xhci_mem_init()
2509 xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), in xhci_mem_init()
2519 ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; in xhci_mem_init()
2527 xhci->devs[i] = NULL; in xhci_mem_init()
2538 temp = readl(&xhci->op_regs->dev_notification); in xhci_mem_init()
2541 writel(temp, &xhci->op_regs->dev_notification); in xhci_mem_init()
2549 return -ENOMEM; in xhci_mem_init()