Lines Matching +full:additional +full:- +full:devs

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/dma-mapping.h>
19 #include "xhci-trace.h"
20 #include "xhci-debugfs.h"
36 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_segment_alloc()
42 seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma); in xhci_segment_alloc()
43 if (!seg->trbs) { in xhci_segment_alloc()
49 seg->bounce_buf = kzalloc_node(max_packet, flags, in xhci_segment_alloc()
51 if (!seg->bounce_buf) { in xhci_segment_alloc()
52 dma_pool_free(xhci->segment_pool, seg->trbs, dma); in xhci_segment_alloc()
57 seg->num = num; in xhci_segment_alloc()
58 seg->dma = dma; in xhci_segment_alloc()
59 seg->next = NULL; in xhci_segment_alloc()
66 if (seg->trbs) { in xhci_segment_free()
67 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma); in xhci_segment_free()
68 seg->trbs = NULL; in xhci_segment_free()
70 kfree(seg->bounce_buf); in xhci_segment_free()
78 ring->last_seg->next = NULL; in xhci_ring_segments_free()
79 seg = ring->first_seg; in xhci_ring_segments_free()
82 next = seg->next; in xhci_ring_segments_free()
101 if (!seg || !seg->next) in xhci_set_link_trb()
104 trb = &seg->trbs[TRBS_PER_SEGMENT - 1]; in xhci_set_link_trb()
107 val = le32_to_cpu(trb->link.control); in xhci_set_link_trb()
112 trb->link.control = cpu_to_le32(val); in xhci_set_link_trb()
113 trb->link.segment_ptr = cpu_to_le64(seg->next->dma); in xhci_set_link_trb()
121 if (ring->type == TYPE_EVENT) in xhci_initialize_ring_segments()
124 chain_links = xhci_link_chain_quirk(xhci, ring->type); in xhci_initialize_ring_segments()
125 xhci_for_each_ring_seg(ring->first_seg, seg) in xhci_initialize_ring_segments()
129 ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= cpu_to_le32(LINK_TOGGLE); in xhci_initialize_ring_segments()
145 if (dst->cycle_state == 0) { in xhci_link_rings()
146 xhci_for_each_ring_seg(src->first_seg, seg) { in xhci_link_rings()
148 seg->trbs[i].link.control |= cpu_to_le32(TRB_CYCLE); in xhci_link_rings()
152 src->last_seg->next = dst->enq_seg->next; in xhci_link_rings()
153 dst->enq_seg->next = src->first_seg; in xhci_link_rings()
154 if (dst->type != TYPE_EVENT) { in xhci_link_rings()
155 chain_links = xhci_link_chain_quirk(xhci, dst->type); in xhci_link_rings()
156 xhci_set_link_trb(dst->enq_seg, chain_links); in xhci_link_rings()
157 xhci_set_link_trb(src->last_seg, chain_links); in xhci_link_rings()
159 dst->num_segs += src->num_segs; in xhci_link_rings()
161 if (dst->enq_seg == dst->last_seg) { in xhci_link_rings()
162 if (dst->type != TYPE_EVENT) in xhci_link_rings()
163 dst->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control in xhci_link_rings()
166 dst->last_seg = src->last_seg; in xhci_link_rings()
167 } else if (dst->type != TYPE_EVENT) { in xhci_link_rings()
168 src->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control &= ~cpu_to_le32(LINK_TOGGLE); in xhci_link_rings()
171 for (seg = dst->enq_seg; seg != dst->last_seg; seg = seg->next) in xhci_link_rings()
172 seg->next->num = seg->num + 1; in xhci_link_rings()
198 * The radix tree uses an unsigned long as a key pair. On 32-bit systems, an
199 * unsigned long will be 32-bits; on a 64-bit system an unsigned long will be
200 * 64-bits. Since we only request 32-bit DMA addresses, we can use that as the
201 * key on 32-bit or 64-bit systems (it would also be fine if we asked for 64-bit
202 * PCI DMA addresses on a 64-bit system). There might be a problem on 32-bit
203 * extended systems (where the DMA address can be bigger than 32-bits),
204 * if we allow the PCI dma mask to be bigger than 32-bits. So don't do that.
214 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in xhci_insert_segment_mapping()
233 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in xhci_remove_segment_mapping()
275 if (WARN_ON_ONCE(ring->trb_address_map == NULL)) in xhci_remove_stream_mapping()
278 xhci_for_each_ring_seg(ring->first_seg, seg) in xhci_remove_stream_mapping()
279 xhci_remove_segment_mapping(ring->trb_address_map, seg); in xhci_remove_stream_mapping()
284 return xhci_update_stream_segment_mapping(ring->trb_address_map, ring, in xhci_update_stream_mapping()
285 ring->first_seg, mem_flags); in xhci_update_stream_mapping()
296 if (ring->first_seg) { in xhci_ring_free()
297 if (ring->type == TYPE_STREAM) in xhci_ring_free()
308 ring->enqueue = ring->first_seg->trbs; in xhci_initialize_ring_info()
309 ring->enq_seg = ring->first_seg; in xhci_initialize_ring_info()
310 ring->dequeue = ring->enqueue; in xhci_initialize_ring_info()
311 ring->deq_seg = ring->first_seg; in xhci_initialize_ring_info()
319 ring->cycle_state = 1; in xhci_initialize_ring_info()
325 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in xhci_initialize_ring_info()
335 prev = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags); in xhci_alloc_segments_for_ring()
337 return -ENOMEM; in xhci_alloc_segments_for_ring()
340 ring->first_seg = prev; in xhci_alloc_segments_for_ring()
341 while (num < ring->num_segs) { in xhci_alloc_segments_for_ring()
344 next = xhci_segment_alloc(xhci, ring->bounce_buf_len, num, flags); in xhci_alloc_segments_for_ring()
348 prev->next = next; in xhci_alloc_segments_for_ring()
352 ring->last_seg = prev; in xhci_alloc_segments_for_ring()
354 ring->last_seg->next = ring->first_seg; in xhci_alloc_segments_for_ring()
358 ring->last_seg = prev; in xhci_alloc_segments_for_ring()
360 return -ENOMEM; in xhci_alloc_segments_for_ring()
375 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_ring_alloc()
381 ring->num_segs = num_segs; in xhci_ring_alloc()
382 ring->bounce_buf_len = max_packet; in xhci_ring_alloc()
383 INIT_LIST_HEAD(&ring->td_list); in xhci_ring_alloc()
384 ring->type = type; in xhci_ring_alloc()
406 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring); in xhci_free_endpoint_ring()
407 virt_dev->eps[ep_index].ring = NULL; in xhci_free_endpoint_ring()
424 new_ring.bounce_buf_len = ring->bounce_buf_len; in xhci_ring_expansion()
425 new_ring.type = ring->type; in xhci_ring_expansion()
428 return -ENOMEM; in xhci_ring_expansion()
432 if (ring->type == TYPE_STREAM) { in xhci_ring_expansion()
433 ret = xhci_update_stream_segment_mapping(ring->trb_address_map, ring, in xhci_ring_expansion()
443 ring->num_segs); in xhci_ring_expansion()
456 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_container_ctx()
465 ctx->type = type; in xhci_alloc_container_ctx()
466 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024; in xhci_alloc_container_ctx()
468 ctx->size += CTX_SIZE(xhci->hcc_params); in xhci_alloc_container_ctx()
470 ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma); in xhci_alloc_container_ctx()
471 if (!ctx->bytes) { in xhci_alloc_container_ctx()
483 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma); in xhci_free_container_ctx()
490 if (ctx->type != XHCI_CTX_TYPE_INPUT) in xhci_get_input_control_ctx()
493 return (struct xhci_input_control_ctx *)ctx->bytes; in xhci_get_input_control_ctx()
499 if (ctx->type == XHCI_CTX_TYPE_DEVICE) in xhci_get_slot_ctx()
500 return (struct xhci_slot_ctx *)ctx->bytes; in xhci_get_slot_ctx()
503 (ctx->bytes + CTX_SIZE(xhci->hcc_params)); in xhci_get_slot_ctx()
512 if (ctx->type == XHCI_CTX_TYPE_INPUT) in xhci_get_ep_ctx()
516 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); in xhci_get_ep_ctx()
526 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_stream_ctx()
532 dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
534 dma_pool_free(xhci->small_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
540 * - how many streams the endpoint supports,
541 * - the maximum primary stream array size the host controller supports,
542 * - and how many streams the device driver asks for.
551 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_ctx()
557 return dma_pool_zalloc(xhci->medium_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
559 return dma_pool_zalloc(xhci->small_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
566 if (ep->ep_state & EP_HAS_STREAMS) in xhci_dma_to_transfer_ring()
567 return radix_tree_lookup(&ep->stream_info->trb_address_map, in xhci_dma_to_transfer_ring()
569 return ep->ring; in xhci_dma_to_transfer_ring()
591 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_info()
595 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) { in xhci_alloc_stream_info()
599 xhci->cmd_ring_reserved_trbs++; in xhci_alloc_stream_info()
606 stream_info->num_streams = num_streams; in xhci_alloc_stream_info()
607 stream_info->num_stream_ctxs = num_stream_ctxs; in xhci_alloc_stream_info()
610 stream_info->stream_rings = kcalloc_node( in xhci_alloc_stream_info()
613 if (!stream_info->stream_rings) in xhci_alloc_stream_info()
617 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci, in xhci_alloc_stream_info()
618 num_stream_ctxs, &stream_info->ctx_array_dma, in xhci_alloc_stream_info()
620 if (!stream_info->stream_ctx_array) in xhci_alloc_stream_info()
624 stream_info->free_streams_command = in xhci_alloc_stream_info()
626 if (!stream_info->free_streams_command) in xhci_alloc_stream_info()
629 INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC); in xhci_alloc_stream_info()
637 stream_info->stream_rings[cur_stream] = in xhci_alloc_stream_info()
639 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
642 cur_ring->stream_id = cur_stream; in xhci_alloc_stream_info()
643 cur_ring->trb_address_map = &stream_info->trb_address_map; in xhci_alloc_stream_info()
645 addr = cur_ring->first_seg->dma | in xhci_alloc_stream_info()
647 cur_ring->cycle_state; in xhci_alloc_stream_info()
648 stream_info->stream_ctx_array[cur_stream].stream_ring = in xhci_alloc_stream_info()
657 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
672 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
675 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
678 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_alloc_stream_info()
681 stream_info->num_stream_ctxs, in xhci_alloc_stream_info()
682 stream_info->stream_ctx_array, in xhci_alloc_stream_info()
683 stream_info->ctx_array_dma); in xhci_alloc_stream_info()
685 kfree(stream_info->stream_rings); in xhci_alloc_stream_info()
689 xhci->cmd_ring_reserved_trbs--; in xhci_alloc_stream_info()
705 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; in xhci_setup_streams_ep_input_ctx()
709 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK); in xhci_setup_streams_ep_input_ctx()
710 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams) in xhci_setup_streams_ep_input_ctx()
712 ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma); in xhci_setup_streams_ep_input_ctx()
724 ep_ctx->ep_info &= cpu_to_le32(~(EP_MAXPSTREAMS_MASK | EP_HAS_LSA)); in xhci_setup_no_streams_ep_input_ctx()
725 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue); in xhci_setup_no_streams_ep_input_ctx()
726 ep_ctx->deq = cpu_to_le64(addr | ep->ring->cycle_state); in xhci_setup_no_streams_ep_input_ctx()
742 for (cur_stream = 1; cur_stream < stream_info->num_streams; in xhci_free_stream_info()
744 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_free_stream_info()
747 stream_info->stream_rings[cur_stream] = NULL; in xhci_free_stream_info()
750 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_free_stream_info()
751 xhci->cmd_ring_reserved_trbs--; in xhci_free_stream_info()
752 if (stream_info->stream_ctx_array) in xhci_free_stream_info()
754 stream_info->num_stream_ctxs, in xhci_free_stream_info()
755 stream_info->stream_ctx_array, in xhci_free_stream_info()
756 stream_info->ctx_array_dma); in xhci_free_stream_info()
758 kfree(stream_info->stream_rings); in xhci_free_stream_info()
776 if (!virt_dev->rhub_port) { in xhci_free_tt_info()
781 tt_list_head = &(xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_free_tt_info()
783 /* Multi-TT hubs will have more than one entry */ in xhci_free_tt_info()
784 if (tt_info->slot_id == slot_id) { in xhci_free_tt_info()
786 list_del(&tt_info->tt_list); in xhci_free_tt_info()
802 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_tt_info()
804 if (!tt->multi) in xhci_alloc_tt_info()
807 num_ports = hdev->maxchild; in xhci_alloc_tt_info()
816 INIT_LIST_HEAD(&tt_info->tt_list); in xhci_alloc_tt_info()
817 list_add(&tt_info->tt_list, in xhci_alloc_tt_info()
818 &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_alloc_tt_info()
819 tt_info->slot_id = virt_dev->udev->slot_id; in xhci_alloc_tt_info()
820 if (tt->multi) in xhci_alloc_tt_info()
821 tt_info->ttport = i+1; in xhci_alloc_tt_info()
822 bw_table = &tt_info->bw_table; in xhci_alloc_tt_info()
824 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_alloc_tt_info()
829 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id); in xhci_alloc_tt_info()
830 return -ENOMEM; in xhci_alloc_tt_info()
835 * Should be called with xhci->lock held if there is any chance the TT lists
846 if (slot_id == 0 || !xhci->devs[slot_id]) in xhci_free_virt_device()
849 dev = xhci->devs[slot_id]; in xhci_free_virt_device()
851 xhci->dcbaa->dev_context_ptrs[slot_id] = 0; in xhci_free_virt_device()
857 if (dev->tt_info) in xhci_free_virt_device()
858 old_active_eps = dev->tt_info->active_eps; in xhci_free_virt_device()
861 if (dev->eps[i].ring) in xhci_free_virt_device()
862 xhci_ring_free(xhci, dev->eps[i].ring); in xhci_free_virt_device()
863 if (dev->eps[i].stream_info) in xhci_free_virt_device()
865 dev->eps[i].stream_info); in xhci_free_virt_device()
874 if (!list_empty(&dev->eps[i].bw_endpoint_list)) { in xhci_free_virt_device()
875 list_del_init(&dev->eps[i].bw_endpoint_list); in xhci_free_virt_device()
885 if (dev->in_ctx) in xhci_free_virt_device()
886 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_free_virt_device()
887 if (dev->out_ctx) in xhci_free_virt_device()
888 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_free_virt_device()
890 if (dev->udev && dev->udev->slot_id) in xhci_free_virt_device()
891 dev->udev->slot_id = 0; in xhci_free_virt_device()
892 if (dev->rhub_port && dev->rhub_port->slot_id == slot_id) in xhci_free_virt_device()
893 dev->rhub_port->slot_id = 0; in xhci_free_virt_device()
894 kfree(xhci->devs[slot_id]); in xhci_free_virt_device()
895 xhci->devs[slot_id] = NULL; in xhci_free_virt_device()
902 * We can't rely on udev at this point to find child-parent relationships.
911 vdev = xhci->devs[slot_id]; in xhci_free_virt_devices_depth_first()
915 if (!vdev->rhub_port) { in xhci_free_virt_devices_depth_first()
920 tt_list_head = &(xhci->rh_bw[vdev->rhub_port->hw_portnum].tts); in xhci_free_virt_devices_depth_first()
923 if (tt_info->slot_id == slot_id) { in xhci_free_virt_devices_depth_first()
925 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_free_virt_devices_depth_first()
926 vdev = xhci->devs[i]; in xhci_free_virt_devices_depth_first()
927 if (vdev && (vdev->tt_info == tt_info)) in xhci_free_virt_devices_depth_first()
946 if (slot_id == 0 || xhci->devs[slot_id]) { in xhci_alloc_virt_device()
955 dev->slot_id = slot_id; in xhci_alloc_virt_device()
958 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); in xhci_alloc_virt_device()
959 if (!dev->out_ctx) in xhci_alloc_virt_device()
962 xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma); in xhci_alloc_virt_device()
965 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags); in xhci_alloc_virt_device()
966 if (!dev->in_ctx) in xhci_alloc_virt_device()
969 xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma); in xhci_alloc_virt_device()
973 dev->eps[i].ep_index = i; in xhci_alloc_virt_device()
974 dev->eps[i].vdev = dev; in xhci_alloc_virt_device()
975 dev->eps[i].xhci = xhci; in xhci_alloc_virt_device()
976 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); in xhci_alloc_virt_device()
977 INIT_LIST_HEAD(&dev->eps[i].bw_endpoint_list); in xhci_alloc_virt_device()
981 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, TYPE_CTRL, 0, flags); in xhci_alloc_virt_device()
982 if (!dev->eps[0].ring) in xhci_alloc_virt_device()
985 dev->udev = udev; in xhci_alloc_virt_device()
988 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma); in xhci_alloc_virt_device()
991 &xhci->dcbaa->dev_context_ptrs[slot_id], in xhci_alloc_virt_device()
992 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id])); in xhci_alloc_virt_device()
996 xhci->devs[slot_id] = dev; in xhci_alloc_virt_device()
1001 if (dev->in_ctx) in xhci_alloc_virt_device()
1002 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_alloc_virt_device()
1003 if (dev->out_ctx) in xhci_alloc_virt_device()
1004 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_alloc_virt_device()
1017 virt_dev = xhci->devs[udev->slot_id]; in xhci_copy_ep0_dequeue_into_input_ctx()
1018 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0); in xhci_copy_ep0_dequeue_into_input_ctx()
1019 ep_ring = virt_dev->eps[0].ring; in xhci_copy_ep0_dequeue_into_input_ctx()
1027 ep0_ctx->deq = cpu_to_le64(xhci_trb_virt_to_dma(ep_ring->enq_seg, in xhci_copy_ep0_dequeue_into_input_ctx()
1028 ep_ring->enqueue) in xhci_copy_ep0_dequeue_into_input_ctx()
1029 | ep_ring->cycle_state); in xhci_copy_ep0_dequeue_into_input_ctx()
1048 if (udev->speed >= USB_SPEED_SUPER) in xhci_find_rhub_port()
1051 hcd = xhci->main_hcd; in xhci_find_rhub_port()
1053 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; in xhci_find_rhub_port()
1054 top_dev = top_dev->parent) in xhci_find_rhub_port()
1058 return rhub->ports[top_dev->portnum - 1]; in xhci_find_rhub_port()
1069 dev = xhci->devs[udev->slot_id]; in xhci_setup_addressable_virt_dev()
1071 if (udev->slot_id == 0 || !dev) { in xhci_setup_addressable_virt_dev()
1073 udev->slot_id); in xhci_setup_addressable_virt_dev()
1074 return -EINVAL; in xhci_setup_addressable_virt_dev()
1076 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); in xhci_setup_addressable_virt_dev()
1077 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); in xhci_setup_addressable_virt_dev()
1079 /* 3) Only the control endpoint is valid - one endpoint context */ in xhci_setup_addressable_virt_dev()
1080 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); in xhci_setup_addressable_virt_dev()
1081 switch (udev->speed) { in xhci_setup_addressable_virt_dev()
1083 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SSP); in xhci_setup_addressable_virt_dev()
1087 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS); in xhci_setup_addressable_virt_dev()
1091 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS); in xhci_setup_addressable_virt_dev()
1094 /* USB core guesses at a 64-byte max packet first for FS devices */ in xhci_setup_addressable_virt_dev()
1096 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS); in xhci_setup_addressable_virt_dev()
1100 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS); in xhci_setup_addressable_virt_dev()
1105 return -EINVAL; in xhci_setup_addressable_virt_dev()
1108 dev->rhub_port = xhci_find_rhub_port(xhci, udev); in xhci_setup_addressable_virt_dev()
1109 if (!dev->rhub_port) in xhci_setup_addressable_virt_dev()
1110 return -EINVAL; in xhci_setup_addressable_virt_dev()
1112 if (!udev->parent->parent) in xhci_setup_addressable_virt_dev()
1113 dev->rhub_port->slot_id = udev->slot_id; in xhci_setup_addressable_virt_dev()
1114 slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(dev->rhub_port->hw_portnum + 1)); in xhci_setup_addressable_virt_dev()
1116 udev->slot_id, dev->rhub_port->hw_portnum, dev->rhub_port->hcd_portnum); in xhci_setup_addressable_virt_dev()
1124 if (!udev->tt || !udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1125 dev->bw_table = &xhci->rh_bw[dev->rhub_port->hw_portnum].bw_table; in xhci_setup_addressable_virt_dev()
1130 rh_bw = &xhci->rh_bw[dev->rhub_port->hw_portnum]; in xhci_setup_addressable_virt_dev()
1132 list_for_each_entry(tt_bw, &rh_bw->tts, tt_list) { in xhci_setup_addressable_virt_dev()
1133 if (tt_bw->slot_id != udev->tt->hub->slot_id) in xhci_setup_addressable_virt_dev()
1136 if (!dev->udev->tt->multi || in xhci_setup_addressable_virt_dev()
1137 (udev->tt->multi && in xhci_setup_addressable_virt_dev()
1138 tt_bw->ttport == dev->udev->ttport)) { in xhci_setup_addressable_virt_dev()
1139 dev->bw_table = &tt_bw->bw_table; in xhci_setup_addressable_virt_dev()
1140 dev->tt_info = tt_bw; in xhci_setup_addressable_virt_dev()
1144 if (!dev->tt_info) in xhci_setup_addressable_virt_dev()
1149 if (udev->tt && udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1150 slot_ctx->tt_info = cpu_to_le32(udev->tt->hub->slot_id | in xhci_setup_addressable_virt_dev()
1151 (udev->ttport << 8)); in xhci_setup_addressable_virt_dev()
1152 if (udev->tt->multi) in xhci_setup_addressable_virt_dev()
1153 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_setup_addressable_virt_dev()
1155 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); in xhci_setup_addressable_virt_dev()
1156 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); in xhci_setup_addressable_virt_dev()
1158 /* Step 4 - ring already allocated */ in xhci_setup_addressable_virt_dev()
1160 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP)); in xhci_setup_addressable_virt_dev()
1163 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) | in xhci_setup_addressable_virt_dev()
1166 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma | in xhci_setup_addressable_virt_dev()
1167 dev->eps[0].ring->cycle_state); in xhci_setup_addressable_virt_dev()
1177 * Convert interval expressed as 2^(bInterval - 1) == interval into
1186 interval = clamp_val(ep->desc.bInterval, 1, 16) - 1; in xhci_parse_exponent_interval()
1187 if (interval != ep->desc.bInterval - 1) in xhci_parse_exponent_interval()
1188 dev_warn(&udev->dev, in xhci_parse_exponent_interval()
1189 "ep %#x - rounding interval to %d %sframes\n", in xhci_parse_exponent_interval()
1190 ep->desc.bEndpointAddress, in xhci_parse_exponent_interval()
1192 udev->speed == USB_SPEED_FULL ? "" : "micro"); in xhci_parse_exponent_interval()
1194 if (udev->speed == USB_SPEED_FULL) { in xhci_parse_exponent_interval()
1207 * Convert bInterval expressed in microframes (in 1-255 range) to exponent of
1216 interval = fls(desc_interval) - 1; in xhci_microframes_to_exponent()
1219 dev_dbg(&udev->dev, in xhci_microframes_to_exponent()
1220 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n", in xhci_microframes_to_exponent()
1221 ep->desc.bEndpointAddress, in xhci_microframes_to_exponent()
1231 if (ep->desc.bInterval == 0) in xhci_parse_microframe_interval()
1234 ep->desc.bInterval, 0, 15); in xhci_parse_microframe_interval()
1242 ep->desc.bInterval * 8, 3, 10); in xhci_parse_frame_interval()
1258 switch (udev->speed) { in xhci_get_endpoint_interval()
1261 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_endpoint_interval()
1262 usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_get_endpoint_interval()
1270 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1271 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1277 if (usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1289 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1290 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1303 * High speed endpoint descriptors can define "the number of additional
1310 if (udev->speed < USB_SPEED_SUPER || in xhci_get_endpoint_mult()
1311 !usb_endpoint_xfer_isoc(&ep->desc)) in xhci_get_endpoint_mult()
1313 return ep->ss_ep_comp.bmAttributes; in xhci_get_endpoint_mult()
1320 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_endpoint_max_burst()
1321 return ep->ss_ep_comp.bMaxBurst; in xhci_get_endpoint_max_burst()
1323 if (udev->speed == USB_SPEED_HIGH && in xhci_get_endpoint_max_burst()
1324 (usb_endpoint_xfer_isoc(&ep->desc) || in xhci_get_endpoint_max_burst()
1325 usb_endpoint_xfer_int(&ep->desc))) in xhci_get_endpoint_max_burst()
1326 return usb_endpoint_maxp_mult(&ep->desc) - 1; in xhci_get_endpoint_max_burst()
1335 in = usb_endpoint_dir_in(&ep->desc); in xhci_get_endpoint_type()
1337 switch (usb_endpoint_type(&ep->desc)) { in xhci_get_endpoint_type()
1361 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_max_esit_payload()
1362 usb_endpoint_xfer_bulk(&ep->desc)) in xhci_get_max_esit_payload()
1366 if ((udev->speed >= USB_SPEED_SUPER_PLUS) && in xhci_get_max_esit_payload()
1367 USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) in xhci_get_max_esit_payload()
1368 return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); in xhci_get_max_esit_payload()
1371 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_max_esit_payload()
1372 return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); in xhci_get_max_esit_payload()
1374 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_get_max_esit_payload()
1375 max_burst = usb_endpoint_maxp_mult(&ep->desc); in xhci_get_max_esit_payload()
1402 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_init()
1403 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_init()
1407 return -EINVAL; in xhci_endpoint_init()
1409 ring_type = usb_endpoint_type(&ep->desc); in xhci_endpoint_init()
1421 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_endpoint_init()
1422 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_endpoint_init()
1423 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) && in xhci_endpoint_init()
1424 udev->speed >= USB_SPEED_HIGH && in xhci_endpoint_init()
1431 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_endpoint_init()
1438 if (!usb_endpoint_xfer_isoc(&ep->desc)) in xhci_endpoint_init()
1441 if (usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_endpoint_init()
1442 if (udev->speed == USB_SPEED_HIGH) in xhci_endpoint_init()
1444 if (udev->speed == USB_SPEED_FULL) { in xhci_endpoint_init()
1450 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) in xhci_endpoint_init()
1453 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) in xhci_endpoint_init()
1457 virt_dev->eps[ep_index].new_ring = in xhci_endpoint_init()
1459 if (!virt_dev->eps[ep_index].new_ring) in xhci_endpoint_init()
1460 return -ENOMEM; in xhci_endpoint_init()
1462 virt_dev->eps[ep_index].skip = false; in xhci_endpoint_init()
1463 ep_ring = virt_dev->eps[ep_index].new_ring; in xhci_endpoint_init()
1466 ep_ctx->ep_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) | in xhci_endpoint_init()
1469 ep_ctx->ep_info2 = cpu_to_le32(EP_TYPE(endpoint_type) | in xhci_endpoint_init()
1473 ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma | in xhci_endpoint_init()
1474 ep_ring->cycle_state); in xhci_endpoint_init()
1476 ep_ctx->tx_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) | in xhci_endpoint_init()
1489 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_zero()
1490 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_zero()
1492 ep_ctx->ep_info = 0; in xhci_endpoint_zero()
1493 ep_ctx->ep_info2 = 0; in xhci_endpoint_zero()
1494 ep_ctx->deq = 0; in xhci_endpoint_zero()
1495 ep_ctx->tx_info = 0; in xhci_endpoint_zero()
1503 bw_info->ep_interval = 0; in xhci_clear_endpoint_bw_info()
1504 bw_info->mult = 0; in xhci_clear_endpoint_bw_info()
1505 bw_info->num_packets = 0; in xhci_clear_endpoint_bw_info()
1506 bw_info->max_packet_size = 0; in xhci_clear_endpoint_bw_info()
1507 bw_info->type = 0; in xhci_clear_endpoint_bw_info()
1508 bw_info->max_esit_payload = 0; in xhci_clear_endpoint_bw_info()
1522 bw_info = &virt_dev->eps[i].bw_info; in xhci_update_bw_info()
1525 * unconditionally clearing the bandwidth info for non-periodic in xhci_update_bw_info()
1537 ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1539 /* Ignore non-periodic endpoints */ in xhci_update_bw_info()
1546 bw_info->ep_interval = CTX_TO_EP_INTERVAL( in xhci_update_bw_info()
1547 le32_to_cpu(ep_ctx->ep_info)); in xhci_update_bw_info()
1548 /* Number of packets and mult are zero-based in the in xhci_update_bw_info()
1549 * input context, but we want one-based for the in xhci_update_bw_info()
1552 bw_info->mult = CTX_TO_EP_MULT( in xhci_update_bw_info()
1553 le32_to_cpu(ep_ctx->ep_info)) + 1; in xhci_update_bw_info()
1554 bw_info->num_packets = CTX_TO_MAX_BURST( in xhci_update_bw_info()
1555 le32_to_cpu(ep_ctx->ep_info2)) + 1; in xhci_update_bw_info()
1556 bw_info->max_packet_size = MAX_PACKET_DECODED( in xhci_update_bw_info()
1557 le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1558 bw_info->type = ep_type; in xhci_update_bw_info()
1559 bw_info->max_esit_payload = CTX_TO_MAX_ESIT_PAYLOAD( in xhci_update_bw_info()
1560 le32_to_cpu(ep_ctx->tx_info)); in xhci_update_bw_info()
1580 in_ep_ctx->ep_info = out_ep_ctx->ep_info; in xhci_endpoint_copy()
1581 in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2; in xhci_endpoint_copy()
1582 in_ep_ctx->deq = out_ep_ctx->deq; in xhci_endpoint_copy()
1583 in_ep_ctx->tx_info = out_ep_ctx->tx_info; in xhci_endpoint_copy()
1584 if (xhci->quirks & XHCI_MTK_HOST) { in xhci_endpoint_copy()
1585 in_ep_ctx->reserved[0] = out_ep_ctx->reserved[0]; in xhci_endpoint_copy()
1586 in_ep_ctx->reserved[1] = out_ep_ctx->reserved[1]; in xhci_endpoint_copy()
1605 in_slot_ctx->dev_info = out_slot_ctx->dev_info; in xhci_slot_copy()
1606 in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2; in xhci_slot_copy()
1607 in_slot_ctx->tt_info = out_slot_ctx->tt_info; in xhci_slot_copy()
1608 in_slot_ctx->dev_state = out_slot_ctx->dev_state; in xhci_slot_copy()
1615 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_alloc()
1616 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_alloc()
1624 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags, in scratchpad_alloc()
1626 if (!xhci->scratchpad) in scratchpad_alloc()
1629 xhci->scratchpad->sp_array = dma_alloc_coherent(dev, in scratchpad_alloc()
1631 &xhci->scratchpad->sp_dma, flags); in scratchpad_alloc()
1632 if (!xhci->scratchpad->sp_array) in scratchpad_alloc()
1635 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *), in scratchpad_alloc()
1637 if (!xhci->scratchpad->sp_buffers) in scratchpad_alloc()
1640 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); in scratchpad_alloc()
1643 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma, in scratchpad_alloc()
1648 xhci->scratchpad->sp_array[i] = dma; in scratchpad_alloc()
1649 xhci->scratchpad->sp_buffers[i] = buf; in scratchpad_alloc()
1655 while (i--) in scratchpad_alloc()
1656 dma_free_coherent(dev, xhci->page_size, in scratchpad_alloc()
1657 xhci->scratchpad->sp_buffers[i], in scratchpad_alloc()
1658 xhci->scratchpad->sp_array[i]); in scratchpad_alloc()
1660 kfree(xhci->scratchpad->sp_buffers); in scratchpad_alloc()
1664 xhci->scratchpad->sp_array, in scratchpad_alloc()
1665 xhci->scratchpad->sp_dma); in scratchpad_alloc()
1668 kfree(xhci->scratchpad); in scratchpad_alloc()
1669 xhci->scratchpad = NULL; in scratchpad_alloc()
1672 return -ENOMEM; in scratchpad_alloc()
1679 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_free()
1681 if (!xhci->scratchpad) in scratchpad_free()
1684 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_free()
1687 dma_free_coherent(dev, xhci->page_size, in scratchpad_free()
1688 xhci->scratchpad->sp_buffers[i], in scratchpad_free()
1689 xhci->scratchpad->sp_array[i]); in scratchpad_free()
1691 kfree(xhci->scratchpad->sp_buffers); in scratchpad_free()
1693 xhci->scratchpad->sp_array, in scratchpad_free()
1694 xhci->scratchpad->sp_dma); in scratchpad_free()
1695 kfree(xhci->scratchpad); in scratchpad_free()
1696 xhci->scratchpad = NULL; in scratchpad_free()
1703 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_command()
1710 command->completion = in xhci_alloc_command()
1713 if (!command->completion) { in xhci_alloc_command()
1717 init_completion(command->completion); in xhci_alloc_command()
1720 command->status = 0; in xhci_alloc_command()
1722 command->timeout_ms = XHCI_CMD_DEFAULT_TIMEOUT; in xhci_alloc_command()
1723 INIT_LIST_HEAD(&command->cmd_list); in xhci_alloc_command()
1736 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, in xhci_alloc_command_with_ctx()
1738 if (!command->in_ctx) { in xhci_alloc_command_with_ctx()
1739 kfree(command->completion); in xhci_alloc_command_with_ctx()
1755 command->in_ctx); in xhci_free_command()
1756 kfree(command->completion); in xhci_free_command()
1770 size = array_size(sizeof(struct xhci_erst_entry), evt_ring->num_segs); in xhci_alloc_erst()
1771 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev, in xhci_alloc_erst()
1772 size, &erst->erst_dma_addr, flags); in xhci_alloc_erst()
1773 if (!erst->entries) in xhci_alloc_erst()
1774 return -ENOMEM; in xhci_alloc_erst()
1776 erst->num_entries = evt_ring->num_segs; in xhci_alloc_erst()
1778 seg = evt_ring->first_seg; in xhci_alloc_erst()
1779 for (val = 0; val < evt_ring->num_segs; val++) { in xhci_alloc_erst()
1780 entry = &erst->entries[val]; in xhci_alloc_erst()
1781 entry->seg_addr = cpu_to_le64(seg->dma); in xhci_alloc_erst()
1782 entry->seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in xhci_alloc_erst()
1783 entry->rsvd = 0; in xhci_alloc_erst()
1784 seg = seg->next; in xhci_alloc_erst()
1803 if (ir->ir_set) { in xhci_remove_interrupter()
1804 tmp = readl(&ir->ir_set->erst_size); in xhci_remove_interrupter()
1806 writel(tmp, &ir->ir_set->erst_size); in xhci_remove_interrupter()
1808 xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue); in xhci_remove_interrupter()
1815 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_interrupter()
1821 erst_size = array_size(sizeof(struct xhci_erst_entry), ir->erst.num_entries); in xhci_free_interrupter()
1822 if (ir->erst.entries) in xhci_free_interrupter()
1824 ir->erst.entries, in xhci_free_interrupter()
1825 ir->erst.erst_dma_addr); in xhci_free_interrupter()
1826 ir->erst.entries = NULL; in xhci_free_interrupter()
1829 if (ir->event_ring) in xhci_free_interrupter()
1830 xhci_ring_free(xhci, ir->event_ring); in xhci_free_interrupter()
1832 ir->event_ring = NULL; in xhci_free_interrupter()
1842 spin_lock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1845 if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) { in xhci_remove_secondary_interrupter()
1847 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1851 intr_num = ir->intr_num; in xhci_remove_secondary_interrupter()
1854 xhci->interrupters[intr_num] = NULL; in xhci_remove_secondary_interrupter()
1856 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1864 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_cleanup()
1867 cancel_delayed_work_sync(&xhci->cmd_timer); in xhci_mem_cleanup()
1869 for (i = 0; xhci->interrupters && i < xhci->max_interrupters; i++) { in xhci_mem_cleanup()
1870 if (xhci->interrupters[i]) { in xhci_mem_cleanup()
1871 xhci_remove_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1872 xhci_free_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1873 xhci->interrupters[i] = NULL; in xhci_mem_cleanup()
1878 if (xhci->cmd_ring) in xhci_mem_cleanup()
1879 xhci_ring_free(xhci, xhci->cmd_ring); in xhci_mem_cleanup()
1880 xhci->cmd_ring = NULL; in xhci_mem_cleanup()
1884 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_mem_cleanup()
1885 for (i = 0; i < num_ports && xhci->rh_bw; i++) { in xhci_mem_cleanup()
1886 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table; in xhci_mem_cleanup()
1888 struct list_head *ep = &bwt->interval_bw[j].endpoints; in xhci_mem_cleanup()
1890 list_del_init(ep->next); in xhci_mem_cleanup()
1894 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--) in xhci_mem_cleanup()
1897 dma_pool_destroy(xhci->segment_pool); in xhci_mem_cleanup()
1898 xhci->segment_pool = NULL; in xhci_mem_cleanup()
1901 dma_pool_destroy(xhci->device_pool); in xhci_mem_cleanup()
1902 xhci->device_pool = NULL; in xhci_mem_cleanup()
1905 dma_pool_destroy(xhci->small_streams_pool); in xhci_mem_cleanup()
1906 xhci->small_streams_pool = NULL; in xhci_mem_cleanup()
1910 dma_pool_destroy(xhci->medium_streams_pool); in xhci_mem_cleanup()
1911 xhci->medium_streams_pool = NULL; in xhci_mem_cleanup()
1915 if (xhci->dcbaa) in xhci_mem_cleanup()
1916 dma_free_coherent(dev, sizeof(*xhci->dcbaa), in xhci_mem_cleanup()
1917 xhci->dcbaa, xhci->dcbaa->dma); in xhci_mem_cleanup()
1918 xhci->dcbaa = NULL; in xhci_mem_cleanup()
1922 if (!xhci->rh_bw) in xhci_mem_cleanup()
1927 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) { in xhci_mem_cleanup()
1928 list_del(&tt->tt_list); in xhci_mem_cleanup()
1934 xhci->cmd_ring_reserved_trbs = 0; in xhci_mem_cleanup()
1935 xhci->usb2_rhub.num_ports = 0; in xhci_mem_cleanup()
1936 xhci->usb3_rhub.num_ports = 0; in xhci_mem_cleanup()
1937 xhci->num_active_eps = 0; in xhci_mem_cleanup()
1938 kfree(xhci->usb2_rhub.ports); in xhci_mem_cleanup()
1939 kfree(xhci->usb3_rhub.ports); in xhci_mem_cleanup()
1940 kfree(xhci->hw_ports); in xhci_mem_cleanup()
1941 kfree(xhci->rh_bw); in xhci_mem_cleanup()
1942 for (i = 0; i < xhci->num_port_caps; i++) in xhci_mem_cleanup()
1943 kfree(xhci->port_caps[i].psi); in xhci_mem_cleanup()
1944 kfree(xhci->port_caps); in xhci_mem_cleanup()
1945 kfree(xhci->interrupters); in xhci_mem_cleanup()
1946 xhci->num_port_caps = 0; in xhci_mem_cleanup()
1948 xhci->usb2_rhub.ports = NULL; in xhci_mem_cleanup()
1949 xhci->usb3_rhub.ports = NULL; in xhci_mem_cleanup()
1950 xhci->hw_ports = NULL; in xhci_mem_cleanup()
1951 xhci->rh_bw = NULL; in xhci_mem_cleanup()
1952 xhci->port_caps = NULL; in xhci_mem_cleanup()
1953 xhci->interrupters = NULL; in xhci_mem_cleanup()
1955 xhci->page_size = 0; in xhci_mem_cleanup()
1956 xhci->page_shift = 0; in xhci_mem_cleanup()
1957 xhci->usb2_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1958 xhci->usb3_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1965 deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, in xhci_set_hc_event_deq()
1966 ir->event_ring->dequeue); in xhci_set_hc_event_deq()
1975 xhci_write_64(xhci, deq & ERST_PTR_MASK, &ir->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
1985 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_add_in_port()
1993 rhub = &xhci->usb3_rhub; in xhci_add_in_port()
1995 * Some hosts incorrectly use sub-minor version for minor in xhci_add_in_port()
2007 if (xhci->quirks & XHCI_ZHAOXIN_HOST) { in xhci_add_in_port()
2013 rhub = &xhci->usb2_rhub; in xhci_add_in_port()
2029 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) in xhci_add_in_port()
2033 port_cap = &xhci->port_caps[xhci->num_port_caps++]; in xhci_add_in_port()
2034 if (xhci->num_port_caps > max_caps) in xhci_add_in_port()
2037 port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp); in xhci_add_in_port()
2039 if (port_cap->psi_count) { in xhci_add_in_port()
2040 port_cap->psi = kcalloc_node(port_cap->psi_count, in xhci_add_in_port()
2041 sizeof(*port_cap->psi), in xhci_add_in_port()
2043 if (!port_cap->psi) in xhci_add_in_port()
2044 port_cap->psi_count = 0; in xhci_add_in_port()
2046 port_cap->psi_uid_count++; in xhci_add_in_port()
2047 for (i = 0; i < port_cap->psi_count; i++) { in xhci_add_in_port()
2048 port_cap->psi[i] = readl(addr + 4 + i); in xhci_add_in_port()
2053 if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) != in xhci_add_in_port()
2054 XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1]))) in xhci_add_in_port()
2055 port_cap->psi_uid_count++; in xhci_add_in_port()
2057 if (xhci->quirks & XHCI_ZHAOXIN_HOST && in xhci_add_in_port()
2059 XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5) in xhci_add_in_port()
2063 XHCI_EXT_PORT_PSIV(port_cap->psi[i]), in xhci_add_in_port()
2064 XHCI_EXT_PORT_PSIE(port_cap->psi[i]), in xhci_add_in_port()
2065 XHCI_EXT_PORT_PLT(port_cap->psi[i]), in xhci_add_in_port()
2066 XHCI_EXT_PORT_PFD(port_cap->psi[i]), in xhci_add_in_port()
2067 XHCI_EXT_PORT_LP(port_cap->psi[i]), in xhci_add_in_port()
2068 XHCI_EXT_PORT_PSIM(port_cap->psi[i])); in xhci_add_in_port()
2072 rhub->maj_rev = major_revision; in xhci_add_in_port()
2074 if (rhub->min_rev < minor_revision) in xhci_add_in_port()
2075 rhub->min_rev = minor_revision; in xhci_add_in_port()
2077 port_cap->maj_rev = major_revision; in xhci_add_in_port()
2078 port_cap->min_rev = minor_revision; in xhci_add_in_port()
2079 port_cap->protocol_caps = temp; in xhci_add_in_port()
2081 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) && in xhci_add_in_port()
2085 xhci->hw_lpm_support = 1; in xhci_add_in_port()
2088 port_offset--; in xhci_add_in_port()
2090 struct xhci_port *hw_port = &xhci->hw_ports[i]; in xhci_add_in_port()
2092 if (hw_port->rhub) { in xhci_add_in_port()
2095 hw_port->rhub->maj_rev, major_revision); in xhci_add_in_port()
2099 if (hw_port->rhub != rhub && in xhci_add_in_port()
2100 hw_port->hcd_portnum != DUPLICATE_ENTRY) { in xhci_add_in_port()
2101 hw_port->rhub->num_ports--; in xhci_add_in_port()
2102 hw_port->hcd_portnum = DUPLICATE_ENTRY; in xhci_add_in_port()
2106 hw_port->rhub = rhub; in xhci_add_in_port()
2107 hw_port->port_cap = port_cap; in xhci_add_in_port()
2108 rhub->num_ports++; in xhci_add_in_port()
2118 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_create_rhub_port_array()
2120 if (!rhub->num_ports) in xhci_create_rhub_port_array()
2122 rhub->ports = kcalloc_node(rhub->num_ports, sizeof(*rhub->ports), in xhci_create_rhub_port_array()
2124 if (!rhub->ports) in xhci_create_rhub_port_array()
2127 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { in xhci_create_rhub_port_array()
2128 if (xhci->hw_ports[i].rhub != rhub || in xhci_create_rhub_port_array()
2129 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY) in xhci_create_rhub_port_array()
2131 xhci->hw_ports[i].hcd_portnum = port_index; in xhci_create_rhub_port_array()
2132 rhub->ports[port_index] = &xhci->hw_ports[i]; in xhci_create_rhub_port_array()
2134 if (port_index == rhub->num_ports) in xhci_create_rhub_port_array()
2154 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_setup_port_arrays()
2156 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_setup_port_arrays()
2157 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports), in xhci_setup_port_arrays()
2159 if (!xhci->hw_ports) in xhci_setup_port_arrays()
2160 return -ENOMEM; in xhci_setup_port_arrays()
2163 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base + in xhci_setup_port_arrays()
2165 xhci->hw_ports[i].hw_portnum = i; in xhci_setup_port_arrays()
2167 init_completion(&xhci->hw_ports[i].rexit_done); in xhci_setup_port_arrays()
2168 init_completion(&xhci->hw_ports[i].u3exit_done); in xhci_setup_port_arrays()
2171 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags, in xhci_setup_port_arrays()
2173 if (!xhci->rh_bw) in xhci_setup_port_arrays()
2174 return -ENOMEM; in xhci_setup_port_arrays()
2178 INIT_LIST_HEAD(&xhci->rh_bw[i].tts); in xhci_setup_port_arrays()
2179 bw_table = &xhci->rh_bw[i].bw_table; in xhci_setup_port_arrays()
2181 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_setup_port_arrays()
2183 base = &xhci->cap_regs->hc_capbase; in xhci_setup_port_arrays()
2188 return -ENODEV; in xhci_setup_port_arrays()
2199 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps), in xhci_setup_port_arrays()
2201 if (!xhci->port_caps) in xhci_setup_port_arrays()
2202 return -ENOMEM; in xhci_setup_port_arrays()
2208 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports == in xhci_setup_port_arrays()
2214 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) { in xhci_setup_port_arrays()
2216 return -ENODEV; in xhci_setup_port_arrays()
2220 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports); in xhci_setup_port_arrays()
2225 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) { in xhci_setup_port_arrays()
2229 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS; in xhci_setup_port_arrays()
2231 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) { in xhci_setup_port_arrays()
2235 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN; in xhci_setup_port_arrays()
2238 if (!xhci->usb2_rhub.num_ports) in xhci_setup_port_arrays()
2241 if (!xhci->usb3_rhub.num_ports) in xhci_setup_port_arrays()
2244 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags); in xhci_setup_port_arrays()
2245 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags); in xhci_setup_port_arrays()
2253 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_interrupter()
2261 max_segs = BIT(HCS_ERST_MAX(xhci->hcs_params2)); in xhci_alloc_interrupter()
2268 ir->event_ring = xhci_ring_alloc(xhci, segs, TYPE_EVENT, 0, flags); in xhci_alloc_interrupter()
2269 if (!ir->event_ring) { in xhci_alloc_interrupter()
2275 ret = xhci_alloc_erst(xhci, ir->event_ring, &ir->erst, flags); in xhci_alloc_interrupter()
2278 xhci_ring_free(xhci, ir->event_ring); in xhci_alloc_interrupter()
2293 if (intr_num >= xhci->max_interrupters) { in xhci_add_interrupter()
2295 intr_num, xhci->max_interrupters); in xhci_add_interrupter()
2296 return -EINVAL; in xhci_add_interrupter()
2299 if (xhci->interrupters[intr_num]) { in xhci_add_interrupter()
2301 return -EINVAL; in xhci_add_interrupter()
2304 xhci->interrupters[intr_num] = ir; in xhci_add_interrupter()
2305 ir->intr_num = intr_num; in xhci_add_interrupter()
2306 ir->ir_set = &xhci->run_regs->ir_set[intr_num]; in xhci_add_interrupter()
2309 erst_size = readl(&ir->ir_set->erst_size); in xhci_add_interrupter()
2311 erst_size |= ir->event_ring->num_segs; in xhci_add_interrupter()
2312 writel(erst_size, &ir->ir_set->erst_size); in xhci_add_interrupter()
2314 erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_add_interrupter()
2316 erst_base |= ir->erst.erst_dma_addr & ~ERST_BASE_RSVDP; in xhci_add_interrupter()
2317 if (xhci->quirks & XHCI_WRITE_64_HI_LO) in xhci_add_interrupter()
2318 hi_lo_writeq(erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2320 xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2335 int err = -ENOSPC; in xhci_create_secondary_interrupter()
2337 if (!xhci->interrupters || xhci->max_interrupters <= 1) in xhci_create_secondary_interrupter()
2344 spin_lock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2347 for (i = 1; i < xhci->max_interrupters; i++) { in xhci_create_secondary_interrupter()
2348 if (xhci->interrupters[i] == NULL) { in xhci_create_secondary_interrupter()
2354 spin_unlock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2358 xhci->max_interrupters); in xhci_create_secondary_interrupter()
2369 i, xhci->max_interrupters); in xhci_create_secondary_interrupter()
2378 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_init()
2385 INIT_LIST_HEAD(&xhci->cmd_list); in xhci_mem_init()
2388 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); in xhci_mem_init()
2389 init_completion(&xhci->cmd_ring_stop_completion); in xhci_mem_init()
2391 page_size = readl(&xhci->op_regs->page_size); in xhci_mem_init()
2401 xhci->page_shift = 12; in xhci_mem_init()
2402 xhci->page_size = 1 << xhci->page_shift; in xhci_mem_init()
2404 "HCD page size set to %iK", xhci->page_size / 1024); in xhci_mem_init()
2410 val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1)); in xhci_mem_init()
2413 val2 = readl(&xhci->op_regs->config_reg); in xhci_mem_init()
2417 writel(val, &xhci->op_regs->config_reg); in xhci_mem_init()
2420 * xHCI section 5.4.6 - Device Context array must be in xhci_mem_init()
2421 * "physically contiguous and 64-byte (cache line) aligned". in xhci_mem_init()
2423 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, in xhci_mem_init()
2425 if (!xhci->dcbaa) in xhci_mem_init()
2427 xhci->dcbaa->dma = dma; in xhci_mem_init()
2430 &xhci->dcbaa->dma, xhci->dcbaa); in xhci_mem_init()
2431 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); in xhci_mem_init()
2436 * however, the command ring segment needs 64-byte aligned segments in xhci_mem_init()
2440 if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH) in xhci_mem_init()
2441 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2442 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2); in xhci_mem_init()
2444 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2445 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); in xhci_mem_init()
2448 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, in xhci_mem_init()
2449 2112, 64, xhci->page_size); in xhci_mem_init()
2450 if (!xhci->segment_pool || !xhci->device_pool) in xhci_mem_init()
2454 * and only need to be 16-byte aligned. in xhci_mem_init()
2456 xhci->small_streams_pool = in xhci_mem_init()
2459 xhci->medium_streams_pool = in xhci_mem_init()
2466 if (!xhci->small_streams_pool || !xhci->medium_streams_pool) in xhci_mem_init()
2470 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, TYPE_COMMAND, 0, flags); in xhci_mem_init()
2471 if (!xhci->cmd_ring) in xhci_mem_init()
2474 "Allocated command ring at %p", xhci->cmd_ring); in xhci_mem_init()
2476 &xhci->cmd_ring->first_seg->dma); in xhci_mem_init()
2479 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2481 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | in xhci_mem_init()
2482 xhci->cmd_ring->cycle_state; in xhci_mem_init()
2485 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2491 xhci->cmd_ring_reserved_trbs++; in xhci_mem_init()
2493 val = readl(&xhci->cap_regs->db_off); in xhci_mem_init()
2498 xhci->dba = (void __iomem *) xhci->cap_regs + val; in xhci_mem_init()
2503 xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), in xhci_mem_init()
2513 ir->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; in xhci_mem_init()
2516 xhci->devs[i] = NULL; in xhci_mem_init()
2527 temp = readl(&xhci->op_regs->dev_notification); in xhci_mem_init()
2530 writel(temp, &xhci->op_regs->dev_notification); in xhci_mem_init()
2538 return -ENOMEM; in xhci_mem_init()