Lines Matching +full:num +full:- +full:hc +full:- +full:interrupters

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/dma-mapping.h>
19 #include "xhci-trace.h"
20 #include "xhci-debugfs.h"
31 unsigned int num, in xhci_segment_alloc() argument
36 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_segment_alloc()
42 seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma); in xhci_segment_alloc()
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()
333 unsigned int num = 0; in xhci_alloc_segments_for_ring() local
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()
338 num++; 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()
350 num++; 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()
491 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_port_bw_ctx()
497 ctx->size = GET_PORT_BW_ARRAY_SIZE; in xhci_alloc_port_bw_ctx()
499 ctx->bytes = dma_pool_zalloc(xhci->port_bw_pool, flags, &ctx->dma); in xhci_alloc_port_bw_ctx()
500 if (!ctx->bytes) { in xhci_alloc_port_bw_ctx()
512 dma_pool_free(xhci->port_bw_pool, ctx->bytes, ctx->dma); in xhci_free_port_bw_ctx()
519 if (ctx->type != XHCI_CTX_TYPE_INPUT) in xhci_get_input_control_ctx()
522 return (struct xhci_input_control_ctx *)ctx->bytes; in xhci_get_input_control_ctx()
528 if (ctx->type == XHCI_CTX_TYPE_DEVICE) in xhci_get_slot_ctx()
529 return (struct xhci_slot_ctx *)ctx->bytes; in xhci_get_slot_ctx()
532 (ctx->bytes + CTX_SIZE(xhci->hcc_params)); in xhci_get_slot_ctx()
541 if (ctx->type == XHCI_CTX_TYPE_INPUT) in xhci_get_ep_ctx()
545 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); in xhci_get_ep_ctx()
555 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_stream_ctx()
561 dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
563 dma_pool_free(xhci->small_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
569 * - how many streams the endpoint supports,
570 * - the maximum primary stream array size the host controller supports,
571 * - and how many streams the device driver asks for.
580 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_ctx()
586 return dma_pool_zalloc(xhci->medium_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
588 return dma_pool_zalloc(xhci->small_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
595 if (ep->ep_state & EP_HAS_STREAMS) in xhci_dma_to_transfer_ring()
596 return radix_tree_lookup(&ep->stream_info->trb_address_map, in xhci_dma_to_transfer_ring()
598 return ep->ring; in xhci_dma_to_transfer_ring()
620 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_info()
624 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) { in xhci_alloc_stream_info()
628 xhci->cmd_ring_reserved_trbs++; in xhci_alloc_stream_info()
635 stream_info->num_streams = num_streams; in xhci_alloc_stream_info()
636 stream_info->num_stream_ctxs = num_stream_ctxs; in xhci_alloc_stream_info()
639 stream_info->stream_rings = kcalloc_node( in xhci_alloc_stream_info()
642 if (!stream_info->stream_rings) in xhci_alloc_stream_info()
646 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci, in xhci_alloc_stream_info()
647 num_stream_ctxs, &stream_info->ctx_array_dma, in xhci_alloc_stream_info()
649 if (!stream_info->stream_ctx_array) in xhci_alloc_stream_info()
653 stream_info->free_streams_command = in xhci_alloc_stream_info()
655 if (!stream_info->free_streams_command) in xhci_alloc_stream_info()
658 INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC); in xhci_alloc_stream_info()
666 stream_info->stream_rings[cur_stream] = in xhci_alloc_stream_info()
668 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
671 cur_ring->stream_id = cur_stream; in xhci_alloc_stream_info()
672 cur_ring->trb_address_map = &stream_info->trb_address_map; in xhci_alloc_stream_info()
674 addr = cur_ring->first_seg->dma | in xhci_alloc_stream_info()
676 cur_ring->cycle_state; in xhci_alloc_stream_info()
677 stream_info->stream_ctx_array[cur_stream].stream_ring = in xhci_alloc_stream_info()
686 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
701 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
704 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
707 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_alloc_stream_info()
710 stream_info->num_stream_ctxs, in xhci_alloc_stream_info()
711 stream_info->stream_ctx_array, in xhci_alloc_stream_info()
712 stream_info->ctx_array_dma); in xhci_alloc_stream_info()
714 kfree(stream_info->stream_rings); in xhci_alloc_stream_info()
718 xhci->cmd_ring_reserved_trbs--; in xhci_alloc_stream_info()
734 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; in xhci_setup_streams_ep_input_ctx()
738 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK); in xhci_setup_streams_ep_input_ctx()
739 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams) in xhci_setup_streams_ep_input_ctx()
741 ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma); in xhci_setup_streams_ep_input_ctx()
753 ep_ctx->ep_info &= cpu_to_le32(~(EP_MAXPSTREAMS_MASK | EP_HAS_LSA)); in xhci_setup_no_streams_ep_input_ctx()
754 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue); in xhci_setup_no_streams_ep_input_ctx()
755 ep_ctx->deq = cpu_to_le64(addr | ep->ring->cycle_state); in xhci_setup_no_streams_ep_input_ctx()
771 for (cur_stream = 1; cur_stream < stream_info->num_streams; in xhci_free_stream_info()
773 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_free_stream_info()
776 stream_info->stream_rings[cur_stream] = NULL; in xhci_free_stream_info()
779 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_free_stream_info()
780 xhci->cmd_ring_reserved_trbs--; in xhci_free_stream_info()
781 if (stream_info->stream_ctx_array) in xhci_free_stream_info()
783 stream_info->num_stream_ctxs, in xhci_free_stream_info()
784 stream_info->stream_ctx_array, in xhci_free_stream_info()
785 stream_info->ctx_array_dma); in xhci_free_stream_info()
787 kfree(stream_info->stream_rings); in xhci_free_stream_info()
805 if (!virt_dev->rhub_port) { in xhci_free_tt_info()
810 tt_list_head = &(xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_free_tt_info()
812 /* Multi-TT hubs will have more than one entry */ in xhci_free_tt_info()
813 if (tt_info->slot_id == slot_id) { in xhci_free_tt_info()
815 list_del(&tt_info->tt_list); in xhci_free_tt_info()
831 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_tt_info()
833 if (!tt->multi) in xhci_alloc_tt_info()
836 num_ports = hdev->maxchild; in xhci_alloc_tt_info()
845 INIT_LIST_HEAD(&tt_info->tt_list); in xhci_alloc_tt_info()
846 list_add(&tt_info->tt_list, in xhci_alloc_tt_info()
847 &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].tts); in xhci_alloc_tt_info()
848 tt_info->slot_id = virt_dev->udev->slot_id; in xhci_alloc_tt_info()
849 if (tt->multi) in xhci_alloc_tt_info()
850 tt_info->ttport = i+1; in xhci_alloc_tt_info()
851 bw_table = &tt_info->bw_table; in xhci_alloc_tt_info()
853 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_alloc_tt_info()
858 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id); in xhci_alloc_tt_info()
859 return -ENOMEM; in xhci_alloc_tt_info()
864 * Should be called with xhci->lock held if there is any chance the TT lists
875 if (slot_id == 0 || !xhci->devs[slot_id]) in xhci_free_virt_device()
878 dev = xhci->devs[slot_id]; in xhci_free_virt_device()
880 xhci->dcbaa->dev_context_ptrs[slot_id] = 0; in xhci_free_virt_device()
886 if (dev->tt_info) in xhci_free_virt_device()
887 old_active_eps = dev->tt_info->active_eps; in xhci_free_virt_device()
890 if (dev->eps[i].ring) in xhci_free_virt_device()
891 xhci_ring_free(xhci, dev->eps[i].ring); in xhci_free_virt_device()
892 if (dev->eps[i].stream_info) in xhci_free_virt_device()
894 dev->eps[i].stream_info); in xhci_free_virt_device()
903 if (!list_empty(&dev->eps[i].bw_endpoint_list)) { in xhci_free_virt_device()
904 list_del_init(&dev->eps[i].bw_endpoint_list); in xhci_free_virt_device()
914 if (dev->in_ctx) in xhci_free_virt_device()
915 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_free_virt_device()
916 if (dev->out_ctx) in xhci_free_virt_device()
917 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_free_virt_device()
919 if (dev->udev && dev->udev->slot_id) in xhci_free_virt_device()
920 dev->udev->slot_id = 0; in xhci_free_virt_device()
921 if (dev->rhub_port && dev->rhub_port->slot_id == slot_id) in xhci_free_virt_device()
922 dev->rhub_port->slot_id = 0; in xhci_free_virt_device()
923 kfree(xhci->devs[slot_id]); in xhci_free_virt_device()
924 xhci->devs[slot_id] = NULL; in xhci_free_virt_device()
931 * We can't rely on udev at this point to find child-parent relationships.
940 vdev = xhci->devs[slot_id]; in xhci_free_virt_devices_depth_first()
944 if (!vdev->rhub_port) { in xhci_free_virt_devices_depth_first()
949 tt_list_head = &(xhci->rh_bw[vdev->rhub_port->hw_portnum].tts); in xhci_free_virt_devices_depth_first()
952 if (tt_info->slot_id == slot_id) { in xhci_free_virt_devices_depth_first()
954 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_free_virt_devices_depth_first()
955 vdev = xhci->devs[i]; in xhci_free_virt_devices_depth_first()
956 if (vdev && (vdev->tt_info == tt_info)) in xhci_free_virt_devices_depth_first()
975 if (slot_id == 0 || xhci->devs[slot_id]) { in xhci_alloc_virt_device()
984 dev->slot_id = slot_id; in xhci_alloc_virt_device()
986 /* Allocate the (output) device context that will be used in the HC. */ in xhci_alloc_virt_device()
987 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); in xhci_alloc_virt_device()
988 if (!dev->out_ctx) in xhci_alloc_virt_device()
991 xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma); in xhci_alloc_virt_device()
994 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags); in xhci_alloc_virt_device()
995 if (!dev->in_ctx) in xhci_alloc_virt_device()
998 xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma); in xhci_alloc_virt_device()
1002 dev->eps[i].ep_index = i; in xhci_alloc_virt_device()
1003 dev->eps[i].vdev = dev; in xhci_alloc_virt_device()
1004 dev->eps[i].xhci = xhci; in xhci_alloc_virt_device()
1005 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); in xhci_alloc_virt_device()
1006 INIT_LIST_HEAD(&dev->eps[i].bw_endpoint_list); in xhci_alloc_virt_device()
1010 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, TYPE_CTRL, 0, flags); in xhci_alloc_virt_device()
1011 if (!dev->eps[0].ring) in xhci_alloc_virt_device()
1014 dev->udev = udev; in xhci_alloc_virt_device()
1017 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma); in xhci_alloc_virt_device()
1020 &xhci->dcbaa->dev_context_ptrs[slot_id], in xhci_alloc_virt_device()
1021 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id])); in xhci_alloc_virt_device()
1025 xhci->devs[slot_id] = dev; in xhci_alloc_virt_device()
1030 if (dev->in_ctx) in xhci_alloc_virt_device()
1031 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_alloc_virt_device()
1032 if (dev->out_ctx) in xhci_alloc_virt_device()
1033 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_alloc_virt_device()
1046 virt_dev = xhci->devs[udev->slot_id]; in xhci_copy_ep0_dequeue_into_input_ctx()
1047 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0); in xhci_copy_ep0_dequeue_into_input_ctx()
1048 ep_ring = virt_dev->eps[0].ring; in xhci_copy_ep0_dequeue_into_input_ctx()
1056 ep0_ctx->deq = cpu_to_le64(xhci_trb_virt_to_dma(ep_ring->enq_seg, in xhci_copy_ep0_dequeue_into_input_ctx()
1057 ep_ring->enqueue) in xhci_copy_ep0_dequeue_into_input_ctx()
1058 | ep_ring->cycle_state); in xhci_copy_ep0_dequeue_into_input_ctx()
1077 if (udev->speed >= USB_SPEED_SUPER) in xhci_find_rhub_port()
1080 hcd = xhci->main_hcd; in xhci_find_rhub_port()
1082 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; in xhci_find_rhub_port()
1083 top_dev = top_dev->parent) in xhci_find_rhub_port()
1087 return rhub->ports[top_dev->portnum - 1]; in xhci_find_rhub_port()
1098 dev = xhci->devs[udev->slot_id]; in xhci_setup_addressable_virt_dev()
1100 if (udev->slot_id == 0 || !dev) { in xhci_setup_addressable_virt_dev()
1102 udev->slot_id); in xhci_setup_addressable_virt_dev()
1103 return -EINVAL; in xhci_setup_addressable_virt_dev()
1105 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); in xhci_setup_addressable_virt_dev()
1106 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); in xhci_setup_addressable_virt_dev()
1108 /* 3) Only the control endpoint is valid - one endpoint context */ in xhci_setup_addressable_virt_dev()
1109 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); in xhci_setup_addressable_virt_dev()
1110 switch (udev->speed) { in xhci_setup_addressable_virt_dev()
1112 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SSP); in xhci_setup_addressable_virt_dev()
1116 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS); in xhci_setup_addressable_virt_dev()
1120 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS); in xhci_setup_addressable_virt_dev()
1123 /* USB core guesses at a 64-byte max packet first for FS devices */ in xhci_setup_addressable_virt_dev()
1125 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS); in xhci_setup_addressable_virt_dev()
1129 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS); in xhci_setup_addressable_virt_dev()
1134 return -EINVAL; in xhci_setup_addressable_virt_dev()
1137 dev->rhub_port = xhci_find_rhub_port(xhci, udev); in xhci_setup_addressable_virt_dev()
1138 if (!dev->rhub_port) in xhci_setup_addressable_virt_dev()
1139 return -EINVAL; in xhci_setup_addressable_virt_dev()
1141 if (!udev->parent->parent) in xhci_setup_addressable_virt_dev()
1142 dev->rhub_port->slot_id = udev->slot_id; in xhci_setup_addressable_virt_dev()
1143 slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(dev->rhub_port->hw_portnum + 1)); in xhci_setup_addressable_virt_dev()
1145 udev->slot_id, dev->rhub_port->hw_portnum, dev->rhub_port->hcd_portnum); in xhci_setup_addressable_virt_dev()
1153 if (!udev->tt || !udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1154 dev->bw_table = &xhci->rh_bw[dev->rhub_port->hw_portnum].bw_table; in xhci_setup_addressable_virt_dev()
1159 rh_bw = &xhci->rh_bw[dev->rhub_port->hw_portnum]; in xhci_setup_addressable_virt_dev()
1161 list_for_each_entry(tt_bw, &rh_bw->tts, tt_list) { in xhci_setup_addressable_virt_dev()
1162 if (tt_bw->slot_id != udev->tt->hub->slot_id) in xhci_setup_addressable_virt_dev()
1165 if (!dev->udev->tt->multi || in xhci_setup_addressable_virt_dev()
1166 (udev->tt->multi && in xhci_setup_addressable_virt_dev()
1167 tt_bw->ttport == dev->udev->ttport)) { in xhci_setup_addressable_virt_dev()
1168 dev->bw_table = &tt_bw->bw_table; in xhci_setup_addressable_virt_dev()
1169 dev->tt_info = tt_bw; in xhci_setup_addressable_virt_dev()
1173 if (!dev->tt_info) in xhci_setup_addressable_virt_dev()
1178 if (udev->tt && udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1179 slot_ctx->tt_info = cpu_to_le32(udev->tt->hub->slot_id | in xhci_setup_addressable_virt_dev()
1180 (udev->ttport << 8)); in xhci_setup_addressable_virt_dev()
1181 if (udev->tt->multi) in xhci_setup_addressable_virt_dev()
1182 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_setup_addressable_virt_dev()
1184 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); in xhci_setup_addressable_virt_dev()
1185 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); in xhci_setup_addressable_virt_dev()
1187 /* Step 4 - ring already allocated */ in xhci_setup_addressable_virt_dev()
1189 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP)); in xhci_setup_addressable_virt_dev()
1192 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) | in xhci_setup_addressable_virt_dev()
1195 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma | in xhci_setup_addressable_virt_dev()
1196 dev->eps[0].ring->cycle_state); in xhci_setup_addressable_virt_dev()
1206 * Convert interval expressed as 2^(bInterval - 1) == interval into
1215 interval = clamp_val(ep->desc.bInterval, 1, 16) - 1; in xhci_parse_exponent_interval()
1216 if (interval != ep->desc.bInterval - 1) in xhci_parse_exponent_interval()
1217 dev_warn(&udev->dev, in xhci_parse_exponent_interval()
1218 "ep %#x - rounding interval to %d %sframes\n", in xhci_parse_exponent_interval()
1219 ep->desc.bEndpointAddress, in xhci_parse_exponent_interval()
1221 udev->speed == USB_SPEED_FULL ? "" : "micro"); in xhci_parse_exponent_interval()
1223 if (udev->speed == USB_SPEED_FULL) { in xhci_parse_exponent_interval()
1236 * Convert bInterval expressed in microframes (in 1-255 range) to exponent of
1245 interval = fls(desc_interval) - 1; in xhci_microframes_to_exponent()
1248 dev_dbg(&udev->dev, in xhci_microframes_to_exponent()
1249 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n", in xhci_microframes_to_exponent()
1250 ep->desc.bEndpointAddress, in xhci_microframes_to_exponent()
1260 if (ep->desc.bInterval == 0) in xhci_parse_microframe_interval()
1263 ep->desc.bInterval, 0, 15); in xhci_parse_microframe_interval()
1271 ep->desc.bInterval * 8, 3, 10); in xhci_parse_frame_interval()
1287 switch (udev->speed) { in xhci_get_endpoint_interval()
1290 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_endpoint_interval()
1291 usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_get_endpoint_interval()
1299 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1300 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1306 if (usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1318 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1319 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1339 if (udev->speed < USB_SPEED_SUPER || in xhci_get_endpoint_mult()
1340 !usb_endpoint_xfer_isoc(&ep->desc)) in xhci_get_endpoint_mult()
1342 return ep->ss_ep_comp.bmAttributes; in xhci_get_endpoint_mult()
1349 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_endpoint_max_burst()
1350 return ep->ss_ep_comp.bMaxBurst; in xhci_get_endpoint_max_burst()
1352 if (udev->speed == USB_SPEED_HIGH && in xhci_get_endpoint_max_burst()
1353 (usb_endpoint_xfer_isoc(&ep->desc) || in xhci_get_endpoint_max_burst()
1354 usb_endpoint_xfer_int(&ep->desc))) in xhci_get_endpoint_max_burst()
1355 return usb_endpoint_maxp_mult(&ep->desc) - 1; in xhci_get_endpoint_max_burst()
1364 in = usb_endpoint_dir_in(&ep->desc); in xhci_get_endpoint_type()
1366 switch (usb_endpoint_type(&ep->desc)) { in xhci_get_endpoint_type()
1390 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_max_esit_payload()
1391 usb_endpoint_xfer_bulk(&ep->desc)) in xhci_get_max_esit_payload()
1395 if ((udev->speed >= USB_SPEED_SUPER_PLUS) && in xhci_get_max_esit_payload()
1396 USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) in xhci_get_max_esit_payload()
1397 return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); in xhci_get_max_esit_payload()
1400 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_max_esit_payload()
1401 return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); in xhci_get_max_esit_payload()
1403 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_get_max_esit_payload()
1404 max_burst = usb_endpoint_maxp_mult(&ep->desc); in xhci_get_max_esit_payload()
1431 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_init()
1432 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_init()
1436 return -EINVAL; in xhci_endpoint_init()
1438 ring_type = usb_endpoint_type(&ep->desc); in xhci_endpoint_init()
1450 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_endpoint_init()
1451 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_endpoint_init()
1452 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_9) && in xhci_endpoint_init()
1456 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) && in xhci_endpoint_init()
1457 udev->speed >= USB_SPEED_HIGH && in xhci_endpoint_init()
1464 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_endpoint_init()
1471 if (!usb_endpoint_xfer_isoc(&ep->desc)) in xhci_endpoint_init()
1474 if (usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_endpoint_init()
1475 if (udev->speed == USB_SPEED_HIGH) in xhci_endpoint_init()
1477 if (udev->speed == USB_SPEED_FULL) { in xhci_endpoint_init()
1483 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) in xhci_endpoint_init()
1486 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) in xhci_endpoint_init()
1490 virt_dev->eps[ep_index].new_ring = in xhci_endpoint_init()
1492 if (!virt_dev->eps[ep_index].new_ring) in xhci_endpoint_init()
1493 return -ENOMEM; in xhci_endpoint_init()
1495 virt_dev->eps[ep_index].skip = false; in xhci_endpoint_init()
1496 ep_ring = virt_dev->eps[ep_index].new_ring; in xhci_endpoint_init()
1499 ep_ctx->ep_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) | in xhci_endpoint_init()
1502 ep_ctx->ep_info2 = cpu_to_le32(EP_TYPE(endpoint_type) | in xhci_endpoint_init()
1506 ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma | in xhci_endpoint_init()
1507 ep_ring->cycle_state); in xhci_endpoint_init()
1509 ep_ctx->tx_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) | in xhci_endpoint_init()
1522 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_zero()
1523 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_zero()
1525 ep_ctx->ep_info = 0; in xhci_endpoint_zero()
1526 ep_ctx->ep_info2 = 0; in xhci_endpoint_zero()
1527 ep_ctx->deq = 0; in xhci_endpoint_zero()
1528 ep_ctx->tx_info = 0; in xhci_endpoint_zero()
1536 bw_info->ep_interval = 0; in xhci_clear_endpoint_bw_info()
1537 bw_info->mult = 0; in xhci_clear_endpoint_bw_info()
1538 bw_info->num_packets = 0; in xhci_clear_endpoint_bw_info()
1539 bw_info->max_packet_size = 0; in xhci_clear_endpoint_bw_info()
1540 bw_info->type = 0; in xhci_clear_endpoint_bw_info()
1541 bw_info->max_esit_payload = 0; in xhci_clear_endpoint_bw_info()
1555 bw_info = &virt_dev->eps[i].bw_info; in xhci_update_bw_info()
1558 * unconditionally clearing the bandwidth info for non-periodic in xhci_update_bw_info()
1570 ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1572 /* Ignore non-periodic endpoints */ in xhci_update_bw_info()
1579 bw_info->ep_interval = CTX_TO_EP_INTERVAL( in xhci_update_bw_info()
1580 le32_to_cpu(ep_ctx->ep_info)); in xhci_update_bw_info()
1581 /* Number of packets and mult are zero-based in the in xhci_update_bw_info()
1582 * input context, but we want one-based for the in xhci_update_bw_info()
1585 bw_info->mult = CTX_TO_EP_MULT( in xhci_update_bw_info()
1586 le32_to_cpu(ep_ctx->ep_info)) + 1; in xhci_update_bw_info()
1587 bw_info->num_packets = CTX_TO_MAX_BURST( in xhci_update_bw_info()
1588 le32_to_cpu(ep_ctx->ep_info2)) + 1; in xhci_update_bw_info()
1589 bw_info->max_packet_size = MAX_PACKET_DECODED( in xhci_update_bw_info()
1590 le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1591 bw_info->type = ep_type; in xhci_update_bw_info()
1592 bw_info->max_esit_payload = CTX_TO_MAX_ESIT_PAYLOAD( in xhci_update_bw_info()
1593 le32_to_cpu(ep_ctx->tx_info)); in xhci_update_bw_info()
1613 in_ep_ctx->ep_info = out_ep_ctx->ep_info; in xhci_endpoint_copy()
1614 in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2; in xhci_endpoint_copy()
1615 in_ep_ctx->deq = out_ep_ctx->deq; in xhci_endpoint_copy()
1616 in_ep_ctx->tx_info = out_ep_ctx->tx_info; in xhci_endpoint_copy()
1617 if (xhci->quirks & XHCI_MTK_HOST) { in xhci_endpoint_copy()
1618 in_ep_ctx->reserved[0] = out_ep_ctx->reserved[0]; in xhci_endpoint_copy()
1619 in_ep_ctx->reserved[1] = out_ep_ctx->reserved[1]; in xhci_endpoint_copy()
1638 in_slot_ctx->dev_info = out_slot_ctx->dev_info; in xhci_slot_copy()
1639 in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2; in xhci_slot_copy()
1640 in_slot_ctx->tt_info = out_slot_ctx->tt_info; in xhci_slot_copy()
1641 in_slot_ctx->dev_state = out_slot_ctx->dev_state; in xhci_slot_copy()
1648 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_alloc()
1649 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_alloc()
1657 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags, in scratchpad_alloc()
1659 if (!xhci->scratchpad) in scratchpad_alloc()
1662 xhci->scratchpad->sp_array = dma_alloc_coherent(dev, in scratchpad_alloc()
1664 &xhci->scratchpad->sp_dma, flags); in scratchpad_alloc()
1665 if (!xhci->scratchpad->sp_array) in scratchpad_alloc()
1668 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *), in scratchpad_alloc()
1670 if (!xhci->scratchpad->sp_buffers) in scratchpad_alloc()
1673 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); in scratchpad_alloc()
1676 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma, in scratchpad_alloc()
1681 xhci->scratchpad->sp_array[i] = dma; in scratchpad_alloc()
1682 xhci->scratchpad->sp_buffers[i] = buf; in scratchpad_alloc()
1688 while (i--) in scratchpad_alloc()
1689 dma_free_coherent(dev, xhci->page_size, in scratchpad_alloc()
1690 xhci->scratchpad->sp_buffers[i], in scratchpad_alloc()
1691 xhci->scratchpad->sp_array[i]); in scratchpad_alloc()
1693 kfree(xhci->scratchpad->sp_buffers); in scratchpad_alloc()
1697 xhci->scratchpad->sp_array, in scratchpad_alloc()
1698 xhci->scratchpad->sp_dma); in scratchpad_alloc()
1701 kfree(xhci->scratchpad); in scratchpad_alloc()
1702 xhci->scratchpad = NULL; in scratchpad_alloc()
1705 return -ENOMEM; in scratchpad_alloc()
1712 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_free()
1714 if (!xhci->scratchpad) in scratchpad_free()
1717 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_free()
1720 dma_free_coherent(dev, xhci->page_size, in scratchpad_free()
1721 xhci->scratchpad->sp_buffers[i], in scratchpad_free()
1722 xhci->scratchpad->sp_array[i]); in scratchpad_free()
1724 kfree(xhci->scratchpad->sp_buffers); in scratchpad_free()
1726 xhci->scratchpad->sp_array, in scratchpad_free()
1727 xhci->scratchpad->sp_dma); in scratchpad_free()
1728 kfree(xhci->scratchpad); in scratchpad_free()
1729 xhci->scratchpad = NULL; in scratchpad_free()
1736 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_command()
1743 command->completion = in xhci_alloc_command()
1746 if (!command->completion) { in xhci_alloc_command()
1750 init_completion(command->completion); in xhci_alloc_command()
1753 command->status = 0; in xhci_alloc_command()
1755 command->timeout_ms = XHCI_CMD_DEFAULT_TIMEOUT; in xhci_alloc_command()
1756 INIT_LIST_HEAD(&command->cmd_list); in xhci_alloc_command()
1769 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, in xhci_alloc_command_with_ctx()
1771 if (!command->in_ctx) { in xhci_alloc_command_with_ctx()
1772 kfree(command->completion); in xhci_alloc_command_with_ctx()
1788 command->in_ctx); in xhci_free_command()
1789 kfree(command->completion); in xhci_free_command()
1803 size = array_size(sizeof(struct xhci_erst_entry), evt_ring->num_segs); in xhci_alloc_erst()
1804 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev, in xhci_alloc_erst()
1805 size, &erst->erst_dma_addr, flags); in xhci_alloc_erst()
1806 if (!erst->entries) in xhci_alloc_erst()
1807 return -ENOMEM; in xhci_alloc_erst()
1809 erst->num_entries = evt_ring->num_segs; in xhci_alloc_erst()
1811 seg = evt_ring->first_seg; in xhci_alloc_erst()
1812 for (val = 0; val < evt_ring->num_segs; val++) { in xhci_alloc_erst()
1813 entry = &erst->entries[val]; in xhci_alloc_erst()
1814 entry->seg_addr = cpu_to_le64(seg->dma); in xhci_alloc_erst()
1815 entry->seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in xhci_alloc_erst()
1816 entry->rsvd = 0; in xhci_alloc_erst()
1817 seg = seg->next; in xhci_alloc_erst()
1836 if (ir->ir_set) { in xhci_remove_interrupter()
1837 tmp = readl(&ir->ir_set->erst_size); in xhci_remove_interrupter()
1839 writel(tmp, &ir->ir_set->erst_size); in xhci_remove_interrupter()
1848 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_interrupter()
1854 erst_size = array_size(sizeof(struct xhci_erst_entry), ir->erst.num_entries); in xhci_free_interrupter()
1855 if (ir->erst.entries) in xhci_free_interrupter()
1857 ir->erst.entries, in xhci_free_interrupter()
1858 ir->erst.erst_dma_addr); in xhci_free_interrupter()
1859 ir->erst.entries = NULL; in xhci_free_interrupter()
1862 if (ir->event_ring) in xhci_free_interrupter()
1863 xhci_ring_free(xhci, ir->event_ring); in xhci_free_interrupter()
1865 ir->event_ring = NULL; in xhci_free_interrupter()
1875 spin_lock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1878 if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) { in xhci_remove_secondary_interrupter()
1880 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1888 xhci_skip_sec_intr_events(xhci, ir->event_ring, ir); in xhci_remove_secondary_interrupter()
1889 intr_num = ir->intr_num; in xhci_remove_secondary_interrupter()
1892 xhci->interrupters[intr_num] = NULL; in xhci_remove_secondary_interrupter()
1894 spin_unlock_irq(&xhci->lock); in xhci_remove_secondary_interrupter()
1902 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_cleanup()
1905 cancel_delayed_work_sync(&xhci->cmd_timer); in xhci_mem_cleanup()
1907 for (i = 0; xhci->interrupters && i < xhci->max_interrupters; i++) { in xhci_mem_cleanup()
1908 if (xhci->interrupters[i]) { in xhci_mem_cleanup()
1909 xhci_remove_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1910 xhci_free_interrupter(xhci, xhci->interrupters[i]); in xhci_mem_cleanup()
1911 xhci->interrupters[i] = NULL; in xhci_mem_cleanup()
1914 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed interrupters"); in xhci_mem_cleanup()
1916 if (xhci->cmd_ring) in xhci_mem_cleanup()
1917 xhci_ring_free(xhci, xhci->cmd_ring); in xhci_mem_cleanup()
1918 xhci->cmd_ring = NULL; in xhci_mem_cleanup()
1922 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_mem_cleanup()
1923 for (i = 0; i < num_ports && xhci->rh_bw; i++) { in xhci_mem_cleanup()
1924 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table; in xhci_mem_cleanup()
1926 struct list_head *ep = &bwt->interval_bw[j].endpoints; in xhci_mem_cleanup()
1928 list_del_init(ep->next); in xhci_mem_cleanup()
1932 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--) in xhci_mem_cleanup()
1935 dma_pool_destroy(xhci->segment_pool); in xhci_mem_cleanup()
1936 xhci->segment_pool = NULL; in xhci_mem_cleanup()
1939 dma_pool_destroy(xhci->device_pool); in xhci_mem_cleanup()
1940 xhci->device_pool = NULL; in xhci_mem_cleanup()
1943 dma_pool_destroy(xhci->small_streams_pool); in xhci_mem_cleanup()
1944 xhci->small_streams_pool = NULL; in xhci_mem_cleanup()
1948 dma_pool_destroy(xhci->port_bw_pool); in xhci_mem_cleanup()
1949 xhci->port_bw_pool = NULL; in xhci_mem_cleanup()
1953 dma_pool_destroy(xhci->medium_streams_pool); in xhci_mem_cleanup()
1954 xhci->medium_streams_pool = NULL; in xhci_mem_cleanup()
1958 if (xhci->dcbaa) in xhci_mem_cleanup()
1959 dma_free_coherent(dev, sizeof(*xhci->dcbaa), in xhci_mem_cleanup()
1960 xhci->dcbaa, xhci->dcbaa->dma); in xhci_mem_cleanup()
1961 xhci->dcbaa = NULL; in xhci_mem_cleanup()
1965 if (!xhci->rh_bw) in xhci_mem_cleanup()
1970 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) { in xhci_mem_cleanup()
1971 list_del(&tt->tt_list); in xhci_mem_cleanup()
1977 xhci->cmd_ring_reserved_trbs = 0; in xhci_mem_cleanup()
1978 xhci->usb2_rhub.num_ports = 0; in xhci_mem_cleanup()
1979 xhci->usb3_rhub.num_ports = 0; in xhci_mem_cleanup()
1980 xhci->num_active_eps = 0; in xhci_mem_cleanup()
1981 kfree(xhci->usb2_rhub.ports); in xhci_mem_cleanup()
1982 kfree(xhci->usb3_rhub.ports); in xhci_mem_cleanup()
1983 kfree(xhci->hw_ports); in xhci_mem_cleanup()
1984 kfree(xhci->rh_bw); in xhci_mem_cleanup()
1985 for (i = 0; i < xhci->num_port_caps; i++) in xhci_mem_cleanup()
1986 kfree(xhci->port_caps[i].psi); in xhci_mem_cleanup()
1987 kfree(xhci->port_caps); in xhci_mem_cleanup()
1988 kfree(xhci->interrupters); in xhci_mem_cleanup()
1989 xhci->num_port_caps = 0; in xhci_mem_cleanup()
1991 xhci->usb2_rhub.ports = NULL; in xhci_mem_cleanup()
1992 xhci->usb3_rhub.ports = NULL; in xhci_mem_cleanup()
1993 xhci->hw_ports = NULL; in xhci_mem_cleanup()
1994 xhci->rh_bw = NULL; in xhci_mem_cleanup()
1995 xhci->port_caps = NULL; in xhci_mem_cleanup()
1996 xhci->interrupters = NULL; in xhci_mem_cleanup()
1998 xhci->page_size = 0; in xhci_mem_cleanup()
1999 xhci->usb2_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
2000 xhci->usb3_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
2007 deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, in xhci_set_hc_event_deq()
2008 ir->event_ring->dequeue); in xhci_set_hc_event_deq()
2011 /* Update HC event ring dequeue pointer */ in xhci_set_hc_event_deq()
2017 xhci_write_64(xhci, deq & ERST_PTR_MASK, &ir->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
2027 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_add_in_port()
2035 rhub = &xhci->usb3_rhub; in xhci_add_in_port()
2037 * Some hosts incorrectly use sub-minor version for minor in xhci_add_in_port()
2049 if (xhci->quirks & XHCI_ZHAOXIN_HOST) { in xhci_add_in_port()
2055 rhub = &xhci->usb2_rhub; in xhci_add_in_port()
2071 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) in xhci_add_in_port()
2075 port_cap = &xhci->port_caps[xhci->num_port_caps++]; in xhci_add_in_port()
2076 if (xhci->num_port_caps > max_caps) in xhci_add_in_port()
2079 port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp); in xhci_add_in_port()
2081 if (port_cap->psi_count) { in xhci_add_in_port()
2082 port_cap->psi = kcalloc_node(port_cap->psi_count, in xhci_add_in_port()
2083 sizeof(*port_cap->psi), in xhci_add_in_port()
2085 if (!port_cap->psi) in xhci_add_in_port()
2086 port_cap->psi_count = 0; in xhci_add_in_port()
2088 port_cap->psi_uid_count++; in xhci_add_in_port()
2089 for (i = 0; i < port_cap->psi_count; i++) { in xhci_add_in_port()
2090 port_cap->psi[i] = readl(addr + 4 + i); in xhci_add_in_port()
2095 if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) != in xhci_add_in_port()
2096 XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1]))) in xhci_add_in_port()
2097 port_cap->psi_uid_count++; in xhci_add_in_port()
2099 if (xhci->quirks & XHCI_ZHAOXIN_HOST && in xhci_add_in_port()
2101 XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5) in xhci_add_in_port()
2105 XHCI_EXT_PORT_PSIV(port_cap->psi[i]), in xhci_add_in_port()
2106 XHCI_EXT_PORT_PSIE(port_cap->psi[i]), in xhci_add_in_port()
2107 XHCI_EXT_PORT_PLT(port_cap->psi[i]), in xhci_add_in_port()
2108 XHCI_EXT_PORT_PFD(port_cap->psi[i]), in xhci_add_in_port()
2109 XHCI_EXT_PORT_LP(port_cap->psi[i]), in xhci_add_in_port()
2110 XHCI_EXT_PORT_PSIM(port_cap->psi[i])); in xhci_add_in_port()
2114 rhub->maj_rev = major_revision; in xhci_add_in_port()
2116 if (rhub->min_rev < minor_revision) in xhci_add_in_port()
2117 rhub->min_rev = minor_revision; in xhci_add_in_port()
2119 port_cap->maj_rev = major_revision; in xhci_add_in_port()
2120 port_cap->min_rev = minor_revision; in xhci_add_in_port()
2121 port_cap->protocol_caps = temp; in xhci_add_in_port()
2123 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) && in xhci_add_in_port()
2127 xhci->hw_lpm_support = 1; in xhci_add_in_port()
2130 port_offset--; in xhci_add_in_port()
2132 struct xhci_port *hw_port = &xhci->hw_ports[i]; in xhci_add_in_port()
2134 if (hw_port->rhub) { in xhci_add_in_port()
2137 hw_port->rhub->maj_rev, major_revision); in xhci_add_in_port()
2141 if (hw_port->rhub != rhub && in xhci_add_in_port()
2142 hw_port->hcd_portnum != DUPLICATE_ENTRY) { in xhci_add_in_port()
2143 hw_port->rhub->num_ports--; in xhci_add_in_port()
2144 hw_port->hcd_portnum = DUPLICATE_ENTRY; in xhci_add_in_port()
2148 hw_port->rhub = rhub; in xhci_add_in_port()
2149 hw_port->port_cap = port_cap; in xhci_add_in_port()
2150 rhub->num_ports++; in xhci_add_in_port()
2160 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_create_rhub_port_array()
2162 if (!rhub->num_ports) in xhci_create_rhub_port_array()
2164 rhub->ports = kcalloc_node(rhub->num_ports, sizeof(*rhub->ports), in xhci_create_rhub_port_array()
2166 if (!rhub->ports) in xhci_create_rhub_port_array()
2169 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { in xhci_create_rhub_port_array()
2170 if (xhci->hw_ports[i].rhub != rhub || in xhci_create_rhub_port_array()
2171 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY) in xhci_create_rhub_port_array()
2173 xhci->hw_ports[i].hcd_portnum = port_index; in xhci_create_rhub_port_array()
2174 rhub->ports[port_index] = &xhci->hw_ports[i]; in xhci_create_rhub_port_array()
2176 if (port_index == rhub->num_ports) in xhci_create_rhub_port_array()
2196 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_setup_port_arrays()
2198 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_setup_port_arrays()
2199 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports), in xhci_setup_port_arrays()
2201 if (!xhci->hw_ports) in xhci_setup_port_arrays()
2202 return -ENOMEM; in xhci_setup_port_arrays()
2205 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base + in xhci_setup_port_arrays()
2207 xhci->hw_ports[i].hw_portnum = i; in xhci_setup_port_arrays()
2209 init_completion(&xhci->hw_ports[i].rexit_done); in xhci_setup_port_arrays()
2210 init_completion(&xhci->hw_ports[i].u3exit_done); in xhci_setup_port_arrays()
2213 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags, in xhci_setup_port_arrays()
2215 if (!xhci->rh_bw) in xhci_setup_port_arrays()
2216 return -ENOMEM; in xhci_setup_port_arrays()
2220 INIT_LIST_HEAD(&xhci->rh_bw[i].tts); in xhci_setup_port_arrays()
2221 bw_table = &xhci->rh_bw[i].bw_table; in xhci_setup_port_arrays()
2223 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_setup_port_arrays()
2225 base = &xhci->cap_regs->hc_capbase; in xhci_setup_port_arrays()
2230 return -ENODEV; in xhci_setup_port_arrays()
2241 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps), in xhci_setup_port_arrays()
2243 if (!xhci->port_caps) in xhci_setup_port_arrays()
2244 return -ENOMEM; in xhci_setup_port_arrays()
2250 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports == in xhci_setup_port_arrays()
2256 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) { in xhci_setup_port_arrays()
2258 return -ENODEV; in xhci_setup_port_arrays()
2262 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports); in xhci_setup_port_arrays()
2267 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) { in xhci_setup_port_arrays()
2271 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS; in xhci_setup_port_arrays()
2273 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) { in xhci_setup_port_arrays()
2277 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN; in xhci_setup_port_arrays()
2280 if (!xhci->usb2_rhub.num_ports) in xhci_setup_port_arrays()
2283 if (!xhci->usb3_rhub.num_ports) in xhci_setup_port_arrays()
2286 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags); in xhci_setup_port_arrays()
2287 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags); in xhci_setup_port_arrays()
2295 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_interrupter()
2303 max_segs = BIT(HCS_ERST_MAX(xhci->hcs_params2)); in xhci_alloc_interrupter()
2310 ir->event_ring = xhci_ring_alloc(xhci, segs, TYPE_EVENT, 0, flags); in xhci_alloc_interrupter()
2311 if (!ir->event_ring) { in xhci_alloc_interrupter()
2317 ret = xhci_alloc_erst(xhci, ir->event_ring, &ir->erst, flags); in xhci_alloc_interrupter()
2320 xhci_ring_free(xhci, ir->event_ring); in xhci_alloc_interrupter()
2334 ir = xhci->interrupters[intr_num]; in xhci_add_interrupter()
2335 ir->intr_num = intr_num; in xhci_add_interrupter()
2336 ir->ir_set = &xhci->run_regs->ir_set[intr_num]; in xhci_add_interrupter()
2339 erst_size = readl(&ir->ir_set->erst_size); in xhci_add_interrupter()
2341 erst_size |= ir->event_ring->num_segs; in xhci_add_interrupter()
2342 writel(erst_size, &ir->ir_set->erst_size); in xhci_add_interrupter()
2344 erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_add_interrupter()
2346 erst_base |= ir->erst.erst_dma_addr & ERST_BASE_ADDRESS_MASK; in xhci_add_interrupter()
2347 if (xhci->quirks & XHCI_WRITE_64_HI_LO) in xhci_add_interrupter()
2348 hi_lo_writeq(erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2350 xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2363 int err = -ENOSPC; in xhci_create_secondary_interrupter()
2365 if (!xhci->interrupters || xhci->max_interrupters <= 1 || in xhci_create_secondary_interrupter()
2366 intr_num >= xhci->max_interrupters) in xhci_create_secondary_interrupter()
2373 spin_lock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2376 for (i = 1; i < xhci->max_interrupters; i++) { in xhci_create_secondary_interrupter()
2377 if (!xhci->interrupters[i]) { in xhci_create_secondary_interrupter()
2378 xhci->interrupters[i] = ir; in xhci_create_secondary_interrupter()
2385 if (!xhci->interrupters[intr_num]) { in xhci_create_secondary_interrupter()
2386 xhci->interrupters[intr_num] = ir; in xhci_create_secondary_interrupter()
2391 spin_unlock_irq(&xhci->lock); in xhci_create_secondary_interrupter()
2394 xhci_warn(xhci, "Failed to add secondary interrupter, max interrupters %d\n", in xhci_create_secondary_interrupter()
2395 xhci->max_interrupters); in xhci_create_secondary_interrupter()
2402 xhci_dbg(xhci, "Add secondary interrupter %d, max interrupters %d\n", in xhci_create_secondary_interrupter()
2403 ir->intr_num, xhci->max_interrupters); in xhci_create_secondary_interrupter()
2411 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_init()
2415 * xHCI section 5.4.6 - Device Context array must be in xhci_mem_init()
2416 * "physically contiguous and 64-byte (cache line) aligned". in xhci_mem_init()
2418 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, flags); in xhci_mem_init()
2419 if (!xhci->dcbaa) in xhci_mem_init()
2422 xhci->dcbaa->dma = dma; in xhci_mem_init()
2425 &xhci->dcbaa->dma, xhci->dcbaa); in xhci_mem_init()
2430 * however, the command ring segment needs 64-byte aligned segments in xhci_mem_init()
2434 if (xhci->quirks & XHCI_TRB_OVERFETCH) in xhci_mem_init()
2435 /* Buggy HC prefetches beyond segment bounds - allocate dummy space at the end */ in xhci_mem_init()
2436 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2437 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2); in xhci_mem_init()
2439 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2440 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); in xhci_mem_init()
2441 if (!xhci->segment_pool) in xhci_mem_init()
2445 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, 2112, 64, in xhci_mem_init()
2446 xhci->page_size); in xhci_mem_init()
2447 if (!xhci->device_pool) in xhci_mem_init()
2452 * and only need to be 16-byte aligned. in xhci_mem_init()
2454 xhci->small_streams_pool = dma_pool_create("xHCI 256 byte stream ctx arrays", in xhci_mem_init()
2456 if (!xhci->small_streams_pool) in xhci_mem_init()
2464 xhci->medium_streams_pool = dma_pool_create("xHCI 1KB stream ctx arrays", in xhci_mem_init()
2466 if (!xhci->medium_streams_pool) in xhci_mem_init()
2472 * to be 16-byte aligned. in xhci_mem_init()
2474 xhci->port_bw_pool = dma_pool_create("xHCI 256 port bw ctx arrays", in xhci_mem_init()
2476 if (!xhci->port_bw_pool) in xhci_mem_init()
2480 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, TYPE_COMMAND, 0, flags); in xhci_mem_init()
2481 if (!xhci->cmd_ring) in xhci_mem_init()
2484 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Allocated command ring at %p", xhci->cmd_ring); in xhci_mem_init()
2486 &xhci->cmd_ring->first_seg->dma); in xhci_mem_init()
2493 xhci->cmd_ring_reserved_trbs++; in xhci_mem_init()
2497 xhci->interrupters = kcalloc_node(xhci->max_interrupters, sizeof(*xhci->interrupters), in xhci_mem_init()
2499 if (!xhci->interrupters) in xhci_mem_init()
2502 xhci->interrupters[0] = xhci_alloc_interrupter(xhci, 0, flags); in xhci_mem_init()
2503 if (!xhci->interrupters[0]) in xhci_mem_init()
2518 return -ENOMEM; in xhci_mem_init()