Lines Matching +full:endpoint +full:- +full:base

1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/dma-mapping.h>
18 #include "cdnsp-gadget.h"
19 #include "cdnsp-trace.h"
42 seg->trbs = dma_pool_zalloc(pdev->segment_pool, flags, &dma); in cdnsp_segment_alloc()
43 if (!seg->trbs) { in cdnsp_segment_alloc()
49 seg->bounce_buf = kzalloc(max_packet, flags | GFP_DMA); in cdnsp_segment_alloc()
50 if (!seg->bounce_buf) in cdnsp_segment_alloc()
57 seg->trbs[i].link.control |= cpu_to_le32(TRB_CYCLE); in cdnsp_segment_alloc()
59 seg->dma = dma; in cdnsp_segment_alloc()
60 seg->next = NULL; in cdnsp_segment_alloc()
65 dma_pool_free(pdev->segment_pool, seg->trbs, dma); in cdnsp_segment_alloc()
74 if (seg->trbs) in cdnsp_segment_free()
75 dma_pool_free(pdev->segment_pool, seg->trbs, seg->dma); in cdnsp_segment_free()
77 kfree(seg->bounce_buf); in cdnsp_segment_free()
86 seg = first->next; in cdnsp_free_segments_for_ring()
89 struct cdnsp_segment *next = seg->next; in cdnsp_free_segments_for_ring()
116 prev->next = next; in cdnsp_link_segments()
118 link = &prev->trbs[TRBS_PER_SEGMENT - 1].link; in cdnsp_link_segments()
119 link->segment_ptr = cpu_to_le64(next->dma); in cdnsp_link_segments()
125 val = le32_to_cpu(link->control); in cdnsp_link_segments()
128 link->control = cpu_to_le32(val); in cdnsp_link_segments()
147 next = ring->enq_seg->next; in cdnsp_link_rings()
148 cdnsp_link_segments(pdev, ring->enq_seg, first, ring->type); in cdnsp_link_rings()
149 cdnsp_link_segments(pdev, last, next, ring->type); in cdnsp_link_rings()
150 ring->num_segs += num_segs; in cdnsp_link_rings()
151 ring->num_trbs_free += (TRBS_PER_SEGMENT - 1) * num_segs; in cdnsp_link_rings()
153 if (ring->type != TYPE_EVENT && ring->enq_seg == ring->last_seg) { in cdnsp_link_rings()
154 ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= in cdnsp_link_rings()
156 last->trbs[TRBS_PER_SEGMENT - 1].link.control |= in cdnsp_link_rings()
158 ring->last_seg = last; in cdnsp_link_rings()
167 * since the endpoint may stop before it reaches that event data TRB.
185 * The radix tree uses an unsigned long as a key pair. On 32-bit systems, an
186 * unsigned long will be 32-bits; on a 64-bit system an unsigned long will be
187 * 64-bits. Since we only request 32-bit DMA addresses, we can use that as the
188 * key on 32-bit or 64-bit systems (it would also be fine if we asked for 64-bit
189 * PCI DMA addresses on a 64-bit system). There might be a problem on 32-bit
190 * extended systems (where the DMA address can be bigger than 32-bits),
191 * if we allow the PCI dma mask to be bigger than 32-bits. So don't do that.
201 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in cdnsp_insert_segment_mapping()
222 key = (unsigned long)(seg->dma >> TRB_SEGMENT_SHIFT); in cdnsp_remove_segment_mapping()
245 seg = seg->next; in cdnsp_update_stream_segment_mapping()
257 seg = seg->next; in cdnsp_update_stream_segment_mapping()
267 seg = ring->first_seg; in cdnsp_remove_stream_mapping()
269 cdnsp_remove_segment_mapping(ring->trb_address_map, seg); in cdnsp_remove_stream_mapping()
270 seg = seg->next; in cdnsp_remove_stream_mapping()
271 } while (seg != ring->first_seg); in cdnsp_remove_stream_mapping()
276 return cdnsp_update_stream_segment_mapping(ring->trb_address_map, ring, in cdnsp_update_stream_mapping()
277 ring->first_seg, ring->last_seg, GFP_ATOMIC); in cdnsp_update_stream_mapping()
287 if (ring->first_seg) { in cdnsp_ring_free()
288 if (ring->type == TYPE_STREAM) in cdnsp_ring_free()
291 cdnsp_free_segments_for_ring(pdev, ring->first_seg); in cdnsp_ring_free()
299 ring->enqueue = ring->first_seg->trbs; in cdnsp_initialize_ring_info()
300 ring->enq_seg = ring->first_seg; in cdnsp_initialize_ring_info()
301 ring->dequeue = ring->enqueue; in cdnsp_initialize_ring_info()
302 ring->deq_seg = ring->first_seg; in cdnsp_initialize_ring_info()
312 ring->cycle_state = 1; in cdnsp_initialize_ring_info()
318 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in cdnsp_initialize_ring_info()
336 return -ENOMEM; in cdnsp_alloc_segments_for_ring()
338 num_segs--; in cdnsp_alloc_segments_for_ring()
349 return -ENOMEM; in cdnsp_alloc_segments_for_ring()
355 num_segs--; in cdnsp_alloc_segments_for_ring()
383 ring->num_segs = num_segs; in cdnsp_ring_alloc()
384 ring->bounce_buf_len = max_packet; in cdnsp_ring_alloc()
385 INIT_LIST_HEAD(&ring->td_list); in cdnsp_ring_alloc()
386 ring->type = type; in cdnsp_ring_alloc()
391 ret = cdnsp_alloc_segments_for_ring(pdev, &ring->first_seg, in cdnsp_ring_alloc()
392 &ring->last_seg, num_segs, in cdnsp_ring_alloc()
399 ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |= in cdnsp_ring_alloc()
412 cdnsp_ring_free(pdev, pep->ring); in cdnsp_free_endpoint_rings()
413 pep->ring = NULL; in cdnsp_free_endpoint_rings()
432 num_segs_needed = (num_trbs + (TRBS_PER_SEGMENT - 1) - 1) / in cdnsp_ring_expansion()
433 (TRBS_PER_SEGMENT - 1); in cdnsp_ring_expansion()
436 num_segs = max(ring->num_segs, num_segs_needed); in cdnsp_ring_expansion()
439 ring->cycle_state, ring->type, in cdnsp_ring_expansion()
440 ring->bounce_buf_len, flags); in cdnsp_ring_expansion()
442 return -ENOMEM; in cdnsp_ring_expansion()
444 if (ring->type == TYPE_STREAM) in cdnsp_ring_expansion()
445 ret = cdnsp_update_stream_segment_mapping(ring->trb_address_map, in cdnsp_ring_expansion()
463 int size = HCC_64BYTE_CONTEXT(pdev->hcc_params) ? 2048 : 1024; in cdnsp_init_device_ctx()
465 pdev->out_ctx.type = CDNSP_CTX_TYPE_DEVICE; in cdnsp_init_device_ctx()
466 pdev->out_ctx.size = size; in cdnsp_init_device_ctx()
467 pdev->out_ctx.ctx_size = CTX_SIZE(pdev->hcc_params); in cdnsp_init_device_ctx()
468 pdev->out_ctx.bytes = dma_pool_zalloc(pdev->device_pool, GFP_ATOMIC, in cdnsp_init_device_ctx()
469 &pdev->out_ctx.dma); in cdnsp_init_device_ctx()
471 if (!pdev->out_ctx.bytes) in cdnsp_init_device_ctx()
472 return -ENOMEM; in cdnsp_init_device_ctx()
474 pdev->in_ctx.type = CDNSP_CTX_TYPE_INPUT; in cdnsp_init_device_ctx()
475 pdev->in_ctx.ctx_size = pdev->out_ctx.ctx_size; in cdnsp_init_device_ctx()
476 pdev->in_ctx.size = size + pdev->out_ctx.ctx_size; in cdnsp_init_device_ctx()
477 pdev->in_ctx.bytes = dma_pool_zalloc(pdev->device_pool, GFP_ATOMIC, in cdnsp_init_device_ctx()
478 &pdev->in_ctx.dma); in cdnsp_init_device_ctx()
480 if (!pdev->in_ctx.bytes) { in cdnsp_init_device_ctx()
481 dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, in cdnsp_init_device_ctx()
482 pdev->out_ctx.dma); in cdnsp_init_device_ctx()
483 return -ENOMEM; in cdnsp_init_device_ctx()
492 if (ctx->type != CDNSP_CTX_TYPE_INPUT) in cdnsp_get_input_control_ctx()
495 return (struct cdnsp_input_control_ctx *)ctx->bytes; in cdnsp_get_input_control_ctx()
500 if (ctx->type == CDNSP_CTX_TYPE_DEVICE) in cdnsp_get_slot_ctx()
501 return (struct cdnsp_slot_ctx *)ctx->bytes; in cdnsp_get_slot_ctx()
503 return (struct cdnsp_slot_ctx *)(ctx->bytes + ctx->ctx_size); in cdnsp_get_slot_ctx()
511 if (ctx->type == CDNSP_CTX_TYPE_INPUT) in cdnsp_get_ep_ctx()
514 return (struct cdnsp_ep_ctx *)(ctx->bytes + (ep_index * ctx->ctx_size)); in cdnsp_get_ep_ctx()
520 dma_pool_free(pdev->device_pool, pep->stream_info.stream_ctx_array, in cdnsp_free_stream_ctx()
521 pep->stream_info.ctx_array_dma); in cdnsp_free_stream_ctx()
529 pep->stream_info.num_stream_ctxs; in cdnsp_alloc_stream_ctx()
539 return dma_pool_zalloc(pdev->device_pool, GFP_DMA32 | GFP_ATOMIC, in cdnsp_alloc_stream_ctx()
540 &pep->stream_info.ctx_array_dma); in cdnsp_alloc_stream_ctx()
545 if (pep->ep_state & EP_HAS_STREAMS) in cdnsp_dma_to_transfer_ring()
546 return radix_tree_lookup(&pep->stream_info.trb_address_map, in cdnsp_dma_to_transfer_ring()
549 return pep->ring; in cdnsp_dma_to_transfer_ring()
553 * Change an endpoint's internal structure so it supports stream IDs.
573 stream_info = &pep->stream_info; in cdnsp_alloc_stream_info()
574 stream_info->num_streams = num_streams; in cdnsp_alloc_stream_info()
575 stream_info->num_stream_ctxs = num_stream_ctxs; in cdnsp_alloc_stream_info()
578 stream_info->stream_rings = kcalloc(num_streams, in cdnsp_alloc_stream_info()
581 if (!stream_info->stream_rings) in cdnsp_alloc_stream_info()
582 return -ENOMEM; in cdnsp_alloc_stream_info()
585 stream_info->stream_ctx_array = cdnsp_alloc_stream_ctx(pdev, pep); in cdnsp_alloc_stream_info()
586 if (!stream_info->stream_ctx_array) in cdnsp_alloc_stream_info()
589 memset(stream_info->stream_ctx_array, 0, in cdnsp_alloc_stream_info()
591 INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC); in cdnsp_alloc_stream_info()
592 mps = usb_endpoint_maxp(pep->endpoint.desc); in cdnsp_alloc_stream_info()
602 stream_info->stream_rings[cur_stream] = cur_ring; in cdnsp_alloc_stream_info()
607 cur_ring->stream_id = cur_stream; in cdnsp_alloc_stream_info()
608 cur_ring->trb_address_map = &stream_info->trb_address_map; in cdnsp_alloc_stream_info()
611 addr = cur_ring->first_seg->dma | SCT_FOR_CTX(SCT_PRI_TR) | in cdnsp_alloc_stream_info()
612 cur_ring->cycle_state; in cdnsp_alloc_stream_info()
614 stream_info->stream_ctx_array[cur_stream].stream_ring = in cdnsp_alloc_stream_info()
628 cur_ring = stream_info->stream_rings[cur_stream]; in cdnsp_alloc_stream_info()
631 stream_info->stream_rings[cur_stream] = NULL; in cdnsp_alloc_stream_info()
636 kfree(pep->stream_info.stream_rings); in cdnsp_alloc_stream_info()
638 return -ENOMEM; in cdnsp_alloc_stream_info()
641 /* Frees all stream contexts associated with the endpoint. */
645 struct cdnsp_stream_info *stream_info = &pep->stream_info; in cdnsp_free_stream_info()
649 if (!(pep->ep_state & EP_HAS_STREAMS)) in cdnsp_free_stream_info()
652 for (cur_stream = 1; cur_stream < stream_info->num_streams; in cdnsp_free_stream_info()
654 cur_ring = stream_info->stream_rings[cur_stream]; in cdnsp_free_stream_info()
657 stream_info->stream_rings[cur_stream] = NULL; in cdnsp_free_stream_info()
661 if (stream_info->stream_ctx_array) in cdnsp_free_stream_info()
664 kfree(stream_info->stream_rings); in cdnsp_free_stream_info()
665 pep->ep_state &= ~EP_HAS_STREAMS; in cdnsp_free_stream_info()
671 pdev->dcbaa->dev_context_ptrs[1] = 0; in cdnsp_free_priv_device()
673 cdnsp_free_endpoint_rings(pdev, &pdev->eps[0]); in cdnsp_free_priv_device()
675 if (pdev->in_ctx.bytes) in cdnsp_free_priv_device()
676 dma_pool_free(pdev->device_pool, pdev->in_ctx.bytes, in cdnsp_free_priv_device()
677 pdev->in_ctx.dma); in cdnsp_free_priv_device()
679 if (pdev->out_ctx.bytes) in cdnsp_free_priv_device()
680 dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, in cdnsp_free_priv_device()
681 pdev->out_ctx.dma); in cdnsp_free_priv_device()
683 pdev->in_ctx.bytes = NULL; in cdnsp_free_priv_device()
684 pdev->out_ctx.bytes = NULL; in cdnsp_free_priv_device()
695 /* Allocate endpoint 0 ring. */ in cdnsp_alloc_priv_device()
696 pdev->eps[0].ring = cdnsp_ring_alloc(pdev, 2, TYPE_CTRL, 0, GFP_ATOMIC); in cdnsp_alloc_priv_device()
697 if (!pdev->eps[0].ring) in cdnsp_alloc_priv_device()
701 pdev->dcbaa->dev_context_ptrs[1] = cpu_to_le64(pdev->out_ctx.dma); in cdnsp_alloc_priv_device()
702 pdev->cmd.in_ctx = &pdev->in_ctx; in cdnsp_alloc_priv_device()
707 dma_pool_free(pdev->device_pool, pdev->out_ctx.bytes, in cdnsp_alloc_priv_device()
708 pdev->out_ctx.dma); in cdnsp_alloc_priv_device()
709 dma_pool_free(pdev->device_pool, pdev->in_ctx.bytes, in cdnsp_alloc_priv_device()
710 pdev->in_ctx.dma); in cdnsp_alloc_priv_device()
717 struct cdnsp_ep_ctx *ep0_ctx = pdev->eps[0].in_ctx; in cdnsp_copy_ep0_dequeue_into_input_ctx()
718 struct cdnsp_ring *ep_ring = pdev->eps[0].ring; in cdnsp_copy_ep0_dequeue_into_input_ctx()
721 dma = cdnsp_trb_virt_to_dma(ep_ring->enq_seg, ep_ring->enqueue); in cdnsp_copy_ep0_dequeue_into_input_ctx()
722 ep0_ctx->deq = cpu_to_le64(dma | ep_ring->cycle_state); in cdnsp_copy_ep0_dequeue_into_input_ctx()
732 ep0_ctx = cdnsp_get_ep_ctx(&pdev->in_ctx, 0); in cdnsp_setup_addressable_priv_dev()
733 slot_ctx = cdnsp_get_slot_ctx(&pdev->in_ctx); in cdnsp_setup_addressable_priv_dev()
735 /* Only the control endpoint is valid - one endpoint context. */ in cdnsp_setup_addressable_priv_dev()
736 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in cdnsp_setup_addressable_priv_dev()
738 switch (pdev->gadget.speed) { in cdnsp_setup_addressable_priv_dev()
740 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SSP); in cdnsp_setup_addressable_priv_dev()
744 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS); in cdnsp_setup_addressable_priv_dev()
748 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS); in cdnsp_setup_addressable_priv_dev()
752 slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS); in cdnsp_setup_addressable_priv_dev()
757 return -EINVAL; in cdnsp_setup_addressable_priv_dev()
760 port = DEV_PORT(pdev->active_port->port_num); in cdnsp_setup_addressable_priv_dev()
761 slot_ctx->dev_port |= cpu_to_le32(port); in cdnsp_setup_addressable_priv_dev()
762 slot_ctx->dev_state = cpu_to_le32((pdev->device_address & in cdnsp_setup_addressable_priv_dev()
764 ep0_ctx->tx_info = cpu_to_le32(EP_AVG_TRB_LENGTH(0x8)); in cdnsp_setup_addressable_priv_dev()
765 ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP)); in cdnsp_setup_addressable_priv_dev()
766 ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) | in cdnsp_setup_addressable_priv_dev()
769 ep0_ctx->deq = cpu_to_le64(pdev->eps[0].ring->first_seg->dma | in cdnsp_setup_addressable_priv_dev()
770 pdev->eps[0].ring->cycle_state); in cdnsp_setup_addressable_priv_dev()
778 * Convert interval expressed as 2^(bInterval - 1) == interval into
786 interval = clamp_val(pep->endpoint.desc->bInterval, 1, 16) - 1; in cdnsp_parse_exponent_interval()
787 if (interval != pep->endpoint.desc->bInterval - 1) in cdnsp_parse_exponent_interval()
788 dev_warn(&g->dev, "ep %s - rounding interval to %d %sframes\n", in cdnsp_parse_exponent_interval()
789 pep->name, 1 << interval, in cdnsp_parse_exponent_interval()
790 g->speed == USB_SPEED_FULL ? "" : "micro"); in cdnsp_parse_exponent_interval()
797 if (g->speed == USB_SPEED_FULL) in cdnsp_parse_exponent_interval()
808 * Convert bInterval expressed in microframes (in 1-255 range) to exponent of
819 interval = fls(desc_interval) - 1; in cdnsp_microframes_to_exponent()
827 * field is set to N, it will service the endpoint every 2^(Interval)*125us.
834 switch (g->speed) { in cdnsp_get_endpoint_interval()
838 if (usb_endpoint_xfer_int(pep->endpoint.desc) || in cdnsp_get_endpoint_interval()
839 usb_endpoint_xfer_isoc(pep->endpoint.desc)) in cdnsp_get_endpoint_interval()
843 if (usb_endpoint_xfer_isoc(pep->endpoint.desc)) { in cdnsp_get_endpoint_interval()
845 } else if (usb_endpoint_xfer_int(pep->endpoint.desc)) { in cdnsp_get_endpoint_interval()
846 interval = pep->endpoint.desc->bInterval << 3; in cdnsp_get_endpoint_interval()
861 * The "Mult" field in the endpoint context is only set for SuperSpeed isoc eps.
862 * High speed endpoint descriptors can define "the number of additional
864 * endpoint context field.
868 if (g->speed < USB_SPEED_SUPER || in cdnsp_get_endpoint_mult()
869 !usb_endpoint_xfer_isoc(pep->endpoint.desc)) in cdnsp_get_endpoint_mult()
872 return pep->endpoint.comp_desc->bmAttributes; in cdnsp_get_endpoint_mult()
879 if (g->speed >= USB_SPEED_SUPER) in cdnsp_get_endpoint_max_burst()
880 return pep->endpoint.comp_desc->bMaxBurst; in cdnsp_get_endpoint_max_burst()
882 if (g->speed == USB_SPEED_HIGH && in cdnsp_get_endpoint_max_burst()
883 (usb_endpoint_xfer_isoc(pep->endpoint.desc) || in cdnsp_get_endpoint_max_burst()
884 usb_endpoint_xfer_int(pep->endpoint.desc))) in cdnsp_get_endpoint_max_burst()
885 return usb_endpoint_maxp_mult(pep->endpoint.desc) - 1; in cdnsp_get_endpoint_max_burst()
911 * Return the maximum endpoint service interval time (ESIT) payload.
922 if (usb_endpoint_xfer_control(pep->endpoint.desc) || in cdnsp_get_max_esit_payload()
923 usb_endpoint_xfer_bulk(pep->endpoint.desc)) in cdnsp_get_max_esit_payload()
927 if (g->speed >= USB_SPEED_SUPER_PLUS && in cdnsp_get_max_esit_payload()
928 USB_SS_SSP_ISOC_COMP(pep->endpoint.desc->bmAttributes)) in cdnsp_get_max_esit_payload()
929 return le16_to_cpu(pep->endpoint.comp_desc->wBytesPerInterval); in cdnsp_get_max_esit_payload()
931 else if (g->speed >= USB_SPEED_SUPER) in cdnsp_get_max_esit_payload()
932 return le16_to_cpu(pep->endpoint.comp_desc->wBytesPerInterval); in cdnsp_get_max_esit_payload()
934 max_packet = usb_endpoint_maxp(pep->endpoint.desc); in cdnsp_get_max_esit_payload()
935 max_burst = usb_endpoint_maxp_mult(pep->endpoint.desc); in cdnsp_get_max_esit_payload()
957 ep_ctx = pep->in_ctx; in cdnsp_endpoint_init()
959 endpoint_type = cdnsp_get_endpoint_type(pep->endpoint.desc); in cdnsp_endpoint_init()
961 return -EINVAL; in cdnsp_endpoint_init()
963 ring_type = usb_endpoint_type(pep->endpoint.desc); in cdnsp_endpoint_init()
966 * Get values to fill the endpoint context, mostly from ep descriptor. in cdnsp_endpoint_init()
971 max_esit_payload = cdnsp_get_max_esit_payload(&pdev->gadget, pep); in cdnsp_endpoint_init()
972 interval = cdnsp_get_endpoint_interval(&pdev->gadget, pep); in cdnsp_endpoint_init()
973 mult = cdnsp_get_endpoint_mult(&pdev->gadget, pep); in cdnsp_endpoint_init()
974 max_packet = usb_endpoint_maxp(pep->endpoint.desc); in cdnsp_endpoint_init()
975 max_burst = cdnsp_get_endpoint_max_burst(&pdev->gadget, pep); in cdnsp_endpoint_init()
979 if (!usb_endpoint_xfer_isoc(pep->endpoint.desc)) in cdnsp_endpoint_init()
981 if (usb_endpoint_xfer_bulk(pep->endpoint.desc) && in cdnsp_endpoint_init()
982 pdev->gadget.speed == USB_SPEED_HIGH) in cdnsp_endpoint_init()
985 if (usb_endpoint_xfer_control(pep->endpoint.desc)) in cdnsp_endpoint_init()
988 /* Set up the endpoint ring. */ in cdnsp_endpoint_init()
989 pep->ring = cdnsp_ring_alloc(pdev, 2, ring_type, max_packet, mem_flags); in cdnsp_endpoint_init()
990 if (!pep->ring) in cdnsp_endpoint_init()
991 return -ENOMEM; in cdnsp_endpoint_init()
993 pep->skip = false; in cdnsp_endpoint_init()
995 /* Fill the endpoint context */ in cdnsp_endpoint_init()
996 ep_ctx->ep_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) | in cdnsp_endpoint_init()
998 ep_ctx->ep_info2 = cpu_to_le32(EP_TYPE(endpoint_type) | in cdnsp_endpoint_init()
1001 ep_ctx->deq = cpu_to_le64(pep->ring->first_seg->dma | in cdnsp_endpoint_init()
1002 pep->ring->cycle_state); in cdnsp_endpoint_init()
1004 ep_ctx->tx_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) | in cdnsp_endpoint_init()
1007 if (usb_endpoint_xfer_bulk(pep->endpoint.desc) && in cdnsp_endpoint_init()
1008 pdev->gadget.speed > USB_SPEED_HIGH) { in cdnsp_endpoint_init()
1019 pep->in_ctx->ep_info = 0; in cdnsp_endpoint_zero()
1020 pep->in_ctx->ep_info2 = 0; in cdnsp_endpoint_zero()
1021 pep->in_ctx->deq = 0; in cdnsp_endpoint_zero()
1022 pep->in_ctx->tx_info = 0; in cdnsp_endpoint_zero()
1034 size = sizeof(struct cdnsp_erst_entry) * evt_ring->num_segs; in cdnsp_alloc_erst()
1035 erst->entries = dma_alloc_coherent(pdev->dev, size, in cdnsp_alloc_erst()
1036 &erst->erst_dma_addr, GFP_KERNEL); in cdnsp_alloc_erst()
1037 if (!erst->entries) in cdnsp_alloc_erst()
1038 return -ENOMEM; in cdnsp_alloc_erst()
1040 erst->num_entries = evt_ring->num_segs; in cdnsp_alloc_erst()
1042 seg = evt_ring->first_seg; in cdnsp_alloc_erst()
1043 for (val = 0; val < evt_ring->num_segs; val++) { in cdnsp_alloc_erst()
1044 entry = &erst->entries[val]; in cdnsp_alloc_erst()
1045 entry->seg_addr = cpu_to_le64(seg->dma); in cdnsp_alloc_erst()
1046 entry->seg_size = cpu_to_le32(TRBS_PER_SEGMENT); in cdnsp_alloc_erst()
1047 entry->rsvd = 0; in cdnsp_alloc_erst()
1048 seg = seg->next; in cdnsp_alloc_erst()
1056 size_t size = sizeof(struct cdnsp_erst_entry) * (erst->num_entries); in cdnsp_free_erst()
1057 struct device *dev = pdev->dev; in cdnsp_free_erst()
1059 if (erst->entries) in cdnsp_free_erst()
1060 dma_free_coherent(dev, size, erst->entries, in cdnsp_free_erst()
1061 erst->erst_dma_addr); in cdnsp_free_erst()
1063 erst->entries = NULL; in cdnsp_free_erst()
1068 struct device *dev = pdev->dev; in cdnsp_mem_cleanup()
1071 cdnsp_free_erst(pdev, &pdev->erst); in cdnsp_mem_cleanup()
1073 if (pdev->event_ring) in cdnsp_mem_cleanup()
1074 cdnsp_ring_free(pdev, pdev->event_ring); in cdnsp_mem_cleanup()
1076 pdev->event_ring = NULL; in cdnsp_mem_cleanup()
1078 if (pdev->cmd_ring) in cdnsp_mem_cleanup()
1079 cdnsp_ring_free(pdev, pdev->cmd_ring); in cdnsp_mem_cleanup()
1081 pdev->cmd_ring = NULL; in cdnsp_mem_cleanup()
1083 dma_pool_destroy(pdev->segment_pool); in cdnsp_mem_cleanup()
1084 pdev->segment_pool = NULL; in cdnsp_mem_cleanup()
1085 dma_pool_destroy(pdev->device_pool); in cdnsp_mem_cleanup()
1086 pdev->device_pool = NULL; in cdnsp_mem_cleanup()
1088 dma_free_coherent(dev, sizeof(*pdev->dcbaa), in cdnsp_mem_cleanup()
1089 pdev->dcbaa, pdev->dcbaa->dma); in cdnsp_mem_cleanup()
1091 pdev->dcbaa = NULL; in cdnsp_mem_cleanup()
1093 pdev->usb2_port.exist = 0; in cdnsp_mem_cleanup()
1094 pdev->usb3_port.exist = 0; in cdnsp_mem_cleanup()
1095 pdev->usb2_port.port_num = 0; in cdnsp_mem_cleanup()
1096 pdev->usb3_port.port_num = 0; in cdnsp_mem_cleanup()
1097 pdev->active_port = NULL; in cdnsp_mem_cleanup()
1105 deq = cdnsp_trb_virt_to_dma(pdev->event_ring->deq_seg, in cdnsp_set_event_deq()
1106 pdev->event_ring->dequeue); in cdnsp_set_event_deq()
1109 temp = cdnsp_read_64(&pdev->ir_set->erst_dequeue); in cdnsp_set_event_deq()
1119 &pdev->ir_set->erst_dequeue); in cdnsp_set_event_deq()
1129 port->maj_rev = CDNSP_EXT_PORT_MAJOR(temp); in cdnsp_add_in_port()
1130 port->min_rev = CDNSP_EXT_PORT_MINOR(temp); in cdnsp_add_in_port()
1137 trace_cdnsp_port_info(addr, port_offset, port_count, port->maj_rev); in cdnsp_add_in_port()
1139 port->port_num = port_offset; in cdnsp_add_in_port()
1140 port->exist = 1; in cdnsp_add_in_port()
1149 void __iomem *base; in cdnsp_setup_port_arrays() local
1153 base = &pdev->cap_regs->hc_capbase; in cdnsp_setup_port_arrays()
1154 offset = cdnsp_find_next_ext_cap(base, 0, in cdnsp_setup_port_arrays()
1156 pdev->port20_regs = base + offset; in cdnsp_setup_port_arrays()
1158 offset = cdnsp_find_next_ext_cap(base, 0, D_XEC_CFG_3XPORT_CAP); in cdnsp_setup_port_arrays()
1159 pdev->port3x_regs = base + offset; in cdnsp_setup_port_arrays()
1162 base = &pdev->cap_regs->hc_capbase; in cdnsp_setup_port_arrays()
1168 offset = cdnsp_find_next_ext_cap(base, offset, in cdnsp_setup_port_arrays()
1170 temp = readl(base + offset); in cdnsp_setup_port_arrays()
1173 !pdev->usb3_port.port_num) in cdnsp_setup_port_arrays()
1174 cdnsp_add_in_port(pdev, &pdev->usb3_port, in cdnsp_setup_port_arrays()
1175 base + offset); in cdnsp_setup_port_arrays()
1178 !pdev->usb2_port.port_num) in cdnsp_setup_port_arrays()
1179 cdnsp_add_in_port(pdev, &pdev->usb2_port, in cdnsp_setup_port_arrays()
1180 base + offset); in cdnsp_setup_port_arrays()
1183 if (!pdev->usb2_port.exist || !pdev->usb3_port.exist) { in cdnsp_setup_port_arrays()
1184 dev_err(pdev->dev, "Error: Only one port detected\n"); in cdnsp_setup_port_arrays()
1185 return -ENODEV; in cdnsp_setup_port_arrays()
1190 pdev->usb2_port.regs = (struct cdnsp_port_regs __iomem *) in cdnsp_setup_port_arrays()
1191 (&pdev->op_regs->port_reg_base + NUM_PORT_REGS * in cdnsp_setup_port_arrays()
1192 (pdev->usb2_port.port_num - 1)); in cdnsp_setup_port_arrays()
1194 pdev->usb3_port.regs = (struct cdnsp_port_regs __iomem *) in cdnsp_setup_port_arrays()
1195 (&pdev->op_regs->port_reg_base + NUM_PORT_REGS * in cdnsp_setup_port_arrays()
1196 (pdev->usb3_port.port_num - 1)); in cdnsp_setup_port_arrays()
1202 * Initialize memory for CDNSP (one-time init).
1210 struct device *dev = pdev->dev; in cdnsp_mem_init()
1211 int ret = -ENOMEM; in cdnsp_mem_init()
1223 val = readl(&pdev->op_regs->config_reg); in cdnsp_mem_init()
1225 writel(val, &pdev->op_regs->config_reg); in cdnsp_mem_init()
1229 * and 64-byte (cache line) aligned. in cdnsp_mem_init()
1231 pdev->dcbaa = dma_alloc_coherent(dev, sizeof(*pdev->dcbaa), in cdnsp_mem_init()
1233 if (!pdev->dcbaa) in cdnsp_mem_init()
1234 return -ENOMEM; in cdnsp_mem_init()
1236 pdev->dcbaa->dma = dma; in cdnsp_mem_init()
1238 cdnsp_write_64(dma, &pdev->op_regs->dcbaa_ptr); in cdnsp_mem_init()
1243 * however, the command ring segment needs 64-byte aligned segments in cdnsp_mem_init()
1248 pdev->segment_pool = dma_pool_create("CDNSP ring segments", dev, in cdnsp_mem_init()
1251 if (!pdev->segment_pool) in cdnsp_mem_init()
1254 pdev->device_pool = dma_pool_create("CDNSP input/output contexts", dev, in cdnsp_mem_init()
1256 if (!pdev->device_pool) in cdnsp_mem_init()
1261 pdev->cmd_ring = cdnsp_ring_alloc(pdev, 1, TYPE_COMMAND, 0, GFP_KERNEL); in cdnsp_mem_init()
1262 if (!pdev->cmd_ring) in cdnsp_mem_init()
1266 val_64 = cdnsp_read_64(&pdev->op_regs->cmd_ring); in cdnsp_mem_init()
1268 (pdev->cmd_ring->first_seg->dma & (u64)~CMD_RING_RSVD_BITS) | in cdnsp_mem_init()
1269 pdev->cmd_ring->cycle_state; in cdnsp_mem_init()
1270 cdnsp_write_64(val_64, &pdev->op_regs->cmd_ring); in cdnsp_mem_init()
1272 val = readl(&pdev->cap_regs->db_off); in cdnsp_mem_init()
1274 pdev->dba = (void __iomem *)pdev->cap_regs + val; in cdnsp_mem_init()
1277 pdev->ir_set = &pdev->run_regs->ir_set[0]; in cdnsp_mem_init()
1283 pdev->event_ring = cdnsp_ring_alloc(pdev, ERST_NUM_SEGS, TYPE_EVENT, in cdnsp_mem_init()
1285 if (!pdev->event_ring) in cdnsp_mem_init()
1288 ret = cdnsp_alloc_erst(pdev, pdev->event_ring, &pdev->erst); in cdnsp_mem_init()
1293 val = readl(&pdev->ir_set->erst_size); in cdnsp_mem_init()
1296 writel(val, &pdev->ir_set->erst_size); in cdnsp_mem_init()
1298 /* Set the segment table base address. */ in cdnsp_mem_init()
1299 val_64 = cdnsp_read_64(&pdev->ir_set->erst_base); in cdnsp_mem_init()
1301 val_64 |= (pdev->erst.erst_dma_addr & (u64)~ERST_PTR_MASK); in cdnsp_mem_init()
1302 cdnsp_write_64(val_64, &pdev->ir_set->erst_base); in cdnsp_mem_init()
1313 dev_err(pdev->dev, in cdnsp_mem_init()
1321 cdnsp_free_erst(pdev, &pdev->erst); in cdnsp_mem_init()
1323 cdnsp_ring_free(pdev, pdev->event_ring); in cdnsp_mem_init()
1325 cdnsp_ring_free(pdev, pdev->cmd_ring); in cdnsp_mem_init()
1327 dma_pool_destroy(pdev->device_pool); in cdnsp_mem_init()
1329 dma_pool_destroy(pdev->segment_pool); in cdnsp_mem_init()
1331 dma_free_coherent(dev, sizeof(*pdev->dcbaa), pdev->dcbaa, in cdnsp_mem_init()
1332 pdev->dcbaa->dma); in cdnsp_mem_init()