Lines Matching +full:additional +full:- +full:devs
1 // SPDX-License-Identifier: GPL-2.0
15 #include <linux/dma-mapping.h>
18 #include "xhci-trace.h"
19 #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()
60 seg->trbs[i].link.control |= cpu_to_le32(TRB_CYCLE); in xhci_segment_alloc()
62 seg->dma = dma; in xhci_segment_alloc()
63 seg->next = NULL; in xhci_segment_alloc()
70 if (seg->trbs) { in xhci_segment_free()
71 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma); in xhci_segment_free()
72 seg->trbs = NULL; in xhci_segment_free()
74 kfree(seg->bounce_buf); in xhci_segment_free()
83 seg = first->next; in xhci_free_segments_for_ring()
85 struct xhci_segment *next = seg->next; in xhci_free_segments_for_ring()
107 prev->next = next; in xhci_link_segments()
109 prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = in xhci_link_segments()
110 cpu_to_le64(next->dma); in xhci_link_segments()
113 val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control); in xhci_link_segments()
118 prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val); in xhci_link_segments()
138 (ring->type == TYPE_ISOC && in xhci_link_rings()
139 (xhci->quirks & XHCI_AMD_0x96_HOST))); in xhci_link_rings()
141 next = ring->enq_seg->next; in xhci_link_rings()
142 xhci_link_segments(ring->enq_seg, first, ring->type, chain_links); in xhci_link_rings()
143 xhci_link_segments(last, next, ring->type, chain_links); in xhci_link_rings()
144 ring->num_segs += num_segs; in xhci_link_rings()
145 ring->num_trbs_free += (TRBS_PER_SEGMENT - 1) * num_segs; in xhci_link_rings()
147 if (ring->type != TYPE_EVENT && ring->enq_seg == ring->last_seg) { in xhci_link_rings()
148 ring->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control in xhci_link_rings()
150 last->trbs[TRBS_PER_SEGMENT-1].link.control in xhci_link_rings()
152 ring->last_seg = last; in xhci_link_rings()
179 * The radix tree uses an unsigned long as a key pair. On 32-bit systems, an
180 * unsigned long will be 32-bits; on a 64-bit system an unsigned long will be
181 * 64-bits. Since we only request 32-bit DMA addresses, we can use that as the
182 * key on 32-bit or 64-bit systems (it would also be fine if we asked for 64-bit
183 * PCI DMA addresses on a 64-bit system). There might be a problem on 32-bit
184 * extended systems (where the DMA address can be bigger than 32-bits),
185 * if we allow the PCI dma mask to be bigger than 32-bits. So don't do that.
195 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in xhci_insert_segment_mapping()
214 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in xhci_remove_segment_mapping()
241 seg = seg->next; in xhci_update_stream_segment_mapping()
253 seg = seg->next; in xhci_update_stream_segment_mapping()
263 if (WARN_ON_ONCE(ring->trb_address_map == NULL)) in xhci_remove_stream_mapping()
266 seg = ring->first_seg; in xhci_remove_stream_mapping()
268 xhci_remove_segment_mapping(ring->trb_address_map, seg); in xhci_remove_stream_mapping()
269 seg = seg->next; in xhci_remove_stream_mapping()
270 } while (seg != ring->first_seg); in xhci_remove_stream_mapping()
275 return xhci_update_stream_segment_mapping(ring->trb_address_map, ring, in xhci_update_stream_mapping()
276 ring->first_seg, ring->last_seg, mem_flags); in xhci_update_stream_mapping()
287 if (ring->first_seg) { in xhci_ring_free()
288 if (ring->type == TYPE_STREAM) in xhci_ring_free()
290 xhci_free_segments_for_ring(xhci, ring->first_seg); in xhci_ring_free()
300 ring->enqueue = ring->first_seg->trbs; in xhci_initialize_ring_info()
301 ring->enq_seg = ring->first_seg; in xhci_initialize_ring_info()
302 ring->dequeue = ring->enqueue; in xhci_initialize_ring_info()
303 ring->deq_seg = ring->first_seg; in xhci_initialize_ring_info()
311 ring->cycle_state = cycle_state; in xhci_initialize_ring_info()
317 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in xhci_initialize_ring_info()
332 (xhci->quirks & XHCI_AMD_0x96_HOST))); in xhci_alloc_segments_for_ring()
336 return -ENOMEM; in xhci_alloc_segments_for_ring()
337 num_segs--; in xhci_alloc_segments_for_ring()
347 next = prev->next; in xhci_alloc_segments_for_ring()
351 return -ENOMEM; in xhci_alloc_segments_for_ring()
356 num_segs--; in xhci_alloc_segments_for_ring()
377 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_ring_alloc()
383 ring->num_segs = num_segs; in xhci_ring_alloc()
384 ring->bounce_buf_len = max_packet; in xhci_ring_alloc()
385 INIT_LIST_HEAD(&ring->td_list); in xhci_ring_alloc()
386 ring->type = type; in xhci_ring_alloc()
390 ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg, in xhci_ring_alloc()
391 &ring->last_seg, num_segs, cycle_state, type, in xhci_ring_alloc()
399 ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= in xhci_ring_alloc()
415 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring); in xhci_free_endpoint_ring()
416 virt_dev->eps[ep_index].ring = NULL; in xhci_free_endpoint_ring()
432 num_segs_needed = (num_trbs + (TRBS_PER_SEGMENT - 1) - 1) / in xhci_ring_expansion()
433 (TRBS_PER_SEGMENT - 1); in xhci_ring_expansion()
436 num_segs = ring->num_segs > num_segs_needed ? in xhci_ring_expansion()
437 ring->num_segs : num_segs_needed; in xhci_ring_expansion()
440 num_segs, ring->cycle_state, ring->type, in xhci_ring_expansion()
441 ring->bounce_buf_len, flags); in xhci_ring_expansion()
443 return -ENOMEM; in xhci_ring_expansion()
445 if (ring->type == TYPE_STREAM) in xhci_ring_expansion()
446 ret = xhci_update_stream_segment_mapping(ring->trb_address_map, in xhci_ring_expansion()
451 next = first->next; in xhci_ring_expansion()
464 ring->num_segs); in xhci_ring_expansion()
473 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_container_ctx()
482 ctx->type = type; in xhci_alloc_container_ctx()
483 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024; in xhci_alloc_container_ctx()
485 ctx->size += CTX_SIZE(xhci->hcc_params); in xhci_alloc_container_ctx()
487 ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma); in xhci_alloc_container_ctx()
488 if (!ctx->bytes) { in xhci_alloc_container_ctx()
500 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma); in xhci_free_container_ctx()
507 if (ctx->type != XHCI_CTX_TYPE_INPUT) in xhci_get_input_control_ctx()
510 return (struct xhci_input_control_ctx *)ctx->bytes; in xhci_get_input_control_ctx()
516 if (ctx->type == XHCI_CTX_TYPE_DEVICE) in xhci_get_slot_ctx()
517 return (struct xhci_slot_ctx *)ctx->bytes; in xhci_get_slot_ctx()
520 (ctx->bytes + CTX_SIZE(xhci->hcc_params)); in xhci_get_slot_ctx()
529 if (ctx->type == XHCI_CTX_TYPE_INPUT) in xhci_get_ep_ctx()
533 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); in xhci_get_ep_ctx()
543 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_stream_ctx()
550 return dma_pool_free(xhci->small_streams_pool, in xhci_free_stream_ctx()
553 return dma_pool_free(xhci->medium_streams_pool, in xhci_free_stream_ctx()
560 * - how many streams the endpoint supports,
561 * - the maximum primary stream array size the host controller supports,
562 * - and how many streams the device driver asks for.
571 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_ctx()
578 return dma_pool_alloc(xhci->small_streams_pool, in xhci_alloc_stream_ctx()
581 return dma_pool_alloc(xhci->medium_streams_pool, in xhci_alloc_stream_ctx()
589 if (ep->ep_state & EP_HAS_STREAMS) in xhci_dma_to_transfer_ring()
590 return radix_tree_lookup(&ep->stream_info->trb_address_map, in xhci_dma_to_transfer_ring()
592 return ep->ring; in xhci_dma_to_transfer_ring()
600 struct xhci_virt_ep *ep = &dev->eps[ep_index]; in xhci_stream_id_to_ring()
603 return ep->ring; in xhci_stream_id_to_ring()
604 if (!ep->stream_info) in xhci_stream_id_to_ring()
607 if (stream_id >= ep->stream_info->num_streams) in xhci_stream_id_to_ring()
609 return ep->stream_info->stream_rings[stream_id]; in xhci_stream_id_to_ring()
631 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_info()
636 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) { in xhci_alloc_stream_info()
640 xhci->cmd_ring_reserved_trbs++; in xhci_alloc_stream_info()
647 stream_info->num_streams = num_streams; in xhci_alloc_stream_info()
648 stream_info->num_stream_ctxs = num_stream_ctxs; in xhci_alloc_stream_info()
651 stream_info->stream_rings = kcalloc_node( in xhci_alloc_stream_info()
654 if (!stream_info->stream_rings) in xhci_alloc_stream_info()
658 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci, in xhci_alloc_stream_info()
659 num_stream_ctxs, &stream_info->ctx_array_dma, in xhci_alloc_stream_info()
661 if (!stream_info->stream_ctx_array) in xhci_alloc_stream_info()
663 memset(stream_info->stream_ctx_array, 0, in xhci_alloc_stream_info()
667 stream_info->free_streams_command = in xhci_alloc_stream_info()
669 if (!stream_info->free_streams_command) in xhci_alloc_stream_info()
672 INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC); in xhci_alloc_stream_info()
680 stream_info->stream_rings[cur_stream] = in xhci_alloc_stream_info()
683 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
686 cur_ring->stream_id = cur_stream; in xhci_alloc_stream_info()
687 cur_ring->trb_address_map = &stream_info->trb_address_map; in xhci_alloc_stream_info()
689 addr = cur_ring->first_seg->dma | in xhci_alloc_stream_info()
691 cur_ring->cycle_state; in xhci_alloc_stream_info()
692 stream_info->stream_ctx_array[cur_stream].stream_ring = in xhci_alloc_stream_info()
700 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
715 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
718 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
721 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_alloc_stream_info()
724 stream_info->num_stream_ctxs, in xhci_alloc_stream_info()
725 stream_info->stream_ctx_array, in xhci_alloc_stream_info()
726 stream_info->ctx_array_dma); in xhci_alloc_stream_info()
728 kfree(stream_info->stream_rings); in xhci_alloc_stream_info()
732 xhci->cmd_ring_reserved_trbs--; in xhci_alloc_stream_info()
748 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; in xhci_setup_streams_ep_input_ctx()
752 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK); in xhci_setup_streams_ep_input_ctx()
753 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams) in xhci_setup_streams_ep_input_ctx()
755 ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma); in xhci_setup_streams_ep_input_ctx()
767 ep_ctx->ep_info &= cpu_to_le32(~(EP_MAXPSTREAMS_MASK | EP_HAS_LSA)); in xhci_setup_no_streams_ep_input_ctx()
768 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue); in xhci_setup_no_streams_ep_input_ctx()
769 ep_ctx->deq = cpu_to_le64(addr | ep->ring->cycle_state); in xhci_setup_no_streams_ep_input_ctx()
785 for (cur_stream = 1; cur_stream < stream_info->num_streams; in xhci_free_stream_info()
787 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_free_stream_info()
790 stream_info->stream_rings[cur_stream] = NULL; in xhci_free_stream_info()
793 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_free_stream_info()
794 xhci->cmd_ring_reserved_trbs--; in xhci_free_stream_info()
795 if (stream_info->stream_ctx_array) in xhci_free_stream_info()
797 stream_info->num_stream_ctxs, in xhci_free_stream_info()
798 stream_info->stream_ctx_array, in xhci_free_stream_info()
799 stream_info->ctx_array_dma); in xhci_free_stream_info()
801 kfree(stream_info->stream_rings); in xhci_free_stream_info()
811 timer_setup(&ep->stop_cmd_timer, xhci_stop_endpoint_command_watchdog, in xhci_init_endpoint_timer()
813 ep->xhci = xhci; in xhci_init_endpoint_timer()
827 if (virt_dev->real_port == 0 || in xhci_free_tt_info()
828 virt_dev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { in xhci_free_tt_info()
833 tt_list_head = &(xhci->rh_bw[virt_dev->real_port - 1].tts); in xhci_free_tt_info()
835 /* Multi-TT hubs will have more than one entry */ in xhci_free_tt_info()
836 if (tt_info->slot_id == slot_id) { in xhci_free_tt_info()
838 list_del(&tt_info->tt_list); in xhci_free_tt_info()
854 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_tt_info()
856 if (!tt->multi) in xhci_alloc_tt_info()
859 num_ports = hdev->maxchild; in xhci_alloc_tt_info()
868 INIT_LIST_HEAD(&tt_info->tt_list); in xhci_alloc_tt_info()
869 list_add(&tt_info->tt_list, in xhci_alloc_tt_info()
870 &xhci->rh_bw[virt_dev->real_port - 1].tts); in xhci_alloc_tt_info()
871 tt_info->slot_id = virt_dev->udev->slot_id; in xhci_alloc_tt_info()
872 if (tt->multi) in xhci_alloc_tt_info()
873 tt_info->ttport = i+1; in xhci_alloc_tt_info()
874 bw_table = &tt_info->bw_table; in xhci_alloc_tt_info()
876 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_alloc_tt_info()
881 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id); in xhci_alloc_tt_info()
882 return -ENOMEM; in xhci_alloc_tt_info()
887 * Should be called with xhci->lock held if there is any chance the TT lists
898 if (slot_id == 0 || !xhci->devs[slot_id]) in xhci_free_virt_device()
901 dev = xhci->devs[slot_id]; in xhci_free_virt_device()
903 xhci->dcbaa->dev_context_ptrs[slot_id] = 0; in xhci_free_virt_device()
909 if (dev->tt_info) in xhci_free_virt_device()
910 old_active_eps = dev->tt_info->active_eps; in xhci_free_virt_device()
913 if (dev->eps[i].ring) in xhci_free_virt_device()
914 xhci_ring_free(xhci, dev->eps[i].ring); in xhci_free_virt_device()
915 if (dev->eps[i].stream_info) in xhci_free_virt_device()
917 dev->eps[i].stream_info); in xhci_free_virt_device()
926 if (!list_empty(&dev->eps[i].bw_endpoint_list)) { in xhci_free_virt_device()
927 list_del_init(&dev->eps[i].bw_endpoint_list); in xhci_free_virt_device()
937 if (dev->in_ctx) in xhci_free_virt_device()
938 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_free_virt_device()
939 if (dev->out_ctx) in xhci_free_virt_device()
940 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_free_virt_device()
942 if (dev->udev && dev->udev->slot_id) in xhci_free_virt_device()
943 dev->udev->slot_id = 0; in xhci_free_virt_device()
944 kfree(xhci->devs[slot_id]); in xhci_free_virt_device()
945 xhci->devs[slot_id] = NULL; in xhci_free_virt_device()
952 * We can't rely on udev at this point to find child-parent relationships.
961 vdev = xhci->devs[slot_id]; in xhci_free_virt_devices_depth_first()
965 if (vdev->real_port == 0 || in xhci_free_virt_devices_depth_first()
966 vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { in xhci_free_virt_devices_depth_first()
967 xhci_dbg(xhci, "Bad vdev->real_port.\n"); in xhci_free_virt_devices_depth_first()
971 tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts); in xhci_free_virt_devices_depth_first()
974 if (tt_info->slot_id == slot_id) { in xhci_free_virt_devices_depth_first()
976 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_free_virt_devices_depth_first()
977 vdev = xhci->devs[i]; in xhci_free_virt_devices_depth_first()
978 if (vdev && (vdev->tt_info == tt_info)) in xhci_free_virt_devices_depth_first()
997 if (slot_id == 0 || xhci->devs[slot_id]) { in xhci_alloc_virt_device()
1006 dev->slot_id = slot_id; in xhci_alloc_virt_device()
1009 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); in xhci_alloc_virt_device()
1010 if (!dev->out_ctx) in xhci_alloc_virt_device()
1014 (unsigned long long)dev->out_ctx->dma); in xhci_alloc_virt_device()
1017 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags); in xhci_alloc_virt_device()
1018 if (!dev->in_ctx) in xhci_alloc_virt_device()
1022 (unsigned long long)dev->in_ctx->dma); in xhci_alloc_virt_device()
1026 dev->eps[i].ep_index = i; in xhci_alloc_virt_device()
1027 dev->eps[i].vdev = dev; in xhci_alloc_virt_device()
1028 xhci_init_endpoint_timer(xhci, &dev->eps[i]); in xhci_alloc_virt_device()
1029 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); in xhci_alloc_virt_device()
1030 INIT_LIST_HEAD(&dev->eps[i].bw_endpoint_list); in xhci_alloc_virt_device()
1034 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, 1, TYPE_CTRL, 0, flags); in xhci_alloc_virt_device()
1035 if (!dev->eps[0].ring) in xhci_alloc_virt_device()
1038 dev->udev = udev; in xhci_alloc_virt_device()
1041 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma); in xhci_alloc_virt_device()
1044 &xhci->dcbaa->dev_context_ptrs[slot_id], in xhci_alloc_virt_device()
1045 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id])); in xhci_alloc_virt_device()
1049 xhci->devs[slot_id] = dev; in xhci_alloc_virt_device()
1054 if (dev->in_ctx) in xhci_alloc_virt_device()
1055 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_alloc_virt_device()
1056 if (dev->out_ctx) in xhci_alloc_virt_device()
1057 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_alloc_virt_device()
1070 virt_dev = xhci->devs[udev->slot_id]; in xhci_copy_ep0_dequeue_into_input_ctx()
1071 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0); in xhci_copy_ep0_dequeue_into_input_ctx()
1072 ep_ring = virt_dev->eps[0].ring; in xhci_copy_ep0_dequeue_into_input_ctx()
1080 ep0_ctx->deq = cpu_to_le64(xhci_trb_virt_to_dma(ep_ring->enq_seg, in xhci_copy_ep0_dequeue_into_input_ctx()
1081 ep_ring->enqueue) in xhci_copy_ep0_dequeue_into_input_ctx()
1082 | ep_ring->cycle_state); in xhci_copy_ep0_dequeue_into_input_ctx()
1101 if (udev->speed >= USB_SPEED_SUPER) in xhci_find_real_port_number()
1102 hcd = xhci->shared_hcd; in xhci_find_real_port_number()
1104 hcd = xhci->main_hcd; in xhci_find_real_port_number()
1106 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; in xhci_find_real_port_number()
1107 top_dev = top_dev->parent) in xhci_find_real_port_number()
1110 return xhci_find_raw_port_number(hcd, top_dev->portnum); in xhci_find_real_port_number()
1123 dev = xhci->devs[udev->slot_id]; in xhci_setup_addressable_virt_dev()
1125 if (udev->slot_id == 0 || !dev) { in xhci_setup_addressable_virt_dev()
1127 udev->slot_id); in xhci_setup_addressable_virt_dev()
1128 return -EINVAL; in xhci_setup_addressable_virt_dev()
1130 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); in xhci_setup_addressable_virt_dev()
1131 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); in xhci_setup_addressable_virt_dev()
1133 /* 3) Only the control endpoint is valid - one endpoint context */ in xhci_setup_addressable_virt_dev()
1134 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); in xhci_setup_addressable_virt_dev()
1135 switch (udev->speed) { in xhci_setup_addressable_virt_dev()
1137 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SSP); in xhci_setup_addressable_virt_dev()
1141 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS); in xhci_setup_addressable_virt_dev()
1145 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS); in xhci_setup_addressable_virt_dev()
1148 /* USB core guesses at a 64-byte max packet first for FS devices */ in xhci_setup_addressable_virt_dev()
1150 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS); in xhci_setup_addressable_virt_dev()
1154 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS); in xhci_setup_addressable_virt_dev()
1159 return -EINVAL; in xhci_setup_addressable_virt_dev()
1163 return -EINVAL; in xhci_setup_addressable_virt_dev()
1168 return -EINVAL; in xhci_setup_addressable_virt_dev()
1169 slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(port_num)); in xhci_setup_addressable_virt_dev()
1171 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; in xhci_setup_addressable_virt_dev()
1172 top_dev = top_dev->parent) in xhci_setup_addressable_virt_dev()
1174 dev->fake_port = top_dev->portnum; in xhci_setup_addressable_virt_dev()
1175 dev->real_port = port_num; in xhci_setup_addressable_virt_dev()
1177 xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->fake_port); in xhci_setup_addressable_virt_dev()
1185 if (!udev->tt || !udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1186 dev->bw_table = &xhci->rh_bw[port_num - 1].bw_table; in xhci_setup_addressable_virt_dev()
1191 rh_bw = &xhci->rh_bw[port_num - 1]; in xhci_setup_addressable_virt_dev()
1193 list_for_each_entry(tt_bw, &rh_bw->tts, tt_list) { in xhci_setup_addressable_virt_dev()
1194 if (tt_bw->slot_id != udev->tt->hub->slot_id) in xhci_setup_addressable_virt_dev()
1197 if (!dev->udev->tt->multi || in xhci_setup_addressable_virt_dev()
1198 (udev->tt->multi && in xhci_setup_addressable_virt_dev()
1199 tt_bw->ttport == dev->udev->ttport)) { in xhci_setup_addressable_virt_dev()
1200 dev->bw_table = &tt_bw->bw_table; in xhci_setup_addressable_virt_dev()
1201 dev->tt_info = tt_bw; in xhci_setup_addressable_virt_dev()
1205 if (!dev->tt_info) in xhci_setup_addressable_virt_dev()
1210 if (udev->tt && udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1211 slot_ctx->tt_info = cpu_to_le32(udev->tt->hub->slot_id | in xhci_setup_addressable_virt_dev()
1212 (udev->ttport << 8)); in xhci_setup_addressable_virt_dev()
1213 if (udev->tt->multi) in xhci_setup_addressable_virt_dev()
1214 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_setup_addressable_virt_dev()
1216 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); in xhci_setup_addressable_virt_dev()
1217 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); in xhci_setup_addressable_virt_dev()
1219 /* Step 4 - ring already allocated */ in xhci_setup_addressable_virt_dev()
1221 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP)); in xhci_setup_addressable_virt_dev()
1224 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) | in xhci_setup_addressable_virt_dev()
1227 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma | in xhci_setup_addressable_virt_dev()
1228 dev->eps[0].ring->cycle_state); in xhci_setup_addressable_virt_dev()
1238 * Convert interval expressed as 2^(bInterval - 1) == interval into
1247 interval = clamp_val(ep->desc.bInterval, 1, 16) - 1; in xhci_parse_exponent_interval()
1248 if (interval != ep->desc.bInterval - 1) in xhci_parse_exponent_interval()
1249 dev_warn(&udev->dev, in xhci_parse_exponent_interval()
1250 "ep %#x - rounding interval to %d %sframes\n", in xhci_parse_exponent_interval()
1251 ep->desc.bEndpointAddress, in xhci_parse_exponent_interval()
1253 udev->speed == USB_SPEED_FULL ? "" : "micro"); in xhci_parse_exponent_interval()
1255 if (udev->speed == USB_SPEED_FULL) { in xhci_parse_exponent_interval()
1268 * Convert bInterval expressed in microframes (in 1-255 range) to exponent of
1277 interval = fls(desc_interval) - 1; in xhci_microframes_to_exponent()
1280 dev_dbg(&udev->dev, in xhci_microframes_to_exponent()
1281 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n", in xhci_microframes_to_exponent()
1282 ep->desc.bEndpointAddress, in xhci_microframes_to_exponent()
1292 if (ep->desc.bInterval == 0) in xhci_parse_microframe_interval()
1295 ep->desc.bInterval, 0, 15); in xhci_parse_microframe_interval()
1303 ep->desc.bInterval * 8, 3, 10); in xhci_parse_frame_interval()
1319 switch (udev->speed) { in xhci_get_endpoint_interval()
1322 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_endpoint_interval()
1323 usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_get_endpoint_interval()
1331 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1332 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1338 if (usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1350 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1351 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1364 * High speed endpoint descriptors can define "the number of additional
1371 if (udev->speed < USB_SPEED_SUPER || in xhci_get_endpoint_mult()
1372 !usb_endpoint_xfer_isoc(&ep->desc)) in xhci_get_endpoint_mult()
1374 return ep->ss_ep_comp.bmAttributes; in xhci_get_endpoint_mult()
1381 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_endpoint_max_burst()
1382 return ep->ss_ep_comp.bMaxBurst; in xhci_get_endpoint_max_burst()
1384 if (udev->speed == USB_SPEED_HIGH && in xhci_get_endpoint_max_burst()
1385 (usb_endpoint_xfer_isoc(&ep->desc) || in xhci_get_endpoint_max_burst()
1386 usb_endpoint_xfer_int(&ep->desc))) in xhci_get_endpoint_max_burst()
1387 return usb_endpoint_maxp_mult(&ep->desc) - 1; in xhci_get_endpoint_max_burst()
1396 in = usb_endpoint_dir_in(&ep->desc); in xhci_get_endpoint_type()
1398 switch (usb_endpoint_type(&ep->desc)) { in xhci_get_endpoint_type()
1422 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_max_esit_payload()
1423 usb_endpoint_xfer_bulk(&ep->desc)) in xhci_get_max_esit_payload()
1427 if ((udev->speed >= USB_SPEED_SUPER_PLUS) && in xhci_get_max_esit_payload()
1428 USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) in xhci_get_max_esit_payload()
1429 return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); in xhci_get_max_esit_payload()
1431 else if (udev->speed >= USB_SPEED_SUPER) in xhci_get_max_esit_payload()
1432 return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); in xhci_get_max_esit_payload()
1434 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_get_max_esit_payload()
1435 max_burst = usb_endpoint_maxp_mult(&ep->desc); in xhci_get_max_esit_payload()
1462 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_init()
1463 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_init()
1467 return -EINVAL; in xhci_endpoint_init()
1469 ring_type = usb_endpoint_type(&ep->desc); in xhci_endpoint_init()
1481 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_endpoint_init()
1482 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_endpoint_init()
1483 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) && in xhci_endpoint_init()
1484 udev->speed >= USB_SPEED_HIGH && in xhci_endpoint_init()
1491 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_endpoint_init()
1498 if (!usb_endpoint_xfer_isoc(&ep->desc)) in xhci_endpoint_init()
1501 if (usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_endpoint_init()
1502 if (udev->speed == USB_SPEED_HIGH) in xhci_endpoint_init()
1504 if (udev->speed == USB_SPEED_FULL) { in xhci_endpoint_init()
1510 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) in xhci_endpoint_init()
1513 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) in xhci_endpoint_init()
1517 virt_dev->eps[ep_index].new_ring = in xhci_endpoint_init()
1519 if (!virt_dev->eps[ep_index].new_ring) in xhci_endpoint_init()
1520 return -ENOMEM; in xhci_endpoint_init()
1522 virt_dev->eps[ep_index].skip = false; in xhci_endpoint_init()
1523 ep_ring = virt_dev->eps[ep_index].new_ring; in xhci_endpoint_init()
1526 ep_ctx->ep_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) | in xhci_endpoint_init()
1529 ep_ctx->ep_info2 = cpu_to_le32(EP_TYPE(endpoint_type) | in xhci_endpoint_init()
1533 ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma | in xhci_endpoint_init()
1534 ep_ring->cycle_state); in xhci_endpoint_init()
1536 ep_ctx->tx_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) | in xhci_endpoint_init()
1549 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_zero()
1550 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_zero()
1552 ep_ctx->ep_info = 0; in xhci_endpoint_zero()
1553 ep_ctx->ep_info2 = 0; in xhci_endpoint_zero()
1554 ep_ctx->deq = 0; in xhci_endpoint_zero()
1555 ep_ctx->tx_info = 0; in xhci_endpoint_zero()
1563 bw_info->ep_interval = 0; in xhci_clear_endpoint_bw_info()
1564 bw_info->mult = 0; in xhci_clear_endpoint_bw_info()
1565 bw_info->num_packets = 0; in xhci_clear_endpoint_bw_info()
1566 bw_info->max_packet_size = 0; in xhci_clear_endpoint_bw_info()
1567 bw_info->type = 0; in xhci_clear_endpoint_bw_info()
1568 bw_info->max_esit_payload = 0; in xhci_clear_endpoint_bw_info()
1582 bw_info = &virt_dev->eps[i].bw_info; in xhci_update_bw_info()
1585 * unconditionally clearing the bandwidth info for non-periodic in xhci_update_bw_info()
1597 ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1599 /* Ignore non-periodic endpoints */ in xhci_update_bw_info()
1606 bw_info->ep_interval = CTX_TO_EP_INTERVAL( in xhci_update_bw_info()
1607 le32_to_cpu(ep_ctx->ep_info)); in xhci_update_bw_info()
1608 /* Number of packets and mult are zero-based in the in xhci_update_bw_info()
1609 * input context, but we want one-based for the in xhci_update_bw_info()
1612 bw_info->mult = CTX_TO_EP_MULT( in xhci_update_bw_info()
1613 le32_to_cpu(ep_ctx->ep_info)) + 1; in xhci_update_bw_info()
1614 bw_info->num_packets = CTX_TO_MAX_BURST( in xhci_update_bw_info()
1615 le32_to_cpu(ep_ctx->ep_info2)) + 1; in xhci_update_bw_info()
1616 bw_info->max_packet_size = MAX_PACKET_DECODED( in xhci_update_bw_info()
1617 le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1618 bw_info->type = ep_type; in xhci_update_bw_info()
1619 bw_info->max_esit_payload = CTX_TO_MAX_ESIT_PAYLOAD( in xhci_update_bw_info()
1620 le32_to_cpu(ep_ctx->tx_info)); in xhci_update_bw_info()
1640 in_ep_ctx->ep_info = out_ep_ctx->ep_info; in xhci_endpoint_copy()
1641 in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2; in xhci_endpoint_copy()
1642 in_ep_ctx->deq = out_ep_ctx->deq; in xhci_endpoint_copy()
1643 in_ep_ctx->tx_info = out_ep_ctx->tx_info; in xhci_endpoint_copy()
1644 if (xhci->quirks & XHCI_MTK_HOST) { in xhci_endpoint_copy()
1645 in_ep_ctx->reserved[0] = out_ep_ctx->reserved[0]; in xhci_endpoint_copy()
1646 in_ep_ctx->reserved[1] = out_ep_ctx->reserved[1]; in xhci_endpoint_copy()
1665 in_slot_ctx->dev_info = out_slot_ctx->dev_info; in xhci_slot_copy()
1666 in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2; in xhci_slot_copy()
1667 in_slot_ctx->tt_info = out_slot_ctx->tt_info; in xhci_slot_copy()
1668 in_slot_ctx->dev_state = out_slot_ctx->dev_state; in xhci_slot_copy()
1675 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_alloc()
1676 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_alloc()
1684 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags, in scratchpad_alloc()
1686 if (!xhci->scratchpad) in scratchpad_alloc()
1689 xhci->scratchpad->sp_array = dma_alloc_coherent(dev, in scratchpad_alloc()
1691 &xhci->scratchpad->sp_dma, flags); in scratchpad_alloc()
1692 if (!xhci->scratchpad->sp_array) in scratchpad_alloc()
1695 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *), in scratchpad_alloc()
1697 if (!xhci->scratchpad->sp_buffers) in scratchpad_alloc()
1700 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); in scratchpad_alloc()
1703 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma, in scratchpad_alloc()
1708 xhci->scratchpad->sp_array[i] = dma; in scratchpad_alloc()
1709 xhci->scratchpad->sp_buffers[i] = buf; in scratchpad_alloc()
1715 for (i = i - 1; i >= 0; i--) { in scratchpad_alloc()
1716 dma_free_coherent(dev, xhci->page_size, in scratchpad_alloc()
1717 xhci->scratchpad->sp_buffers[i], in scratchpad_alloc()
1718 xhci->scratchpad->sp_array[i]); in scratchpad_alloc()
1721 kfree(xhci->scratchpad->sp_buffers); in scratchpad_alloc()
1725 xhci->scratchpad->sp_array, in scratchpad_alloc()
1726 xhci->scratchpad->sp_dma); in scratchpad_alloc()
1729 kfree(xhci->scratchpad); in scratchpad_alloc()
1730 xhci->scratchpad = NULL; in scratchpad_alloc()
1733 return -ENOMEM; in scratchpad_alloc()
1740 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_free()
1742 if (!xhci->scratchpad) in scratchpad_free()
1745 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_free()
1748 dma_free_coherent(dev, xhci->page_size, in scratchpad_free()
1749 xhci->scratchpad->sp_buffers[i], in scratchpad_free()
1750 xhci->scratchpad->sp_array[i]); in scratchpad_free()
1752 kfree(xhci->scratchpad->sp_buffers); in scratchpad_free()
1754 xhci->scratchpad->sp_array, in scratchpad_free()
1755 xhci->scratchpad->sp_dma); in scratchpad_free()
1756 kfree(xhci->scratchpad); in scratchpad_free()
1757 xhci->scratchpad = NULL; in scratchpad_free()
1764 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_command()
1771 command->completion = in xhci_alloc_command()
1774 if (!command->completion) { in xhci_alloc_command()
1778 init_completion(command->completion); in xhci_alloc_command()
1781 command->status = 0; in xhci_alloc_command()
1782 INIT_LIST_HEAD(&command->cmd_list); in xhci_alloc_command()
1795 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, in xhci_alloc_command_with_ctx()
1797 if (!command->in_ctx) { in xhci_alloc_command_with_ctx()
1798 kfree(command->completion); in xhci_alloc_command_with_ctx()
1814 command->in_ctx); in xhci_free_command()
1815 kfree(command->completion); in xhci_free_command()
1829 size = sizeof(struct xhci_erst_entry) * evt_ring->num_segs; in xhci_alloc_erst()
1830 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev, in xhci_alloc_erst()
1831 size, &erst->erst_dma_addr, flags); in xhci_alloc_erst()
1832 if (!erst->entries) in xhci_alloc_erst()
1833 return -ENOMEM; in xhci_alloc_erst()
1835 erst->num_entries = evt_ring->num_segs; in xhci_alloc_erst()
1837 seg = evt_ring->first_seg; in xhci_alloc_erst()
1838 for (val = 0; val < evt_ring->num_segs; val++) { in xhci_alloc_erst()
1839 entry = &erst->entries[val]; in xhci_alloc_erst()
1840 entry->seg_addr = cpu_to_le64(seg->dma); in xhci_alloc_erst()
1841 entry->seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in xhci_alloc_erst()
1842 entry->rsvd = 0; in xhci_alloc_erst()
1843 seg = seg->next; in xhci_alloc_erst()
1852 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_erst()
1854 size = sizeof(struct xhci_erst_entry) * (erst->num_entries); in xhci_free_erst()
1855 if (erst->entries) in xhci_free_erst()
1857 erst->entries, in xhci_free_erst()
1858 erst->erst_dma_addr); in xhci_free_erst()
1859 erst->entries = NULL; in xhci_free_erst()
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 xhci_free_erst(xhci, &xhci->erst); in xhci_mem_cleanup()
1871 if (xhci->event_ring) in xhci_mem_cleanup()
1872 xhci_ring_free(xhci, xhci->event_ring); in xhci_mem_cleanup()
1873 xhci->event_ring = NULL; in xhci_mem_cleanup()
1876 if (xhci->lpm_command) in xhci_mem_cleanup()
1877 xhci_free_command(xhci, xhci->lpm_command); in xhci_mem_cleanup()
1878 xhci->lpm_command = NULL; in xhci_mem_cleanup()
1879 if (xhci->cmd_ring) in xhci_mem_cleanup()
1880 xhci_ring_free(xhci, xhci->cmd_ring); in xhci_mem_cleanup()
1881 xhci->cmd_ring = NULL; in xhci_mem_cleanup()
1885 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_mem_cleanup()
1886 for (i = 0; i < num_ports && xhci->rh_bw; i++) { in xhci_mem_cleanup()
1887 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table; in xhci_mem_cleanup()
1889 struct list_head *ep = &bwt->interval_bw[j].endpoints; in xhci_mem_cleanup()
1891 list_del_init(ep->next); in xhci_mem_cleanup()
1895 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--) in xhci_mem_cleanup()
1898 dma_pool_destroy(xhci->segment_pool); in xhci_mem_cleanup()
1899 xhci->segment_pool = NULL; in xhci_mem_cleanup()
1902 dma_pool_destroy(xhci->device_pool); in xhci_mem_cleanup()
1903 xhci->device_pool = NULL; in xhci_mem_cleanup()
1906 dma_pool_destroy(xhci->small_streams_pool); in xhci_mem_cleanup()
1907 xhci->small_streams_pool = NULL; in xhci_mem_cleanup()
1911 dma_pool_destroy(xhci->medium_streams_pool); in xhci_mem_cleanup()
1912 xhci->medium_streams_pool = NULL; in xhci_mem_cleanup()
1916 if (xhci->dcbaa) in xhci_mem_cleanup()
1917 dma_free_coherent(dev, sizeof(*xhci->dcbaa), in xhci_mem_cleanup()
1918 xhci->dcbaa, xhci->dcbaa->dma); in xhci_mem_cleanup()
1919 xhci->dcbaa = NULL; in xhci_mem_cleanup()
1923 if (!xhci->rh_bw) in xhci_mem_cleanup()
1928 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) { in xhci_mem_cleanup()
1929 list_del(&tt->tt_list); in xhci_mem_cleanup()
1935 xhci->cmd_ring_reserved_trbs = 0; in xhci_mem_cleanup()
1936 xhci->usb2_rhub.num_ports = 0; in xhci_mem_cleanup()
1937 xhci->usb3_rhub.num_ports = 0; in xhci_mem_cleanup()
1938 xhci->num_active_eps = 0; in xhci_mem_cleanup()
1939 kfree(xhci->usb2_rhub.ports); in xhci_mem_cleanup()
1940 kfree(xhci->usb3_rhub.ports); in xhci_mem_cleanup()
1941 kfree(xhci->hw_ports); in xhci_mem_cleanup()
1942 kfree(xhci->rh_bw); in xhci_mem_cleanup()
1943 kfree(xhci->ext_caps); in xhci_mem_cleanup()
1944 for (i = 0; i < xhci->num_port_caps; i++) in xhci_mem_cleanup()
1945 kfree(xhci->port_caps[i].psi); in xhci_mem_cleanup()
1946 kfree(xhci->port_caps); in xhci_mem_cleanup()
1947 xhci->num_port_caps = 0; in xhci_mem_cleanup()
1949 xhci->usb2_rhub.ports = NULL; in xhci_mem_cleanup()
1950 xhci->usb3_rhub.ports = NULL; in xhci_mem_cleanup()
1951 xhci->hw_ports = NULL; in xhci_mem_cleanup()
1952 xhci->rh_bw = NULL; in xhci_mem_cleanup()
1953 xhci->ext_caps = NULL; in xhci_mem_cleanup()
1954 xhci->port_caps = NULL; in xhci_mem_cleanup()
1956 xhci->page_size = 0; in xhci_mem_cleanup()
1957 xhci->page_shift = 0; in xhci_mem_cleanup()
1958 xhci->usb2_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1959 xhci->usb3_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1993 return -1; in xhci_test_trb_in_td()
2008 { xhci->event_ring->first_seg->dma - 16, NULL }, in xhci_check_trb_in_td_math()
2010 { xhci->event_ring->first_seg->dma - 1, NULL }, in xhci_check_trb_in_td_math()
2012 { xhci->event_ring->first_seg->dma, xhci->event_ring->first_seg }, in xhci_check_trb_in_td_math()
2014 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 1)*16, in xhci_check_trb_in_td_math()
2015 xhci->event_ring->first_seg }, in xhci_check_trb_in_td_math()
2017 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 1)*16 + 1, NULL }, in xhci_check_trb_in_td_math()
2019 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT)*16, NULL }, in xhci_check_trb_in_td_math()
2031 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2032 .start_trb = xhci->event_ring->first_seg->trbs, in xhci_check_trb_in_td_math()
2033 .end_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1], in xhci_check_trb_in_td_math()
2034 .input_dma = xhci->cmd_ring->first_seg->dma, in xhci_check_trb_in_td_math()
2038 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2039 .start_trb = xhci->event_ring->first_seg->trbs, in xhci_check_trb_in_td_math()
2040 .end_trb = &xhci->cmd_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1], in xhci_check_trb_in_td_math()
2041 .input_dma = xhci->cmd_ring->first_seg->dma, in xhci_check_trb_in_td_math()
2045 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2046 .start_trb = xhci->cmd_ring->first_seg->trbs, in xhci_check_trb_in_td_math()
2047 .end_trb = &xhci->cmd_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1], in xhci_check_trb_in_td_math()
2048 .input_dma = xhci->cmd_ring->first_seg->dma, in xhci_check_trb_in_td_math()
2052 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2053 .start_trb = &xhci->event_ring->first_seg->trbs[0], in xhci_check_trb_in_td_math()
2054 .end_trb = &xhci->event_ring->first_seg->trbs[3], in xhci_check_trb_in_td_math()
2055 .input_dma = xhci->event_ring->first_seg->dma + 4*16, in xhci_check_trb_in_td_math()
2059 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2060 .start_trb = &xhci->event_ring->first_seg->trbs[3], in xhci_check_trb_in_td_math()
2061 .end_trb = &xhci->event_ring->first_seg->trbs[6], in xhci_check_trb_in_td_math()
2062 .input_dma = xhci->event_ring->first_seg->dma + 2*16, in xhci_check_trb_in_td_math()
2066 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2067 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3], in xhci_check_trb_in_td_math()
2068 .end_trb = &xhci->event_ring->first_seg->trbs[1], in xhci_check_trb_in_td_math()
2069 .input_dma = xhci->event_ring->first_seg->dma + 2*16, in xhci_check_trb_in_td_math()
2073 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2074 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3], in xhci_check_trb_in_td_math()
2075 .end_trb = &xhci->event_ring->first_seg->trbs[1], in xhci_check_trb_in_td_math()
2076 .input_dma = xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 4)*16, in xhci_check_trb_in_td_math()
2080 { .input_seg = xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2081 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3], in xhci_check_trb_in_td_math()
2082 .end_trb = &xhci->event_ring->first_seg->trbs[1], in xhci_check_trb_in_td_math()
2083 .input_dma = xhci->cmd_ring->first_seg->dma + 2*16, in xhci_check_trb_in_td_math()
2094 xhci->event_ring->first_seg, in xhci_check_trb_in_td_math()
2095 xhci->event_ring->first_seg->trbs, in xhci_check_trb_in_td_math()
2096 &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1], in xhci_check_trb_in_td_math()
2125 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, in xhci_set_hc_event_deq()
2126 xhci->event_ring->dequeue); in xhci_set_hc_event_deq()
2131 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
2141 &xhci->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
2151 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_add_in_port()
2159 rhub = &xhci->usb3_rhub; in xhci_add_in_port()
2161 * Some hosts incorrectly use sub-minor version for minor in xhci_add_in_port()
2173 if (xhci->quirks & XHCI_ZHAOXIN_HOST) { in xhci_add_in_port()
2179 rhub = &xhci->usb2_rhub; in xhci_add_in_port()
2197 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) in xhci_add_in_port()
2201 port_cap = &xhci->port_caps[xhci->num_port_caps++]; in xhci_add_in_port()
2202 if (xhci->num_port_caps > max_caps) in xhci_add_in_port()
2205 port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp); in xhci_add_in_port()
2207 if (port_cap->psi_count) { in xhci_add_in_port()
2208 port_cap->psi = kcalloc_node(port_cap->psi_count, in xhci_add_in_port()
2209 sizeof(*port_cap->psi), in xhci_add_in_port()
2211 if (!port_cap->psi) in xhci_add_in_port()
2212 port_cap->psi_count = 0; in xhci_add_in_port()
2214 port_cap->psi_uid_count++; in xhci_add_in_port()
2215 for (i = 0; i < port_cap->psi_count; i++) { in xhci_add_in_port()
2216 port_cap->psi[i] = readl(addr + 4 + i); in xhci_add_in_port()
2221 if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) != in xhci_add_in_port()
2222 XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1]))) in xhci_add_in_port()
2223 port_cap->psi_uid_count++; in xhci_add_in_port()
2225 if (xhci->quirks & XHCI_ZHAOXIN_HOST && in xhci_add_in_port()
2227 XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5) in xhci_add_in_port()
2231 XHCI_EXT_PORT_PSIV(port_cap->psi[i]), in xhci_add_in_port()
2232 XHCI_EXT_PORT_PSIE(port_cap->psi[i]), in xhci_add_in_port()
2233 XHCI_EXT_PORT_PLT(port_cap->psi[i]), in xhci_add_in_port()
2234 XHCI_EXT_PORT_PFD(port_cap->psi[i]), in xhci_add_in_port()
2235 XHCI_EXT_PORT_LP(port_cap->psi[i]), in xhci_add_in_port()
2236 XHCI_EXT_PORT_PSIM(port_cap->psi[i])); in xhci_add_in_port()
2240 rhub->maj_rev = major_revision; in xhci_add_in_port()
2242 if (rhub->min_rev < minor_revision) in xhci_add_in_port()
2243 rhub->min_rev = minor_revision; in xhci_add_in_port()
2245 port_cap->maj_rev = major_revision; in xhci_add_in_port()
2246 port_cap->min_rev = minor_revision; in xhci_add_in_port()
2249 if (major_revision < 0x03 && xhci->num_ext_caps < max_caps) in xhci_add_in_port()
2250 xhci->ext_caps[xhci->num_ext_caps++] = temp; in xhci_add_in_port()
2252 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) && in xhci_add_in_port()
2256 xhci->hw_lpm_support = 1; in xhci_add_in_port()
2259 port_offset--; in xhci_add_in_port()
2261 struct xhci_port *hw_port = &xhci->hw_ports[i]; in xhci_add_in_port()
2263 if (hw_port->rhub) { in xhci_add_in_port()
2268 hw_port->rhub->maj_rev, major_revision); in xhci_add_in_port()
2272 if (hw_port->rhub != rhub && in xhci_add_in_port()
2273 hw_port->hcd_portnum != DUPLICATE_ENTRY) { in xhci_add_in_port()
2274 hw_port->rhub->num_ports--; in xhci_add_in_port()
2275 hw_port->hcd_portnum = DUPLICATE_ENTRY; in xhci_add_in_port()
2279 hw_port->rhub = rhub; in xhci_add_in_port()
2280 hw_port->port_cap = port_cap; in xhci_add_in_port()
2281 rhub->num_ports++; in xhci_add_in_port()
2291 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_create_rhub_port_array()
2293 if (!rhub->num_ports) in xhci_create_rhub_port_array()
2295 rhub->ports = kcalloc_node(rhub->num_ports, sizeof(*rhub->ports), in xhci_create_rhub_port_array()
2297 if (!rhub->ports) in xhci_create_rhub_port_array()
2300 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { in xhci_create_rhub_port_array()
2301 if (xhci->hw_ports[i].rhub != rhub || in xhci_create_rhub_port_array()
2302 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY) in xhci_create_rhub_port_array()
2304 xhci->hw_ports[i].hcd_portnum = port_index; in xhci_create_rhub_port_array()
2305 rhub->ports[port_index] = &xhci->hw_ports[i]; in xhci_create_rhub_port_array()
2307 if (port_index == rhub->num_ports) in xhci_create_rhub_port_array()
2327 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_setup_port_arrays()
2329 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_setup_port_arrays()
2330 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports), in xhci_setup_port_arrays()
2332 if (!xhci->hw_ports) in xhci_setup_port_arrays()
2333 return -ENOMEM; in xhci_setup_port_arrays()
2336 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base + in xhci_setup_port_arrays()
2338 xhci->hw_ports[i].hw_portnum = i; in xhci_setup_port_arrays()
2340 init_completion(&xhci->hw_ports[i].rexit_done); in xhci_setup_port_arrays()
2341 init_completion(&xhci->hw_ports[i].u3exit_done); in xhci_setup_port_arrays()
2344 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags, in xhci_setup_port_arrays()
2346 if (!xhci->rh_bw) in xhci_setup_port_arrays()
2347 return -ENOMEM; in xhci_setup_port_arrays()
2351 INIT_LIST_HEAD(&xhci->rh_bw[i].tts); in xhci_setup_port_arrays()
2352 bw_table = &xhci->rh_bw[i].bw_table; in xhci_setup_port_arrays()
2354 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_setup_port_arrays()
2356 base = &xhci->cap_regs->hc_capbase; in xhci_setup_port_arrays()
2361 return -ENODEV; in xhci_setup_port_arrays()
2372 xhci->ext_caps = kcalloc_node(cap_count, sizeof(*xhci->ext_caps), in xhci_setup_port_arrays()
2374 if (!xhci->ext_caps) in xhci_setup_port_arrays()
2375 return -ENOMEM; in xhci_setup_port_arrays()
2377 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps), in xhci_setup_port_arrays()
2379 if (!xhci->port_caps) in xhci_setup_port_arrays()
2380 return -ENOMEM; in xhci_setup_port_arrays()
2386 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports == in xhci_setup_port_arrays()
2392 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) { in xhci_setup_port_arrays()
2394 return -ENODEV; in xhci_setup_port_arrays()
2398 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports); in xhci_setup_port_arrays()
2403 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) { in xhci_setup_port_arrays()
2407 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS; in xhci_setup_port_arrays()
2409 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) { in xhci_setup_port_arrays()
2413 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN; in xhci_setup_port_arrays()
2421 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags); in xhci_setup_port_arrays()
2422 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags); in xhci_setup_port_arrays()
2430 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_init()
2436 INIT_LIST_HEAD(&xhci->cmd_list); in xhci_mem_init()
2439 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); in xhci_mem_init()
2440 init_completion(&xhci->cmd_ring_stop_completion); in xhci_mem_init()
2442 page_size = readl(&xhci->op_regs->page_size); in xhci_mem_init()
2456 xhci->page_shift = 12; in xhci_mem_init()
2457 xhci->page_size = 1 << xhci->page_shift; in xhci_mem_init()
2459 "HCD page size set to %iK", xhci->page_size / 1024); in xhci_mem_init()
2465 val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1)); in xhci_mem_init()
2468 val2 = readl(&xhci->op_regs->config_reg); in xhci_mem_init()
2472 writel(val, &xhci->op_regs->config_reg); in xhci_mem_init()
2475 * xHCI section 5.4.6 - doorbell array must be in xhci_mem_init()
2476 * "physically contiguous and 64-byte (cache line) aligned". in xhci_mem_init()
2478 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, in xhci_mem_init()
2480 if (!xhci->dcbaa) in xhci_mem_init()
2482 xhci->dcbaa->dma = dma; in xhci_mem_init()
2485 (unsigned long long)xhci->dcbaa->dma, xhci->dcbaa); in xhci_mem_init()
2486 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); in xhci_mem_init()
2491 * however, the command ring segment needs 64-byte aligned segments in xhci_mem_init()
2495 if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH) in xhci_mem_init()
2496 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2497 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2); in xhci_mem_init()
2499 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2500 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); in xhci_mem_init()
2503 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, in xhci_mem_init()
2504 2112, 64, xhci->page_size); in xhci_mem_init()
2505 if (!xhci->segment_pool || !xhci->device_pool) in xhci_mem_init()
2509 * and only need to be 16-byte aligned. in xhci_mem_init()
2511 xhci->small_streams_pool = in xhci_mem_init()
2514 xhci->medium_streams_pool = in xhci_mem_init()
2521 if (!xhci->small_streams_pool || !xhci->medium_streams_pool) in xhci_mem_init()
2525 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, 0, flags); in xhci_mem_init()
2526 if (!xhci->cmd_ring) in xhci_mem_init()
2529 "Allocated command ring at %p", xhci->cmd_ring); in xhci_mem_init()
2531 (unsigned long long)xhci->cmd_ring->first_seg->dma); in xhci_mem_init()
2534 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2536 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | in xhci_mem_init()
2537 xhci->cmd_ring->cycle_state; in xhci_mem_init()
2540 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2542 xhci->lpm_command = xhci_alloc_command_with_ctx(xhci, true, flags); in xhci_mem_init()
2543 if (!xhci->lpm_command) in xhci_mem_init()
2550 xhci->cmd_ring_reserved_trbs++; in xhci_mem_init()
2552 val = readl(&xhci->cap_regs->db_off); in xhci_mem_init()
2557 xhci->dba = (void __iomem *) xhci->cap_regs + val; in xhci_mem_init()
2559 xhci->ir_set = &xhci->run_regs->ir_set[0]; in xhci_mem_init()
2566 xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, 1, TYPE_EVENT, in xhci_mem_init()
2568 if (!xhci->event_ring) in xhci_mem_init()
2573 ret = xhci_alloc_erst(xhci, xhci->event_ring, &xhci->erst, flags); in xhci_mem_init()
2578 val = readl(&xhci->ir_set->erst_size); in xhci_mem_init()
2584 writel(val, &xhci->ir_set->erst_size); in xhci_mem_init()
2591 (unsigned long long)xhci->erst.erst_dma_addr); in xhci_mem_init()
2592 val_64 = xhci_read_64(xhci, &xhci->ir_set->erst_base); in xhci_mem_init()
2594 val_64 |= (xhci->erst.erst_dma_addr & (u64) ~ERST_PTR_MASK); in xhci_mem_init()
2595 xhci_write_64(xhci, val_64, &xhci->ir_set->erst_base); in xhci_mem_init()
2608 xhci->devs[i] = NULL; in xhci_mem_init()
2619 temp = readl(&xhci->op_regs->dev_notification); in xhci_mem_init()
2622 writel(temp, &xhci->op_regs->dev_notification); in xhci_mem_init()
2630 return -ENOMEM; in xhci_mem_init()