Lines Matching +full:generic +full:- +full:uhci

1 // SPDX-License-Identifier: GPL-2.0
26 * until you reach a non-link TRB.
59 #include <linux/dma-mapping.h>
61 #include "xhci-trace.h"
76 if (!seg || !trb || trb < seg->trbs) in xhci_trb_virt_to_dma()
79 segment_offset = trb - seg->trbs; in xhci_trb_virt_to_dma()
82 return seg->dma + (segment_offset * sizeof(*trb)); in xhci_trb_virt_to_dma()
87 return TRB_TYPE_NOOP_LE32(trb->generic.field[3]); in trb_is_noop()
92 return TRB_TYPE_LINK_LE32(trb->link.control); in trb_is_link()
97 return trb == &seg->trbs[TRBS_PER_SEGMENT - 1]; in last_trb_on_seg()
103 return last_trb_on_seg(seg, trb) && (seg->next == ring->first_seg); in last_trb_on_ring()
108 return le32_to_cpu(trb->link.control) & LINK_TOGGLE; in link_trb_toggles_cycle()
113 struct urb_priv *urb_priv = td->urb->hcpriv; in last_td_in_urb()
115 return urb_priv->num_tds_done == urb_priv->num_tds; in last_td_in_urb()
120 return ((le32_to_cpu(ring->dequeue->event_cmd.flags) & TRB_CYCLE) == in unhandled_event_trb()
121 ring->cycle_state); in unhandled_event_trb()
126 struct urb_priv *urb_priv = urb->hcpriv; in inc_td_cnt()
128 urb_priv->num_tds_done++; in inc_td_cnt()
135 trb->link.control &= cpu_to_le32(~TRB_CHAIN); in trb_to_noop()
137 trb->generic.field[0] = 0; in trb_to_noop()
138 trb->generic.field[1] = 0; in trb_to_noop()
139 trb->generic.field[2] = 0; in trb_to_noop()
141 trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE); in trb_to_noop()
142 trb->generic.field[3] |= cpu_to_le32(TRB_TYPE(noop_type)); in trb_to_noop()
154 *seg = (*seg)->next; in next_trb()
155 *trb = ((*seg)->trbs); in next_trb()
169 if (ring->type == TYPE_EVENT) { in inc_deq()
170 if (!last_trb_on_seg(ring->deq_seg, ring->dequeue)) { in inc_deq()
171 ring->dequeue++; in inc_deq()
174 if (last_trb_on_ring(ring, ring->deq_seg, ring->dequeue)) in inc_deq()
175 ring->cycle_state ^= 1; in inc_deq()
176 ring->deq_seg = ring->deq_seg->next; in inc_deq()
177 ring->dequeue = ring->deq_seg->trbs; in inc_deq()
185 if (!trb_is_link(ring->dequeue)) { in inc_deq()
186 if (last_trb_on_seg(ring->deq_seg, ring->dequeue)) in inc_deq()
189 ring->dequeue++; in inc_deq()
192 while (trb_is_link(ring->dequeue)) { in inc_deq()
193 ring->deq_seg = ring->deq_seg->next; in inc_deq()
194 ring->dequeue = ring->deq_seg->trbs; in inc_deq()
198 if (link_trb_count++ > ring->num_segs) { in inc_deq()
214 while (trb_is_link(ring->enqueue)) { in inc_enq_past_link()
225 if (!xhci_link_chain_quirk(xhci, ring->type)) { in inc_enq_past_link()
226 ring->enqueue->link.control &= cpu_to_le32(~TRB_CHAIN); in inc_enq_past_link()
227 ring->enqueue->link.control |= cpu_to_le32(chain); in inc_enq_past_link()
232 ring->enqueue->link.control ^= cpu_to_le32(TRB_CYCLE); in inc_enq_past_link()
235 if (link_trb_toggles_cycle(ring->enqueue)) in inc_enq_past_link()
236 ring->cycle_state ^= 1; in inc_enq_past_link()
238 ring->enq_seg = ring->enq_seg->next; in inc_enq_past_link()
239 ring->enqueue = ring->enq_seg->trbs; in inc_enq_past_link()
243 if (link_trb_count++ > ring->num_segs) { in inc_enq_past_link()
266 chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN; in inc_enq()
268 if (last_trb_on_seg(ring->enq_seg, ring->enqueue)) { in inc_enq()
273 ring->enqueue++; in inc_enq()
281 if (trb_is_link(ring->enqueue) && (chain || more_trbs_coming)) in inc_enq()
296 start_dma = xhci_trb_virt_to_dma(td->start_seg, td->start_trb); in trb_in_td()
297 cur_seg = td->start_seg; in trb_in_td()
304 &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); in trb_in_td()
306 end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->end_trb); in trb_in_td()
319 (suspect_dma >= cur_seg->dma && in trb_in_td()
329 cur_seg = cur_seg->next; in trb_in_td()
330 start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]); in trb_in_td()
331 } while (cur_seg != td->start_seg); in trb_in_td()
344 struct xhci_segment *enq_seg = ring->enq_seg; in xhci_num_trbs_free()
345 union xhci_trb *enq = ring->enqueue; in xhci_num_trbs_free()
352 enq_seg = enq_seg->next; in xhci_num_trbs_free()
353 enq = enq_seg->trbs; in xhci_num_trbs_free()
357 if (enq == ring->dequeue) in xhci_num_trbs_free()
358 return ring->num_segs * (TRBS_PER_SEGMENT - 1); in xhci_num_trbs_free()
361 if (ring->deq_seg == enq_seg && ring->dequeue >= enq) in xhci_num_trbs_free()
362 return free + (ring->dequeue - enq); in xhci_num_trbs_free()
363 last_on_seg = &enq_seg->trbs[TRBS_PER_SEGMENT - 1]; in xhci_num_trbs_free()
364 free += last_on_seg - enq; in xhci_num_trbs_free()
365 enq_seg = enq_seg->next; in xhci_num_trbs_free()
366 enq = enq_seg->trbs; in xhci_num_trbs_free()
367 } while (i++ < ring->num_segs); in xhci_num_trbs_free()
386 enq_used = ring->enqueue - ring->enq_seg->trbs; in xhci_ring_expansion_needed()
389 trbs_past_seg = enq_used + num_trbs - (TRBS_PER_SEGMENT - 1); in xhci_ring_expansion_needed()
401 if (trb_is_link(ring->enqueue) && ring->enq_seg->next->trbs == ring->dequeue) in xhci_ring_expansion_needed()
404 new_segs = 1 + (trbs_past_seg / (TRBS_PER_SEGMENT - 1)); in xhci_ring_expansion_needed()
405 seg = ring->enq_seg; in xhci_ring_expansion_needed()
408 seg = seg->next; in xhci_ring_expansion_needed()
409 if (seg == ring->deq_seg) { in xhci_ring_expansion_needed()
414 new_segs--; in xhci_ring_expansion_needed()
423 if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) in xhci_ring_cmd_db()
430 writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
432 readl(&xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
437 return mod_delayed_work(system_wq, &xhci->cmd_timer, in xhci_mod_cmd_timer()
438 msecs_to_jiffies(xhci->current_cmd->timeout_ms)); in xhci_mod_cmd_timer()
443 return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command, in xhci_next_queued_cmd()
448 * Turn all commands on command ring with status set to "aborted" to no-op trbs.
450 * This must be called with command ring stopped and xhci->lock held.
457 /* Turn all aborted commands in list to no-ops, then restart */ in xhci_handle_stopped_cmd_ring()
458 list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) { in xhci_handle_stopped_cmd_ring()
460 if (i_cmd->status != COMP_COMMAND_ABORTED) in xhci_handle_stopped_cmd_ring()
463 i_cmd->status = COMP_COMMAND_RING_STOPPED; in xhci_handle_stopped_cmd_ring()
465 xhci_dbg(xhci, "Turn aborted command %p to no-op\n", in xhci_handle_stopped_cmd_ring()
466 i_cmd->command_trb); in xhci_handle_stopped_cmd_ring()
468 trb_to_noop(i_cmd->command_trb, TRB_CMD_NOOP); in xhci_handle_stopped_cmd_ring()
472 * completion event is received for these no-op commands in xhci_handle_stopped_cmd_ring()
476 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_handle_stopped_cmd_ring()
479 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && in xhci_handle_stopped_cmd_ring()
480 !(xhci->xhc_state & XHCI_STATE_DYING)) { in xhci_handle_stopped_cmd_ring()
481 xhci->current_cmd = cur_cmd; in xhci_handle_stopped_cmd_ring()
488 /* Must be called with xhci->lock held, releases and acquires lock back */
491 struct xhci_segment *new_seg = xhci->cmd_ring->deq_seg; in xhci_abort_cmd_ring()
492 union xhci_trb *new_deq = xhci->cmd_ring->dequeue; in xhci_abort_cmd_ring()
498 reinit_completion(&xhci->cmd_ring_stop_completion); in xhci_abort_cmd_ring()
513 xhci_write_64(xhci, crcr | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
517 * seconds then driver handles it as if host died (-ENODEV). in xhci_abort_cmd_ring()
518 * In the future we should distinguish between -ENODEV and -ETIMEDOUT in xhci_abort_cmd_ring()
519 * and try to recover a -ETIMEDOUT with a host controller reset. in xhci_abort_cmd_ring()
521 ret = xhci_handshake_check_state(xhci, &xhci->op_regs->cmd_ring, in xhci_abort_cmd_ring()
536 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_abort_cmd_ring()
537 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, in xhci_abort_cmd_ring()
539 spin_lock_irqsave(&xhci->lock, flags); in xhci_abort_cmd_ring()
554 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; in xhci_ring_ep_doorbell()
555 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_ring_ep_doorbell()
556 unsigned int ep_state = ep->ep_state; in xhci_ring_ep_doorbell()
583 ep = &xhci->devs[slot_id]->eps[ep_index]; in ring_doorbell_for_active_rings()
586 if (!(ep->ep_state & EP_HAS_STREAMS)) { in ring_doorbell_for_active_rings()
587 if (ep->ring && !(list_empty(&ep->ring->td_list))) in ring_doorbell_for_active_rings()
592 for (stream_id = 1; stream_id < ep->stream_info->num_streams; in ring_doorbell_for_active_rings()
594 struct xhci_stream_info *stream_info = ep->stream_info; in ring_doorbell_for_active_rings()
595 if (!list_empty(&stream_info->stream_rings[stream_id]->td_list)) in ring_doorbell_for_active_rings()
620 if (!xhci->devs[slot_id]) { in xhci_get_virt_ep()
625 return &xhci->devs[slot_id]->eps[ep_index]; in xhci_get_virt_ep()
633 if (!(ep->ep_state & EP_HAS_STREAMS)) in xhci_virt_ep_to_ring()
634 return ep->ring; in xhci_virt_ep_to_ring()
636 if (!ep->stream_info) in xhci_virt_ep_to_ring()
639 if (stream_id == 0 || stream_id >= ep->stream_info->num_streams) { in xhci_virt_ep_to_ring()
641 stream_id, ep->vdev->slot_id, ep->ep_index); in xhci_virt_ep_to_ring()
645 return ep->stream_info->stream_rings[stream_id]; in xhci_virt_ep_to_ring()
679 ep = &vdev->eps[ep_index]; in xhci_get_hw_deq()
681 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_get_hw_deq()
682 st_ctx = &ep->stream_info->stream_ctx_array[stream_id]; in xhci_get_hw_deq()
683 return le64_to_cpu(st_ctx->stream_ring); in xhci_get_hw_deq()
685 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_get_hw_deq()
686 return le64_to_cpu(ep_ctx->deq); in xhci_get_hw_deq()
693 struct xhci_virt_device *dev = xhci->devs[slot_id]; in xhci_move_dequeue_past_td()
694 struct xhci_virt_ep *ep = &dev->eps[ep_index]; in xhci_move_dequeue_past_td()
712 return -ENODEV; in xhci_move_dequeue_past_td()
716 new_seg = ep_ring->deq_seg; in xhci_move_dequeue_past_td()
717 new_deq = ep_ring->dequeue; in xhci_move_dequeue_past_td()
718 new_cycle = le32_to_cpu(td->end_trb->generic.field[3]) & TRB_CYCLE; in xhci_move_dequeue_past_td()
732 if (new_deq == td->end_trb) in xhci_move_dequeue_past_td()
742 if (new_deq == ep->ring->dequeue) { in xhci_move_dequeue_past_td()
744 return -EINVAL; in xhci_move_dequeue_past_td()
754 return -EINVAL; in xhci_move_dequeue_past_td()
757 if ((ep->ep_state & SET_DEQ_PENDING)) { in xhci_move_dequeue_past_td()
760 return -EBUSY; in xhci_move_dequeue_past_td()
767 return -ENOMEM; in xhci_move_dequeue_past_td()
781 ep->queued_deq_seg = new_seg; in xhci_move_dequeue_past_td()
782 ep->queued_deq_ptr = new_deq; in xhci_move_dequeue_past_td()
792 ep->ep_state |= SET_DEQ_PENDING; in xhci_move_dequeue_past_td()
803 struct xhci_segment *seg = td->start_seg; in td_to_noop()
804 union xhci_trb *trb = td->start_trb; in td_to_noop()
810 if (flip_cycle && trb != td->start_trb && trb != td->end_trb) in td_to_noop()
811 trb->generic.field[3] ^= cpu_to_le32(TRB_CYCLE); in td_to_noop()
813 if (trb == td->end_trb) in td_to_noop()
823 struct urb *urb = cur_td->urb; in xhci_giveback_urb_in_irq()
824 struct urb_priv *urb_priv = urb->hcpriv; in xhci_giveback_urb_in_irq()
825 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in xhci_giveback_urb_in_irq()
827 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { in xhci_giveback_urb_in_irq()
828 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; in xhci_giveback_urb_in_irq()
829 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_giveback_urb_in_irq()
830 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_giveback_urb_in_irq()
843 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_unmap_td_bounce_buffer()
844 struct xhci_segment *seg = td->bounce_seg; in xhci_unmap_td_bounce_buffer()
845 struct urb *urb = td->urb; in xhci_unmap_td_bounce_buffer()
852 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len, in xhci_unmap_td_bounce_buffer()
857 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len, in xhci_unmap_td_bounce_buffer()
860 if (urb->num_sgs) { in xhci_unmap_td_bounce_buffer()
861 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, seg->bounce_buf, in xhci_unmap_td_bounce_buffer()
862 seg->bounce_len, seg->bounce_offs); in xhci_unmap_td_bounce_buffer()
863 if (len != seg->bounce_len) in xhci_unmap_td_bounce_buffer()
865 len, seg->bounce_len); in xhci_unmap_td_bounce_buffer()
867 memcpy(urb->transfer_buffer + seg->bounce_offs, seg->bounce_buf, in xhci_unmap_td_bounce_buffer()
868 seg->bounce_len); in xhci_unmap_td_bounce_buffer()
870 seg->bounce_len = 0; in xhci_unmap_td_bounce_buffer()
871 seg->bounce_offs = 0; in xhci_unmap_td_bounce_buffer()
880 urb = td->urb; in xhci_td_cleanup()
887 * length, urb->actual_length will be a very big number (since it's in xhci_td_cleanup()
890 if (urb->actual_length > urb->transfer_buffer_length) { in xhci_td_cleanup()
892 urb->transfer_buffer_length, urb->actual_length); in xhci_td_cleanup()
893 urb->actual_length = 0; in xhci_td_cleanup()
897 if (!list_empty(&td->td_list)) in xhci_td_cleanup()
898 list_del_init(&td->td_list); in xhci_td_cleanup()
900 if (!list_empty(&td->cancelled_td_list)) in xhci_td_cleanup()
901 list_del_init(&td->cancelled_td_list); in xhci_td_cleanup()
906 if ((urb->actual_length != urb->transfer_buffer_length && in xhci_td_cleanup()
907 (urb->transfer_flags & URB_SHORT_NOT_OK)) || in xhci_td_cleanup()
908 (status != 0 && !usb_endpoint_xfer_isoc(&urb->ep->desc))) in xhci_td_cleanup()
910 urb, urb->actual_length, in xhci_td_cleanup()
911 urb->transfer_buffer_length, status); in xhci_td_cleanup()
913 /* set isoc urb status to 0 just as EHCI, UHCI, and OHCI */ in xhci_td_cleanup()
914 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) in xhci_td_cleanup()
924 ring->dequeue = td->end_trb; in xhci_dequeue_td()
925 ring->deq_seg = td->end_seg; in xhci_dequeue_td()
937 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, in xhci_giveback_invalidated_tds()
940 ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_giveback_invalidated_tds()
942 if (td->cancel_status == TD_CLEARED) { in xhci_giveback_invalidated_tds()
943 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_giveback_invalidated_tds()
944 __func__, td->urb); in xhci_giveback_invalidated_tds()
945 xhci_td_cleanup(ep->xhci, td, ring, td->status); in xhci_giveback_invalidated_tds()
947 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_giveback_invalidated_tds()
948 __func__, td->urb, td->cancel_status); in xhci_giveback_invalidated_tds()
950 if (ep->xhci->xhc_state & XHCI_STATE_DYING) in xhci_giveback_invalidated_tds()
963 ret = -ENOMEM; in xhci_reset_halted_ep()
967 xhci_dbg(xhci, "%s-reset ep %u, slot %u\n", in xhci_reset_halted_ep()
984 unsigned int slot_id = ep->vdev->slot_id; in xhci_handle_halted_endpoint()
991 if (ep->vdev->flags & VDEV_PORT_ERROR) in xhci_handle_halted_endpoint()
992 return -ENODEV; in xhci_handle_halted_endpoint()
996 ep->ep_state |= EP_HARD_CLEAR_TOGGLE; in xhci_handle_halted_endpoint()
997 if (td && list_empty(&td->cancelled_td_list)) { in xhci_handle_halted_endpoint()
998 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); in xhci_handle_halted_endpoint()
999 td->cancel_status = TD_HALTED; in xhci_handle_halted_endpoint()
1003 if (ep->ep_state & EP_HALTED) { in xhci_handle_halted_endpoint()
1005 ep->ep_index); in xhci_handle_halted_endpoint()
1009 err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type); in xhci_handle_halted_endpoint()
1013 ep->ep_state |= EP_HALTED; in xhci_handle_halted_endpoint()
1023 * We're also in the event handler, so we can't get re-interrupted if another
1037 unsigned int slot_id = ep->vdev->slot_id; in xhci_invalidate_cancelled_tds()
1044 if (ep->ep_state & SET_DEQ_PENDING) in xhci_invalidate_cancelled_tds()
1047 xhci = ep->xhci; in xhci_invalidate_cancelled_tds()
1049 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, cancelled_td_list) { in xhci_invalidate_cancelled_tds()
1053 td->start_seg, td->start_trb), in xhci_invalidate_cancelled_tds()
1054 td->urb->stream_id, td->urb); in xhci_invalidate_cancelled_tds()
1055 list_del_init(&td->td_list); in xhci_invalidate_cancelled_tds()
1056 ring = xhci_urb_to_transfer_ring(xhci, td->urb); in xhci_invalidate_cancelled_tds()
1059 td->urb, td->urb->stream_id); in xhci_invalidate_cancelled_tds()
1068 hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index, in xhci_invalidate_cancelled_tds()
1069 td->urb->stream_id); in xhci_invalidate_cancelled_tds()
1072 if (td->cancel_status == TD_HALTED || trb_in_td(td, hw_deq)) { in xhci_invalidate_cancelled_tds()
1073 switch (td->cancel_status) { in xhci_invalidate_cancelled_tds()
1074 case TD_CLEARED: /* TD is already no-op */ in xhci_invalidate_cancelled_tds()
1081 if (cached_td->urb->stream_id != td->urb->stream_id) { in xhci_invalidate_cancelled_tds()
1085 td->urb->stream_id, td->urb); in xhci_invalidate_cancelled_tds()
1086 td->cancel_status = TD_CLEARING_CACHE_DEFERRED; in xhci_invalidate_cancelled_tds()
1093 td->urb, cached_td->urb, in xhci_invalidate_cancelled_tds()
1094 td->urb->stream_id); in xhci_invalidate_cancelled_tds()
1096 cached_td->cancel_status = TD_CLEARED; in xhci_invalidate_cancelled_tds()
1099 td->cancel_status = TD_CLEARING_CACHE; in xhci_invalidate_cancelled_tds()
1105 td->cancel_status = TD_CLEARED; in xhci_invalidate_cancelled_tds()
1113 err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index, in xhci_invalidate_cancelled_tds()
1114 cached_td->urb->stream_id, in xhci_invalidate_cancelled_tds()
1117 /* Failed to move past cached td, just set cached TDs to no-op */ in xhci_invalidate_cancelled_tds()
1118 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, cancelled_td_list) { in xhci_invalidate_cancelled_tds()
1124 if (td->cancel_status != TD_CLEARING_CACHE && in xhci_invalidate_cancelled_tds()
1125 td->cancel_status != TD_CLEARING_CACHE_DEFERRED) in xhci_invalidate_cancelled_tds()
1128 td->urb); in xhci_invalidate_cancelled_tds()
1130 td->cancel_status = TD_CLEARED; in xhci_invalidate_cancelled_tds()
1141 * Call under xhci->lock on a stopped endpoint.
1151 * Only call for non-running rings without streams.
1158 if (!list_empty(&ep->ring->td_list)) { /* Not streams compatible */ in find_halted_td()
1159 hw_deq = xhci_get_hw_deq(ep->xhci, ep->vdev, ep->ep_index, 0); in find_halted_td()
1161 td = list_first_entry(&ep->ring->td_list, struct xhci_td, td_list); in find_halted_td()
1175 * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain
1189 if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) { in xhci_handle_cmd_stop_ep()
1190 if (!xhci->devs[slot_id]) in xhci_handle_cmd_stop_ep()
1196 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_stop_ep()
1201 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_stop_ep()
1214 * Proper error code is unknown here, it would be -EPIPE if device side in xhci_handle_cmd_stop_ep()
1215 * of enadpoit halted (aka STALL), and -EPROTO if not (transaction error) in xhci_handle_cmd_stop_ep()
1216 * We use -EPROTO, if device is stalled it should return a stall error on in xhci_handle_cmd_stop_ep()
1217 * next transfer, which then will return -EPIPE, and device side stall is in xhci_handle_cmd_stop_ep()
1227 if (ep->ep_state & EP_HALTED) in xhci_handle_cmd_stop_ep()
1230 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_handle_cmd_stop_ep()
1236 td->status = -EPROTO; in xhci_handle_cmd_stop_ep()
1245 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_cmd_stop_ep()
1256 if (ep->ep_state & EP_HALTED) in xhci_handle_cmd_stop_ep()
1277 if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100))) in xhci_handle_cmd_stop_ep()
1282 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_cmd_stop_ep()
1296 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_cmd_stop_ep()
1308 list_for_each_entry_safe(cur_td, tmp, &ring->td_list, td_list) { in xhci_kill_ring_urbs()
1309 list_del_init(&cur_td->td_list); in xhci_kill_ring_urbs()
1311 if (!list_empty(&cur_td->cancelled_td_list)) in xhci_kill_ring_urbs()
1312 list_del_init(&cur_td->cancelled_td_list); in xhci_kill_ring_urbs()
1316 inc_td_cnt(cur_td->urb); in xhci_kill_ring_urbs()
1318 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_ring_urbs()
1334 if ((ep->ep_state & EP_HAS_STREAMS) || in xhci_kill_endpoint_urbs()
1335 (ep->ep_state & EP_GETTING_NO_STREAMS)) { in xhci_kill_endpoint_urbs()
1338 for (stream_id = 1; stream_id < ep->stream_info->num_streams; in xhci_kill_endpoint_urbs()
1340 ring = ep->stream_info->stream_rings[stream_id]; in xhci_kill_endpoint_urbs()
1350 ring = ep->ring; in xhci_kill_endpoint_urbs()
1359 list_for_each_entry_safe(cur_td, tmp, &ep->cancelled_td_list, in xhci_kill_endpoint_urbs()
1361 list_del_init(&cur_td->cancelled_td_list); in xhci_kill_endpoint_urbs()
1362 inc_td_cnt(cur_td->urb); in xhci_kill_endpoint_urbs()
1365 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_endpoint_urbs()
1375 * Call with xhci->lock held.
1376 * lock is relased and re-acquired while giving back urb.
1382 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_hc_died()
1386 xhci->xhc_state |= XHCI_STATE_DYING; in xhci_hc_died()
1391 for (i = 0; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_hc_died()
1392 if (!xhci->devs[i]) in xhci_hc_died()
1399 if (!(xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_hc_died()
1422 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_set_deq()
1423 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); in xhci_handle_cmd_set_deq()
1436 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_set_deq()
1437 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in xhci_handle_cmd_set_deq()
1441 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_handle_cmd_set_deq()
1442 stream_ctx = &ep->stream_info->stream_ctx_array[stream_id]; in xhci_handle_cmd_set_deq()
1443 trace_xhci_handle_cmd_set_deq_stream(ep->stream_info, stream_id); in xhci_handle_cmd_set_deq()
1457 slot_state = le32_to_cpu(slot_ctx->dev_state); in xhci_handle_cmd_set_deq()
1481 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_handle_cmd_set_deq()
1482 deq = le64_to_cpu(stream_ctx->stream_ring) & SCTX_DEQ_MASK; in xhci_handle_cmd_set_deq()
1493 if (xhci->quirks & XHCI_CDNS_SCTX_QUIRK) { in xhci_handle_cmd_set_deq()
1494 stream_ctx->reserved[0] = 0; in xhci_handle_cmd_set_deq()
1495 stream_ctx->reserved[1] = 0; in xhci_handle_cmd_set_deq()
1498 deq = le64_to_cpu(ep_ctx->deq) & ~EP_CTX_CYCLE_MASK; in xhci_handle_cmd_set_deq()
1502 if (xhci_trb_virt_to_dma(ep->queued_deq_seg, in xhci_handle_cmd_set_deq()
1503 ep->queued_deq_ptr) == deq) { in xhci_handle_cmd_set_deq()
1507 ep_ring->deq_seg = ep->queued_deq_seg; in xhci_handle_cmd_set_deq()
1508 ep_ring->dequeue = ep->queued_deq_ptr; in xhci_handle_cmd_set_deq()
1512 ep->queued_deq_seg, ep->queued_deq_ptr); in xhci_handle_cmd_set_deq()
1516 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, in xhci_handle_cmd_set_deq()
1518 ep_ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_handle_cmd_set_deq()
1519 if (td->cancel_status == TD_CLEARING_CACHE) { in xhci_handle_cmd_set_deq()
1520 td->cancel_status = TD_CLEARED; in xhci_handle_cmd_set_deq()
1521 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_handle_cmd_set_deq()
1522 __func__, td->urb); in xhci_handle_cmd_set_deq()
1523 xhci_td_cleanup(ep->xhci, td, ep_ring, td->status); in xhci_handle_cmd_set_deq()
1525 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_handle_cmd_set_deq()
1526 __func__, td->urb, td->cancel_status); in xhci_handle_cmd_set_deq()
1530 ep->ep_state &= ~SET_DEQ_PENDING; in xhci_handle_cmd_set_deq()
1531 ep->queued_deq_seg = NULL; in xhci_handle_cmd_set_deq()
1532 ep->queued_deq_ptr = NULL; in xhci_handle_cmd_set_deq()
1535 if (!list_empty(&ep->cancelled_td_list)) { in xhci_handle_cmd_set_deq()
1536 xhci_dbg(ep->xhci, "%s: Pending TDs to clear, continuing with invalidation\n", in xhci_handle_cmd_set_deq()
1545 xhci_dbg(ep->xhci, "%s: All TDs cleared, ring doorbell\n", __func__); in xhci_handle_cmd_set_deq()
1557 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_reset_ep()
1562 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_reset_ep()
1575 ep->ep_state &= ~EP_HALTED; in xhci_handle_cmd_reset_ep()
1580 if ((le32_to_cpu(trb->generic.field[3])) & TRB_TSP) in xhci_handle_cmd_reset_ep()
1588 command->slot_id = slot_id; in xhci_handle_cmd_enable_slot()
1590 command->slot_id = 0; in xhci_handle_cmd_enable_slot()
1598 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_disable_slot()
1602 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_handle_cmd_disable_slot()
1605 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) in xhci_handle_cmd_disable_slot()
1623 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_config_ep()
1626 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_handle_cmd_config_ep()
1632 add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_handle_cmd_config_ep()
1635 ep_index = xhci_last_valid_endpoint(add_flags) - 1; in xhci_handle_cmd_config_ep()
1637 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, ep_index); in xhci_handle_cmd_config_ep()
1648 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_addr_dev()
1651 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_addr_dev()
1660 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_dev()
1666 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_reset_dev()
1675 if (!(xhci->quirks & XHCI_NEC_HOST)) { in xhci_handle_cmd_nec_get_fw()
1676 xhci_warn(xhci, "WARN NEC_GET_FW command on non-NEC host\n"); in xhci_handle_cmd_nec_get_fw()
1681 NEC_FW_MAJOR(le32_to_cpu(event->status)), in xhci_handle_cmd_nec_get_fw()
1682 NEC_FW_MINOR(le32_to_cpu(event->status))); in xhci_handle_cmd_nec_get_fw()
1687 list_del(&cmd->cmd_list); in xhci_complete_del_and_free_cmd()
1689 if (cmd->completion) { in xhci_complete_del_and_free_cmd()
1690 cmd->status = comp_code; in xhci_complete_del_and_free_cmd()
1691 cmd->comp_param = comp_param; in xhci_complete_del_and_free_cmd()
1692 complete(cmd->completion); in xhci_complete_del_and_free_cmd()
1701 xhci->current_cmd = NULL; in xhci_cleanup_command_queue()
1702 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) in xhci_cleanup_command_queue()
1717 spin_lock_irqsave(&xhci->lock, flags); in xhci_handle_command_timeout()
1723 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { in xhci_handle_command_timeout()
1724 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1728 cmd_field3 = le32_to_cpu(xhci->current_cmd->command_trb->generic.field[3]); in xhci_handle_command_timeout()
1729 usbsts = readl(&xhci->op_regs->status); in xhci_handle_command_timeout()
1741 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_command_timeout()
1749 xhci->current_cmd->status = COMP_COMMAND_ABORTED; in xhci_handle_command_timeout()
1752 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_handle_command_timeout()
1758 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && in xhci_handle_command_timeout()
1761 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; in xhci_handle_command_timeout()
1768 if (xhci->xhc_state & XHCI_STATE_REMOVING) { in xhci_handle_command_timeout()
1777 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); in xhci_handle_command_timeout()
1780 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1787 unsigned int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); in handle_cmd_completion()
1788 u32 status = le32_to_cpu(event->status); in handle_cmd_completion()
1801 cmd_dma = le64_to_cpu(event->cmd_trb); in handle_cmd_completion()
1802 cmd_trb = xhci->cmd_ring->dequeue; in handle_cmd_completion()
1804 trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic, cmd_dma); in handle_cmd_completion()
1806 cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status)); in handle_cmd_completion()
1810 complete_all(&xhci->cmd_ring_stop_completion); in handle_cmd_completion()
1814 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in handle_cmd_completion()
1826 cmd = list_first_entry(&xhci->cmd_list, struct xhci_command, cmd_list); in handle_cmd_completion()
1828 cancel_delayed_work(&xhci->cmd_timer); in handle_cmd_completion()
1830 if (cmd->command_trb != xhci->cmd_ring->dequeue) { in handle_cmd_completion()
1843 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in handle_cmd_completion()
1844 if (cmd->status == COMP_COMMAND_ABORTED) { in handle_cmd_completion()
1845 if (xhci->current_cmd == cmd) in handle_cmd_completion()
1846 xhci->current_cmd = NULL; in handle_cmd_completion()
1851 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); in handle_cmd_completion()
1860 if (!cmd->completion) in handle_cmd_completion()
1870 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1871 if (!cmd->completion) in handle_cmd_completion()
1877 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1881 /* Is this an aborted command turned to NO-OP? */ in handle_cmd_completion()
1882 if (cmd->status == COMP_COMMAND_RING_STOPPED) in handle_cmd_completion()
1887 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1895 le32_to_cpu(cmd_trb->generic.field[3])); in handle_cmd_completion()
1910 if (!list_is_singular(&xhci->cmd_list)) { in handle_cmd_completion()
1911 xhci->current_cmd = list_first_entry(&cmd->cmd_list, in handle_cmd_completion()
1914 } else if (xhci->current_cmd == cmd) { in handle_cmd_completion()
1915 xhci->current_cmd = NULL; in handle_cmd_completion()
1921 inc_deq(xhci, xhci->cmd_ring); in handle_cmd_completion()
1928 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) in handle_vendor_event()
1929 handle_cmd_completion(xhci, &event->event_cmd); in handle_vendor_event()
1938 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->generic.field[3])); in handle_device_notification()
1939 if (!xhci->devs[slot_id]) { in handle_device_notification()
1947 udev = xhci->devs[slot_id]->udev; in handle_device_notification()
1948 if (udev && udev->parent) in handle_device_notification()
1949 usb_wakeup_notification(udev->parent, udev->portnum); in handle_device_notification()
1955 * As per ThunderX2errata-129 USB 2 device may come up as USB 1
1972 writel(0x6F, hcd->regs + 0x1048); in xhci_cavium_reset_phy_quirk()
1974 /* De-assert the PHY reset */ in xhci_cavium_reset_phy_quirk()
1975 writel(0x7F, hcd->regs + 0x1048); in xhci_cavium_reset_phy_quirk()
1977 pll_lock_check = readl(hcd->regs + 0x1070); in xhci_cavium_reset_phy_quirk()
1978 } while (!(pll_lock_check & 0x1) && --retry_count); in xhci_cavium_reset_phy_quirk()
1993 if (GET_COMP_CODE(le32_to_cpu(event->generic.field[2])) != COMP_SUCCESS) in handle_port_status()
1997 port_id = GET_PORT_ID(le32_to_cpu(event->generic.field[0])); in handle_port_status()
1998 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); in handle_port_status()
2006 port = &xhci->hw_ports[port_id - 1]; in handle_port_status()
2007 if (!port || !port->rhub || port->hcd_portnum == DUPLICATE_ENTRY) { in handle_port_status()
2015 if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) { in handle_port_status()
2021 hcd = port->rhub->hcd; in handle_port_status()
2022 bus_state = &port->rhub->bus_state; in handle_port_status()
2023 hcd_portnum = port->hcd_portnum; in handle_port_status()
2024 portsc = readl(port->addr); in handle_port_status()
2026 xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n", in handle_port_status()
2027 hcd->self.busnum, hcd_portnum + 1, port_id, portsc); in handle_port_status()
2031 if (hcd->state == HC_STATE_SUSPENDED) { in handle_port_status()
2036 if (hcd->speed >= HCD_USB3 && in handle_port_status()
2038 if (port->slot_id && xhci->devs[port->slot_id]) in handle_port_status()
2039 xhci->devs[port->slot_id]->flags |= VDEV_PORT_ERROR; in handle_port_status()
2045 cmd_reg = readl(&xhci->op_regs->command); in handle_port_status()
2057 bus_state->port_remote_wakeup |= 1 << hcd_portnum; in handle_port_status()
2059 usb_hcd_start_port_resume(&hcd->self, hcd_portnum); in handle_port_status()
2066 } else if (!test_bit(hcd_portnum, &bus_state->resuming_ports)) { in handle_port_status()
2068 port->resume_timestamp = jiffies + in handle_port_status()
2070 set_bit(hcd_portnum, &bus_state->resuming_ports); in handle_port_status()
2073 * usb device auto-resume latency around ~40ms. in handle_port_status()
2075 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in handle_port_status()
2076 mod_timer(&hcd->rh_timer, in handle_port_status()
2077 port->resume_timestamp); in handle_port_status()
2078 usb_hcd_start_port_resume(&hcd->self, hcd_portnum); in handle_port_status()
2089 complete(&port->u3exit_done); in handle_port_status()
2092 * U3Exit state after a host-initiated resume. If it's a device in handle_port_status()
2097 if (port->slot_id && xhci->devs[port->slot_id]) in handle_port_status()
2098 xhci_ring_device(xhci, port->slot_id); in handle_port_status()
2099 if (bus_state->port_remote_wakeup & (1 << hcd_portnum)) { in handle_port_status()
2101 usb_wakeup_notification(hcd->self.root_hub, in handle_port_status()
2109 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or in handle_port_status()
2113 if (hcd->speed < HCD_USB3 && port->rexit_active) { in handle_port_status()
2114 complete(&port->rexit_done); in handle_port_status()
2115 port->rexit_active = false; in handle_port_status()
2120 if (hcd->speed < HCD_USB3) { in handle_port_status()
2122 if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) && in handle_port_status()
2137 * xHCI port-status-change events occur when the "or" of all the in handle_port_status()
2138 * status-change bits in the portsc register changes from 0 to 1. in handle_port_status()
2144 __func__, hcd->self.busnum); in handle_port_status()
2145 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in handle_port_status()
2146 spin_unlock(&xhci->lock); in handle_port_status()
2149 spin_lock(&xhci->lock); in handle_port_status()
2156 * As part of low/full-speed endpoint-halt processing in xhci_clear_hub_tt_buffer()
2159 if (td->urb->dev->tt && !usb_pipeint(td->urb->pipe) && in xhci_clear_hub_tt_buffer()
2160 (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && in xhci_clear_hub_tt_buffer()
2161 !(ep->ep_state & EP_CLEARING_TT)) { in xhci_clear_hub_tt_buffer()
2162 ep->ep_state |= EP_CLEARING_TT; in xhci_clear_hub_tt_buffer()
2163 td->urb->ep->hcpriv = td->urb->dev; in xhci_clear_hub_tt_buffer()
2164 if (usb_hub_clear_tt_buffer(td->urb)) in xhci_clear_hub_tt_buffer()
2165 ep->ep_state &= ~EP_CLEARING_TT; in xhci_clear_hub_tt_buffer()
2203 * treat as not-an-error. in xhci_is_vendor_info_code()
2219 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in finish_td()
2251 if ((ep->ep_state & EP_HALTED) && in finish_td()
2252 !list_empty(&td->cancelled_td_list)) { in finish_td()
2255 td->start_seg, td->start_trb)); in finish_td()
2276 if (ep->ep_index != 0) in finish_td()
2286 xhci_dequeue_td(xhci, td, ep_ring, td->status); in finish_td()
2293 union xhci_trb *trb = td->start_trb; in sum_trb_lengths()
2294 struct xhci_segment *seg = td->start_seg; in sum_trb_lengths()
2298 sum += TRB_LEN(le32_to_cpu(trb->generic.field[2])); in sum_trb_lengths()
2315 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(ep_trb->generic.field[3])); in process_ctrl_td()
2316 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in process_ctrl_td()
2317 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_ctrl_td()
2318 requested = td->urb->transfer_buffer_length; in process_ctrl_td()
2319 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_ctrl_td()
2326 td->status = -ESHUTDOWN; in process_ctrl_td()
2329 td->status = 0; in process_ctrl_td()
2332 td->status = 0; in process_ctrl_td()
2336 td->urb->actual_length = remaining; in process_ctrl_td()
2343 td->urb->actual_length = 0; in process_ctrl_td()
2347 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2350 td->urb->actual_length = requested; in process_ctrl_td()
2363 trb_comp_code, ep->ep_index); in process_ctrl_td()
2368 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2369 else if (!td->urb_length_set) in process_ctrl_td()
2370 td->urb->actual_length = 0; in process_ctrl_td()
2384 td->urb_length_set = true; in process_ctrl_td()
2385 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2391 if (!td->urb_length_set) in process_ctrl_td()
2392 td->urb->actual_length = requested; in process_ctrl_td()
2413 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_isoc_td()
2414 urb_priv = td->urb->hcpriv; in process_isoc_td()
2415 idx = urb_priv->num_tds_done; in process_isoc_td()
2416 frame = &td->urb->iso_frame_desc[idx]; in process_isoc_td()
2417 requested = frame->length; in process_isoc_td()
2418 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_isoc_td()
2419 ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2])); in process_isoc_td()
2420 short_framestatus = td->urb->transfer_flags & URB_SHORT_NOT_OK ? in process_isoc_td()
2421 -EREMOTEIO : 0; in process_isoc_td()
2427 if (td->error_mid_td) in process_isoc_td()
2430 frame->status = short_framestatus; in process_isoc_td()
2434 frame->status = 0; in process_isoc_td()
2437 frame->status = short_framestatus; in process_isoc_td()
2441 frame->status = -ECOMM; in process_isoc_td()
2447 frame->status = -EOVERFLOW; in process_isoc_td()
2448 if (ep_trb != td->end_trb) in process_isoc_td()
2449 td->error_mid_td = true; in process_isoc_td()
2452 frame->status = -EXDEV; in process_isoc_td()
2454 if (ep_trb != td->end_trb) in process_isoc_td()
2455 td->error_mid_td = true; in process_isoc_td()
2459 frame->status = -EPROTO; in process_isoc_td()
2462 frame->status = -EPROTO; in process_isoc_td()
2464 if (ep_trb != td->end_trb) in process_isoc_td()
2465 td->error_mid_td = true; in process_isoc_td()
2472 frame->status = short_framestatus; in process_isoc_td()
2483 frame->status = -1; in process_isoc_td()
2487 if (td->urb_length_set) in process_isoc_td()
2491 frame->actual_length = sum_trb_lengths(td, ep_trb) + in process_isoc_td()
2492 ep_trb_len - remaining; in process_isoc_td()
2494 frame->actual_length = requested; in process_isoc_td()
2496 td->urb->actual_length += frame->actual_length; in process_isoc_td()
2500 if (td->error_mid_td && ep_trb != td->end_trb) { in process_isoc_td()
2502 td->urb_length_set = true; in process_isoc_td()
2515 urb_priv = td->urb->hcpriv; in skip_isoc_td()
2516 idx = urb_priv->num_tds_done; in skip_isoc_td()
2517 frame = &td->urb->iso_frame_desc[idx]; in skip_isoc_td()
2520 frame->status = -EXDEV; in skip_isoc_td()
2523 frame->actual_length = 0; in skip_isoc_td()
2525 xhci_dequeue_td(xhci, td, ep->ring, status); in skip_isoc_td()
2539 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in process_bulk_intr_td()
2540 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_bulk_intr_td()
2541 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_bulk_intr_td()
2542 ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2])); in process_bulk_intr_td()
2543 requested = td->urb->transfer_buffer_length; in process_bulk_intr_td()
2547 ep->err_count = 0; in process_bulk_intr_td()
2549 if (ep_trb != td->end_trb || remaining) { in process_bulk_intr_td()
2551 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2552 td->urb->ep->desc.bEndpointAddress, in process_bulk_intr_td()
2555 td->status = 0; in process_bulk_intr_td()
2558 td->status = 0; in process_bulk_intr_td()
2561 td->urb->actual_length = remaining; in process_bulk_intr_td()
2565 td->urb->actual_length = sum_trb_lengths(td, ep_trb); in process_bulk_intr_td()
2568 if (xhci->quirks & XHCI_NO_SOFT_RETRY || in process_bulk_intr_td()
2569 (ep->err_count++ > MAX_SOFT_RETRY) || in process_bulk_intr_td()
2570 le32_to_cpu(slot_ctx->tt_info) & TT_SLOT) in process_bulk_intr_td()
2573 td->status = 0; in process_bulk_intr_td()
2582 if (ep_trb == td->end_trb) in process_bulk_intr_td()
2583 td->urb->actual_length = requested - remaining; in process_bulk_intr_td()
2585 td->urb->actual_length = in process_bulk_intr_td()
2587 ep_trb_len - remaining; in process_bulk_intr_td()
2592 td->urb->actual_length = 0; in process_bulk_intr_td()
2607 xhci_dbg(xhci, "Stream transaction error ep %u no id\n", ep->ep_index); in handle_transferless_tx_event()
2608 if (ep->err_count++ > MAX_SOFT_RETRY) in handle_transferless_tx_event()
2619 trb_comp_code, ep->vdev->slot_id, ep->ep_index); in handle_transferless_tx_event()
2620 return -ENODEV; in handle_transferless_tx_event()
2628 switch (ring->old_trb_comp_code) { in xhci_spurious_success_tx_event()
2630 return xhci->quirks & XHCI_SPURIOUS_SUCCESS; in xhci_spurious_success_tx_event()
2634 return xhci->quirks & XHCI_ETRON_HOST && in xhci_spurious_success_tx_event()
2635 ring->type == TYPE_ISOC; in xhci_spurious_success_tx_event()
2658 int status = -EINPROGRESS; in handle_tx_event()
2663 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); in handle_tx_event()
2664 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; in handle_tx_event()
2665 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in handle_tx_event()
2666 ep_trb_dma = le64_to_cpu(event->buffer); in handle_tx_event()
2675 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in handle_tx_event()
2693 if (EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) { in handle_tx_event()
2696 slot_id, ep_index, ep_ring->old_trb_comp_code); in handle_tx_event()
2708 "Stopped on No-op or Link TRB for slot %u ep %u\n", in handle_tx_event()
2720 status = -EPIPE; in handle_tx_event()
2725 status = -EPROTO; in handle_tx_event()
2730 status = -EPROTO; in handle_tx_event()
2735 status = -EOVERFLOW; in handle_tx_event()
2742 status = -EILSEQ; in handle_tx_event()
2749 status = -ENOSR; in handle_tx_event()
2781 ep->skip = true; in handle_tx_event()
2787 ep->skip = true; in handle_tx_event()
2798 status = -EPROTO; in handle_tx_event()
2808 if (ep->skip) in handle_tx_event()
2818 * xhci 4.9.1 states that if there are errors in mult-TRB in handle_tx_event()
2826 td = list_first_entry_or_null(&ep_ring->td_list, struct xhci_td, td_list); in handle_tx_event()
2828 if (td && td->error_mid_td && !trb_in_td(td, ep_trb_dma)) { in handle_tx_event()
2830 xhci_dequeue_td(xhci, td, ep_ring, td->status); in handle_tx_event()
2837 if (list_empty(&ep_ring->td_list)) { in handle_tx_event()
2852 ep->skip = false; in handle_tx_event()
2857 td = list_first_entry(&ep_ring->td_list, struct xhci_td, in handle_tx_event()
2865 if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { in handle_tx_event()
2872 if (!list_empty(&ep_ring->td_list)) { in handle_tx_event()
2889 ep->skip = false; in handle_tx_event()
2900 * TD pointed by 'ep_ring->dequeue' because that the hardware dequeue in handle_tx_event()
2916 &ep_trb_dma, trb_comp_code, ep_ring->old_trb_comp_code); in handle_tx_event()
2917 ep_ring->old_trb_comp_code = 0; in handle_tx_event()
2925 if (ep->skip) { in handle_tx_event()
2929 ep->skip = false; in handle_tx_event()
2933 * If ep->skip is set, it means there are missed tds on the in handle_tx_event()
2938 } while (ep->skip); in handle_tx_event()
2940 ep_ring->old_trb_comp_code = trb_comp_code; in handle_tx_event()
2946 ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) / sizeof(*ep_trb)]; in handle_tx_event()
2950 * No-op TRB could trigger interrupts in a case where a URB was killed in handle_tx_event()
2959 td->status = status; in handle_tx_event()
2962 if (usb_endpoint_xfer_control(&td->urb->ep->desc)) in handle_tx_event()
2964 else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) in handle_tx_event()
2977 xhci_err(xhci, "Event dma %pad for ep %d status %d not part of TD at %016llx - %016llx\n", in handle_tx_event()
2979 (unsigned long long)xhci_trb_virt_to_dma(td->start_seg, td->start_trb), in handle_tx_event()
2980 (unsigned long long)xhci_trb_virt_to_dma(td->end_seg, td->end_trb)); in handle_tx_event()
2982 return -ESHUTDOWN; in handle_tx_event()
2987 ir->event_ring->deq_seg, in handle_tx_event()
2988 ir->event_ring->dequeue), in handle_tx_event()
2989 lower_32_bits(le64_to_cpu(event->buffer)), in handle_tx_event()
2990 upper_32_bits(le64_to_cpu(event->buffer)), in handle_tx_event()
2991 le32_to_cpu(event->transfer_len), in handle_tx_event()
2992 le32_to_cpu(event->flags)); in handle_tx_event()
2993 return -ENODEV; in handle_tx_event()
2997 * This function handles one OS-owned event on the event ring. It may drop
2998 * xhci->lock between event processing (e.g. to pass up port status changes).
3005 trace_xhci_handle_event(ir->event_ring, &event->generic, in xhci_handle_event_trb()
3006 xhci_trb_virt_to_dma(ir->event_ring->deq_seg, in xhci_handle_event_trb()
3007 ir->event_ring->dequeue)); in xhci_handle_event_trb()
3014 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->event_cmd.flags)); in xhci_handle_event_trb()
3019 handle_cmd_completion(xhci, &event->event_cmd); in xhci_handle_event_trb()
3025 handle_tx_event(xhci, ir, &event->trans_event); in xhci_handle_event_trb()
3036 /* Any of the above functions may drop and re-acquire the lock, so check in xhci_handle_event_trb()
3037 * to make sure a watchdog timer didn't mark the host as non-responsive. in xhci_handle_event_trb()
3039 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_handle_event_trb()
3041 return -ENODEV; in xhci_handle_event_trb()
3049 * - When all events have finished
3050 * - To avoid "Event Ring Full Error" condition
3059 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
3060 deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, in xhci_update_erst_dequeue()
3061 ir->event_ring->dequeue); in xhci_update_erst_dequeue()
3072 temp_64 = ir->event_ring->deq_seg->num & ERST_DESI_MASK; in xhci_update_erst_dequeue()
3078 xhci_write_64(xhci, temp_64, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
3084 if (!ir->ip_autoclear) { in xhci_clear_interrupt_pending()
3087 iman = readl(&ir->ir_set->iman); in xhci_clear_interrupt_pending()
3089 writel(iman, &ir->ir_set->iman); in xhci_clear_interrupt_pending()
3092 readl(&ir->ir_set->iman); in xhci_clear_interrupt_pending()
3097 * Handle all OS-owned events on an interrupter event ring. It may drop
3098 * and reaquire xhci->lock between event processing.
3110 if (!ir->event_ring || !ir->event_ring->dequeue) { in xhci_handle_events()
3112 return -ENOMEM; in xhci_handle_events()
3115 if (xhci->xhc_state & XHCI_STATE_DYING || in xhci_handle_events()
3116 xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_handle_events()
3120 temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_handle_events()
3121 xhci_write_64(xhci, temp | ERST_EHB, &ir->ir_set->erst_dequeue); in xhci_handle_events()
3122 return -ENODEV; in xhci_handle_events()
3126 while (unhandled_event_trb(ir->event_ring)) { in xhci_handle_events()
3128 err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue); in xhci_handle_events()
3137 if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) in xhci_handle_events()
3138 ir->isoc_bei_interval = ir->isoc_bei_interval / 2; in xhci_handle_events()
3144 inc_deq(xhci, ir->event_ring); in xhci_handle_events()
3172 erdp_reg = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_skip_sec_intr_events()
3179 current_trb = ir->event_ring->dequeue; in xhci_skip_sec_intr_events()
3181 ring->cycle_state = le32_to_cpu(current_trb->event_cmd.flags) & TRB_CYCLE; in xhci_skip_sec_intr_events()
3197 spin_lock(&xhci->lock); in xhci_irq()
3199 status = readl(&xhci->op_regs->status); in xhci_irq()
3223 * so we can receive interrupts from other MSI-X interrupters. in xhci_irq()
3227 writel(status, &xhci->op_regs->status); in xhci_irq()
3230 xhci_handle_events(xhci, xhci->interrupters[0], false); in xhci_irq()
3232 spin_unlock(&xhci->lock); in xhci_irq()
3246 * Generic function for queueing a TRB on a ring.
3258 trb = &ring->enqueue->generic; in queue_trb()
3259 trb->field[0] = cpu_to_le32(field1); in queue_trb()
3260 trb->field[1] = cpu_to_le32(field2); in queue_trb()
3261 trb->field[2] = cpu_to_le32(field3); in queue_trb()
3264 trb->field[3] = cpu_to_le32(field4); in queue_trb()
3267 xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue)); in queue_trb()
3289 return -ENOENT; in prepare_ring()
3293 /* XXX not sure if this should be -ENOENT or not */ in prepare_ring()
3294 return -EINVAL; in prepare_ring()
3307 return -EINVAL; in prepare_ring()
3310 if (ep_ring != xhci->cmd_ring) { in prepare_ring()
3314 return -ENOMEM; in prepare_ring()
3322 return -ENOMEM; in prepare_ring()
3327 if (trb_is_link(ep_ring->enqueue)) in prepare_ring()
3330 if (last_trb_on_seg(ep_ring->enq_seg, ep_ring->enqueue)) { in prepare_ring()
3332 return -EINVAL; in prepare_ring()
3351 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in prepare_transfer()
3353 ep_ring = xhci_triad_to_transfer_ring(xhci, xdev->slot_id, ep_index, in prepare_transfer()
3358 return -EINVAL; in prepare_transfer()
3366 urb_priv = urb->hcpriv; in prepare_transfer()
3367 td = &urb_priv->td[td_index]; in prepare_transfer()
3369 INIT_LIST_HEAD(&td->td_list); in prepare_transfer()
3370 INIT_LIST_HEAD(&td->cancelled_td_list); in prepare_transfer()
3373 ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb); in prepare_transfer()
3378 td->urb = urb; in prepare_transfer()
3380 list_add_tail(&td->td_list, &ep_ring->td_list); in prepare_transfer()
3381 td->start_seg = ep_ring->enq_seg; in prepare_transfer()
3382 td->start_trb = ep_ring->enqueue; in prepare_transfer()
3391 num_trbs = DIV_ROUND_UP(len + (addr & (TRB_MAX_BUFF_SIZE - 1)), in count_trbs()
3401 return count_trbs(urb->transfer_dma, urb->transfer_buffer_length); in count_trbs_needed()
3409 full_len = urb->transfer_buffer_length; in count_sg_trbs_needed()
3411 for_each_sg(urb->sg, sg, urb->num_mapped_sgs, i) { in count_sg_trbs_needed()
3415 full_len -= len; in count_sg_trbs_needed()
3427 addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset); in count_isoc_trbs_needed()
3428 len = urb->iso_frame_desc[i].length; in count_isoc_trbs_needed()
3435 if (unlikely(running_total != urb->transfer_buffer_length)) in check_trb_math()
3436 dev_err(&urb->dev->dev, "%s - ep %#x - Miscalculated tx length, " in check_trb_math()
3439 urb->ep->desc.bEndpointAddress, in check_trb_math()
3441 urb->transfer_buffer_length, in check_trb_math()
3442 urb->transfer_buffer_length); in check_trb_math()
3455 start_trb->field[3] |= cpu_to_le32(start_cycle); in giveback_first_trb()
3457 start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE); in giveback_first_trb()
3466 xhci_interval = EP_INTERVAL_TO_UFRAMES(le32_to_cpu(ep_ctx->ep_info)); in check_interval()
3467 ep_interval = urb->interval; in check_interval()
3470 if (urb->dev->speed == USB_SPEED_LOW || in check_interval()
3471 urb->dev->speed == USB_SPEED_FULL) in check_interval()
3478 dev_dbg_ratelimited(&urb->dev->dev, in check_interval()
3482 urb->interval = xhci_interval; in check_interval()
3484 if (urb->dev->speed == USB_SPEED_LOW || in check_interval()
3485 urb->dev->speed == USB_SPEED_FULL) in check_interval()
3486 urb->interval /= 8; in check_interval()
3501 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); in xhci_queue_intr_tx()
3517 * TD size = total_packet_count - packets_transferred
3534 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) in xhci_td_remainder()
3535 return ((td_total_len - transferred) >> 10); in xhci_td_remainder()
3537 /* One TRB with a zero-length data packet. */ in xhci_td_remainder()
3543 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) in xhci_td_remainder()
3546 maxp = usb_endpoint_maxp(&urb->ep->desc); in xhci_td_remainder()
3550 return (total_packet_count - ((transferred + trb_buff_len) / maxp)); in xhci_td_remainder()
3557 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_align_td()
3563 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_align_td()
3575 *trb_buff_len -= unalign; in xhci_align_td()
3585 new_buff_len = max_pkt - (enqd_len % max_pkt); in xhci_align_td()
3587 if (new_buff_len > (urb->transfer_buffer_length - enqd_len)) in xhci_align_td()
3588 new_buff_len = (urb->transfer_buffer_length - enqd_len); in xhci_align_td()
3592 if (urb->num_sgs) { in xhci_align_td()
3593 len = sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_align_td()
3594 seg->bounce_buf, new_buff_len, enqd_len); in xhci_align_td()
3599 memcpy(seg->bounce_buf, urb->transfer_buffer + enqd_len, new_buff_len); in xhci_align_td()
3602 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, in xhci_align_td()
3605 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, in xhci_align_td()
3609 if (dma_mapping_error(dev, seg->bounce_dma)) { in xhci_align_td()
3615 seg->bounce_len = new_buff_len; in xhci_align_td()
3616 seg->bounce_offs = enqd_len; in xhci_align_td()
3623 /* This is very similar to what ehci-q.c qtd_fill() does */
3644 return -EINVAL; in xhci_queue_bulk_tx()
3646 full_len = urb->transfer_buffer_length; in xhci_queue_bulk_tx()
3648 if (urb->num_sgs && !(urb->transfer_flags & URB_DMA_MAP_SINGLE)) { in xhci_queue_bulk_tx()
3649 num_sgs = urb->num_mapped_sgs; in xhci_queue_bulk_tx()
3650 sg = urb->sg; in xhci_queue_bulk_tx()
3656 addr = (u64) urb->transfer_dma; in xhci_queue_bulk_tx()
3659 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3660 ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3665 urb_priv = urb->hcpriv; in xhci_queue_bulk_tx()
3667 /* Deal with URB_ZERO_PACKET - need one more td/trb */ in xhci_queue_bulk_tx()
3668 if (urb->transfer_flags & URB_ZERO_PACKET && urb_priv->num_tds > 1) in xhci_queue_bulk_tx()
3671 td = &urb_priv->td[0]; in xhci_queue_bulk_tx()
3678 start_trb = &ring->enqueue->generic; in xhci_queue_bulk_tx()
3679 start_cycle = ring->cycle_state; in xhci_queue_bulk_tx()
3682 /* Queue the TRBs, even if they are zero-length */ in xhci_queue_bulk_tx()
3692 trb_buff_len = full_len - enqd_len; in xhci_queue_bulk_tx()
3700 field |= ring->cycle_state; in xhci_queue_bulk_tx()
3707 if (trb_is_link(ring->enqueue + 1)) { in xhci_queue_bulk_tx()
3710 ring->enq_seg)) { in xhci_queue_bulk_tx()
3711 send_addr = ring->enq_seg->bounce_dma; in xhci_queue_bulk_tx()
3713 td->bounce_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3721 td->end_trb = ring->enqueue; in xhci_queue_bulk_tx()
3722 td->end_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3724 memcpy(&send_addr, urb->transfer_buffer, in xhci_queue_bulk_tx()
3753 --num_sgs; in xhci_queue_bulk_tx()
3754 sent_len -= block_len; in xhci_queue_bulk_tx()
3762 block_len -= sent_len; in xhci_queue_bulk_tx()
3767 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3768 ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3770 urb_priv->td[1].end_trb = ring->enqueue; in xhci_queue_bulk_tx()
3771 urb_priv->td[1].end_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3772 field = TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; in xhci_queue_bulk_tx()
3777 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3782 /* Caller must have locked xhci->lock */
3798 return -EINVAL; in xhci_queue_ctrl_tx()
3804 if (!urb->setup_packet) in xhci_queue_ctrl_tx()
3805 return -EINVAL; in xhci_queue_ctrl_tx()
3807 if ((xhci->quirks & XHCI_ETRON_HOST) && in xhci_queue_ctrl_tx()
3808 urb->dev->speed >= USB_SPEED_SUPER) { in xhci_queue_ctrl_tx()
3814 if (last_trb_on_seg(ep_ring->enq_seg, ep_ring->enqueue + 1)) { in xhci_queue_ctrl_tx()
3815 field = TRB_TYPE(TRB_TR_NOOP) | ep_ring->cycle_state; in xhci_queue_ctrl_tx()
3828 if (urb->transfer_buffer_length > 0) in xhci_queue_ctrl_tx()
3830 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_ctrl_tx()
3831 ep_index, urb->stream_id, in xhci_queue_ctrl_tx()
3836 urb_priv = urb->hcpriv; in xhci_queue_ctrl_tx()
3837 td = &urb_priv->td[0]; in xhci_queue_ctrl_tx()
3844 start_trb = &ep_ring->enqueue->generic; in xhci_queue_ctrl_tx()
3845 start_cycle = ep_ring->cycle_state; in xhci_queue_ctrl_tx()
3847 /* Queue setup TRB - see section 6.4.1.2.1 */ in xhci_queue_ctrl_tx()
3849 setup = (struct usb_ctrlrequest *) urb->setup_packet; in xhci_queue_ctrl_tx()
3856 if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { in xhci_queue_ctrl_tx()
3857 if (urb->transfer_buffer_length > 0) { in xhci_queue_ctrl_tx()
3858 if (setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3866 setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16, in xhci_queue_ctrl_tx()
3867 le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16, in xhci_queue_ctrl_tx()
3879 if (urb->transfer_buffer_length > 0) { in xhci_queue_ctrl_tx()
3884 memcpy(&addr, urb->transfer_buffer, in xhci_queue_ctrl_tx()
3885 urb->transfer_buffer_length); in xhci_queue_ctrl_tx()
3889 addr = (u64) urb->transfer_dma; in xhci_queue_ctrl_tx()
3893 urb->transfer_buffer_length, in xhci_queue_ctrl_tx()
3894 urb->transfer_buffer_length, in xhci_queue_ctrl_tx()
3896 length_field = TRB_LEN(urb->transfer_buffer_length) | in xhci_queue_ctrl_tx()
3899 if (setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3905 field | ep_ring->cycle_state); in xhci_queue_ctrl_tx()
3909 td->end_trb = ep_ring->enqueue; in xhci_queue_ctrl_tx()
3910 td->end_seg = ep_ring->enq_seg; in xhci_queue_ctrl_tx()
3912 /* Queue status TRB - see Table 7 and sections 4.11.2.2 and 6.4.1.2.3 */ in xhci_queue_ctrl_tx()
3914 if (urb->transfer_buffer_length > 0 && setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3923 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state); in xhci_queue_ctrl_tx()
3943 if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER) in xhci_get_burst_count()
3946 max_burst = urb->ep->ss_ep_comp.bMaxBurst; in xhci_get_burst_count()
3947 return DIV_ROUND_UP(total_packet_count, max_burst + 1) - 1; in xhci_get_burst_count()
3964 if (xhci->hci_version < 0x100) in xhci_get_last_burst_packet_count()
3967 if (urb->dev->speed >= USB_SPEED_SUPER) { in xhci_get_last_burst_packet_count()
3969 max_burst = urb->ep->ss_ep_comp.bMaxBurst; in xhci_get_last_burst_packet_count()
3972 * number of packets, but the TLBPC field is zero-based. in xhci_get_last_burst_packet_count()
3976 return residue - 1; in xhci_get_last_burst_packet_count()
3980 return total_packet_count - 1; in xhci_get_last_burst_packet_count()
3996 if (urb->dev->speed == USB_SPEED_LOW || in xhci_get_isoc_frame_id()
3997 urb->dev->speed == USB_SPEED_FULL) in xhci_get_isoc_frame_id()
3998 start_frame = urb->start_frame + index * urb->interval; in xhci_get_isoc_frame_id()
4000 start_frame = (urb->start_frame + index * urb->interval) >> 3; in xhci_get_isoc_frame_id()
4010 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_get_isoc_frame_id()
4011 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_get_isoc_frame_id()
4027 current_frame_id = readl(&xhci->run_regs->microframe_index); in xhci_get_isoc_frame_id()
4038 ret = -EINVAL; in xhci_get_isoc_frame_id()
4042 ret = -EINVAL; in xhci_get_isoc_frame_id()
4044 ret = -EINVAL; in xhci_get_isoc_frame_id()
4048 if (ret == -EINVAL || start_frame == start_frame_id) { in xhci_get_isoc_frame_id()
4050 if (urb->dev->speed == USB_SPEED_LOW || in xhci_get_isoc_frame_id()
4051 urb->dev->speed == USB_SPEED_FULL) in xhci_get_isoc_frame_id()
4052 urb->start_frame = start_frame; in xhci_get_isoc_frame_id()
4054 urb->start_frame = start_frame << 3; in xhci_get_isoc_frame_id()
4074 if (xhci->hci_version < 0x100) in trb_block_event_intr()
4077 if (i == num_tds - 1) in trb_block_event_intr()
4083 if (i && ir->isoc_bei_interval && xhci->quirks & XHCI_AVOID_BEI) in trb_block_event_intr()
4084 return !!(i % ir->isoc_bei_interval); in trb_block_event_intr()
4109 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx()
4110 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; in xhci_queue_isoc_tx()
4111 ir = xhci->interrupters[0]; in xhci_queue_isoc_tx()
4113 num_tds = urb->number_of_packets; in xhci_queue_isoc_tx()
4116 return -EINVAL; in xhci_queue_isoc_tx()
4118 start_addr = (u64) urb->transfer_dma; in xhci_queue_isoc_tx()
4119 start_trb = &ep_ring->enqueue->generic; in xhci_queue_isoc_tx()
4120 start_cycle = ep_ring->cycle_state; in xhci_queue_isoc_tx()
4122 urb_priv = urb->hcpriv; in xhci_queue_isoc_tx()
4123 /* Queue the TRBs for each TD, even if they are zero-length */ in xhci_queue_isoc_tx()
4131 addr = start_addr + urb->iso_frame_desc[i].offset; in xhci_queue_isoc_tx()
4132 td_len = urb->iso_frame_desc[i].length; in xhci_queue_isoc_tx()
4134 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_queue_isoc_tx()
4137 /* A zero-length transfer still involves at least one packet. */ in xhci_queue_isoc_tx()
4146 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, in xhci_queue_isoc_tx()
4147 urb->stream_id, trbs_per_td, urb, i, mem_flags); in xhci_queue_isoc_tx()
4153 td = &urb_priv->td[i]; in xhci_queue_isoc_tx()
4156 if (!(urb->transfer_flags & URB_ISO_ASAP) && in xhci_queue_isoc_tx()
4157 HCC_CFC(xhci->hcc_params)) { in xhci_queue_isoc_tx()
4170 (i ? ep_ring->cycle_state : !start_cycle); in xhci_queue_isoc_tx()
4173 if (!xep->use_extended_tbc) in xhci_queue_isoc_tx()
4183 ep_ring->cycle_state; in xhci_queue_isoc_tx()
4190 if (j < trbs_per_td - 1) { in xhci_queue_isoc_tx()
4195 td->end_trb = ep_ring->enqueue; in xhci_queue_isoc_tx()
4196 td->end_seg = ep_ring->enq_seg; in xhci_queue_isoc_tx()
4215 if (first_trb && xep->use_extended_tbc) in xhci_queue_isoc_tx()
4229 td_remain_len -= trb_buff_len; in xhci_queue_isoc_tx()
4235 ret = -EINVAL; in xhci_queue_isoc_tx()
4241 if (HCC_CFC(xhci->hcc_params)) in xhci_queue_isoc_tx()
4242 xep->next_frame_id = urb->start_frame + num_tds * urb->interval; in xhci_queue_isoc_tx()
4244 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_queue_isoc_tx()
4245 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_queue_isoc_tx()
4248 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; in xhci_queue_isoc_tx()
4250 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_isoc_tx()
4256 for (i--; i >= 0; i--) in xhci_queue_isoc_tx()
4257 list_del_init(&urb_priv->td[i].td_list); in xhci_queue_isoc_tx()
4260 * into No-ops with a software-owned cycle bit. That way the hardware in xhci_queue_isoc_tx()
4262 * overwrite them. td->start_trb and td->start_seg are already set. in xhci_queue_isoc_tx()
4264 urb_priv->td[0].end_trb = ep_ring->enqueue; in xhci_queue_isoc_tx()
4266 td_to_noop(&urb_priv->td[0], true); in xhci_queue_isoc_tx()
4269 ep_ring->enqueue = urb_priv->td[0].start_trb; in xhci_queue_isoc_tx()
4270 ep_ring->enq_seg = urb_priv->td[0].start_seg; in xhci_queue_isoc_tx()
4271 ep_ring->cycle_state = start_cycle; in xhci_queue_isoc_tx()
4272 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb); in xhci_queue_isoc_tx()
4280 * update urb->start_frame if URB_ISO_ASAP is set in transfer_flags or
4295 xdev = xhci->devs[slot_id]; in xhci_queue_isoc_tx_prepare()
4296 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx_prepare()
4297 ep_ring = xdev->eps[ep_index].ring; in xhci_queue_isoc_tx_prepare()
4298 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in xhci_queue_isoc_tx_prepare()
4301 num_tds = urb->number_of_packets; in xhci_queue_isoc_tx_prepare()
4319 /* Calculate the start frame and put it in urb->start_frame. */ in xhci_queue_isoc_tx_prepare()
4320 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { in xhci_queue_isoc_tx_prepare()
4322 urb->start_frame = xep->next_frame_id; in xhci_queue_isoc_tx_prepare()
4327 start_frame = readl(&xhci->run_regs->microframe_index); in xhci_queue_isoc_tx_prepare()
4333 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_queue_isoc_tx_prepare()
4334 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_queue_isoc_tx_prepare()
4343 if (urb->dev->speed == USB_SPEED_LOW || in xhci_queue_isoc_tx_prepare()
4344 urb->dev->speed == USB_SPEED_FULL) { in xhci_queue_isoc_tx_prepare()
4345 start_frame = roundup(start_frame, urb->interval << 3); in xhci_queue_isoc_tx_prepare()
4346 urb->start_frame = start_frame >> 3; in xhci_queue_isoc_tx_prepare()
4348 start_frame = roundup(start_frame, urb->interval); in xhci_queue_isoc_tx_prepare()
4349 urb->start_frame = start_frame; in xhci_queue_isoc_tx_prepare()
4359 /* Generic function for queueing a command TRB on the command ring.
4364 * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
4371 int reserved_trbs = xhci->cmd_ring_reserved_trbs; in queue_command()
4374 if ((xhci->xhc_state & XHCI_STATE_DYING) || in queue_command()
4375 (xhci->xhc_state & XHCI_STATE_HALTED)) { in queue_command()
4377 return -ESHUTDOWN; in queue_command()
4383 ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, in queue_command()
4393 cmd->command_trb = xhci->cmd_ring->enqueue; in queue_command()
4396 if (list_empty(&xhci->cmd_list)) { in queue_command()
4397 xhci->current_cmd = cmd; in queue_command()
4401 list_add_tail(&cmd->cmd_list, &xhci->cmd_list); in queue_command()
4403 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, in queue_command()
4404 field4 | xhci->cmd_ring->cycle_state); in queue_command()