Lines Matching +full:num +full:- +full:hc +full:- +full:interrupters
1 // SPDX-License-Identifier: GPL-2.0
26 * until you reach a non-link TRB.
42 * and endpoint rings. If HC is the producer for the event ring,
51 * updates event ring dequeue pointer. HC is the consumer for the command and
57 #include <linux/dma-mapping.h>
59 #include "xhci-trace.h"
74 if (!seg || !trb || trb < seg->trbs) in xhci_trb_virt_to_dma()
77 segment_offset = trb - seg->trbs; in xhci_trb_virt_to_dma()
80 return seg->dma + (segment_offset * sizeof(*trb)); in xhci_trb_virt_to_dma()
85 return TRB_TYPE_NOOP_LE32(trb->generic.field[3]); in trb_is_noop()
90 return TRB_TYPE_LINK_LE32(trb->link.control); in trb_is_link()
95 return trb == &seg->trbs[TRBS_PER_SEGMENT - 1]; in last_trb_on_seg()
101 return last_trb_on_seg(seg, trb) && (seg->next == ring->first_seg); in last_trb_on_ring()
106 return le32_to_cpu(trb->link.control) & LINK_TOGGLE; in link_trb_toggles_cycle()
111 struct urb_priv *urb_priv = td->urb->hcpriv; in last_td_in_urb()
113 return urb_priv->num_tds_done == urb_priv->num_tds; in last_td_in_urb()
118 return ((le32_to_cpu(ring->dequeue->event_cmd.flags) & TRB_CYCLE) == in unhandled_event_trb()
119 ring->cycle_state); in unhandled_event_trb()
124 struct urb_priv *urb_priv = urb->hcpriv; in inc_td_cnt()
126 urb_priv->num_tds_done++; in inc_td_cnt()
133 trb->link.control &= cpu_to_le32(~TRB_CHAIN); in trb_to_noop()
135 trb->generic.field[0] = 0; in trb_to_noop()
136 trb->generic.field[1] = 0; in trb_to_noop()
137 trb->generic.field[2] = 0; in trb_to_noop()
139 trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE); in trb_to_noop()
140 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()
182 if (!trb_is_link(ring->dequeue)) { in inc_deq()
183 if (last_trb_on_seg(ring->deq_seg, ring->dequeue)) in inc_deq()
186 ring->dequeue++; in inc_deq()
189 while (trb_is_link(ring->dequeue)) { in inc_deq()
190 ring->deq_seg = ring->deq_seg->next; in inc_deq()
191 ring->dequeue = ring->deq_seg->trbs; in inc_deq()
193 if (link_trb_count++ > ring->num_segs) { in inc_deq()
227 chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN; in inc_enq()
229 if (last_trb_on_seg(ring->enq_seg, ring->enqueue)) { in inc_enq()
234 next = ++(ring->enqueue); in inc_enq()
253 if (!xhci_link_chain_quirk(xhci, ring->type)) { in inc_enq()
254 next->link.control &= cpu_to_le32(~TRB_CHAIN); in inc_enq()
255 next->link.control |= cpu_to_le32(chain); in inc_enq()
259 next->link.control ^= cpu_to_le32(TRB_CYCLE); in inc_enq()
263 ring->cycle_state ^= 1; in inc_enq()
265 ring->enq_seg = ring->enq_seg->next; in inc_enq()
266 ring->enqueue = ring->enq_seg->trbs; in inc_enq()
267 next = ring->enqueue; in inc_enq()
269 if (link_trb_count++ > ring->num_segs) { in inc_enq()
286 struct xhci_segment *enq_seg = ring->enq_seg; in xhci_num_trbs_free()
287 union xhci_trb *enq = ring->enqueue; in xhci_num_trbs_free()
294 enq_seg = enq_seg->next; in xhci_num_trbs_free()
295 enq = enq_seg->trbs; in xhci_num_trbs_free()
299 if (enq == ring->dequeue) in xhci_num_trbs_free()
300 return ring->num_segs * (TRBS_PER_SEGMENT - 1); in xhci_num_trbs_free()
303 if (ring->deq_seg == enq_seg && ring->dequeue >= enq) in xhci_num_trbs_free()
304 return free + (ring->dequeue - enq); in xhci_num_trbs_free()
305 last_on_seg = &enq_seg->trbs[TRBS_PER_SEGMENT - 1]; in xhci_num_trbs_free()
306 free += last_on_seg - enq; in xhci_num_trbs_free()
307 enq_seg = enq_seg->next; in xhci_num_trbs_free()
308 enq = enq_seg->trbs; in xhci_num_trbs_free()
309 } while (i++ < ring->num_segs); in xhci_num_trbs_free()
328 enq_used = ring->enqueue - ring->enq_seg->trbs; in xhci_ring_expansion_needed()
331 trbs_past_seg = enq_used + num_trbs - (TRBS_PER_SEGMENT - 1); in xhci_ring_expansion_needed()
343 if (trb_is_link(ring->enqueue) && ring->enq_seg->next->trbs == ring->dequeue) in xhci_ring_expansion_needed()
346 new_segs = 1 + (trbs_past_seg / (TRBS_PER_SEGMENT - 1)); in xhci_ring_expansion_needed()
347 seg = ring->enq_seg; in xhci_ring_expansion_needed()
350 seg = seg->next; in xhci_ring_expansion_needed()
351 if (seg == ring->deq_seg) { in xhci_ring_expansion_needed()
356 new_segs--; in xhci_ring_expansion_needed()
365 if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) in xhci_ring_cmd_db()
372 writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
374 readl(&xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
379 return mod_delayed_work(system_wq, &xhci->cmd_timer, in xhci_mod_cmd_timer()
380 msecs_to_jiffies(xhci->current_cmd->timeout_ms)); in xhci_mod_cmd_timer()
385 return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command, in xhci_next_queued_cmd()
390 * Turn all commands on command ring with status set to "aborted" to no-op trbs.
392 * This must be called with command ring stopped and xhci->lock held.
399 /* Turn all aborted commands in list to no-ops, then restart */ in xhci_handle_stopped_cmd_ring()
400 list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) { in xhci_handle_stopped_cmd_ring()
402 if (i_cmd->status != COMP_COMMAND_ABORTED) in xhci_handle_stopped_cmd_ring()
405 i_cmd->status = COMP_COMMAND_RING_STOPPED; in xhci_handle_stopped_cmd_ring()
407 xhci_dbg(xhci, "Turn aborted command %p to no-op\n", in xhci_handle_stopped_cmd_ring()
408 i_cmd->command_trb); in xhci_handle_stopped_cmd_ring()
410 trb_to_noop(i_cmd->command_trb, TRB_CMD_NOOP); in xhci_handle_stopped_cmd_ring()
414 * completion event is received for these no-op commands in xhci_handle_stopped_cmd_ring()
418 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_handle_stopped_cmd_ring()
421 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && in xhci_handle_stopped_cmd_ring()
422 !(xhci->xhc_state & XHCI_STATE_DYING)) { in xhci_handle_stopped_cmd_ring()
423 xhci->current_cmd = cur_cmd; in xhci_handle_stopped_cmd_ring()
429 /* Must be called with xhci->lock held, releases and aquires lock back */
432 struct xhci_segment *new_seg = xhci->cmd_ring->deq_seg; in xhci_abort_cmd_ring()
433 union xhci_trb *new_deq = xhci->cmd_ring->dequeue; in xhci_abort_cmd_ring()
439 reinit_completion(&xhci->cmd_ring_stop_completion); in xhci_abort_cmd_ring()
454 xhci_write_64(xhci, crcr | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
458 * seconds then driver handles it as if host died (-ENODEV). in xhci_abort_cmd_ring()
459 * In the future we should distinguish between -ENODEV and -ETIMEDOUT in xhci_abort_cmd_ring()
460 * and try to recover a -ETIMEDOUT with a host controller reset. in xhci_abort_cmd_ring()
462 ret = xhci_handshake_check_state(xhci, &xhci->op_regs->cmd_ring, in xhci_abort_cmd_ring()
477 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_abort_cmd_ring()
478 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, in xhci_abort_cmd_ring()
480 spin_lock_irqsave(&xhci->lock, flags); in xhci_abort_cmd_ring()
495 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; in xhci_ring_ep_doorbell()
496 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_ring_ep_doorbell()
497 unsigned int ep_state = ep->ep_state; in xhci_ring_ep_doorbell()
524 ep = &xhci->devs[slot_id]->eps[ep_index]; in ring_doorbell_for_active_rings()
527 if (!(ep->ep_state & EP_HAS_STREAMS)) { in ring_doorbell_for_active_rings()
528 if (ep->ring && !(list_empty(&ep->ring->td_list))) in ring_doorbell_for_active_rings()
533 for (stream_id = 1; stream_id < ep->stream_info->num_streams; in ring_doorbell_for_active_rings()
535 struct xhci_stream_info *stream_info = ep->stream_info; in ring_doorbell_for_active_rings()
536 if (!list_empty(&stream_info->stream_rings[stream_id]->td_list)) in ring_doorbell_for_active_rings()
561 if (!xhci->devs[slot_id]) { in xhci_get_virt_ep()
566 return &xhci->devs[slot_id]->eps[ep_index]; in xhci_get_virt_ep()
574 if (!(ep->ep_state & EP_HAS_STREAMS)) in xhci_virt_ep_to_ring()
575 return ep->ring; in xhci_virt_ep_to_ring()
577 if (!ep->stream_info) in xhci_virt_ep_to_ring()
580 if (stream_id == 0 || stream_id >= ep->stream_info->num_streams) { in xhci_virt_ep_to_ring()
582 stream_id, ep->vdev->slot_id, ep->ep_index); in xhci_virt_ep_to_ring()
586 return ep->stream_info->stream_rings[stream_id]; in xhci_virt_ep_to_ring()
620 ep = &vdev->eps[ep_index]; in xhci_get_hw_deq()
622 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_get_hw_deq()
623 st_ctx = &ep->stream_info->stream_ctx_array[stream_id]; in xhci_get_hw_deq()
624 return le64_to_cpu(st_ctx->stream_ring); in xhci_get_hw_deq()
626 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_get_hw_deq()
627 return le64_to_cpu(ep_ctx->deq); in xhci_get_hw_deq()
634 struct xhci_virt_device *dev = xhci->devs[slot_id]; in xhci_move_dequeue_past_td()
635 struct xhci_virt_ep *ep = &dev->eps[ep_index]; in xhci_move_dequeue_past_td()
653 return -ENODEV; in xhci_move_dequeue_past_td()
657 new_seg = ep_ring->deq_seg; in xhci_move_dequeue_past_td()
658 new_deq = ep_ring->dequeue; in xhci_move_dequeue_past_td()
674 if (new_deq == td->last_trb) in xhci_move_dequeue_past_td()
684 if (new_deq == ep->ring->dequeue) { in xhci_move_dequeue_past_td()
686 return -EINVAL; in xhci_move_dequeue_past_td()
696 return -EINVAL; in xhci_move_dequeue_past_td()
699 if ((ep->ep_state & SET_DEQ_PENDING)) { in xhci_move_dequeue_past_td()
702 return -EBUSY; in xhci_move_dequeue_past_td()
709 return -ENOMEM; in xhci_move_dequeue_past_td()
723 ep->queued_deq_seg = new_seg; in xhci_move_dequeue_past_td()
724 ep->queued_deq_ptr = new_deq; in xhci_move_dequeue_past_td()
730 * this command completes. The HC won't set the dequeue pointer in xhci_move_dequeue_past_td()
734 ep->ep_state |= SET_DEQ_PENDING; in xhci_move_dequeue_past_td()
746 struct xhci_segment *seg = td->start_seg; in td_to_noop()
747 union xhci_trb *trb = td->first_trb; in td_to_noop()
753 if (flip_cycle && trb != td->first_trb && trb != td->last_trb) in td_to_noop()
754 trb->generic.field[3] ^= cpu_to_le32(TRB_CYCLE); in td_to_noop()
756 if (trb == td->last_trb) in td_to_noop()
766 struct urb *urb = cur_td->urb; in xhci_giveback_urb_in_irq()
767 struct urb_priv *urb_priv = urb->hcpriv; in xhci_giveback_urb_in_irq()
768 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in xhci_giveback_urb_in_irq()
770 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { in xhci_giveback_urb_in_irq()
771 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; in xhci_giveback_urb_in_irq()
772 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_giveback_urb_in_irq()
773 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_giveback_urb_in_irq()
786 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_unmap_td_bounce_buffer()
787 struct xhci_segment *seg = td->bounce_seg; in xhci_unmap_td_bounce_buffer()
788 struct urb *urb = td->urb; in xhci_unmap_td_bounce_buffer()
795 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len, in xhci_unmap_td_bounce_buffer()
800 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len, in xhci_unmap_td_bounce_buffer()
803 if (urb->num_sgs) { in xhci_unmap_td_bounce_buffer()
804 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, seg->bounce_buf, in xhci_unmap_td_bounce_buffer()
805 seg->bounce_len, seg->bounce_offs); in xhci_unmap_td_bounce_buffer()
806 if (len != seg->bounce_len) in xhci_unmap_td_bounce_buffer()
808 len, seg->bounce_len); in xhci_unmap_td_bounce_buffer()
810 memcpy(urb->transfer_buffer + seg->bounce_offs, seg->bounce_buf, in xhci_unmap_td_bounce_buffer()
811 seg->bounce_len); in xhci_unmap_td_bounce_buffer()
813 seg->bounce_len = 0; in xhci_unmap_td_bounce_buffer()
814 seg->bounce_offs = 0; in xhci_unmap_td_bounce_buffer()
823 urb = td->urb; in xhci_td_cleanup()
830 * length, urb->actual_length will be a very big number (since it's in xhci_td_cleanup()
833 if (urb->actual_length > urb->transfer_buffer_length) { in xhci_td_cleanup()
835 urb->transfer_buffer_length, urb->actual_length); in xhci_td_cleanup()
836 urb->actual_length = 0; in xhci_td_cleanup()
840 if (!list_empty(&td->td_list)) in xhci_td_cleanup()
841 list_del_init(&td->td_list); in xhci_td_cleanup()
843 if (!list_empty(&td->cancelled_td_list)) in xhci_td_cleanup()
844 list_del_init(&td->cancelled_td_list); in xhci_td_cleanup()
849 if ((urb->actual_length != urb->transfer_buffer_length && in xhci_td_cleanup()
850 (urb->transfer_flags & URB_SHORT_NOT_OK)) || in xhci_td_cleanup()
851 (status != 0 && !usb_endpoint_xfer_isoc(&urb->ep->desc))) in xhci_td_cleanup()
853 urb, urb->actual_length, in xhci_td_cleanup()
854 urb->transfer_buffer_length, status); in xhci_td_cleanup()
857 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) in xhci_td_cleanup()
872 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, in xhci_giveback_invalidated_tds()
875 ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_giveback_invalidated_tds()
877 if (td->cancel_status == TD_CLEARED) { in xhci_giveback_invalidated_tds()
878 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_giveback_invalidated_tds()
879 __func__, td->urb); in xhci_giveback_invalidated_tds()
880 xhci_td_cleanup(ep->xhci, td, ring, td->status); in xhci_giveback_invalidated_tds()
882 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_giveback_invalidated_tds()
883 __func__, td->urb, td->cancel_status); in xhci_giveback_invalidated_tds()
885 if (ep->xhci->xhc_state & XHCI_STATE_DYING) in xhci_giveback_invalidated_tds()
898 ret = -ENOMEM; in xhci_reset_halted_ep()
902 xhci_dbg(xhci, "%s-reset ep %u, slot %u\n", in xhci_reset_halted_ep()
919 unsigned int slot_id = ep->vdev->slot_id; in xhci_handle_halted_endpoint()
926 if (ep->vdev->flags & VDEV_PORT_ERROR) in xhci_handle_halted_endpoint()
927 return -ENODEV; in xhci_handle_halted_endpoint()
931 ep->ep_state |= EP_HARD_CLEAR_TOGGLE; in xhci_handle_halted_endpoint()
932 if (td && list_empty(&td->cancelled_td_list)) { in xhci_handle_halted_endpoint()
933 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); in xhci_handle_halted_endpoint()
934 td->cancel_status = TD_HALTED; in xhci_handle_halted_endpoint()
938 if (ep->ep_state & EP_HALTED) { in xhci_handle_halted_endpoint()
940 ep->ep_index); in xhci_handle_halted_endpoint()
944 err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type); in xhci_handle_halted_endpoint()
948 ep->ep_state |= EP_HALTED; in xhci_handle_halted_endpoint()
958 * We're also in the event handler, so we can't get re-interrupted if another
972 unsigned int slot_id = ep->vdev->slot_id; in xhci_invalidate_cancelled_tds()
975 xhci = ep->xhci; in xhci_invalidate_cancelled_tds()
977 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, cancelled_td_list) { in xhci_invalidate_cancelled_tds()
981 td->start_seg, td->first_trb), in xhci_invalidate_cancelled_tds()
982 td->urb->stream_id, td->urb); in xhci_invalidate_cancelled_tds()
983 list_del_init(&td->td_list); in xhci_invalidate_cancelled_tds()
984 ring = xhci_urb_to_transfer_ring(xhci, td->urb); in xhci_invalidate_cancelled_tds()
987 td->urb, td->urb->stream_id); in xhci_invalidate_cancelled_tds()
996 hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index, in xhci_invalidate_cancelled_tds()
997 td->urb->stream_id); in xhci_invalidate_cancelled_tds()
1000 if (td->cancel_status == TD_HALTED || trb_in_td(xhci, td, hw_deq, false)) { in xhci_invalidate_cancelled_tds()
1001 switch (td->cancel_status) { in xhci_invalidate_cancelled_tds()
1002 case TD_CLEARED: /* TD is already no-op */ in xhci_invalidate_cancelled_tds()
1009 if (cached_td->urb->stream_id != td->urb->stream_id) { in xhci_invalidate_cancelled_tds()
1013 td->urb->stream_id, td->urb); in xhci_invalidate_cancelled_tds()
1014 td->cancel_status = TD_CLEARING_CACHE_DEFERRED; in xhci_invalidate_cancelled_tds()
1021 td->urb, cached_td->urb, in xhci_invalidate_cancelled_tds()
1022 td->urb->stream_id); in xhci_invalidate_cancelled_tds()
1024 cached_td->cancel_status = TD_CLEARED; in xhci_invalidate_cancelled_tds()
1027 td->cancel_status = TD_CLEARING_CACHE; in xhci_invalidate_cancelled_tds()
1033 td->cancel_status = TD_CLEARED; in xhci_invalidate_cancelled_tds()
1041 err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index, in xhci_invalidate_cancelled_tds()
1042 cached_td->urb->stream_id, in xhci_invalidate_cancelled_tds()
1045 /* Failed to move past cached td, just set cached TDs to no-op */ in xhci_invalidate_cancelled_tds()
1046 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, cancelled_td_list) { in xhci_invalidate_cancelled_tds()
1052 if (td->cancel_status != TD_CLEARING_CACHE && in xhci_invalidate_cancelled_tds()
1053 td->cancel_status != TD_CLEARING_CACHE_DEFERRED) in xhci_invalidate_cancelled_tds()
1056 td->urb); in xhci_invalidate_cancelled_tds()
1058 td->cancel_status = TD_CLEARED; in xhci_invalidate_cancelled_tds()
1066 * Only call for non-running rings without streams.
1073 if (!list_empty(&ep->ring->td_list)) { /* Not streams compatible */ in find_halted_td()
1074 hw_deq = xhci_get_hw_deq(ep->xhci, ep->vdev, ep->ep_index, 0); in find_halted_td()
1076 td = list_first_entry(&ep->ring->td_list, struct xhci_td, td_list); in find_halted_td()
1077 if (trb_in_td(ep->xhci, td, hw_deq, false)) in find_halted_td()
1090 * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain
1104 if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) { in xhci_handle_cmd_stop_ep()
1105 if (!xhci->devs[slot_id]) in xhci_handle_cmd_stop_ep()
1111 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_stop_ep()
1116 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_stop_ep()
1129 * Proper error code is unknown here, it would be -EPIPE if device side in xhci_handle_cmd_stop_ep()
1130 * of enadpoit halted (aka STALL), and -EPROTO if not (transaction error) in xhci_handle_cmd_stop_ep()
1131 * We use -EPROTO, if device is stalled it should return a stall error on in xhci_handle_cmd_stop_ep()
1132 * next transfer, which then will return -EPIPE, and device side stall is in xhci_handle_cmd_stop_ep()
1138 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_handle_cmd_stop_ep()
1144 td->status = -EPROTO; in xhci_handle_cmd_stop_ep()
1150 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_cmd_stop_ep()
1158 if (!(xhci->quirks & XHCI_NEC_HOST)) in xhci_handle_cmd_stop_ep()
1167 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_cmd_stop_ep()
1181 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_cmd_stop_ep()
1193 list_for_each_entry_safe(cur_td, tmp, &ring->td_list, td_list) { in xhci_kill_ring_urbs()
1194 list_del_init(&cur_td->td_list); in xhci_kill_ring_urbs()
1196 if (!list_empty(&cur_td->cancelled_td_list)) in xhci_kill_ring_urbs()
1197 list_del_init(&cur_td->cancelled_td_list); in xhci_kill_ring_urbs()
1201 inc_td_cnt(cur_td->urb); in xhci_kill_ring_urbs()
1203 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_ring_urbs()
1219 if ((ep->ep_state & EP_HAS_STREAMS) || in xhci_kill_endpoint_urbs()
1220 (ep->ep_state & EP_GETTING_NO_STREAMS)) { in xhci_kill_endpoint_urbs()
1223 for (stream_id = 1; stream_id < ep->stream_info->num_streams; in xhci_kill_endpoint_urbs()
1225 ring = ep->stream_info->stream_rings[stream_id]; in xhci_kill_endpoint_urbs()
1235 ring = ep->ring; in xhci_kill_endpoint_urbs()
1244 list_for_each_entry_safe(cur_td, tmp, &ep->cancelled_td_list, in xhci_kill_endpoint_urbs()
1246 list_del_init(&cur_td->cancelled_td_list); in xhci_kill_endpoint_urbs()
1247 inc_td_cnt(cur_td->urb); in xhci_kill_endpoint_urbs()
1250 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_endpoint_urbs()
1260 * Call with xhci->lock held.
1261 * lock is relased and re-acquired while giving back urb.
1267 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_hc_died()
1271 xhci->xhc_state |= XHCI_STATE_DYING; in xhci_hc_died()
1276 for (i = 0; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_hc_died()
1277 if (!xhci->devs[i]) in xhci_hc_died()
1283 /* inform usb core hc died if PCI remove isn't already handling it */ in xhci_hc_died()
1284 if (!(xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_hc_died()
1295 dequeue_temp = ep_ring->dequeue; in update_ring_for_set_deq_completion()
1297 /* If we get two back-to-back stalls, and the first stalled transfer in update_ring_for_set_deq_completion()
1301 * the segment into la-la-land. in update_ring_for_set_deq_completion()
1303 if (trb_is_link(ep_ring->dequeue)) { in update_ring_for_set_deq_completion()
1304 ep_ring->deq_seg = ep_ring->deq_seg->next; in update_ring_for_set_deq_completion()
1305 ep_ring->dequeue = ep_ring->deq_seg->trbs; in update_ring_for_set_deq_completion()
1308 while (ep_ring->dequeue != dev->eps[ep_index].queued_deq_ptr) { in update_ring_for_set_deq_completion()
1310 ep_ring->dequeue++; in update_ring_for_set_deq_completion()
1311 if (trb_is_link(ep_ring->dequeue)) { in update_ring_for_set_deq_completion()
1312 if (ep_ring->dequeue == in update_ring_for_set_deq_completion()
1313 dev->eps[ep_index].queued_deq_ptr) in update_ring_for_set_deq_completion()
1315 ep_ring->deq_seg = ep_ring->deq_seg->next; in update_ring_for_set_deq_completion()
1316 ep_ring->dequeue = ep_ring->deq_seg->trbs; in update_ring_for_set_deq_completion()
1318 if (ep_ring->dequeue == dequeue_temp) { in update_ring_for_set_deq_completion()
1344 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_set_deq()
1345 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); in xhci_handle_cmd_set_deq()
1358 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_set_deq()
1359 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in xhci_handle_cmd_set_deq()
1374 slot_state = le32_to_cpu(slot_ctx->dev_state); in xhci_handle_cmd_set_deq()
1398 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_handle_cmd_set_deq()
1400 &ep->stream_info->stream_ctx_array[stream_id]; in xhci_handle_cmd_set_deq()
1401 deq = le64_to_cpu(ctx->stream_ring) & SCTX_DEQ_MASK; in xhci_handle_cmd_set_deq()
1412 if (xhci->quirks & XHCI_CDNS_SCTX_QUIRK) { in xhci_handle_cmd_set_deq()
1413 ctx->reserved[0] = 0; in xhci_handle_cmd_set_deq()
1414 ctx->reserved[1] = 0; in xhci_handle_cmd_set_deq()
1417 deq = le64_to_cpu(ep_ctx->deq) & ~EP_CTX_CYCLE_MASK; in xhci_handle_cmd_set_deq()
1421 if (xhci_trb_virt_to_dma(ep->queued_deq_seg, in xhci_handle_cmd_set_deq()
1422 ep->queued_deq_ptr) == deq) { in xhci_handle_cmd_set_deq()
1426 update_ring_for_set_deq_completion(xhci, ep->vdev, in xhci_handle_cmd_set_deq()
1431 ep->queued_deq_seg, ep->queued_deq_ptr); in xhci_handle_cmd_set_deq()
1435 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, in xhci_handle_cmd_set_deq()
1437 ep_ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_handle_cmd_set_deq()
1438 if (td->cancel_status == TD_CLEARING_CACHE) { in xhci_handle_cmd_set_deq()
1439 td->cancel_status = TD_CLEARED; in xhci_handle_cmd_set_deq()
1440 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_handle_cmd_set_deq()
1441 __func__, td->urb); in xhci_handle_cmd_set_deq()
1442 xhci_td_cleanup(ep->xhci, td, ep_ring, td->status); in xhci_handle_cmd_set_deq()
1443 } else if (td->cancel_status == TD_CLEARING_CACHE_DEFERRED) { in xhci_handle_cmd_set_deq()
1446 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_handle_cmd_set_deq()
1447 __func__, td->urb, td->cancel_status); in xhci_handle_cmd_set_deq()
1451 ep->ep_state &= ~SET_DEQ_PENDING; in xhci_handle_cmd_set_deq()
1452 ep->queued_deq_seg = NULL; in xhci_handle_cmd_set_deq()
1453 ep->queued_deq_ptr = NULL; in xhci_handle_cmd_set_deq()
1457 xhci_dbg(ep->xhci, "%s: Pending TDs to clear, continuing with invalidation\n", in xhci_handle_cmd_set_deq()
1462 xhci_dbg(ep->xhci, "%s: All TDs cleared, ring doorbell\n", __func__); in xhci_handle_cmd_set_deq()
1474 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_reset_ep()
1479 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_reset_ep()
1492 ep->ep_state &= ~EP_HALTED; in xhci_handle_cmd_reset_ep()
1497 if ((le32_to_cpu(trb->generic.field[3])) & TRB_TSP) in xhci_handle_cmd_reset_ep()
1505 command->slot_id = slot_id; in xhci_handle_cmd_enable_slot()
1507 command->slot_id = 0; in xhci_handle_cmd_enable_slot()
1515 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_disable_slot()
1519 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_handle_cmd_disable_slot()
1522 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) in xhci_handle_cmd_disable_slot()
1540 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_config_ep()
1543 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_handle_cmd_config_ep()
1549 add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_handle_cmd_config_ep()
1552 ep_index = xhci_last_valid_endpoint(add_flags) - 1; in xhci_handle_cmd_config_ep()
1554 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, ep_index); in xhci_handle_cmd_config_ep()
1565 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_addr_dev()
1568 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_addr_dev()
1577 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_dev()
1583 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_reset_dev()
1592 if (!(xhci->quirks & XHCI_NEC_HOST)) { in xhci_handle_cmd_nec_get_fw()
1593 xhci_warn(xhci, "WARN NEC_GET_FW command on non-NEC host\n"); in xhci_handle_cmd_nec_get_fw()
1598 NEC_FW_MAJOR(le32_to_cpu(event->status)), in xhci_handle_cmd_nec_get_fw()
1599 NEC_FW_MINOR(le32_to_cpu(event->status))); in xhci_handle_cmd_nec_get_fw()
1604 list_del(&cmd->cmd_list); in xhci_complete_del_and_free_cmd()
1606 if (cmd->completion) { in xhci_complete_del_and_free_cmd()
1607 cmd->status = status; in xhci_complete_del_and_free_cmd()
1608 complete(cmd->completion); in xhci_complete_del_and_free_cmd()
1617 xhci->current_cmd = NULL; in xhci_cleanup_command_queue()
1618 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) in xhci_cleanup_command_queue()
1633 spin_lock_irqsave(&xhci->lock, flags); in xhci_handle_command_timeout()
1639 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { in xhci_handle_command_timeout()
1640 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1644 cmd_field3 = le32_to_cpu(xhci->current_cmd->command_trb->generic.field[3]); in xhci_handle_command_timeout()
1645 usbsts = readl(&xhci->op_regs->status); in xhci_handle_command_timeout()
1657 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_handle_command_timeout()
1665 xhci->current_cmd->status = COMP_COMMAND_ABORTED; in xhci_handle_command_timeout()
1668 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_handle_command_timeout()
1674 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && in xhci_handle_command_timeout()
1677 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; in xhci_handle_command_timeout()
1684 if (xhci->xhc_state & XHCI_STATE_REMOVING) { in xhci_handle_command_timeout()
1693 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); in xhci_handle_command_timeout()
1696 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1703 unsigned int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); in handle_cmd_completion()
1716 cmd_dma = le64_to_cpu(event->cmd_trb); in handle_cmd_completion()
1717 cmd_trb = xhci->cmd_ring->dequeue; in handle_cmd_completion()
1719 trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic); in handle_cmd_completion()
1721 cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status)); in handle_cmd_completion()
1725 complete_all(&xhci->cmd_ring_stop_completion); in handle_cmd_completion()
1729 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in handle_cmd_completion()
1741 cmd = list_first_entry(&xhci->cmd_list, struct xhci_command, cmd_list); in handle_cmd_completion()
1743 cancel_delayed_work(&xhci->cmd_timer); in handle_cmd_completion()
1745 if (cmd->command_trb != xhci->cmd_ring->dequeue) { in handle_cmd_completion()
1758 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in handle_cmd_completion()
1759 if (cmd->status == COMP_COMMAND_ABORTED) { in handle_cmd_completion()
1760 if (xhci->current_cmd == cmd) in handle_cmd_completion()
1761 xhci->current_cmd = NULL; in handle_cmd_completion()
1766 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); in handle_cmd_completion()
1775 if (!cmd->completion) in handle_cmd_completion()
1785 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1786 if (!cmd->completion) in handle_cmd_completion()
1792 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1796 /* Is this an aborted command turned to NO-OP? */ in handle_cmd_completion()
1797 if (cmd->status == COMP_COMMAND_RING_STOPPED) in handle_cmd_completion()
1802 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1810 le32_to_cpu(cmd_trb->generic.field[3])); in handle_cmd_completion()
1823 if (!list_is_singular(&xhci->cmd_list)) { in handle_cmd_completion()
1824 xhci->current_cmd = list_first_entry(&cmd->cmd_list, in handle_cmd_completion()
1827 } else if (xhci->current_cmd == cmd) { in handle_cmd_completion()
1828 xhci->current_cmd = NULL; in handle_cmd_completion()
1834 inc_deq(xhci, xhci->cmd_ring); in handle_cmd_completion()
1841 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) in handle_vendor_event()
1842 handle_cmd_completion(xhci, &event->event_cmd); in handle_vendor_event()
1851 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->generic.field[3])); in handle_device_notification()
1852 if (!xhci->devs[slot_id]) { in handle_device_notification()
1860 udev = xhci->devs[slot_id]->udev; in handle_device_notification()
1861 if (udev && udev->parent) in handle_device_notification()
1862 usb_wakeup_notification(udev->parent, udev->portnum); in handle_device_notification()
1868 * As per ThunderX2errata-129 USB 2 device may come up as USB 1
1885 writel(0x6F, hcd->regs + 0x1048); in xhci_cavium_reset_phy_quirk()
1887 /* De-assert the PHY reset */ in xhci_cavium_reset_phy_quirk()
1888 writel(0x7F, hcd->regs + 0x1048); in xhci_cavium_reset_phy_quirk()
1890 pll_lock_check = readl(hcd->regs + 0x1070); in xhci_cavium_reset_phy_quirk()
1891 } while (!(pll_lock_check & 0x1) && --retry_count); in xhci_cavium_reset_phy_quirk()
1906 if (GET_COMP_CODE(le32_to_cpu(event->generic.field[2])) != COMP_SUCCESS) in handle_port_status()
1910 port_id = GET_PORT_ID(le32_to_cpu(event->generic.field[0])); in handle_port_status()
1911 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); in handle_port_status()
1919 port = &xhci->hw_ports[port_id - 1]; in handle_port_status()
1920 if (!port || !port->rhub || port->hcd_portnum == DUPLICATE_ENTRY) { in handle_port_status()
1928 if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) { in handle_port_status()
1934 hcd = port->rhub->hcd; in handle_port_status()
1935 bus_state = &port->rhub->bus_state; in handle_port_status()
1936 hcd_portnum = port->hcd_portnum; in handle_port_status()
1937 portsc = readl(port->addr); in handle_port_status()
1939 xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n", in handle_port_status()
1940 hcd->self.busnum, hcd_portnum + 1, port_id, portsc); in handle_port_status()
1944 if (hcd->state == HC_STATE_SUSPENDED) { in handle_port_status()
1949 if (hcd->speed >= HCD_USB3 && in handle_port_status()
1951 if (port->slot_id && xhci->devs[port->slot_id]) in handle_port_status()
1952 xhci->devs[port->slot_id]->flags |= VDEV_PORT_ERROR; in handle_port_status()
1958 cmd_reg = readl(&xhci->op_regs->command); in handle_port_status()
1970 bus_state->port_remote_wakeup |= 1 << hcd_portnum; in handle_port_status()
1972 usb_hcd_start_port_resume(&hcd->self, hcd_portnum); in handle_port_status()
1979 } else if (!test_bit(hcd_portnum, &bus_state->resuming_ports)) { in handle_port_status()
1981 port->resume_timestamp = jiffies + in handle_port_status()
1983 set_bit(hcd_portnum, &bus_state->resuming_ports); in handle_port_status()
1986 * usb device auto-resume latency around ~40ms. in handle_port_status()
1988 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in handle_port_status()
1989 mod_timer(&hcd->rh_timer, in handle_port_status()
1990 port->resume_timestamp); in handle_port_status()
1991 usb_hcd_start_port_resume(&hcd->self, hcd_portnum); in handle_port_status()
2002 complete(&port->u3exit_done); in handle_port_status()
2005 * U3Exit state after a host-initiated resume. If it's a device in handle_port_status()
2010 if (port->slot_id && xhci->devs[port->slot_id]) in handle_port_status()
2011 xhci_ring_device(xhci, port->slot_id); in handle_port_status()
2012 if (bus_state->port_remote_wakeup & (1 << hcd_portnum)) { in handle_port_status()
2014 usb_wakeup_notification(hcd->self.root_hub, in handle_port_status()
2022 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or in handle_port_status()
2026 if (hcd->speed < HCD_USB3 && port->rexit_active) { in handle_port_status()
2027 complete(&port->rexit_done); in handle_port_status()
2028 port->rexit_active = false; in handle_port_status()
2033 if (hcd->speed < HCD_USB3) { in handle_port_status()
2035 if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) && in handle_port_status()
2050 * xHCI port-status-change events occur when the "or" of all the in handle_port_status()
2051 * status-change bits in the portsc register changes from 0 to 1. in handle_port_status()
2057 __func__, hcd->self.busnum); in handle_port_status()
2058 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in handle_port_status()
2059 spin_unlock(&xhci->lock); in handle_port_status()
2062 spin_lock(&xhci->lock); in handle_port_status()
2077 start_dma = xhci_trb_virt_to_dma(td->start_seg, td->first_trb); in trb_in_td()
2078 cur_seg = td->start_seg; in trb_in_td()
2085 &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); in trb_in_td()
2087 end_trb_dma = xhci_trb_virt_to_dma(cur_seg, td->last_trb); in trb_in_td()
2091 …"Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx… in trb_in_td()
2095 (unsigned long long)cur_seg->dma, in trb_in_td()
2109 (suspect_dma >= cur_seg->dma && in trb_in_td()
2119 cur_seg = cur_seg->next; in trb_in_td()
2120 start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]); in trb_in_td()
2121 } while (cur_seg != td->start_seg); in trb_in_td()
2130 * As part of low/full-speed endpoint-halt processing in xhci_clear_hub_tt_buffer()
2133 if (td->urb->dev->tt && !usb_pipeint(td->urb->pipe) && in xhci_clear_hub_tt_buffer()
2134 (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && in xhci_clear_hub_tt_buffer()
2135 !(ep->ep_state & EP_CLEARING_TT)) { in xhci_clear_hub_tt_buffer()
2136 ep->ep_state |= EP_CLEARING_TT; in xhci_clear_hub_tt_buffer()
2137 td->urb->ep->hcpriv = td->urb->dev; in xhci_clear_hub_tt_buffer()
2138 if (usb_hub_clear_tt_buffer(td->urb)) in xhci_clear_hub_tt_buffer()
2139 ep->ep_state &= ~EP_CLEARING_TT; in xhci_clear_hub_tt_buffer()
2177 * treat as not-an-error. in xhci_is_vendor_info_code()
2193 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in finish_td()
2225 if ((ep->ep_state & EP_HALTED) && in finish_td()
2226 !list_empty(&td->cancelled_td_list)) { in finish_td()
2229 td->start_seg, td->first_trb)); in finish_td()
2250 if (ep->ep_index != 0) in finish_td()
2261 ep_ring->dequeue = td->last_trb; in finish_td()
2262 ep_ring->deq_seg = td->last_trb_seg; in finish_td()
2265 return xhci_td_cleanup(xhci, td, ep_ring, td->status); in finish_td()
2273 union xhci_trb *trb = ring->dequeue; in sum_trb_lengths()
2274 struct xhci_segment *seg = ring->deq_seg; in sum_trb_lengths()
2278 sum += TRB_LEN(le32_to_cpu(trb->generic.field[2])); in sum_trb_lengths()
2295 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(ep_trb->generic.field[3])); in process_ctrl_td()
2296 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in process_ctrl_td()
2297 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_ctrl_td()
2298 requested = td->urb->transfer_buffer_length; in process_ctrl_td()
2299 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_ctrl_td()
2306 td->status = -ESHUTDOWN; in process_ctrl_td()
2309 td->status = 0; in process_ctrl_td()
2312 td->status = 0; in process_ctrl_td()
2316 td->urb->actual_length = remaining; in process_ctrl_td()
2323 td->urb->actual_length = 0; in process_ctrl_td()
2327 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2330 td->urb->actual_length = requested; in process_ctrl_td()
2343 trb_comp_code, ep->ep_index); in process_ctrl_td()
2348 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2349 else if (!td->urb_length_set) in process_ctrl_td()
2350 td->urb->actual_length = 0; in process_ctrl_td()
2364 td->urb_length_set = true; in process_ctrl_td()
2365 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2371 if (!td->urb_length_set) in process_ctrl_td()
2372 td->urb->actual_length = requested; in process_ctrl_td()
2393 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_isoc_td()
2394 urb_priv = td->urb->hcpriv; in process_isoc_td()
2395 idx = urb_priv->num_tds_done; in process_isoc_td()
2396 frame = &td->urb->iso_frame_desc[idx]; in process_isoc_td()
2397 requested = frame->length; in process_isoc_td()
2398 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_isoc_td()
2399 ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2])); in process_isoc_td()
2400 short_framestatus = td->urb->transfer_flags & URB_SHORT_NOT_OK ? in process_isoc_td()
2401 -EREMOTEIO : 0; in process_isoc_td()
2407 if (td->error_mid_td) in process_isoc_td()
2410 frame->status = short_framestatus; in process_isoc_td()
2414 frame->status = 0; in process_isoc_td()
2417 frame->status = short_framestatus; in process_isoc_td()
2421 frame->status = -ECOMM; in process_isoc_td()
2427 frame->status = -EOVERFLOW; in process_isoc_td()
2428 if (ep_trb != td->last_trb) in process_isoc_td()
2429 td->error_mid_td = true; in process_isoc_td()
2433 frame->status = -EPROTO; in process_isoc_td()
2436 frame->status = -EPROTO; in process_isoc_td()
2438 if (ep_trb != td->last_trb) in process_isoc_td()
2439 td->error_mid_td = true; in process_isoc_td()
2446 frame->status = short_framestatus; in process_isoc_td()
2457 frame->status = -1; in process_isoc_td()
2461 if (td->urb_length_set) in process_isoc_td()
2465 frame->actual_length = sum_trb_lengths(xhci, ep->ring, ep_trb) + in process_isoc_td()
2466 ep_trb_len - remaining; in process_isoc_td()
2468 frame->actual_length = requested; in process_isoc_td()
2470 td->urb->actual_length += frame->actual_length; in process_isoc_td()
2474 if (td->error_mid_td && ep_trb != td->last_trb) { in process_isoc_td()
2476 td->urb_length_set = true; in process_isoc_td()
2490 urb_priv = td->urb->hcpriv; in skip_isoc_td()
2491 idx = urb_priv->num_tds_done; in skip_isoc_td()
2492 frame = &td->urb->iso_frame_desc[idx]; in skip_isoc_td()
2495 frame->status = -EXDEV; in skip_isoc_td()
2498 frame->actual_length = 0; in skip_isoc_td()
2501 ep->ring->dequeue = td->last_trb; in skip_isoc_td()
2502 ep->ring->deq_seg = td->last_trb_seg; in skip_isoc_td()
2503 inc_deq(xhci, ep->ring); in skip_isoc_td()
2505 return xhci_td_cleanup(xhci, td, ep->ring, status); in skip_isoc_td()
2519 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in process_bulk_intr_td()
2520 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_bulk_intr_td()
2521 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_bulk_intr_td()
2522 ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2])); in process_bulk_intr_td()
2523 requested = td->urb->transfer_buffer_length; in process_bulk_intr_td()
2527 ep->err_count = 0; in process_bulk_intr_td()
2529 if (ep_trb != td->last_trb || remaining) { in process_bulk_intr_td()
2531 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2532 td->urb->ep->desc.bEndpointAddress, in process_bulk_intr_td()
2535 td->status = 0; in process_bulk_intr_td()
2538 td->status = 0; in process_bulk_intr_td()
2541 td->urb->actual_length = remaining; in process_bulk_intr_td()
2545 td->urb->actual_length = sum_trb_lengths(xhci, ep_ring, ep_trb); in process_bulk_intr_td()
2548 if (xhci->quirks & XHCI_NO_SOFT_RETRY || in process_bulk_intr_td()
2549 (ep->err_count++ > MAX_SOFT_RETRY) || in process_bulk_intr_td()
2550 le32_to_cpu(slot_ctx->tt_info) & TT_SLOT) in process_bulk_intr_td()
2553 td->status = 0; in process_bulk_intr_td()
2562 if (ep_trb == td->last_trb) in process_bulk_intr_td()
2563 td->urb->actual_length = requested - remaining; in process_bulk_intr_td()
2565 td->urb->actual_length = in process_bulk_intr_td()
2567 ep_trb_len - remaining; in process_bulk_intr_td()
2572 td->urb->actual_length = 0; in process_bulk_intr_td()
2587 xhci_dbg(xhci, "Stream transaction error ep %u no id\n", ep->ep_index); in handle_transferless_tx_event()
2588 if (ep->err_count++ > MAX_SOFT_RETRY) in handle_transferless_tx_event()
2599 trb_comp_code, ep->vdev->slot_id, ep->ep_index); in handle_transferless_tx_event()
2600 return -ENODEV; in handle_transferless_tx_event()
2622 int status = -EINPROGRESS; in handle_tx_event()
2626 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); in handle_tx_event()
2627 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; in handle_tx_event()
2628 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in handle_tx_event()
2629 ep_trb_dma = le64_to_cpu(event->buffer); in handle_tx_event()
2638 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in handle_tx_event()
2656 if (EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) { in handle_tx_event()
2659 slot_id, ep_index, ep_ring->last_td_was_short); in handle_tx_event()
2671 "Stopped on No-op or Link TRB for slot %u ep %u\n", in handle_tx_event()
2683 status = -EPIPE; in handle_tx_event()
2688 status = -EPROTO; in handle_tx_event()
2693 status = -EPROTO; in handle_tx_event()
2698 status = -EOVERFLOW; in handle_tx_event()
2705 status = -EILSEQ; in handle_tx_event()
2710 "WARN: HC couldn't access mem fast enough for slot %u ep %u\n", in handle_tx_event()
2712 status = -ENOSR; in handle_tx_event()
2731 if (ep->skip) in handle_tx_event()
2736 if (ep->skip) in handle_tx_event()
2746 ep->skip = true; in handle_tx_event()
2752 ep->skip = true; in handle_tx_event()
2763 status = -EPROTO; in handle_tx_event()
2771 "ERROR Unknown event condition %u for slot %u ep %u , HC probably busted\n", in handle_tx_event()
2773 if (ep->skip) in handle_tx_event()
2783 * xhci 4.9.1 states that if there are errors in mult-TRB in handle_tx_event()
2791 td = list_first_entry_or_null(&ep_ring->td_list, struct xhci_td, td_list); in handle_tx_event()
2793 if (td && td->error_mid_td && !trb_in_td(xhci, td, ep_trb_dma, false)) { in handle_tx_event()
2795 ep_ring->dequeue = td->last_trb; in handle_tx_event()
2796 ep_ring->deq_seg = td->last_trb_seg; in handle_tx_event()
2798 xhci_td_cleanup(xhci, td, ep_ring, td->status); in handle_tx_event()
2801 if (list_empty(&ep_ring->td_list)) { in handle_tx_event()
2810 !ep_ring->last_td_was_short) { in handle_tx_event()
2815 ep->skip = false; in handle_tx_event()
2820 td = list_first_entry(&ep_ring->td_list, struct xhci_td, in handle_tx_event()
2828 if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { in handle_tx_event()
2830 if (!list_empty(&ep_ring->td_list)) in handle_tx_event()
2835 ep->skip = false; in handle_tx_event()
2842 * TD pointed by 'ep_ring->dequeue' because that the hardware dequeue in handle_tx_event()
2856 if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && in handle_tx_event()
2857 ep_ring->last_td_was_short) { in handle_tx_event()
2858 ep_ring->last_td_was_short = false; in handle_tx_event()
2862 /* HC is busted, give up! */ in handle_tx_event()
2868 return -ESHUTDOWN; in handle_tx_event()
2871 if (ep->skip) { in handle_tx_event()
2875 ep->skip = false; in handle_tx_event()
2879 * If ep->skip is set, it means there are missed tds on the in handle_tx_event()
2884 } while (ep->skip); in handle_tx_event()
2887 ep_ring->last_td_was_short = true; in handle_tx_event()
2889 ep_ring->last_td_was_short = false; in handle_tx_event()
2891 ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) / sizeof(*ep_trb)]; in handle_tx_event()
2895 * No-op TRB could trigger interrupts in a case where a URB was killed in handle_tx_event()
2904 td->status = status; in handle_tx_event()
2907 if (usb_endpoint_xfer_control(&td->urb->ep->desc)) in handle_tx_event()
2909 else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) in handle_tx_event()
2924 ir->event_ring->deq_seg, in handle_tx_event()
2925 ir->event_ring->dequeue), in handle_tx_event()
2926 lower_32_bits(le64_to_cpu(event->buffer)), in handle_tx_event()
2927 upper_32_bits(le64_to_cpu(event->buffer)), in handle_tx_event()
2928 le32_to_cpu(event->transfer_len), in handle_tx_event()
2929 le32_to_cpu(event->flags)); in handle_tx_event()
2930 return -ENODEV; in handle_tx_event()
2934 * This function handles one OS-owned event on the event ring. It may drop
2935 * xhci->lock between event processing (e.g. to pass up port status changes).
2942 trace_xhci_handle_event(ir->event_ring, &event->generic); in xhci_handle_event_trb()
2949 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->event_cmd.flags)); in xhci_handle_event_trb()
2954 handle_cmd_completion(xhci, &event->event_cmd); in xhci_handle_event_trb()
2960 handle_tx_event(xhci, ir, &event->trans_event); in xhci_handle_event_trb()
2971 /* Any of the above functions may drop and re-acquire the lock, so check in xhci_handle_event_trb()
2972 * to make sure a watchdog timer didn't mark the host as non-responsive. in xhci_handle_event_trb()
2974 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_handle_event_trb()
2976 return -ENODEV; in xhci_handle_event_trb()
2984 * - When all events have finished
2985 * - To avoid "Event Ring Full Error" condition
2994 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
2995 deq = xhci_trb_virt_to_dma(ir->event_ring->deq_seg, in xhci_update_erst_dequeue()
2996 ir->event_ring->dequeue); in xhci_update_erst_dequeue()
3006 /* Update HC event ring dequeue pointer */ in xhci_update_erst_dequeue()
3007 temp_64 = ir->event_ring->deq_seg->num & ERST_DESI_MASK; in xhci_update_erst_dequeue()
3013 xhci_write_64(xhci, temp_64, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
3019 if (!ir->ip_autoclear) { in xhci_clear_interrupt_pending()
3022 irq_pending = readl(&ir->ir_set->irq_pending); in xhci_clear_interrupt_pending()
3024 writel(irq_pending, &ir->ir_set->irq_pending); in xhci_clear_interrupt_pending()
3029 * Handle all OS-owned events on an interrupter event ring. It may drop
3030 * and reaquire xhci->lock between event processing.
3041 if (!ir->event_ring || !ir->event_ring->dequeue) { in xhci_handle_events()
3043 return -ENOMEM; in xhci_handle_events()
3046 if (xhci->xhc_state & XHCI_STATE_DYING || in xhci_handle_events()
3047 xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_handle_events()
3051 temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_handle_events()
3052 xhci_write_64(xhci, temp | ERST_EHB, &ir->ir_set->erst_dequeue); in xhci_handle_events()
3053 return -ENODEV; in xhci_handle_events()
3057 while (unhandled_event_trb(ir->event_ring)) { in xhci_handle_events()
3058 err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue); in xhci_handle_events()
3067 if (ir->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) in xhci_handle_events()
3068 ir->isoc_bei_interval = ir->isoc_bei_interval / 2; in xhci_handle_events()
3074 inc_deq(xhci, ir->event_ring); in xhci_handle_events()
3086 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
3096 spin_lock(&xhci->lock); in xhci_irq()
3098 status = readl(&xhci->op_regs->status); in xhci_irq()
3122 * so we can receive interrupts from other MSI-X interrupters. in xhci_irq()
3126 writel(status, &xhci->op_regs->status); in xhci_irq()
3129 xhci_handle_events(xhci, xhci->interrupters[0]); in xhci_irq()
3131 spin_unlock(&xhci->lock); in xhci_irq()
3157 trb = &ring->enqueue->generic; in queue_trb()
3158 trb->field[0] = cpu_to_le32(field1); in queue_trb()
3159 trb->field[1] = cpu_to_le32(field2); in queue_trb()
3160 trb->field[2] = cpu_to_le32(field3); in queue_trb()
3163 trb->field[3] = cpu_to_le32(field4); in queue_trb()
3188 return -ENOENT; in prepare_ring()
3192 /* XXX not sure if this should be -ENOENT or not */ in prepare_ring()
3193 return -EINVAL; in prepare_ring()
3203 * FIXME issue Configure Endpoint command to try to get the HC in prepare_ring()
3206 return -EINVAL; in prepare_ring()
3209 if (ep_ring != xhci->cmd_ring) { in prepare_ring()
3213 return -ENOMEM; in prepare_ring()
3221 return -ENOMEM; in prepare_ring()
3225 while (trb_is_link(ep_ring->enqueue)) { in prepare_ring()
3229 if (!xhci_link_chain_quirk(xhci, ep_ring->type)) in prepare_ring()
3230 ep_ring->enqueue->link.control &= in prepare_ring()
3233 ep_ring->enqueue->link.control |= in prepare_ring()
3237 ep_ring->enqueue->link.control ^= cpu_to_le32(TRB_CYCLE); in prepare_ring()
3240 if (link_trb_toggles_cycle(ep_ring->enqueue)) in prepare_ring()
3241 ep_ring->cycle_state ^= 1; in prepare_ring()
3243 ep_ring->enq_seg = ep_ring->enq_seg->next; in prepare_ring()
3244 ep_ring->enqueue = ep_ring->enq_seg->trbs; in prepare_ring()
3247 if (link_trb_count++ > ep_ring->num_segs) { in prepare_ring()
3249 return -EINVAL; in prepare_ring()
3253 if (last_trb_on_seg(ep_ring->enq_seg, ep_ring->enqueue)) { in prepare_ring()
3255 return -EINVAL; in prepare_ring()
3274 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in prepare_transfer()
3276 ep_ring = xhci_triad_to_transfer_ring(xhci, xdev->slot_id, ep_index, in prepare_transfer()
3281 return -EINVAL; in prepare_transfer()
3289 urb_priv = urb->hcpriv; in prepare_transfer()
3290 td = &urb_priv->td[td_index]; in prepare_transfer()
3292 INIT_LIST_HEAD(&td->td_list); in prepare_transfer()
3293 INIT_LIST_HEAD(&td->cancelled_td_list); in prepare_transfer()
3296 ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb); in prepare_transfer()
3301 td->urb = urb; in prepare_transfer()
3303 list_add_tail(&td->td_list, &ep_ring->td_list); in prepare_transfer()
3304 td->start_seg = ep_ring->enq_seg; in prepare_transfer()
3305 td->first_trb = ep_ring->enqueue; in prepare_transfer()
3314 num_trbs = DIV_ROUND_UP(len + (addr & (TRB_MAX_BUFF_SIZE - 1)), in count_trbs()
3324 return count_trbs(urb->transfer_dma, urb->transfer_buffer_length); in count_trbs_needed()
3332 full_len = urb->transfer_buffer_length; in count_sg_trbs_needed()
3334 for_each_sg(urb->sg, sg, urb->num_mapped_sgs, i) { in count_sg_trbs_needed()
3338 full_len -= len; in count_sg_trbs_needed()
3350 addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset); in count_isoc_trbs_needed()
3351 len = urb->iso_frame_desc[i].length; in count_isoc_trbs_needed()
3358 if (unlikely(running_total != urb->transfer_buffer_length)) in check_trb_math()
3359 dev_err(&urb->dev->dev, "%s - ep %#x - Miscalculated tx length, " in check_trb_math()
3362 urb->ep->desc.bEndpointAddress, in check_trb_math()
3364 urb->transfer_buffer_length, in check_trb_math()
3365 urb->transfer_buffer_length); in check_trb_math()
3378 start_trb->field[3] |= cpu_to_le32(start_cycle); in giveback_first_trb()
3380 start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE); in giveback_first_trb()
3389 xhci_interval = EP_INTERVAL_TO_UFRAMES(le32_to_cpu(ep_ctx->ep_info)); in check_interval()
3390 ep_interval = urb->interval; in check_interval()
3393 if (urb->dev->speed == USB_SPEED_LOW || in check_interval()
3394 urb->dev->speed == USB_SPEED_FULL) in check_interval()
3401 dev_dbg_ratelimited(&urb->dev->dev, in check_interval()
3405 urb->interval = xhci_interval; in check_interval()
3407 if (urb->dev->speed == USB_SPEED_LOW || in check_interval()
3408 urb->dev->speed == USB_SPEED_FULL) in check_interval()
3409 urb->interval /= 8; in check_interval()
3424 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); in xhci_queue_intr_tx()
3440 * TD size = total_packet_count - packets_transferred
3457 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) in xhci_td_remainder()
3458 return ((td_total_len - transferred) >> 10); in xhci_td_remainder()
3460 /* One TRB with a zero-length data packet. */ in xhci_td_remainder()
3466 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) in xhci_td_remainder()
3469 maxp = usb_endpoint_maxp(&urb->ep->desc); in xhci_td_remainder()
3473 return (total_packet_count - ((transferred + trb_buff_len) / maxp)); in xhci_td_remainder()
3480 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_align_td()
3486 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_align_td()
3498 *trb_buff_len -= unalign; in xhci_align_td()
3508 new_buff_len = max_pkt - (enqd_len % max_pkt); in xhci_align_td()
3510 if (new_buff_len > (urb->transfer_buffer_length - enqd_len)) in xhci_align_td()
3511 new_buff_len = (urb->transfer_buffer_length - enqd_len); in xhci_align_td()
3515 if (urb->num_sgs) { in xhci_align_td()
3516 len = sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_align_td()
3517 seg->bounce_buf, new_buff_len, enqd_len); in xhci_align_td()
3522 memcpy(seg->bounce_buf, urb->transfer_buffer + enqd_len, new_buff_len); in xhci_align_td()
3525 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, in xhci_align_td()
3528 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, in xhci_align_td()
3532 if (dma_mapping_error(dev, seg->bounce_dma)) { in xhci_align_td()
3538 seg->bounce_len = new_buff_len; in xhci_align_td()
3539 seg->bounce_offs = enqd_len; in xhci_align_td()
3546 /* This is very similar to what ehci-q.c qtd_fill() does */
3567 return -EINVAL; in xhci_queue_bulk_tx()
3569 full_len = urb->transfer_buffer_length; in xhci_queue_bulk_tx()
3571 if (urb->num_sgs && !(urb->transfer_flags & URB_DMA_MAP_SINGLE)) { in xhci_queue_bulk_tx()
3572 num_sgs = urb->num_mapped_sgs; in xhci_queue_bulk_tx()
3573 sg = urb->sg; in xhci_queue_bulk_tx()
3579 addr = (u64) urb->transfer_dma; in xhci_queue_bulk_tx()
3582 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3583 ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3588 urb_priv = urb->hcpriv; in xhci_queue_bulk_tx()
3590 /* Deal with URB_ZERO_PACKET - need one more td/trb */ in xhci_queue_bulk_tx()
3591 if (urb->transfer_flags & URB_ZERO_PACKET && urb_priv->num_tds > 1) in xhci_queue_bulk_tx()
3594 td = &urb_priv->td[0]; in xhci_queue_bulk_tx()
3601 start_trb = &ring->enqueue->generic; in xhci_queue_bulk_tx()
3602 start_cycle = ring->cycle_state; in xhci_queue_bulk_tx()
3605 /* Queue the TRBs, even if they are zero-length */ in xhci_queue_bulk_tx()
3615 trb_buff_len = full_len - enqd_len; in xhci_queue_bulk_tx()
3623 field |= ring->cycle_state; in xhci_queue_bulk_tx()
3630 if (trb_is_link(ring->enqueue + 1)) { in xhci_queue_bulk_tx()
3633 ring->enq_seg)) { in xhci_queue_bulk_tx()
3634 send_addr = ring->enq_seg->bounce_dma; in xhci_queue_bulk_tx()
3636 td->bounce_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3644 td->last_trb = ring->enqueue; in xhci_queue_bulk_tx()
3645 td->last_trb_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3647 memcpy(&send_addr, urb->transfer_buffer, in xhci_queue_bulk_tx()
3676 --num_sgs; in xhci_queue_bulk_tx()
3677 sent_len -= block_len; in xhci_queue_bulk_tx()
3685 block_len -= sent_len; in xhci_queue_bulk_tx()
3690 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3691 ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3693 urb_priv->td[1].last_trb = ring->enqueue; in xhci_queue_bulk_tx()
3694 urb_priv->td[1].last_trb_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3695 field = TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; in xhci_queue_bulk_tx()
3700 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3705 /* Caller must have locked xhci->lock */
3721 return -EINVAL; in xhci_queue_ctrl_tx()
3727 if (!urb->setup_packet) in xhci_queue_ctrl_tx()
3728 return -EINVAL; in xhci_queue_ctrl_tx()
3737 if (urb->transfer_buffer_length > 0) in xhci_queue_ctrl_tx()
3739 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_ctrl_tx()
3740 ep_index, urb->stream_id, in xhci_queue_ctrl_tx()
3745 urb_priv = urb->hcpriv; in xhci_queue_ctrl_tx()
3746 td = &urb_priv->td[0]; in xhci_queue_ctrl_tx()
3753 start_trb = &ep_ring->enqueue->generic; in xhci_queue_ctrl_tx()
3754 start_cycle = ep_ring->cycle_state; in xhci_queue_ctrl_tx()
3756 /* Queue setup TRB - see section 6.4.1.2.1 */ in xhci_queue_ctrl_tx()
3758 setup = (struct usb_ctrlrequest *) urb->setup_packet; in xhci_queue_ctrl_tx()
3765 if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { in xhci_queue_ctrl_tx()
3766 if (urb->transfer_buffer_length > 0) { in xhci_queue_ctrl_tx()
3767 if (setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3775 setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16, in xhci_queue_ctrl_tx()
3776 le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16, in xhci_queue_ctrl_tx()
3788 if (urb->transfer_buffer_length > 0) { in xhci_queue_ctrl_tx()
3793 memcpy(&addr, urb->transfer_buffer, in xhci_queue_ctrl_tx()
3794 urb->transfer_buffer_length); in xhci_queue_ctrl_tx()
3798 addr = (u64) urb->transfer_dma; in xhci_queue_ctrl_tx()
3802 urb->transfer_buffer_length, in xhci_queue_ctrl_tx()
3803 urb->transfer_buffer_length, in xhci_queue_ctrl_tx()
3805 length_field = TRB_LEN(urb->transfer_buffer_length) | in xhci_queue_ctrl_tx()
3808 if (setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3814 field | ep_ring->cycle_state); in xhci_queue_ctrl_tx()
3818 td->last_trb = ep_ring->enqueue; in xhci_queue_ctrl_tx()
3819 td->last_trb_seg = ep_ring->enq_seg; in xhci_queue_ctrl_tx()
3821 /* Queue status TRB - see Table 7 and sections 4.11.2.2 and 6.4.1.2.3 */ in xhci_queue_ctrl_tx()
3823 if (urb->transfer_buffer_length > 0 && setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3832 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state); in xhci_queue_ctrl_tx()
3852 if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER) in xhci_get_burst_count()
3855 max_burst = urb->ep->ss_ep_comp.bMaxBurst; in xhci_get_burst_count()
3856 return DIV_ROUND_UP(total_packet_count, max_burst + 1) - 1; in xhci_get_burst_count()
3873 if (xhci->hci_version < 0x100) in xhci_get_last_burst_packet_count()
3876 if (urb->dev->speed >= USB_SPEED_SUPER) { in xhci_get_last_burst_packet_count()
3878 max_burst = urb->ep->ss_ep_comp.bMaxBurst; in xhci_get_last_burst_packet_count()
3881 * number of packets, but the TLBPC field is zero-based. in xhci_get_last_burst_packet_count()
3885 return residue - 1; in xhci_get_last_burst_packet_count()
3889 return total_packet_count - 1; in xhci_get_last_burst_packet_count()
3905 if (urb->dev->speed == USB_SPEED_LOW || in xhci_get_isoc_frame_id()
3906 urb->dev->speed == USB_SPEED_FULL) in xhci_get_isoc_frame_id()
3907 start_frame = urb->start_frame + index * urb->interval; in xhci_get_isoc_frame_id()
3909 start_frame = (urb->start_frame + index * urb->interval) >> 3; in xhci_get_isoc_frame_id()
3919 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_get_isoc_frame_id()
3920 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_get_isoc_frame_id()
3936 current_frame_id = readl(&xhci->run_regs->microframe_index); in xhci_get_isoc_frame_id()
3947 ret = -EINVAL; in xhci_get_isoc_frame_id()
3951 ret = -EINVAL; in xhci_get_isoc_frame_id()
3953 ret = -EINVAL; in xhci_get_isoc_frame_id()
3957 if (ret == -EINVAL || start_frame == start_frame_id) { in xhci_get_isoc_frame_id()
3959 if (urb->dev->speed == USB_SPEED_LOW || in xhci_get_isoc_frame_id()
3960 urb->dev->speed == USB_SPEED_FULL) in xhci_get_isoc_frame_id()
3961 urb->start_frame = start_frame; in xhci_get_isoc_frame_id()
3963 urb->start_frame = start_frame << 3; in xhci_get_isoc_frame_id()
3983 if (xhci->hci_version < 0x100) in trb_block_event_intr()
3986 if (i == num_tds - 1) in trb_block_event_intr()
3992 if (i && ir->isoc_bei_interval && xhci->quirks & XHCI_AVOID_BEI) in trb_block_event_intr()
3993 return !!(i % ir->isoc_bei_interval); in trb_block_event_intr()
4018 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx()
4019 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; in xhci_queue_isoc_tx()
4020 ir = xhci->interrupters[0]; in xhci_queue_isoc_tx()
4022 num_tds = urb->number_of_packets; in xhci_queue_isoc_tx()
4025 return -EINVAL; in xhci_queue_isoc_tx()
4027 start_addr = (u64) urb->transfer_dma; in xhci_queue_isoc_tx()
4028 start_trb = &ep_ring->enqueue->generic; in xhci_queue_isoc_tx()
4029 start_cycle = ep_ring->cycle_state; in xhci_queue_isoc_tx()
4031 urb_priv = urb->hcpriv; in xhci_queue_isoc_tx()
4032 /* Queue the TRBs for each TD, even if they are zero-length */ in xhci_queue_isoc_tx()
4040 addr = start_addr + urb->iso_frame_desc[i].offset; in xhci_queue_isoc_tx()
4041 td_len = urb->iso_frame_desc[i].length; in xhci_queue_isoc_tx()
4043 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_queue_isoc_tx()
4046 /* A zero-length transfer still involves at least one packet. */ in xhci_queue_isoc_tx()
4055 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, in xhci_queue_isoc_tx()
4056 urb->stream_id, trbs_per_td, urb, i, mem_flags); in xhci_queue_isoc_tx()
4062 td = &urb_priv->td[i]; in xhci_queue_isoc_tx()
4065 if (!(urb->transfer_flags & URB_ISO_ASAP) && in xhci_queue_isoc_tx()
4066 HCC_CFC(xhci->hcc_params)) { in xhci_queue_isoc_tx()
4079 (i ? ep_ring->cycle_state : !start_cycle); in xhci_queue_isoc_tx()
4082 if (!xep->use_extended_tbc) in xhci_queue_isoc_tx()
4092 ep_ring->cycle_state; in xhci_queue_isoc_tx()
4099 if (j < trbs_per_td - 1) { in xhci_queue_isoc_tx()
4104 td->last_trb = ep_ring->enqueue; in xhci_queue_isoc_tx()
4105 td->last_trb_seg = ep_ring->enq_seg; in xhci_queue_isoc_tx()
4124 if (first_trb && xep->use_extended_tbc) in xhci_queue_isoc_tx()
4138 td_remain_len -= trb_buff_len; in xhci_queue_isoc_tx()
4144 ret = -EINVAL; in xhci_queue_isoc_tx()
4150 if (HCC_CFC(xhci->hcc_params)) in xhci_queue_isoc_tx()
4151 xep->next_frame_id = urb->start_frame + num_tds * urb->interval; in xhci_queue_isoc_tx()
4153 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_queue_isoc_tx()
4154 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_queue_isoc_tx()
4157 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; in xhci_queue_isoc_tx()
4159 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_isoc_tx()
4165 for (i--; i >= 0; i--) in xhci_queue_isoc_tx()
4166 list_del_init(&urb_priv->td[i].td_list); in xhci_queue_isoc_tx()
4169 * into No-ops with a software-owned cycle bit. That way the hardware in xhci_queue_isoc_tx()
4171 * overwrite them. td->first_trb and td->start_seg are already set. in xhci_queue_isoc_tx()
4173 urb_priv->td[0].last_trb = ep_ring->enqueue; in xhci_queue_isoc_tx()
4175 td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); in xhci_queue_isoc_tx()
4178 ep_ring->enqueue = urb_priv->td[0].first_trb; in xhci_queue_isoc_tx()
4179 ep_ring->enq_seg = urb_priv->td[0].start_seg; in xhci_queue_isoc_tx()
4180 ep_ring->cycle_state = start_cycle; in xhci_queue_isoc_tx()
4181 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb); in xhci_queue_isoc_tx()
4189 * update urb->start_frame if URB_ISO_ASAP is set in transfer_flags or
4190 * Contiguous Frame ID is not supported by HC.
4204 xdev = xhci->devs[slot_id]; in xhci_queue_isoc_tx_prepare()
4205 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx_prepare()
4206 ep_ring = xdev->eps[ep_index].ring; in xhci_queue_isoc_tx_prepare()
4207 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in xhci_queue_isoc_tx_prepare()
4210 num_tds = urb->number_of_packets; in xhci_queue_isoc_tx_prepare()
4228 /* Calculate the start frame and put it in urb->start_frame. */ in xhci_queue_isoc_tx_prepare()
4229 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { in xhci_queue_isoc_tx_prepare()
4231 urb->start_frame = xep->next_frame_id; in xhci_queue_isoc_tx_prepare()
4236 start_frame = readl(&xhci->run_regs->microframe_index); in xhci_queue_isoc_tx_prepare()
4242 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_queue_isoc_tx_prepare()
4243 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_queue_isoc_tx_prepare()
4252 if (urb->dev->speed == USB_SPEED_LOW || in xhci_queue_isoc_tx_prepare()
4253 urb->dev->speed == USB_SPEED_FULL) { in xhci_queue_isoc_tx_prepare()
4254 start_frame = roundup(start_frame, urb->interval << 3); in xhci_queue_isoc_tx_prepare()
4255 urb->start_frame = start_frame >> 3; in xhci_queue_isoc_tx_prepare()
4257 start_frame = roundup(start_frame, urb->interval); in xhci_queue_isoc_tx_prepare()
4258 urb->start_frame = start_frame; in xhci_queue_isoc_tx_prepare()
4273 * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
4280 int reserved_trbs = xhci->cmd_ring_reserved_trbs; in queue_command()
4283 if ((xhci->xhc_state & XHCI_STATE_DYING) || in queue_command()
4284 (xhci->xhc_state & XHCI_STATE_HALTED)) { in queue_command()
4286 return -ESHUTDOWN; in queue_command()
4292 ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, in queue_command()
4302 cmd->command_trb = xhci->cmd_ring->enqueue; in queue_command()
4305 if (list_empty(&xhci->cmd_list)) { in queue_command()
4306 xhci->current_cmd = cmd; in queue_command()
4310 list_add_tail(&cmd->cmd_list, &xhci->cmd_list); in queue_command()
4312 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, in queue_command()
4313 field4 | xhci->cmd_ring->cycle_state); in queue_command()