Lines Matching +full:generic +full:- +full:xhci

1 // SPDX-License-Identifier: GPL-2.0
3 * xHCI host controller driver
16 #include <linux/dma-mapping.h>
18 #include "xhci.h"
19 #include "xhci-trace.h"
20 #include "xhci-debugfs.h"
23 * Allocates a generic ring segment from the ring pool, sets the dma address,
29 static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci, in xhci_segment_alloc() argument
37 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_segment_alloc()
43 seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma); in xhci_segment_alloc()
44 if (!seg->trbs) { in xhci_segment_alloc()
50 seg->bounce_buf = kzalloc_node(max_packet, flags, in xhci_segment_alloc()
52 if (!seg->bounce_buf) { in xhci_segment_alloc()
53 dma_pool_free(xhci->segment_pool, seg->trbs, dma); in xhci_segment_alloc()
61 seg->trbs[i].link.control = cpu_to_le32(TRB_CYCLE); in xhci_segment_alloc()
63 seg->dma = dma; in xhci_segment_alloc()
64 seg->next = NULL; in xhci_segment_alloc()
69 static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg) in xhci_segment_free() argument
71 if (seg->trbs) { in xhci_segment_free()
72 dma_pool_free(xhci->segment_pool, seg->trbs, seg->dma); in xhci_segment_free()
73 seg->trbs = NULL; in xhci_segment_free()
75 kfree(seg->bounce_buf); in xhci_segment_free()
79 static void xhci_free_segments_for_ring(struct xhci_hcd *xhci, in xhci_free_segments_for_ring() argument
84 seg = first->next; in xhci_free_segments_for_ring()
86 struct xhci_segment *next = seg->next; in xhci_free_segments_for_ring()
87 xhci_segment_free(xhci, seg); in xhci_free_segments_for_ring()
90 xhci_segment_free(xhci, first); in xhci_free_segments_for_ring()
108 prev->next = next; in xhci_link_segments()
110 prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = in xhci_link_segments()
111 cpu_to_le64(next->dma); in xhci_link_segments()
114 val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control); in xhci_link_segments()
119 prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val); in xhci_link_segments()
127 static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring, in xhci_link_rings() argument
138 chain_links = !!(xhci_link_trb_quirk(xhci) || in xhci_link_rings()
139 (ring->type == TYPE_ISOC && in xhci_link_rings()
140 (xhci->quirks & XHCI_AMD_0x96_HOST))); in xhci_link_rings()
142 next = ring->enq_seg->next; in xhci_link_rings()
143 xhci_link_segments(ring->enq_seg, first, ring->type, chain_links); in xhci_link_rings()
144 xhci_link_segments(last, next, ring->type, chain_links); in xhci_link_rings()
145 ring->num_segs += 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()
280 void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_ring_free() argument
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()
321 static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci, in xhci_alloc_segments_for_ring() argument
330 chain_links = !!(xhci_link_trb_quirk(xhci) || in xhci_alloc_segments_for_ring()
332 (xhci->quirks & XHCI_AMD_0x96_HOST))); in xhci_alloc_segments_for_ring()
334 prev = xhci_segment_alloc(xhci, cycle_state, max_packet, flags); in xhci_alloc_segments_for_ring()
336 return -ENOMEM; in xhci_alloc_segments_for_ring()
337 num_segs--; in xhci_alloc_segments_for_ring()
343 next = xhci_segment_alloc(xhci, cycle_state, max_packet, flags); in xhci_alloc_segments_for_ring()
347 next = prev->next; in xhci_alloc_segments_for_ring()
348 xhci_segment_free(xhci, prev); in xhci_alloc_segments_for_ring()
351 return -ENOMEM; in xhci_alloc_segments_for_ring()
356 num_segs--; in xhci_alloc_segments_for_ring()
371 struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, in xhci_ring_alloc() argument
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()
411 void xhci_free_endpoint_ring(struct xhci_hcd *xhci, in xhci_free_endpoint_ring() argument
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()
423 int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring, in xhci_ring_expansion() argument
430 ret = xhci_alloc_segments_for_ring(xhci, &first, &last, in xhci_ring_expansion()
431 num_new_segs, ring->cycle_state, ring->type, in xhci_ring_expansion()
432 ring->bounce_buf_len, flags); in xhci_ring_expansion()
434 return -ENOMEM; in xhci_ring_expansion()
436 if (ring->type == TYPE_STREAM) in xhci_ring_expansion()
437 ret = xhci_update_stream_segment_mapping(ring->trb_address_map, in xhci_ring_expansion()
442 next = first->next; in xhci_ring_expansion()
443 xhci_segment_free(xhci, first); in xhci_ring_expansion()
451 xhci_link_rings(xhci, ring, first, last, num_new_segs); in xhci_ring_expansion()
453 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, in xhci_ring_expansion()
455 ring->num_segs); in xhci_ring_expansion()
460 struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, in xhci_alloc_container_ctx() argument
464 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_container_ctx()
473 ctx->type = type; in xhci_alloc_container_ctx()
474 ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024; in xhci_alloc_container_ctx()
476 ctx->size += CTX_SIZE(xhci->hcc_params); in xhci_alloc_container_ctx()
478 ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma); in xhci_alloc_container_ctx()
479 if (!ctx->bytes) { in xhci_alloc_container_ctx()
486 void xhci_free_container_ctx(struct xhci_hcd *xhci, in xhci_free_container_ctx() argument
491 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma); in xhci_free_container_ctx()
498 if (ctx->type != XHCI_CTX_TYPE_INPUT) in xhci_get_input_control_ctx()
501 return (struct xhci_input_control_ctx *)ctx->bytes; in xhci_get_input_control_ctx()
504 struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, in xhci_get_slot_ctx() argument
507 if (ctx->type == XHCI_CTX_TYPE_DEVICE) in xhci_get_slot_ctx()
508 return (struct xhci_slot_ctx *)ctx->bytes; in xhci_get_slot_ctx()
511 (ctx->bytes + CTX_SIZE(xhci->hcc_params)); in xhci_get_slot_ctx()
514 struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, in xhci_get_ep_ctx() argument
520 if (ctx->type == XHCI_CTX_TYPE_INPUT) in xhci_get_ep_ctx()
524 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); in xhci_get_ep_ctx()
530 static void xhci_free_stream_ctx(struct xhci_hcd *xhci, in xhci_free_stream_ctx() argument
534 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_stream_ctx()
540 dma_pool_free(xhci->medium_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
542 dma_pool_free(xhci->small_streams_pool, stream_ctx, dma); in xhci_free_stream_ctx()
548 * - how many streams the endpoint supports,
549 * - the maximum primary stream array size the host controller supports,
550 * - and how many streams the device driver asks for.
555 static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, in xhci_alloc_stream_ctx() argument
559 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_ctx()
565 return dma_pool_zalloc(xhci->medium_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
567 return dma_pool_zalloc(xhci->small_streams_pool, mem_flags, dma); in xhci_alloc_stream_ctx()
574 if (ep->ep_state & EP_HAS_STREAMS) in xhci_dma_to_transfer_ring()
575 return radix_tree_lookup(&ep->stream_info->trb_address_map, in xhci_dma_to_transfer_ring()
577 return ep->ring; in xhci_dma_to_transfer_ring()
589 struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, in xhci_alloc_stream_info() argument
599 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_stream_info()
601 xhci_dbg(xhci, "Allocating %u streams and %u stream context array entries.\n", in xhci_alloc_stream_info()
603 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) { in xhci_alloc_stream_info()
604 xhci_dbg(xhci, "Command ring has no reserved TRBs available\n"); in xhci_alloc_stream_info()
607 xhci->cmd_ring_reserved_trbs++; in xhci_alloc_stream_info()
614 stream_info->num_streams = num_streams; in xhci_alloc_stream_info()
615 stream_info->num_stream_ctxs = num_stream_ctxs; in xhci_alloc_stream_info()
618 stream_info->stream_rings = kcalloc_node( in xhci_alloc_stream_info()
621 if (!stream_info->stream_rings) in xhci_alloc_stream_info()
625 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci, in xhci_alloc_stream_info()
626 num_stream_ctxs, &stream_info->ctx_array_dma, in xhci_alloc_stream_info()
628 if (!stream_info->stream_ctx_array) in xhci_alloc_stream_info()
632 stream_info->free_streams_command = in xhci_alloc_stream_info()
633 xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_alloc_stream_info()
634 if (!stream_info->free_streams_command) in xhci_alloc_stream_info()
637 INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC); in xhci_alloc_stream_info()
645 stream_info->stream_rings[cur_stream] = in xhci_alloc_stream_info()
646 xhci_ring_alloc(xhci, 2, 1, TYPE_STREAM, max_packet, in xhci_alloc_stream_info()
648 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
651 cur_ring->stream_id = cur_stream; in xhci_alloc_stream_info()
652 cur_ring->trb_address_map = &stream_info->trb_address_map; in xhci_alloc_stream_info()
654 addr = cur_ring->first_seg->dma | in xhci_alloc_stream_info()
656 cur_ring->cycle_state; in xhci_alloc_stream_info()
657 stream_info->stream_ctx_array[cur_stream].stream_ring = in xhci_alloc_stream_info()
659 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", cur_stream, addr); in xhci_alloc_stream_info()
663 xhci_ring_free(xhci, cur_ring); in xhci_alloc_stream_info()
664 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
679 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_alloc_stream_info()
681 xhci_ring_free(xhci, cur_ring); in xhci_alloc_stream_info()
682 stream_info->stream_rings[cur_stream] = NULL; in xhci_alloc_stream_info()
685 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_alloc_stream_info()
687 xhci_free_stream_ctx(xhci, in xhci_alloc_stream_info()
688 stream_info->num_stream_ctxs, in xhci_alloc_stream_info()
689 stream_info->stream_ctx_array, in xhci_alloc_stream_info()
690 stream_info->ctx_array_dma); in xhci_alloc_stream_info()
692 kfree(stream_info->stream_rings); in xhci_alloc_stream_info()
696 xhci->cmd_ring_reserved_trbs--; in xhci_alloc_stream_info()
703 void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci, in xhci_setup_streams_ep_input_ctx() argument
712 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2; in xhci_setup_streams_ep_input_ctx()
713 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_setup_streams_ep_input_ctx()
716 ep_ctx->ep_info &= cpu_to_le32(~EP_MAXPSTREAMS_MASK); in xhci_setup_streams_ep_input_ctx()
717 ep_ctx->ep_info |= cpu_to_le32(EP_MAXPSTREAMS(max_primary_streams) in xhci_setup_streams_ep_input_ctx()
719 ep_ctx->deq = cpu_to_le64(stream_info->ctx_array_dma); in xhci_setup_streams_ep_input_ctx()
731 ep_ctx->ep_info &= cpu_to_le32(~(EP_MAXPSTREAMS_MASK | EP_HAS_LSA)); in xhci_setup_no_streams_ep_input_ctx()
732 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue); in xhci_setup_no_streams_ep_input_ctx()
733 ep_ctx->deq = cpu_to_le64(addr | ep->ring->cycle_state); in xhci_setup_no_streams_ep_input_ctx()
740 void xhci_free_stream_info(struct xhci_hcd *xhci, in xhci_free_stream_info() argument
749 for (cur_stream = 1; cur_stream < stream_info->num_streams; in xhci_free_stream_info()
751 cur_ring = stream_info->stream_rings[cur_stream]; in xhci_free_stream_info()
753 xhci_ring_free(xhci, cur_ring); in xhci_free_stream_info()
754 stream_info->stream_rings[cur_stream] = NULL; in xhci_free_stream_info()
757 xhci_free_command(xhci, stream_info->free_streams_command); in xhci_free_stream_info()
758 xhci->cmd_ring_reserved_trbs--; in xhci_free_stream_info()
759 if (stream_info->stream_ctx_array) in xhci_free_stream_info()
760 xhci_free_stream_ctx(xhci, in xhci_free_stream_info()
761 stream_info->num_stream_ctxs, in xhci_free_stream_info()
762 stream_info->stream_ctx_array, in xhci_free_stream_info()
763 stream_info->ctx_array_dma); in xhci_free_stream_info()
765 kfree(stream_info->stream_rings); in xhci_free_stream_info()
772 static void xhci_free_tt_info(struct xhci_hcd *xhci, in xhci_free_tt_info() argument
783 if (virt_dev->real_port == 0 || in xhci_free_tt_info()
784 virt_dev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { in xhci_free_tt_info()
785 xhci_dbg(xhci, "Bad real port.\n"); in xhci_free_tt_info()
789 tt_list_head = &(xhci->rh_bw[virt_dev->real_port - 1].tts); in xhci_free_tt_info()
791 /* Multi-TT hubs will have more than one entry */ in xhci_free_tt_info()
792 if (tt_info->slot_id == slot_id) { in xhci_free_tt_info()
794 list_del(&tt_info->tt_list); in xhci_free_tt_info()
802 int xhci_alloc_tt_info(struct xhci_hcd *xhci, in xhci_alloc_tt_info() argument
810 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_tt_info()
812 if (!tt->multi) in xhci_alloc_tt_info()
815 num_ports = hdev->maxchild; in xhci_alloc_tt_info()
824 INIT_LIST_HEAD(&tt_info->tt_list); in xhci_alloc_tt_info()
825 list_add(&tt_info->tt_list, in xhci_alloc_tt_info()
826 &xhci->rh_bw[virt_dev->real_port - 1].tts); in xhci_alloc_tt_info()
827 tt_info->slot_id = virt_dev->udev->slot_id; in xhci_alloc_tt_info()
828 if (tt->multi) in xhci_alloc_tt_info()
829 tt_info->ttport = i+1; in xhci_alloc_tt_info()
830 bw_table = &tt_info->bw_table; in xhci_alloc_tt_info()
832 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_alloc_tt_info()
837 xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id); in xhci_alloc_tt_info()
838 return -ENOMEM; in xhci_alloc_tt_info()
843 * Should be called with xhci->lock held if there is any chance the TT lists
847 void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) in xhci_free_virt_device() argument
854 if (slot_id == 0 || !xhci->devs[slot_id]) in xhci_free_virt_device()
857 dev = xhci->devs[slot_id]; in xhci_free_virt_device()
859 xhci->dcbaa->dev_context_ptrs[slot_id] = 0; in xhci_free_virt_device()
865 if (dev->tt_info) in xhci_free_virt_device()
866 old_active_eps = dev->tt_info->active_eps; in xhci_free_virt_device()
869 if (dev->eps[i].ring) in xhci_free_virt_device()
870 xhci_ring_free(xhci, dev->eps[i].ring); in xhci_free_virt_device()
871 if (dev->eps[i].stream_info) in xhci_free_virt_device()
872 xhci_free_stream_info(xhci, in xhci_free_virt_device()
873 dev->eps[i].stream_info); in xhci_free_virt_device()
882 if (!list_empty(&dev->eps[i].bw_endpoint_list)) { in xhci_free_virt_device()
883 list_del_init(&dev->eps[i].bw_endpoint_list); in xhci_free_virt_device()
884 xhci_dbg(xhci, "Slot %u endpoint %u not removed from BW list!\n", in xhci_free_virt_device()
889 xhci_free_tt_info(xhci, dev, slot_id); in xhci_free_virt_device()
891 xhci_update_tt_active_eps(xhci, dev, old_active_eps); in xhci_free_virt_device()
893 if (dev->in_ctx) in xhci_free_virt_device()
894 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_free_virt_device()
895 if (dev->out_ctx) in xhci_free_virt_device()
896 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_free_virt_device()
898 if (dev->udev && dev->udev->slot_id) in xhci_free_virt_device()
899 dev->udev->slot_id = 0; in xhci_free_virt_device()
900 kfree(xhci->devs[slot_id]); in xhci_free_virt_device()
901 xhci->devs[slot_id] = NULL; in xhci_free_virt_device()
908 * We can't rely on udev at this point to find child-parent relationships.
910 static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id) in xhci_free_virt_devices_depth_first() argument
917 vdev = xhci->devs[slot_id]; in xhci_free_virt_devices_depth_first()
921 if (vdev->real_port == 0 || in xhci_free_virt_devices_depth_first()
922 vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { in xhci_free_virt_devices_depth_first()
923 xhci_dbg(xhci, "Bad vdev->real_port.\n"); in xhci_free_virt_devices_depth_first()
927 tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts); in xhci_free_virt_devices_depth_first()
930 if (tt_info->slot_id == slot_id) { in xhci_free_virt_devices_depth_first()
932 for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_free_virt_devices_depth_first()
933 vdev = xhci->devs[i]; in xhci_free_virt_devices_depth_first()
934 if (vdev && (vdev->tt_info == tt_info)) in xhci_free_virt_devices_depth_first()
936 xhci, i); in xhci_free_virt_devices_depth_first()
942 xhci_debugfs_remove_slot(xhci, slot_id); in xhci_free_virt_devices_depth_first()
943 xhci_free_virt_device(xhci, slot_id); in xhci_free_virt_devices_depth_first()
946 int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, in xhci_alloc_virt_device() argument
953 if (slot_id == 0 || xhci->devs[slot_id]) { in xhci_alloc_virt_device()
954 xhci_warn(xhci, "Bad Slot ID %d\n", slot_id); in xhci_alloc_virt_device()
962 dev->slot_id = slot_id; in xhci_alloc_virt_device()
965 dev->out_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags); in xhci_alloc_virt_device()
966 if (!dev->out_ctx) in xhci_alloc_virt_device()
969 xhci_dbg(xhci, "Slot %d output ctx = 0x%pad (dma)\n", slot_id, &dev->out_ctx->dma); in xhci_alloc_virt_device()
972 dev->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, flags); in xhci_alloc_virt_device()
973 if (!dev->in_ctx) in xhci_alloc_virt_device()
976 xhci_dbg(xhci, "Slot %d input ctx = 0x%pad (dma)\n", slot_id, &dev->in_ctx->dma); in xhci_alloc_virt_device()
980 dev->eps[i].ep_index = i; in xhci_alloc_virt_device()
981 dev->eps[i].vdev = dev; in xhci_alloc_virt_device()
982 dev->eps[i].xhci = xhci; in xhci_alloc_virt_device()
983 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); in xhci_alloc_virt_device()
984 INIT_LIST_HEAD(&dev->eps[i].bw_endpoint_list); in xhci_alloc_virt_device()
988 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, 1, TYPE_CTRL, 0, flags); in xhci_alloc_virt_device()
989 if (!dev->eps[0].ring) in xhci_alloc_virt_device()
992 dev->udev = udev; in xhci_alloc_virt_device()
995 xhci->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(dev->out_ctx->dma); in xhci_alloc_virt_device()
996 xhci_dbg(xhci, "Set slot id %d dcbaa entry %p to 0x%llx\n", in xhci_alloc_virt_device()
998 &xhci->dcbaa->dev_context_ptrs[slot_id], in xhci_alloc_virt_device()
999 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[slot_id])); in xhci_alloc_virt_device()
1003 xhci->devs[slot_id] = dev; in xhci_alloc_virt_device()
1008 if (dev->in_ctx) in xhci_alloc_virt_device()
1009 xhci_free_container_ctx(xhci, dev->in_ctx); in xhci_alloc_virt_device()
1010 if (dev->out_ctx) in xhci_alloc_virt_device()
1011 xhci_free_container_ctx(xhci, dev->out_ctx); in xhci_alloc_virt_device()
1017 void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci, in xhci_copy_ep0_dequeue_into_input_ctx() argument
1024 virt_dev = xhci->devs[udev->slot_id]; in xhci_copy_ep0_dequeue_into_input_ctx()
1025 ep0_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, 0); in xhci_copy_ep0_dequeue_into_input_ctx()
1026 ep_ring = virt_dev->eps[0].ring; in xhci_copy_ep0_dequeue_into_input_ctx()
1034 ep0_ctx->deq = cpu_to_le64(xhci_trb_virt_to_dma(ep_ring->enq_seg, in xhci_copy_ep0_dequeue_into_input_ctx()
1035 ep_ring->enqueue) in xhci_copy_ep0_dequeue_into_input_ctx()
1036 | ep_ring->cycle_state); in xhci_copy_ep0_dequeue_into_input_ctx()
1040 * The xHCI roothub may have ports of differing speeds in any order in the port
1043 * The xHCI hardware wants to know the roothub port number that the USB device
1049 static u32 xhci_find_real_port_number(struct xhci_hcd *xhci, in xhci_find_real_port_number() argument
1055 if (udev->speed >= USB_SPEED_SUPER) in xhci_find_real_port_number()
1056 hcd = xhci_get_usb3_hcd(xhci); in xhci_find_real_port_number()
1058 hcd = xhci->main_hcd; in xhci_find_real_port_number()
1060 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; in xhci_find_real_port_number()
1061 top_dev = top_dev->parent) in xhci_find_real_port_number()
1064 return xhci_find_raw_port_number(hcd, top_dev->portnum); in xhci_find_real_port_number()
1067 /* Setup an xHCI virtual device for a Set Address command */
1068 int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) in xhci_setup_addressable_virt_dev() argument
1077 dev = xhci->devs[udev->slot_id]; in xhci_setup_addressable_virt_dev()
1079 if (udev->slot_id == 0 || !dev) { in xhci_setup_addressable_virt_dev()
1080 xhci_warn(xhci, "Slot ID %d is not assigned to this device\n", in xhci_setup_addressable_virt_dev()
1081 udev->slot_id); in xhci_setup_addressable_virt_dev()
1082 return -EINVAL; in xhci_setup_addressable_virt_dev()
1084 ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); in xhci_setup_addressable_virt_dev()
1085 slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); in xhci_setup_addressable_virt_dev()
1087 /* 3) Only the control endpoint is valid - one endpoint context */ in xhci_setup_addressable_virt_dev()
1088 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); in xhci_setup_addressable_virt_dev()
1089 switch (udev->speed) { in xhci_setup_addressable_virt_dev()
1091 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SSP); in xhci_setup_addressable_virt_dev()
1095 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS); in xhci_setup_addressable_virt_dev()
1099 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS); in xhci_setup_addressable_virt_dev()
1102 /* USB core guesses at a 64-byte max packet first for FS devices */ in xhci_setup_addressable_virt_dev()
1104 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS); in xhci_setup_addressable_virt_dev()
1108 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS); in xhci_setup_addressable_virt_dev()
1113 return -EINVAL; in xhci_setup_addressable_virt_dev()
1116 port_num = xhci_find_real_port_number(xhci, udev); in xhci_setup_addressable_virt_dev()
1118 return -EINVAL; in xhci_setup_addressable_virt_dev()
1119 slot_ctx->dev_info2 |= cpu_to_le32(ROOT_HUB_PORT(port_num)); in xhci_setup_addressable_virt_dev()
1121 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; in xhci_setup_addressable_virt_dev()
1122 top_dev = top_dev->parent) in xhci_setup_addressable_virt_dev()
1124 dev->fake_port = top_dev->portnum; in xhci_setup_addressable_virt_dev()
1125 dev->real_port = port_num; in xhci_setup_addressable_virt_dev()
1126 xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num); in xhci_setup_addressable_virt_dev()
1127 xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->fake_port); in xhci_setup_addressable_virt_dev()
1135 if (!udev->tt || !udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1136 dev->bw_table = &xhci->rh_bw[port_num - 1].bw_table; in xhci_setup_addressable_virt_dev()
1141 rh_bw = &xhci->rh_bw[port_num - 1]; in xhci_setup_addressable_virt_dev()
1143 list_for_each_entry(tt_bw, &rh_bw->tts, tt_list) { in xhci_setup_addressable_virt_dev()
1144 if (tt_bw->slot_id != udev->tt->hub->slot_id) in xhci_setup_addressable_virt_dev()
1147 if (!dev->udev->tt->multi || in xhci_setup_addressable_virt_dev()
1148 (udev->tt->multi && in xhci_setup_addressable_virt_dev()
1149 tt_bw->ttport == dev->udev->ttport)) { in xhci_setup_addressable_virt_dev()
1150 dev->bw_table = &tt_bw->bw_table; in xhci_setup_addressable_virt_dev()
1151 dev->tt_info = tt_bw; in xhci_setup_addressable_virt_dev()
1155 if (!dev->tt_info) in xhci_setup_addressable_virt_dev()
1156 xhci_warn(xhci, "WARN: Didn't find a matching TT\n"); in xhci_setup_addressable_virt_dev()
1160 if (udev->tt && udev->tt->hub->parent) { in xhci_setup_addressable_virt_dev()
1161 slot_ctx->tt_info = cpu_to_le32(udev->tt->hub->slot_id | in xhci_setup_addressable_virt_dev()
1162 (udev->ttport << 8)); in xhci_setup_addressable_virt_dev()
1163 if (udev->tt->multi) in xhci_setup_addressable_virt_dev()
1164 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_setup_addressable_virt_dev()
1166 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); in xhci_setup_addressable_virt_dev()
1167 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); in xhci_setup_addressable_virt_dev()
1169 /* Step 4 - ring already allocated */ in xhci_setup_addressable_virt_dev()
1171 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP)); in xhci_setup_addressable_virt_dev()
1174 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) | in xhci_setup_addressable_virt_dev()
1177 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma | in xhci_setup_addressable_virt_dev()
1178 dev->eps[0].ring->cycle_state); in xhci_setup_addressable_virt_dev()
1188 * Convert interval expressed as 2^(bInterval - 1) == interval into
1197 interval = clamp_val(ep->desc.bInterval, 1, 16) - 1; in xhci_parse_exponent_interval()
1198 if (interval != ep->desc.bInterval - 1) in xhci_parse_exponent_interval()
1199 dev_warn(&udev->dev, in xhci_parse_exponent_interval()
1200 "ep %#x - rounding interval to %d %sframes\n", in xhci_parse_exponent_interval()
1201 ep->desc.bEndpointAddress, in xhci_parse_exponent_interval()
1203 udev->speed == USB_SPEED_FULL ? "" : "micro"); in xhci_parse_exponent_interval()
1205 if (udev->speed == USB_SPEED_FULL) { in xhci_parse_exponent_interval()
1218 * Convert bInterval expressed in microframes (in 1-255 range) to exponent of
1227 interval = fls(desc_interval) - 1; in xhci_microframes_to_exponent()
1230 dev_dbg(&udev->dev, in xhci_microframes_to_exponent()
1231 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n", in xhci_microframes_to_exponent()
1232 ep->desc.bEndpointAddress, in xhci_microframes_to_exponent()
1242 if (ep->desc.bInterval == 0) in xhci_parse_microframe_interval()
1245 ep->desc.bInterval, 0, 15); in xhci_parse_microframe_interval()
1253 ep->desc.bInterval * 8, 3, 10); in xhci_parse_frame_interval()
1258 * The polling interval is expressed in "microframes". If xHCI's Interval field
1269 switch (udev->speed) { in xhci_get_endpoint_interval()
1272 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_endpoint_interval()
1273 usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_get_endpoint_interval()
1281 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1282 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1288 if (usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1300 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_get_endpoint_interval()
1301 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_get_endpoint_interval()
1321 if (udev->speed < USB_SPEED_SUPER || in xhci_get_endpoint_mult()
1322 !usb_endpoint_xfer_isoc(&ep->desc)) in xhci_get_endpoint_mult()
1324 return ep->ss_ep_comp.bmAttributes; in xhci_get_endpoint_mult()
1331 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_endpoint_max_burst()
1332 return ep->ss_ep_comp.bMaxBurst; in xhci_get_endpoint_max_burst()
1334 if (udev->speed == USB_SPEED_HIGH && in xhci_get_endpoint_max_burst()
1335 (usb_endpoint_xfer_isoc(&ep->desc) || in xhci_get_endpoint_max_burst()
1336 usb_endpoint_xfer_int(&ep->desc))) in xhci_get_endpoint_max_burst()
1337 return usb_endpoint_maxp_mult(&ep->desc) - 1; in xhci_get_endpoint_max_burst()
1346 in = usb_endpoint_dir_in(&ep->desc); in xhci_get_endpoint_type()
1348 switch (usb_endpoint_type(&ep->desc)) { in xhci_get_endpoint_type()
1372 if (usb_endpoint_xfer_control(&ep->desc) || in xhci_get_max_esit_payload()
1373 usb_endpoint_xfer_bulk(&ep->desc)) in xhci_get_max_esit_payload()
1377 if ((udev->speed >= USB_SPEED_SUPER_PLUS) && in xhci_get_max_esit_payload()
1378 USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes)) in xhci_get_max_esit_payload()
1379 return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval); in xhci_get_max_esit_payload()
1382 if (udev->speed >= USB_SPEED_SUPER) in xhci_get_max_esit_payload()
1383 return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); in xhci_get_max_esit_payload()
1385 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_get_max_esit_payload()
1386 max_burst = usb_endpoint_maxp_mult(&ep->desc); in xhci_get_max_esit_payload()
1394 int xhci_endpoint_init(struct xhci_hcd *xhci, in xhci_endpoint_init() argument
1413 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_init()
1414 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_init()
1418 return -EINVAL; in xhci_endpoint_init()
1420 ring_type = usb_endpoint_type(&ep->desc); in xhci_endpoint_init()
1426 * set it to max available. See xHCI 1.1 spec 4.14.1.1 for details. in xhci_endpoint_init()
1432 if (usb_endpoint_xfer_int(&ep->desc) || in xhci_endpoint_init()
1433 usb_endpoint_xfer_isoc(&ep->desc)) { in xhci_endpoint_init()
1434 if ((xhci->quirks & XHCI_LIMIT_ENDPOINT_INTERVAL_7) && in xhci_endpoint_init()
1435 udev->speed >= USB_SPEED_HIGH && in xhci_endpoint_init()
1442 max_packet = usb_endpoint_maxp(&ep->desc); in xhci_endpoint_init()
1449 if (!usb_endpoint_xfer_isoc(&ep->desc)) in xhci_endpoint_init()
1452 if (usb_endpoint_xfer_bulk(&ep->desc)) { in xhci_endpoint_init()
1453 if (udev->speed == USB_SPEED_HIGH) in xhci_endpoint_init()
1455 if (udev->speed == USB_SPEED_FULL) { in xhci_endpoint_init()
1460 /* xHCI 1.0 and 1.1 indicates that ctrl ep avg TRB Length should be 8 */ in xhci_endpoint_init()
1461 if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100) in xhci_endpoint_init()
1463 /* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */ in xhci_endpoint_init()
1464 if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2)) in xhci_endpoint_init()
1468 virt_dev->eps[ep_index].new_ring = in xhci_endpoint_init()
1469 xhci_ring_alloc(xhci, 2, 1, ring_type, max_packet, mem_flags); in xhci_endpoint_init()
1470 if (!virt_dev->eps[ep_index].new_ring) in xhci_endpoint_init()
1471 return -ENOMEM; in xhci_endpoint_init()
1473 virt_dev->eps[ep_index].skip = false; in xhci_endpoint_init()
1474 ep_ring = virt_dev->eps[ep_index].new_ring; in xhci_endpoint_init()
1477 ep_ctx->ep_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) | in xhci_endpoint_init()
1480 ep_ctx->ep_info2 = cpu_to_le32(EP_TYPE(endpoint_type) | in xhci_endpoint_init()
1484 ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma | in xhci_endpoint_init()
1485 ep_ring->cycle_state); in xhci_endpoint_init()
1487 ep_ctx->tx_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) | in xhci_endpoint_init()
1493 void xhci_endpoint_zero(struct xhci_hcd *xhci, in xhci_endpoint_zero() argument
1500 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_endpoint_zero()
1501 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_endpoint_zero()
1503 ep_ctx->ep_info = 0; in xhci_endpoint_zero()
1504 ep_ctx->ep_info2 = 0; in xhci_endpoint_zero()
1505 ep_ctx->deq = 0; in xhci_endpoint_zero()
1506 ep_ctx->tx_info = 0; in xhci_endpoint_zero()
1514 bw_info->ep_interval = 0; in xhci_clear_endpoint_bw_info()
1515 bw_info->mult = 0; in xhci_clear_endpoint_bw_info()
1516 bw_info->num_packets = 0; in xhci_clear_endpoint_bw_info()
1517 bw_info->max_packet_size = 0; in xhci_clear_endpoint_bw_info()
1518 bw_info->type = 0; in xhci_clear_endpoint_bw_info()
1519 bw_info->max_esit_payload = 0; in xhci_clear_endpoint_bw_info()
1522 void xhci_update_bw_info(struct xhci_hcd *xhci, in xhci_update_bw_info() argument
1533 bw_info = &virt_dev->eps[i].bw_info; in xhci_update_bw_info()
1536 * unconditionally clearing the bandwidth info for non-periodic in xhci_update_bw_info()
1547 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, i); in xhci_update_bw_info()
1548 ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1550 /* Ignore non-periodic endpoints */ in xhci_update_bw_info()
1557 bw_info->ep_interval = CTX_TO_EP_INTERVAL( in xhci_update_bw_info()
1558 le32_to_cpu(ep_ctx->ep_info)); in xhci_update_bw_info()
1559 /* Number of packets and mult are zero-based in the in xhci_update_bw_info()
1560 * input context, but we want one-based for the in xhci_update_bw_info()
1563 bw_info->mult = CTX_TO_EP_MULT( in xhci_update_bw_info()
1564 le32_to_cpu(ep_ctx->ep_info)) + 1; in xhci_update_bw_info()
1565 bw_info->num_packets = CTX_TO_MAX_BURST( in xhci_update_bw_info()
1566 le32_to_cpu(ep_ctx->ep_info2)) + 1; in xhci_update_bw_info()
1567 bw_info->max_packet_size = MAX_PACKET_DECODED( in xhci_update_bw_info()
1568 le32_to_cpu(ep_ctx->ep_info2)); in xhci_update_bw_info()
1569 bw_info->type = ep_type; in xhci_update_bw_info()
1570 bw_info->max_esit_payload = CTX_TO_MAX_ESIT_PAYLOAD( in xhci_update_bw_info()
1571 le32_to_cpu(ep_ctx->tx_info)); in xhci_update_bw_info()
1580 void xhci_endpoint_copy(struct xhci_hcd *xhci, in xhci_endpoint_copy() argument
1588 out_ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_endpoint_copy()
1589 in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); in xhci_endpoint_copy()
1591 in_ep_ctx->ep_info = out_ep_ctx->ep_info; in xhci_endpoint_copy()
1592 in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2; in xhci_endpoint_copy()
1593 in_ep_ctx->deq = out_ep_ctx->deq; in xhci_endpoint_copy()
1594 in_ep_ctx->tx_info = out_ep_ctx->tx_info; in xhci_endpoint_copy()
1595 if (xhci->quirks & XHCI_MTK_HOST) { in xhci_endpoint_copy()
1596 in_ep_ctx->reserved[0] = out_ep_ctx->reserved[0]; in xhci_endpoint_copy()
1597 in_ep_ctx->reserved[1] = out_ep_ctx->reserved[1]; in xhci_endpoint_copy()
1606 void xhci_slot_copy(struct xhci_hcd *xhci, in xhci_slot_copy() argument
1613 in_slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); in xhci_slot_copy()
1614 out_slot_ctx = xhci_get_slot_ctx(xhci, out_ctx); in xhci_slot_copy()
1616 in_slot_ctx->dev_info = out_slot_ctx->dev_info; in xhci_slot_copy()
1617 in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2; in xhci_slot_copy()
1618 in_slot_ctx->tt_info = out_slot_ctx->tt_info; in xhci_slot_copy()
1619 in_slot_ctx->dev_state = out_slot_ctx->dev_state; in xhci_slot_copy()
1623 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) in scratchpad_alloc() argument
1626 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_alloc()
1627 int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_alloc()
1629 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in scratchpad_alloc()
1635 xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags, in scratchpad_alloc()
1637 if (!xhci->scratchpad) in scratchpad_alloc()
1640 xhci->scratchpad->sp_array = dma_alloc_coherent(dev, in scratchpad_alloc()
1642 &xhci->scratchpad->sp_dma, flags); in scratchpad_alloc()
1643 if (!xhci->scratchpad->sp_array) in scratchpad_alloc()
1646 xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *), in scratchpad_alloc()
1648 if (!xhci->scratchpad->sp_buffers) in scratchpad_alloc()
1651 xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); in scratchpad_alloc()
1654 void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma, in scratchpad_alloc()
1659 xhci->scratchpad->sp_array[i] = dma; in scratchpad_alloc()
1660 xhci->scratchpad->sp_buffers[i] = buf; in scratchpad_alloc()
1666 while (i--) in scratchpad_alloc()
1667 dma_free_coherent(dev, xhci->page_size, in scratchpad_alloc()
1668 xhci->scratchpad->sp_buffers[i], in scratchpad_alloc()
1669 xhci->scratchpad->sp_array[i]); in scratchpad_alloc()
1671 kfree(xhci->scratchpad->sp_buffers); in scratchpad_alloc()
1675 xhci->scratchpad->sp_array, in scratchpad_alloc()
1676 xhci->scratchpad->sp_dma); in scratchpad_alloc()
1679 kfree(xhci->scratchpad); in scratchpad_alloc()
1680 xhci->scratchpad = NULL; in scratchpad_alloc()
1683 return -ENOMEM; in scratchpad_alloc()
1686 static void scratchpad_free(struct xhci_hcd *xhci) in scratchpad_free() argument
1690 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in scratchpad_free()
1692 if (!xhci->scratchpad) in scratchpad_free()
1695 num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); in scratchpad_free()
1698 dma_free_coherent(dev, xhci->page_size, in scratchpad_free()
1699 xhci->scratchpad->sp_buffers[i], in scratchpad_free()
1700 xhci->scratchpad->sp_array[i]); in scratchpad_free()
1702 kfree(xhci->scratchpad->sp_buffers); in scratchpad_free()
1704 xhci->scratchpad->sp_array, in scratchpad_free()
1705 xhci->scratchpad->sp_dma); in scratchpad_free()
1706 kfree(xhci->scratchpad); in scratchpad_free()
1707 xhci->scratchpad = NULL; in scratchpad_free()
1710 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, in xhci_alloc_command() argument
1714 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_command()
1721 command->completion = in xhci_alloc_command()
1724 if (!command->completion) { in xhci_alloc_command()
1728 init_completion(command->completion); in xhci_alloc_command()
1731 command->status = 0; in xhci_alloc_command()
1733 command->timeout_ms = XHCI_CMD_DEFAULT_TIMEOUT; in xhci_alloc_command()
1734 INIT_LIST_HEAD(&command->cmd_list); in xhci_alloc_command()
1738 struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci, in xhci_alloc_command_with_ctx() argument
1743 command = xhci_alloc_command(xhci, allocate_completion, mem_flags); in xhci_alloc_command_with_ctx()
1747 command->in_ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, in xhci_alloc_command_with_ctx()
1749 if (!command->in_ctx) { in xhci_alloc_command_with_ctx()
1750 kfree(command->completion); in xhci_alloc_command_with_ctx()
1762 void xhci_free_command(struct xhci_hcd *xhci, in xhci_free_command() argument
1765 xhci_free_container_ctx(xhci, in xhci_free_command()
1766 command->in_ctx); in xhci_free_command()
1767 kfree(command->completion); in xhci_free_command()
1771 int xhci_alloc_erst(struct xhci_hcd *xhci, in xhci_alloc_erst() argument
1781 size = size_mul(sizeof(struct xhci_erst_entry), evt_ring->num_segs); in xhci_alloc_erst()
1782 erst->entries = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev, in xhci_alloc_erst()
1783 size, &erst->erst_dma_addr, flags); in xhci_alloc_erst()
1784 if (!erst->entries) in xhci_alloc_erst()
1785 return -ENOMEM; in xhci_alloc_erst()
1787 erst->num_entries = evt_ring->num_segs; in xhci_alloc_erst()
1789 seg = evt_ring->first_seg; in xhci_alloc_erst()
1790 for (val = 0; val < evt_ring->num_segs; val++) { in xhci_alloc_erst()
1791 entry = &erst->entries[val]; in xhci_alloc_erst()
1792 entry->seg_addr = cpu_to_le64(seg->dma); in xhci_alloc_erst()
1793 entry->seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in xhci_alloc_erst()
1794 entry->rsvd = 0; in xhci_alloc_erst()
1795 seg = seg->next; in xhci_alloc_erst()
1802 xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_free_interrupter() argument
1804 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_free_interrupter()
1812 erst_size = sizeof(struct xhci_erst_entry) * ir->erst.num_entries; in xhci_free_interrupter()
1813 if (ir->erst.entries) in xhci_free_interrupter()
1815 ir->erst.entries, in xhci_free_interrupter()
1816 ir->erst.erst_dma_addr); in xhci_free_interrupter()
1817 ir->erst.entries = NULL; in xhci_free_interrupter()
1824 if (ir->ir_set) { in xhci_free_interrupter()
1825 tmp = readl(&ir->ir_set->erst_size); in xhci_free_interrupter()
1827 writel(tmp, &ir->ir_set->erst_size); in xhci_free_interrupter()
1829 tmp64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_free_interrupter()
1831 xhci_write_64(xhci, tmp64, &ir->ir_set->erst_dequeue); in xhci_free_interrupter()
1835 if (ir->event_ring) in xhci_free_interrupter()
1836 xhci_ring_free(xhci, ir->event_ring); in xhci_free_interrupter()
1837 ir->event_ring = NULL; in xhci_free_interrupter()
1842 void xhci_mem_cleanup(struct xhci_hcd *xhci) in xhci_mem_cleanup() argument
1844 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_cleanup()
1847 cancel_delayed_work_sync(&xhci->cmd_timer); in xhci_mem_cleanup()
1849 xhci_free_interrupter(xhci, xhci->interrupter); in xhci_mem_cleanup()
1850 xhci->interrupter = NULL; in xhci_mem_cleanup()
1851 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed primary event ring"); in xhci_mem_cleanup()
1853 if (xhci->cmd_ring) in xhci_mem_cleanup()
1854 xhci_ring_free(xhci, xhci->cmd_ring); in xhci_mem_cleanup()
1855 xhci->cmd_ring = NULL; in xhci_mem_cleanup()
1856 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring"); in xhci_mem_cleanup()
1857 xhci_cleanup_command_queue(xhci); in xhci_mem_cleanup()
1859 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_mem_cleanup()
1860 for (i = 0; i < num_ports && xhci->rh_bw; i++) { in xhci_mem_cleanup()
1861 struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table; in xhci_mem_cleanup()
1863 struct list_head *ep = &bwt->interval_bw[j].endpoints; in xhci_mem_cleanup()
1865 list_del_init(ep->next); in xhci_mem_cleanup()
1869 for (i = HCS_MAX_SLOTS(xhci->hcs_params1); i > 0; i--) in xhci_mem_cleanup()
1870 xhci_free_virt_devices_depth_first(xhci, i); in xhci_mem_cleanup()
1872 dma_pool_destroy(xhci->segment_pool); in xhci_mem_cleanup()
1873 xhci->segment_pool = NULL; in xhci_mem_cleanup()
1874 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed segment pool"); in xhci_mem_cleanup()
1876 dma_pool_destroy(xhci->device_pool); in xhci_mem_cleanup()
1877 xhci->device_pool = NULL; in xhci_mem_cleanup()
1878 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed device context pool"); in xhci_mem_cleanup()
1880 dma_pool_destroy(xhci->small_streams_pool); in xhci_mem_cleanup()
1881 xhci->small_streams_pool = NULL; in xhci_mem_cleanup()
1882 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_cleanup()
1885 dma_pool_destroy(xhci->medium_streams_pool); in xhci_mem_cleanup()
1886 xhci->medium_streams_pool = NULL; in xhci_mem_cleanup()
1887 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_cleanup()
1890 if (xhci->dcbaa) in xhci_mem_cleanup()
1891 dma_free_coherent(dev, sizeof(*xhci->dcbaa), in xhci_mem_cleanup()
1892 xhci->dcbaa, xhci->dcbaa->dma); in xhci_mem_cleanup()
1893 xhci->dcbaa = NULL; in xhci_mem_cleanup()
1895 scratchpad_free(xhci); in xhci_mem_cleanup()
1897 if (!xhci->rh_bw) in xhci_mem_cleanup()
1902 list_for_each_entry_safe(tt, n, &xhci->rh_bw[i].tts, tt_list) { in xhci_mem_cleanup()
1903 list_del(&tt->tt_list); in xhci_mem_cleanup()
1909 xhci->cmd_ring_reserved_trbs = 0; in xhci_mem_cleanup()
1910 xhci->usb2_rhub.num_ports = 0; in xhci_mem_cleanup()
1911 xhci->usb3_rhub.num_ports = 0; in xhci_mem_cleanup()
1912 xhci->num_active_eps = 0; in xhci_mem_cleanup()
1913 kfree(xhci->usb2_rhub.ports); in xhci_mem_cleanup()
1914 kfree(xhci->usb3_rhub.ports); in xhci_mem_cleanup()
1915 kfree(xhci->hw_ports); in xhci_mem_cleanup()
1916 kfree(xhci->rh_bw); in xhci_mem_cleanup()
1917 kfree(xhci->ext_caps); in xhci_mem_cleanup()
1918 for (i = 0; i < xhci->num_port_caps; i++) in xhci_mem_cleanup()
1919 kfree(xhci->port_caps[i].psi); in xhci_mem_cleanup()
1920 kfree(xhci->port_caps); in xhci_mem_cleanup()
1921 xhci->num_port_caps = 0; in xhci_mem_cleanup()
1923 xhci->usb2_rhub.ports = NULL; in xhci_mem_cleanup()
1924 xhci->usb3_rhub.ports = NULL; in xhci_mem_cleanup()
1925 xhci->hw_ports = NULL; in xhci_mem_cleanup()
1926 xhci->rh_bw = NULL; in xhci_mem_cleanup()
1927 xhci->ext_caps = NULL; in xhci_mem_cleanup()
1928 xhci->port_caps = NULL; in xhci_mem_cleanup()
1930 xhci->page_size = 0; in xhci_mem_cleanup()
1931 xhci->page_shift = 0; in xhci_mem_cleanup()
1932 xhci->usb2_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1933 xhci->usb3_rhub.bus_state.bus_suspended = 0; in xhci_mem_cleanup()
1936 static void xhci_set_hc_event_deq(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_set_hc_event_deq() argument
1941 deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, in xhci_set_hc_event_deq()
1942 ir->event_ring->dequeue); in xhci_set_hc_event_deq()
1944 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr.\n"); in xhci_set_hc_event_deq()
1946 temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
1952 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_set_hc_event_deq()
1954 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp, in xhci_set_hc_event_deq()
1955 &ir->ir_set->erst_dequeue); in xhci_set_hc_event_deq()
1958 static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, in xhci_add_in_port() argument
1965 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_add_in_port()
1973 rhub = &xhci->usb3_rhub; in xhci_add_in_port()
1975 * Some hosts incorrectly use sub-minor version for minor in xhci_add_in_port()
1984 * Some zhaoxin's xHCI controller that follow usb3.1 spec in xhci_add_in_port()
1987 if (xhci->quirks & XHCI_ZHAOXIN_HOST) { in xhci_add_in_port()
1993 rhub = &xhci->usb2_rhub; in xhci_add_in_port()
1995 xhci_warn(xhci, "Ignoring unknown port speed, Ext Cap %p, revision = 0x%x\n", in xhci_add_in_port()
2005 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_add_in_port()
2009 if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) in xhci_add_in_port()
2013 port_cap = &xhci->port_caps[xhci->num_port_caps++]; in xhci_add_in_port()
2014 if (xhci->num_port_caps > max_caps) in xhci_add_in_port()
2017 port_cap->psi_count = XHCI_EXT_PORT_PSIC(temp); in xhci_add_in_port()
2019 if (port_cap->psi_count) { in xhci_add_in_port()
2020 port_cap->psi = kcalloc_node(port_cap->psi_count, in xhci_add_in_port()
2021 sizeof(*port_cap->psi), in xhci_add_in_port()
2023 if (!port_cap->psi) in xhci_add_in_port()
2024 port_cap->psi_count = 0; in xhci_add_in_port()
2026 port_cap->psi_uid_count++; in xhci_add_in_port()
2027 for (i = 0; i < port_cap->psi_count; i++) { in xhci_add_in_port()
2028 port_cap->psi[i] = readl(addr + 4 + i); in xhci_add_in_port()
2033 if (i && (XHCI_EXT_PORT_PSIV(port_cap->psi[i]) != in xhci_add_in_port()
2034 XHCI_EXT_PORT_PSIV(port_cap->psi[i - 1]))) in xhci_add_in_port()
2035 port_cap->psi_uid_count++; in xhci_add_in_port()
2037 if (xhci->quirks & XHCI_ZHAOXIN_HOST && in xhci_add_in_port()
2039 XHCI_EXT_PORT_PSIV(port_cap->psi[i]) >= 5) in xhci_add_in_port()
2042 xhci_dbg(xhci, "PSIV:%d PSIE:%d PLT:%d PFD:%d LP:%d PSIM:%d\n", in xhci_add_in_port()
2043 XHCI_EXT_PORT_PSIV(port_cap->psi[i]), in xhci_add_in_port()
2044 XHCI_EXT_PORT_PSIE(port_cap->psi[i]), in xhci_add_in_port()
2045 XHCI_EXT_PORT_PLT(port_cap->psi[i]), in xhci_add_in_port()
2046 XHCI_EXT_PORT_PFD(port_cap->psi[i]), in xhci_add_in_port()
2047 XHCI_EXT_PORT_LP(port_cap->psi[i]), in xhci_add_in_port()
2048 XHCI_EXT_PORT_PSIM(port_cap->psi[i])); in xhci_add_in_port()
2052 rhub->maj_rev = major_revision; in xhci_add_in_port()
2054 if (rhub->min_rev < minor_revision) in xhci_add_in_port()
2055 rhub->min_rev = minor_revision; in xhci_add_in_port()
2057 port_cap->maj_rev = major_revision; in xhci_add_in_port()
2058 port_cap->min_rev = minor_revision; in xhci_add_in_port()
2061 if (major_revision < 0x03 && xhci->num_ext_caps < max_caps) in xhci_add_in_port()
2062 xhci->ext_caps[xhci->num_ext_caps++] = temp; in xhci_add_in_port()
2064 if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) && in xhci_add_in_port()
2066 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_add_in_port()
2067 "xHCI 1.0: support USB2 hardware lpm"); in xhci_add_in_port()
2068 xhci->hw_lpm_support = 1; in xhci_add_in_port()
2071 port_offset--; in xhci_add_in_port()
2073 struct xhci_port *hw_port = &xhci->hw_ports[i]; in xhci_add_in_port()
2075 if (hw_port->rhub) { in xhci_add_in_port()
2076 xhci_warn(xhci, "Duplicate port entry, Ext Cap %p, port %u\n", addr, i); in xhci_add_in_port()
2077 xhci_warn(xhci, "Port was marked as USB %u, duplicated as USB %u\n", in xhci_add_in_port()
2078 hw_port->rhub->maj_rev, major_revision); in xhci_add_in_port()
2082 if (hw_port->rhub != rhub && in xhci_add_in_port()
2083 hw_port->hcd_portnum != DUPLICATE_ENTRY) { in xhci_add_in_port()
2084 hw_port->rhub->num_ports--; in xhci_add_in_port()
2085 hw_port->hcd_portnum = DUPLICATE_ENTRY; in xhci_add_in_port()
2089 hw_port->rhub = rhub; in xhci_add_in_port()
2090 hw_port->port_cap = port_cap; in xhci_add_in_port()
2091 rhub->num_ports++; in xhci_add_in_port()
2096 static void xhci_create_rhub_port_array(struct xhci_hcd *xhci, in xhci_create_rhub_port_array() argument
2101 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_create_rhub_port_array()
2103 if (!rhub->num_ports) in xhci_create_rhub_port_array()
2105 rhub->ports = kcalloc_node(rhub->num_ports, sizeof(*rhub->ports), in xhci_create_rhub_port_array()
2107 if (!rhub->ports) in xhci_create_rhub_port_array()
2110 for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { in xhci_create_rhub_port_array()
2111 if (xhci->hw_ports[i].rhub != rhub || in xhci_create_rhub_port_array()
2112 xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY) in xhci_create_rhub_port_array()
2114 xhci->hw_ports[i].hcd_portnum = port_index; in xhci_create_rhub_port_array()
2115 rhub->ports[port_index] = &xhci->hw_ports[i]; in xhci_create_rhub_port_array()
2117 if (port_index == rhub->num_ports) in xhci_create_rhub_port_array()
2129 static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) in xhci_setup_port_arrays() argument
2137 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_setup_port_arrays()
2139 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); in xhci_setup_port_arrays()
2140 xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports), in xhci_setup_port_arrays()
2142 if (!xhci->hw_ports) in xhci_setup_port_arrays()
2143 return -ENOMEM; in xhci_setup_port_arrays()
2146 xhci->hw_ports[i].addr = &xhci->op_regs->port_status_base + in xhci_setup_port_arrays()
2148 xhci->hw_ports[i].hw_portnum = i; in xhci_setup_port_arrays()
2150 init_completion(&xhci->hw_ports[i].rexit_done); in xhci_setup_port_arrays()
2151 init_completion(&xhci->hw_ports[i].u3exit_done); in xhci_setup_port_arrays()
2154 xhci->rh_bw = kcalloc_node(num_ports, sizeof(*xhci->rh_bw), flags, in xhci_setup_port_arrays()
2156 if (!xhci->rh_bw) in xhci_setup_port_arrays()
2157 return -ENOMEM; in xhci_setup_port_arrays()
2161 INIT_LIST_HEAD(&xhci->rh_bw[i].tts); in xhci_setup_port_arrays()
2162 bw_table = &xhci->rh_bw[i].bw_table; in xhci_setup_port_arrays()
2164 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); in xhci_setup_port_arrays()
2166 base = &xhci->cap_regs->hc_capbase; in xhci_setup_port_arrays()
2170 xhci_err(xhci, "No Extended Capability registers, unable to set up roothub\n"); in xhci_setup_port_arrays()
2171 return -ENODEV; in xhci_setup_port_arrays()
2182 xhci->ext_caps = kcalloc_node(cap_count, sizeof(*xhci->ext_caps), in xhci_setup_port_arrays()
2184 if (!xhci->ext_caps) in xhci_setup_port_arrays()
2185 return -ENOMEM; in xhci_setup_port_arrays()
2187 xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps), in xhci_setup_port_arrays()
2189 if (!xhci->port_caps) in xhci_setup_port_arrays()
2190 return -ENOMEM; in xhci_setup_port_arrays()
2195 xhci_add_in_port(xhci, num_ports, base + offset, cap_count); in xhci_setup_port_arrays()
2196 if (xhci->usb2_rhub.num_ports + xhci->usb3_rhub.num_ports == in xhci_setup_port_arrays()
2202 if (xhci->usb2_rhub.num_ports == 0 && xhci->usb3_rhub.num_ports == 0) { in xhci_setup_port_arrays()
2203 xhci_warn(xhci, "No ports on the roothubs?\n"); in xhci_setup_port_arrays()
2204 return -ENODEV; in xhci_setup_port_arrays()
2206 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_setup_port_arrays()
2208 xhci->usb2_rhub.num_ports, xhci->usb3_rhub.num_ports); in xhci_setup_port_arrays()
2213 if (xhci->usb3_rhub.num_ports > USB_SS_MAXPORTS) { in xhci_setup_port_arrays()
2214 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_setup_port_arrays()
2217 xhci->usb3_rhub.num_ports = USB_SS_MAXPORTS; in xhci_setup_port_arrays()
2219 if (xhci->usb2_rhub.num_ports > USB_MAXCHILDREN) { in xhci_setup_port_arrays()
2220 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_setup_port_arrays()
2223 xhci->usb2_rhub.num_ports = USB_MAXCHILDREN; in xhci_setup_port_arrays()
2226 if (!xhci->usb2_rhub.num_ports) in xhci_setup_port_arrays()
2227 xhci_info(xhci, "USB2 root hub has no ports\n"); in xhci_setup_port_arrays()
2229 if (!xhci->usb3_rhub.num_ports) in xhci_setup_port_arrays()
2230 xhci_info(xhci, "USB3 root hub has no ports\n"); in xhci_setup_port_arrays()
2232 xhci_create_rhub_port_array(xhci, &xhci->usb2_rhub, flags); in xhci_setup_port_arrays()
2233 xhci_create_rhub_port_array(xhci, &xhci->usb3_rhub, flags); in xhci_setup_port_arrays()
2239 xhci_alloc_interrupter(struct xhci_hcd *xhci, gfp_t flags) in xhci_alloc_interrupter() argument
2241 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_alloc_interrupter()
2249 ir->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, 1, TYPE_EVENT, in xhci_alloc_interrupter()
2251 if (!ir->event_ring) { in xhci_alloc_interrupter()
2252 xhci_warn(xhci, "Failed to allocate interrupter event ring\n"); in xhci_alloc_interrupter()
2257 ret = xhci_alloc_erst(xhci, ir->event_ring, &ir->erst, flags); in xhci_alloc_interrupter()
2259 xhci_warn(xhci, "Failed to allocate interrupter erst\n"); in xhci_alloc_interrupter()
2260 xhci_ring_free(xhci, ir->event_ring); in xhci_alloc_interrupter()
2269 xhci_add_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir, in xhci_add_interrupter() argument
2275 if (intr_num > xhci->max_interrupters) { in xhci_add_interrupter()
2276 xhci_warn(xhci, "Can't add interrupter %d, max interrupters %d\n", in xhci_add_interrupter()
2277 intr_num, xhci->max_interrupters); in xhci_add_interrupter()
2278 return -EINVAL; in xhci_add_interrupter()
2281 ir->ir_set = &xhci->run_regs->ir_set[intr_num]; in xhci_add_interrupter()
2284 erst_size = readl(&ir->ir_set->erst_size); in xhci_add_interrupter()
2287 writel(erst_size, &ir->ir_set->erst_size); in xhci_add_interrupter()
2289 erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_add_interrupter()
2291 erst_base |= ir->erst.erst_dma_addr & ~ERST_BASE_RSVDP; in xhci_add_interrupter()
2292 if (xhci->quirks & XHCI_WRITE_64_HI_LO) in xhci_add_interrupter()
2293 hi_lo_writeq(erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2295 xhci_write_64(xhci, erst_base, &ir->ir_set->erst_base); in xhci_add_interrupter()
2298 xhci_set_hc_event_deq(xhci, ir); in xhci_add_interrupter()
2303 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) in xhci_mem_init() argument
2306 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_mem_init()
2312 INIT_LIST_HEAD(&xhci->cmd_list); in xhci_mem_init()
2315 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); in xhci_mem_init()
2316 init_completion(&xhci->cmd_ring_stop_completion); in xhci_mem_init()
2318 page_size = readl(&xhci->op_regs->page_size); in xhci_mem_init()
2319 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2323 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2326 xhci_warn(xhci, "WARN: no supported page size\n"); in xhci_mem_init()
2328 xhci->page_shift = 12; in xhci_mem_init()
2329 xhci->page_size = 1 << xhci->page_shift; in xhci_mem_init()
2330 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2331 "HCD page size set to %iK", xhci->page_size / 1024); in xhci_mem_init()
2337 val = HCS_MAX_SLOTS(readl(&xhci->cap_regs->hcs_params1)); in xhci_mem_init()
2338 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2340 val2 = readl(&xhci->op_regs->config_reg); in xhci_mem_init()
2342 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2344 writel(val, &xhci->op_regs->config_reg); in xhci_mem_init()
2347 * xHCI section 5.4.6 - Device Context array must be in xhci_mem_init()
2348 * "physically contiguous and 64-byte (cache line) aligned". in xhci_mem_init()
2350 xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, in xhci_mem_init()
2352 if (!xhci->dcbaa) in xhci_mem_init()
2354 xhci->dcbaa->dma = dma; in xhci_mem_init()
2355 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2357 &xhci->dcbaa->dma, xhci->dcbaa); in xhci_mem_init()
2358 xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr); in xhci_mem_init()
2363 * however, the command ring segment needs 64-byte aligned segments in xhci_mem_init()
2367 if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH) in xhci_mem_init()
2368 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2369 TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2); in xhci_mem_init()
2371 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, in xhci_mem_init()
2372 TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); in xhci_mem_init()
2375 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, in xhci_mem_init()
2376 2112, 64, xhci->page_size); in xhci_mem_init()
2377 if (!xhci->segment_pool || !xhci->device_pool) in xhci_mem_init()
2381 * and only need to be 16-byte aligned. in xhci_mem_init()
2383 xhci->small_streams_pool = in xhci_mem_init()
2384 dma_pool_create("xHCI 256 byte stream ctx arrays", in xhci_mem_init()
2386 xhci->medium_streams_pool = in xhci_mem_init()
2387 dma_pool_create("xHCI 1KB stream ctx arrays", in xhci_mem_init()
2393 if (!xhci->small_streams_pool || !xhci->medium_streams_pool) in xhci_mem_init()
2397 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, 0, flags); in xhci_mem_init()
2398 if (!xhci->cmd_ring) in xhci_mem_init()
2400 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2401 "Allocated command ring at %p", xhci->cmd_ring); in xhci_mem_init()
2402 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "First segment DMA is 0x%pad", in xhci_mem_init()
2403 &xhci->cmd_ring->first_seg->dma); in xhci_mem_init()
2406 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2408 (xhci->cmd_ring->first_seg->dma & (u64) ~CMD_RING_RSVD_BITS) | in xhci_mem_init()
2409 xhci->cmd_ring->cycle_state; in xhci_mem_init()
2410 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2412 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_mem_init()
2418 xhci->cmd_ring_reserved_trbs++; in xhci_mem_init()
2420 val = readl(&xhci->cap_regs->db_off); in xhci_mem_init()
2422 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2425 xhci->dba = (void __iomem *) xhci->cap_regs + val; in xhci_mem_init()
2428 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_mem_init()
2430 xhci->interrupter = xhci_alloc_interrupter(xhci, flags); in xhci_mem_init()
2431 if (!xhci->interrupter) in xhci_mem_init()
2434 if (xhci_add_interrupter(xhci, xhci->interrupter, 0)) in xhci_mem_init()
2437 xhci->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; in xhci_mem_init()
2445 xhci->devs[i] = NULL; in xhci_mem_init()
2447 if (scratchpad_alloc(xhci, flags)) in xhci_mem_init()
2449 if (xhci_setup_port_arrays(xhci, flags)) in xhci_mem_init()
2456 temp = readl(&xhci->op_regs->dev_notification); in xhci_mem_init()
2459 writel(temp, &xhci->op_regs->dev_notification); in xhci_mem_init()
2464 xhci_halt(xhci); in xhci_mem_init()
2465 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_mem_init()
2466 xhci_mem_cleanup(xhci); in xhci_mem_init()
2467 return -ENOMEM; in xhci_mem_init()