• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0
3 * xHCI host controller driver
26 * until you reach a non-link TRB.
57 #include <linux/dma-mapping.h>
58 #include "xhci.h"
59 #include "xhci-trace.h"
60 #include "xhci-mtk.h"
71 if (!seg || !trb || trb < seg->trbs) in xhci_trb_virt_to_dma()
74 segment_offset = trb - seg->trbs; in xhci_trb_virt_to_dma()
77 return seg->dma + (segment_offset * sizeof(*trb)); in xhci_trb_virt_to_dma()
82 return TRB_TYPE_NOOP_LE32(trb->generic.field[3]); in trb_is_noop()
87 return TRB_TYPE_LINK_LE32(trb->link.control); in trb_is_link()
92 return trb == &seg->trbs[TRBS_PER_SEGMENT - 1]; in last_trb_on_seg()
98 return last_trb_on_seg(seg, trb) && (seg->next == ring->first_seg); in last_trb_on_ring()
103 return le32_to_cpu(trb->link.control) & LINK_TOGGLE; in link_trb_toggles_cycle()
108 struct urb_priv *urb_priv = td->urb->hcpriv; in last_td_in_urb()
110 return urb_priv->num_tds_done == urb_priv->num_tds; in last_td_in_urb()
115 struct urb_priv *urb_priv = urb->hcpriv; in inc_td_cnt()
117 urb_priv->num_tds_done++; in inc_td_cnt()
124 trb->link.control &= cpu_to_le32(~TRB_CHAIN); in trb_to_noop()
126 trb->generic.field[0] = 0; in trb_to_noop()
127 trb->generic.field[1] = 0; in trb_to_noop()
128 trb->generic.field[2] = 0; in trb_to_noop()
130 trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE); in trb_to_noop()
131 trb->generic.field[3] |= cpu_to_le32(TRB_TYPE(noop_type)); in trb_to_noop()
139 static void next_trb(struct xhci_hcd *xhci, in next_trb() argument
145 *seg = (*seg)->next; in next_trb()
146 *trb = ((*seg)->trbs); in next_trb()
156 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) in inc_deq() argument
159 if (ring->type == TYPE_EVENT) { in inc_deq()
160 if (!last_trb_on_seg(ring->deq_seg, ring->dequeue)) { in inc_deq()
161 ring->dequeue++; in inc_deq()
164 if (last_trb_on_ring(ring, ring->deq_seg, ring->dequeue)) in inc_deq()
165 ring->cycle_state ^= 1; in inc_deq()
166 ring->deq_seg = ring->deq_seg->next; in inc_deq()
167 ring->dequeue = ring->deq_seg->trbs; in inc_deq()
172 if (!trb_is_link(ring->dequeue)) { in inc_deq()
173 ring->dequeue++; in inc_deq()
174 ring->num_trbs_free++; in inc_deq()
176 while (trb_is_link(ring->dequeue)) { in inc_deq()
177 ring->deq_seg = ring->deq_seg->next; in inc_deq()
178 ring->dequeue = ring->deq_seg->trbs; in inc_deq()
199 * xHCI hardware can't handle the chain bit being cleared on a link TRB.
204 static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, in inc_enq() argument
210 chain = le32_to_cpu(ring->enqueue->generic.field[3]) & TRB_CHAIN; in inc_enq()
212 if (!trb_is_link(ring->enqueue)) in inc_enq()
213 ring->num_trbs_free--; in inc_enq()
214 next = ++(ring->enqueue); in inc_enq()
233 if (!(ring->type == TYPE_ISOC && in inc_enq()
234 (xhci->quirks & XHCI_AMD_0x96_HOST)) && in inc_enq()
235 !xhci_link_trb_quirk(xhci)) { in inc_enq()
236 next->link.control &= cpu_to_le32(~TRB_CHAIN); in inc_enq()
237 next->link.control |= cpu_to_le32(chain); in inc_enq()
241 next->link.control ^= cpu_to_le32(TRB_CYCLE); in inc_enq()
245 ring->cycle_state ^= 1; in inc_enq()
247 ring->enq_seg = ring->enq_seg->next; in inc_enq()
248 ring->enqueue = ring->enq_seg->trbs; in inc_enq()
249 next = ring->enqueue; in inc_enq()
259 static inline int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring, in room_on_ring() argument
264 if (ring->num_trbs_free < num_trbs) in room_on_ring()
267 if (ring->type != TYPE_COMMAND && ring->type != TYPE_EVENT) { in room_on_ring()
268 num_trbs_in_deq_seg = ring->dequeue - ring->deq_seg->trbs; in room_on_ring()
269 if (ring->num_trbs_free < num_trbs + num_trbs_in_deq_seg) in room_on_ring()
277 void xhci_ring_cmd_db(struct xhci_hcd *xhci) in xhci_ring_cmd_db() argument
279 if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) in xhci_ring_cmd_db()
282 xhci_dbg(xhci, "// Ding dong!\n"); in xhci_ring_cmd_db()
286 writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
288 readl(&xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
291 static bool xhci_mod_cmd_timer(struct xhci_hcd *xhci, unsigned long delay) in xhci_mod_cmd_timer() argument
293 return mod_delayed_work(system_wq, &xhci->cmd_timer, delay); in xhci_mod_cmd_timer()
296 static struct xhci_command *xhci_next_queued_cmd(struct xhci_hcd *xhci) in xhci_next_queued_cmd() argument
298 return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command, in xhci_next_queued_cmd()
303 * Turn all commands on command ring with status set to "aborted" to no-op trbs.
305 * This must be called with command ring stopped and xhci->lock held.
307 static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci, in xhci_handle_stopped_cmd_ring() argument
312 /* Turn all aborted commands in list to no-ops, then restart */ in xhci_handle_stopped_cmd_ring()
313 list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) { in xhci_handle_stopped_cmd_ring()
315 if (i_cmd->status != COMP_COMMAND_ABORTED) in xhci_handle_stopped_cmd_ring()
318 i_cmd->status = COMP_COMMAND_RING_STOPPED; in xhci_handle_stopped_cmd_ring()
320 xhci_dbg(xhci, "Turn aborted command %p to no-op\n", in xhci_handle_stopped_cmd_ring()
321 i_cmd->command_trb); in xhci_handle_stopped_cmd_ring()
323 trb_to_noop(i_cmd->command_trb, TRB_CMD_NOOP); in xhci_handle_stopped_cmd_ring()
327 * completion event is received for these no-op commands in xhci_handle_stopped_cmd_ring()
331 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_handle_stopped_cmd_ring()
334 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && in xhci_handle_stopped_cmd_ring()
335 !(xhci->xhc_state & XHCI_STATE_DYING)) { in xhci_handle_stopped_cmd_ring()
336 xhci->current_cmd = cur_cmd; in xhci_handle_stopped_cmd_ring()
337 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in xhci_handle_stopped_cmd_ring()
338 xhci_ring_cmd_db(xhci); in xhci_handle_stopped_cmd_ring()
342 /* Must be called with xhci->lock held, releases and aquires lock back */
343 static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) in xhci_abort_cmd_ring() argument
345 struct xhci_segment *new_seg = xhci->cmd_ring->deq_seg; in xhci_abort_cmd_ring()
346 union xhci_trb *new_deq = xhci->cmd_ring->dequeue; in xhci_abort_cmd_ring()
350 xhci_dbg(xhci, "Abort command ring\n"); in xhci_abort_cmd_ring()
352 reinit_completion(&xhci->cmd_ring_stop_completion); in xhci_abort_cmd_ring()
362 next_trb(xhci, NULL, &new_seg, &new_deq); in xhci_abort_cmd_ring()
364 next_trb(xhci, NULL, &new_seg, &new_deq); in xhci_abort_cmd_ring()
367 xhci_write_64(xhci, crcr | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
369 /* Section 4.6.1.2 of xHCI 1.0 spec says software should also time the in xhci_abort_cmd_ring()
371 * seconds then driver handles it as if host died (-ENODEV). in xhci_abort_cmd_ring()
372 * In the future we should distinguish between -ENODEV and -ETIMEDOUT in xhci_abort_cmd_ring()
373 * and try to recover a -ETIMEDOUT with a host controller reset. in xhci_abort_cmd_ring()
375 ret = xhci_handshake(&xhci->op_regs->cmd_ring, in xhci_abort_cmd_ring()
378 xhci_err(xhci, "Abort failed to stop command ring: %d\n", ret); in xhci_abort_cmd_ring()
379 xhci_halt(xhci); in xhci_abort_cmd_ring()
380 xhci_hc_died(xhci); in xhci_abort_cmd_ring()
389 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_abort_cmd_ring()
390 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, in xhci_abort_cmd_ring()
392 spin_lock_irqsave(&xhci->lock, flags); in xhci_abort_cmd_ring()
394 xhci_dbg(xhci, "No stop event for abort, ring start fail?\n"); in xhci_abort_cmd_ring()
395 xhci_cleanup_command_queue(xhci); in xhci_abort_cmd_ring()
397 xhci_handle_stopped_cmd_ring(xhci, xhci_next_queued_cmd(xhci)); in xhci_abort_cmd_ring()
402 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, in xhci_ring_ep_doorbell() argument
407 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; in xhci_ring_ep_doorbell()
408 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_ring_ep_doorbell()
409 unsigned int ep_state = ep->ep_state; in xhci_ring_ep_doorbell()
425 * write-posting flush. It'll get there soon enough. in xhci_ring_ep_doorbell()
430 static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in ring_doorbell_for_active_rings() argument
437 ep = &xhci->devs[slot_id]->eps[ep_index]; in ring_doorbell_for_active_rings()
440 if (!(ep->ep_state & EP_HAS_STREAMS)) { in ring_doorbell_for_active_rings()
441 if (ep->ring && !(list_empty(&ep->ring->td_list))) in ring_doorbell_for_active_rings()
442 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, 0); in ring_doorbell_for_active_rings()
446 for (stream_id = 1; stream_id < ep->stream_info->num_streams; in ring_doorbell_for_active_rings()
448 struct xhci_stream_info *stream_info = ep->stream_info; in ring_doorbell_for_active_rings()
449 if (!list_empty(&stream_info->stream_rings[stream_id]->td_list)) in ring_doorbell_for_active_rings()
450 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, in ring_doorbell_for_active_rings()
455 void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in xhci_ring_doorbell_for_active_rings() argument
459 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_ring_doorbell_for_active_rings()
462 static struct xhci_virt_ep *xhci_get_virt_ep(struct xhci_hcd *xhci, in xhci_get_virt_ep() argument
467 xhci_warn(xhci, "Invalid slot_id %u\n", slot_id); in xhci_get_virt_ep()
471 xhci_warn(xhci, "Invalid endpoint index %u\n", ep_index); in xhci_get_virt_ep()
474 if (!xhci->devs[slot_id]) { in xhci_get_virt_ep()
475 xhci_warn(xhci, "No xhci virt device for slot_id %u\n", slot_id); in xhci_get_virt_ep()
479 return &xhci->devs[slot_id]->eps[ep_index]; in xhci_get_virt_ep()
486 struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, in xhci_triad_to_transfer_ring() argument
492 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_triad_to_transfer_ring()
497 if (!(ep->ep_state & EP_HAS_STREAMS)) in xhci_triad_to_transfer_ring()
498 return ep->ring; in xhci_triad_to_transfer_ring()
501 xhci_warn(xhci, in xhci_triad_to_transfer_ring()
508 if (stream_id < ep->stream_info->num_streams) in xhci_triad_to_transfer_ring()
509 return ep->stream_info->stream_rings[stream_id]; in xhci_triad_to_transfer_ring()
511 xhci_warn(xhci, in xhci_triad_to_transfer_ring()
516 ep->stream_info->num_streams - 1, in xhci_triad_to_transfer_ring()
528 static u64 xhci_get_hw_deq(struct xhci_hcd *xhci, struct xhci_virt_device *vdev, in xhci_get_hw_deq() argument
535 ep = &vdev->eps[ep_index]; in xhci_get_hw_deq()
537 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_get_hw_deq()
538 st_ctx = &ep->stream_info->stream_ctx_array[stream_id]; in xhci_get_hw_deq()
539 return le64_to_cpu(st_ctx->stream_ring); in xhci_get_hw_deq()
541 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_get_hw_deq()
542 return le64_to_cpu(ep_ctx->deq); in xhci_get_hw_deq()
552 * - First we update our new ring state to be the same as when the xHC stopped.
553 * - Then we traverse the ring to find the segment that contains
556 * - Finally we move the dequeue state one TRB further, toggling the cycle bit
563 void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, in xhci_find_new_dequeue_state() argument
568 struct xhci_virt_device *dev = xhci->devs[slot_id]; in xhci_find_new_dequeue_state()
569 struct xhci_virt_ep *ep = &dev->eps[ep_index]; in xhci_find_new_dequeue_state()
581 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id, in xhci_find_new_dequeue_state()
584 xhci_warn(xhci, "WARN can't find new dequeue state " in xhci_find_new_dequeue_state()
595 if (list_empty(&ep_ring->td_list)) { in xhci_find_new_dequeue_state()
596 state->new_deq_seg = ep_ring->enq_seg; in xhci_find_new_dequeue_state()
597 state->new_deq_ptr = ep_ring->enqueue; in xhci_find_new_dequeue_state()
598 state->new_cycle_state = ep_ring->cycle_state; in xhci_find_new_dequeue_state()
601 xhci_warn(xhci, "Can't find new dequeue state, missing cur_td\n"); in xhci_find_new_dequeue_state()
607 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
610 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); in xhci_find_new_dequeue_state()
611 new_seg = ep_ring->deq_seg; in xhci_find_new_dequeue_state()
612 new_deq = ep_ring->dequeue; in xhci_find_new_dequeue_state()
615 * Quirk: xHC write-back of the DCS field in the hardware dequeue in xhci_find_new_dequeue_state()
616 * pointer is wrong - use the cycle state of the TRB pointed to by in xhci_find_new_dequeue_state()
619 if (xhci->quirks & XHCI_EP_CTX_BROKEN_DCS && in xhci_find_new_dequeue_state()
620 !(ep->ep_state & EP_HAS_STREAMS)) in xhci_find_new_dequeue_state()
621 halted_seg = trb_in_td(xhci, cur_td->start_seg, in xhci_find_new_dequeue_state()
622 cur_td->first_trb, cur_td->last_trb, in xhci_find_new_dequeue_state()
625 index = ((dma_addr_t)(hw_dequeue & ~0xf) - halted_seg->dma) / in xhci_find_new_dequeue_state()
627 halted_trb = &halted_seg->trbs[index]; in xhci_find_new_dequeue_state()
628 state->new_cycle_state = halted_trb->generic.field[3] & 0x1; in xhci_find_new_dequeue_state()
629 xhci_dbg(xhci, "Endpoint DCS = %d TRB index = %d cycle = %d\n", in xhci_find_new_dequeue_state()
631 state->new_cycle_state); in xhci_find_new_dequeue_state()
633 state->new_cycle_state = hw_dequeue & 0x1; in xhci_find_new_dequeue_state()
635 state->stream_id = stream_id; in xhci_find_new_dequeue_state()
650 if (new_deq == cur_td->last_trb) in xhci_find_new_dequeue_state()
655 state->new_cycle_state ^= 0x1; in xhci_find_new_dequeue_state()
657 next_trb(xhci, ep_ring, &new_seg, &new_deq); in xhci_find_new_dequeue_state()
660 if (new_deq == ep->ring->dequeue) { in xhci_find_new_dequeue_state()
661 xhci_err(xhci, "Error: Failed finding new dequeue state\n"); in xhci_find_new_dequeue_state()
662 state->new_deq_seg = NULL; in xhci_find_new_dequeue_state()
663 state->new_deq_ptr = NULL; in xhci_find_new_dequeue_state()
669 state->new_deq_seg = new_seg; in xhci_find_new_dequeue_state()
670 state->new_deq_ptr = new_deq; in xhci_find_new_dequeue_state()
674 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
675 "Cycle state = 0x%x", state->new_cycle_state); in xhci_find_new_dequeue_state()
677 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
679 state->new_deq_seg); in xhci_find_new_dequeue_state()
680 addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr); in xhci_find_new_dequeue_state()
681 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
690 static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in td_to_noop() argument
693 struct xhci_segment *seg = td->start_seg; in td_to_noop()
694 union xhci_trb *trb = td->first_trb; in td_to_noop()
700 if (flip_cycle && trb != td->first_trb && trb != td->last_trb) in td_to_noop()
701 trb->generic.field[3] ^= cpu_to_le32(TRB_CYCLE); in td_to_noop()
703 if (trb == td->last_trb) in td_to_noop()
706 next_trb(xhci, ep_ring, &seg, &trb); in td_to_noop()
710 static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, in xhci_stop_watchdog_timer_in_irq() argument
713 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_stop_watchdog_timer_in_irq()
715 del_timer(&ep->stop_cmd_timer); in xhci_stop_watchdog_timer_in_irq()
719 * Must be called with xhci->lock held in interrupt context,
720 * releases and re-acquires xhci->lock
722 static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, in xhci_giveback_urb_in_irq() argument
725 struct urb *urb = cur_td->urb; in xhci_giveback_urb_in_irq()
726 struct urb_priv *urb_priv = urb->hcpriv; in xhci_giveback_urb_in_irq()
727 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); in xhci_giveback_urb_in_irq()
729 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { in xhci_giveback_urb_in_irq()
730 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; in xhci_giveback_urb_in_irq()
731 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_giveback_urb_in_irq()
732 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_giveback_urb_in_irq()
742 static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, in xhci_unmap_td_bounce_buffer() argument
745 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_unmap_td_bounce_buffer()
746 struct xhci_segment *seg = td->bounce_seg; in xhci_unmap_td_bounce_buffer()
747 struct urb *urb = td->urb; in xhci_unmap_td_bounce_buffer()
754 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len, in xhci_unmap_td_bounce_buffer()
759 dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len, in xhci_unmap_td_bounce_buffer()
762 if (urb->num_sgs) { in xhci_unmap_td_bounce_buffer()
763 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, seg->bounce_buf, in xhci_unmap_td_bounce_buffer()
764 seg->bounce_len, seg->bounce_offs); in xhci_unmap_td_bounce_buffer()
765 if (len != seg->bounce_len) in xhci_unmap_td_bounce_buffer()
766 xhci_warn(xhci, "WARN Wrong bounce buffer read length: %zu != %d\n", in xhci_unmap_td_bounce_buffer()
767 len, seg->bounce_len); in xhci_unmap_td_bounce_buffer()
769 memcpy(urb->transfer_buffer + seg->bounce_offs, seg->bounce_buf, in xhci_unmap_td_bounce_buffer()
770 seg->bounce_len); in xhci_unmap_td_bounce_buffer()
772 seg->bounce_len = 0; in xhci_unmap_td_bounce_buffer()
773 seg->bounce_offs = 0; in xhci_unmap_td_bounce_buffer()
776 static int xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_td_cleanup() argument
782 urb = td->urb; in xhci_td_cleanup()
785 xhci_unmap_td_bounce_buffer(xhci, ep_ring, td); in xhci_td_cleanup()
789 * length, urb->actual_length will be a very big number (since it's in xhci_td_cleanup()
792 if (urb->actual_length > urb->transfer_buffer_length) { in xhci_td_cleanup()
793 xhci_warn(xhci, "URB req %u and actual %u transfer length mismatch\n", in xhci_td_cleanup()
794 urb->transfer_buffer_length, urb->actual_length); in xhci_td_cleanup()
795 urb->actual_length = 0; in xhci_td_cleanup()
798 list_del_init(&td->td_list); in xhci_td_cleanup()
800 if (!list_empty(&td->cancelled_td_list)) in xhci_td_cleanup()
801 list_del_init(&td->cancelled_td_list); in xhci_td_cleanup()
806 if ((urb->actual_length != urb->transfer_buffer_length && in xhci_td_cleanup()
807 (urb->transfer_flags & URB_SHORT_NOT_OK)) || in xhci_td_cleanup()
808 (status != 0 && !usb_endpoint_xfer_isoc(&urb->ep->desc))) in xhci_td_cleanup()
809 xhci_dbg(xhci, "Giveback URB %p, len = %d, expected = %d, status = %d\n", in xhci_td_cleanup()
810 urb, urb->actual_length, in xhci_td_cleanup()
811 urb->transfer_buffer_length, status); in xhci_td_cleanup()
814 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) in xhci_td_cleanup()
816 xhci_giveback_urb_in_irq(xhci, td, status); in xhci_td_cleanup()
822 static int xhci_reset_halted_ep(struct xhci_hcd *xhci, unsigned int slot_id, in xhci_reset_halted_ep() argument
828 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_reset_halted_ep()
830 ret = -ENOMEM; in xhci_reset_halted_ep()
834 ret = xhci_queue_reset_ep(xhci, command, slot_id, ep_index, reset_type); in xhci_reset_halted_ep()
837 xhci_err(xhci, "ERROR queuing reset endpoint for slot %d ep_index %d, %d\n", in xhci_reset_halted_ep()
842 static void xhci_handle_halted_endpoint(struct xhci_hcd *xhci, in xhci_handle_halted_endpoint() argument
847 unsigned int slot_id = ep->vdev->slot_id; in xhci_handle_halted_endpoint()
854 if (ep->vdev->flags & VDEV_PORT_ERROR) in xhci_handle_halted_endpoint()
857 ep->ep_state |= EP_HALTED; in xhci_handle_halted_endpoint()
859 err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type); in xhci_handle_halted_endpoint()
864 ep->ep_state |= EP_HARD_CLEAR_TOGGLE; in xhci_handle_halted_endpoint()
865 xhci_cleanup_stalled_ring(xhci, slot_id, ep->ep_index, stream_id, in xhci_handle_halted_endpoint()
868 xhci_ring_cmd_db(xhci); in xhci_handle_halted_endpoint()
873 * We have the xHCI lock, so nothing can modify this list until we drop it.
874 * We're also in the event handler, so we can't get re-interrupted if another
881 struct xhci_hcd *xhci; in xhci_invalidate_cancelled_tds() local
887 xhci = ep->xhci; in xhci_invalidate_cancelled_tds()
889 list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list, cancelled_td_list) { in xhci_invalidate_cancelled_tds()
890 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_invalidate_cancelled_tds()
893 td->start_seg, td->first_trb)); in xhci_invalidate_cancelled_tds()
894 list_del_init(&td->td_list); in xhci_invalidate_cancelled_tds()
895 ring = xhci_urb_to_transfer_ring(xhci, td->urb); in xhci_invalidate_cancelled_tds()
897 xhci_warn(xhci, "WARN Cancelled URB %p has invalid stream ID %u.\n", in xhci_invalidate_cancelled_tds()
898 td->urb, td->urb->stream_id); in xhci_invalidate_cancelled_tds()
905 hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index, in xhci_invalidate_cancelled_tds()
906 td->urb->stream_id); in xhci_invalidate_cancelled_tds()
909 if (trb_in_td(xhci, td->start_seg, td->first_trb, in xhci_invalidate_cancelled_tds()
910 td->last_trb, hw_deq, false)) { in xhci_invalidate_cancelled_tds()
911 xhci_find_new_dequeue_state(xhci, ep->vdev->slot_id, in xhci_invalidate_cancelled_tds()
912 ep->ep_index, in xhci_invalidate_cancelled_tds()
913 td->urb->stream_id, in xhci_invalidate_cancelled_tds()
916 td_to_noop(xhci, ring, td, false); in xhci_invalidate_cancelled_tds()
930 * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain
933 static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_stop_ep() argument
945 if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) { in xhci_handle_cmd_stop_ep()
946 if (!xhci->devs[slot_id]) in xhci_handle_cmd_stop_ep()
947 xhci_warn(xhci, "Stop endpoint command " in xhci_handle_cmd_stop_ep()
954 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_stop_ep()
956 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
960 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_stop_ep()
961 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_handle_cmd_stop_ep()
964 last_unlinked_td = list_last_entry(&ep->cancelled_td_list, in xhci_handle_cmd_stop_ep()
967 if (list_empty(&ep->cancelled_td_list)) { in xhci_handle_cmd_stop_ep()
968 xhci_stop_watchdog_timer_in_irq(xhci, ep); in xhci_handle_cmd_stop_ep()
969 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
975 xhci_stop_watchdog_timer_in_irq(xhci, ep); in xhci_handle_cmd_stop_ep()
979 xhci_queue_new_dequeue_state(xhci, slot_id, ep_index, in xhci_handle_cmd_stop_ep()
981 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_stop_ep()
984 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
994 cur_td = list_first_entry(&ep->cancelled_td_list, in xhci_handle_cmd_stop_ep()
996 list_del_init(&cur_td->cancelled_td_list); in xhci_handle_cmd_stop_ep()
1002 ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb); in xhci_handle_cmd_stop_ep()
1003 xhci_unmap_td_bounce_buffer(xhci, ep_ring, cur_td); in xhci_handle_cmd_stop_ep()
1004 inc_td_cnt(cur_td->urb); in xhci_handle_cmd_stop_ep()
1006 xhci_giveback_urb_in_irq(xhci, cur_td, 0); in xhci_handle_cmd_stop_ep()
1011 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_handle_cmd_stop_ep()
1015 /* Return to the event handler with xhci->lock re-acquired */ in xhci_handle_cmd_stop_ep()
1018 static void xhci_kill_ring_urbs(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_kill_ring_urbs() argument
1023 list_for_each_entry_safe(cur_td, tmp, &ring->td_list, td_list) { in xhci_kill_ring_urbs()
1024 list_del_init(&cur_td->td_list); in xhci_kill_ring_urbs()
1026 if (!list_empty(&cur_td->cancelled_td_list)) in xhci_kill_ring_urbs()
1027 list_del_init(&cur_td->cancelled_td_list); in xhci_kill_ring_urbs()
1029 xhci_unmap_td_bounce_buffer(xhci, ring, cur_td); in xhci_kill_ring_urbs()
1031 inc_td_cnt(cur_td->urb); in xhci_kill_ring_urbs()
1033 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_ring_urbs()
1037 static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, in xhci_kill_endpoint_urbs() argument
1045 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_kill_endpoint_urbs()
1049 if ((ep->ep_state & EP_HAS_STREAMS) || in xhci_kill_endpoint_urbs()
1050 (ep->ep_state & EP_GETTING_NO_STREAMS)) { in xhci_kill_endpoint_urbs()
1053 for (stream_id = 1; stream_id < ep->stream_info->num_streams; in xhci_kill_endpoint_urbs()
1055 ring = ep->stream_info->stream_rings[stream_id]; in xhci_kill_endpoint_urbs()
1059 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1062 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1065 ring = ep->ring; in xhci_kill_endpoint_urbs()
1068 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1071 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1074 list_for_each_entry_safe(cur_td, tmp, &ep->cancelled_td_list, in xhci_kill_endpoint_urbs()
1076 list_del_init(&cur_td->cancelled_td_list); in xhci_kill_endpoint_urbs()
1077 inc_td_cnt(cur_td->urb); in xhci_kill_endpoint_urbs()
1080 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_endpoint_urbs()
1090 * Call with xhci->lock held.
1091 * lock is relased and re-acquired while giving back urb.
1093 void xhci_hc_died(struct xhci_hcd *xhci) in xhci_hc_died() argument
1097 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_hc_died()
1100 xhci_err(xhci, "xHCI host controller not responding, assume dead\n"); in xhci_hc_died()
1101 xhci->xhc_state |= XHCI_STATE_DYING; in xhci_hc_died()
1103 xhci_cleanup_command_queue(xhci); in xhci_hc_died()
1106 for (i = 0; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_hc_died()
1107 if (!xhci->devs[i]) in xhci_hc_died()
1110 xhci_kill_endpoint_urbs(xhci, i, j); in xhci_hc_died()
1114 if (!(xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_hc_died()
1115 usb_hc_died(xhci_to_hcd(xhci)); in xhci_hc_died()
1122 * through xhci->state.
1138 struct xhci_hcd *xhci = ep->xhci; in xhci_stop_endpoint_command_watchdog() local
1143 spin_lock_irqsave(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
1146 if (!(ep->ep_state & EP_STOP_CMD_PENDING) || in xhci_stop_endpoint_command_watchdog()
1147 timer_pending(&ep->stop_cmd_timer)) { in xhci_stop_endpoint_command_watchdog()
1148 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
1149 xhci_dbg(xhci, "Stop EP timer raced with cmd completion, exit"); in xhci_stop_endpoint_command_watchdog()
1152 usbsts = readl(&xhci->op_regs->status); in xhci_stop_endpoint_command_watchdog()
1154 xhci_warn(xhci, "xHCI host not responding to stop endpoint command.\n"); in xhci_stop_endpoint_command_watchdog()
1155 xhci_warn(xhci, "USBSTS:%s\n", xhci_decode_usbsts(str, usbsts)); in xhci_stop_endpoint_command_watchdog()
1157 ep->ep_state &= ~EP_STOP_CMD_PENDING; in xhci_stop_endpoint_command_watchdog()
1159 xhci_halt(xhci); in xhci_stop_endpoint_command_watchdog()
1162 * handle a stop endpoint cmd timeout as if host died (-ENODEV). in xhci_stop_endpoint_command_watchdog()
1163 * In the future we could distinguish between -ENODEV and -ETIMEDOUT in xhci_stop_endpoint_command_watchdog()
1164 * and try to recover a -ETIMEDOUT with a host controller reset in xhci_stop_endpoint_command_watchdog()
1166 xhci_hc_died(xhci); in xhci_stop_endpoint_command_watchdog()
1168 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
1169 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_stop_endpoint_command_watchdog()
1170 "xHCI host controller is dead."); in xhci_stop_endpoint_command_watchdog()
1173 static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci, in update_ring_for_set_deq_completion() argument
1182 num_trbs_free_temp = ep_ring->num_trbs_free; in update_ring_for_set_deq_completion()
1183 dequeue_temp = ep_ring->dequeue; in update_ring_for_set_deq_completion()
1185 /* If we get two back-to-back stalls, and the first stalled transfer in update_ring_for_set_deq_completion()
1189 * the segment into la-la-land. in update_ring_for_set_deq_completion()
1191 if (trb_is_link(ep_ring->dequeue)) { in update_ring_for_set_deq_completion()
1192 ep_ring->deq_seg = ep_ring->deq_seg->next; in update_ring_for_set_deq_completion()
1193 ep_ring->dequeue = ep_ring->deq_seg->trbs; in update_ring_for_set_deq_completion()
1196 while (ep_ring->dequeue != dev->eps[ep_index].queued_deq_ptr) { in update_ring_for_set_deq_completion()
1198 ep_ring->num_trbs_free++; in update_ring_for_set_deq_completion()
1199 ep_ring->dequeue++; in update_ring_for_set_deq_completion()
1200 if (trb_is_link(ep_ring->dequeue)) { in update_ring_for_set_deq_completion()
1201 if (ep_ring->dequeue == in update_ring_for_set_deq_completion()
1202 dev->eps[ep_index].queued_deq_ptr) in update_ring_for_set_deq_completion()
1204 ep_ring->deq_seg = ep_ring->deq_seg->next; in update_ring_for_set_deq_completion()
1205 ep_ring->dequeue = ep_ring->deq_seg->trbs; in update_ring_for_set_deq_completion()
1207 if (ep_ring->dequeue == dequeue_temp) { in update_ring_for_set_deq_completion()
1214 xhci_dbg(xhci, "Unable to find new dequeue pointer\n"); in update_ring_for_set_deq_completion()
1215 ep_ring->num_trbs_free = num_trbs_free_temp; in update_ring_for_set_deq_completion()
1226 static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_set_deq() argument
1237 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_set_deq()
1238 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); in xhci_handle_cmd_set_deq()
1239 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1243 dev = xhci->devs[slot_id]; in xhci_handle_cmd_set_deq()
1246 xhci_warn(xhci, "WARN Set TR deq ptr command for freed stream ID %u\n", in xhci_handle_cmd_set_deq()
1252 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); in xhci_handle_cmd_set_deq()
1253 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); in xhci_handle_cmd_set_deq()
1263 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because of stream ID configuration\n"); in xhci_handle_cmd_set_deq()
1266 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.\n"); in xhci_handle_cmd_set_deq()
1268 slot_state = le32_to_cpu(slot_ctx->dev_state); in xhci_handle_cmd_set_deq()
1270 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1275 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed because slot %u was not enabled.\n", in xhci_handle_cmd_set_deq()
1279 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown completion code of %u.\n", in xhci_handle_cmd_set_deq()
1292 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_handle_cmd_set_deq()
1294 &ep->stream_info->stream_ctx_array[stream_id]; in xhci_handle_cmd_set_deq()
1295 deq = le64_to_cpu(ctx->stream_ring) & SCTX_DEQ_MASK; in xhci_handle_cmd_set_deq()
1297 deq = le64_to_cpu(ep_ctx->deq) & ~EP_CTX_CYCLE_MASK; in xhci_handle_cmd_set_deq()
1299 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1301 if (xhci_trb_virt_to_dma(ep->queued_deq_seg, in xhci_handle_cmd_set_deq()
1302 ep->queued_deq_ptr) == deq) { in xhci_handle_cmd_set_deq()
1306 update_ring_for_set_deq_completion(xhci, dev, in xhci_handle_cmd_set_deq()
1309 xhci_warn(xhci, "Mismatch between completed Set TR Deq Ptr command & xHCI internal state.\n"); in xhci_handle_cmd_set_deq()
1310 xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n", in xhci_handle_cmd_set_deq()
1311 ep->queued_deq_seg, ep->queued_deq_ptr); in xhci_handle_cmd_set_deq()
1316 ep->ep_state &= ~SET_DEQ_PENDING; in xhci_handle_cmd_set_deq()
1317 ep->queued_deq_seg = NULL; in xhci_handle_cmd_set_deq()
1318 ep->queued_deq_ptr = NULL; in xhci_handle_cmd_set_deq()
1320 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1323 static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_ep() argument
1331 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); in xhci_handle_cmd_reset_ep()
1332 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1336 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_ep()
1337 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_handle_cmd_reset_ep()
1343 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, in xhci_handle_cmd_reset_ep()
1350 if (xhci->quirks & XHCI_RESET_EP_QUIRK) { in xhci_handle_cmd_reset_ep()
1353 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_handle_cmd_reset_ep()
1357 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_reset_ep()
1359 xhci_queue_configure_endpoint(xhci, command, in xhci_handle_cmd_reset_ep()
1360 xhci->devs[slot_id]->in_ctx->dma, slot_id, in xhci_handle_cmd_reset_ep()
1362 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_reset_ep()
1365 ep->ep_state &= ~EP_HALTED; in xhci_handle_cmd_reset_ep()
1369 if ((le32_to_cpu(trb->generic.field[3])) & TRB_TSP) in xhci_handle_cmd_reset_ep()
1370 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1373 static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_enable_slot() argument
1377 command->slot_id = slot_id; in xhci_handle_cmd_enable_slot()
1379 command->slot_id = 0; in xhci_handle_cmd_enable_slot()
1382 static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_disable_slot() argument
1387 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_disable_slot()
1391 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_handle_cmd_disable_slot()
1394 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) in xhci_handle_cmd_disable_slot()
1396 xhci_free_device_endpoint_resources(xhci, virt_dev, true); in xhci_handle_cmd_disable_slot()
1399 static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_config_ep() argument
1414 * If the command was for a halted endpoint, the xHCI driver in xhci_handle_cmd_config_ep()
1417 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_config_ep()
1418 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_handle_cmd_config_ep()
1420 xhci_warn(xhci, "Could not get input context, bad type.\n"); in xhci_handle_cmd_config_ep()
1424 add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_handle_cmd_config_ep()
1425 drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_handle_cmd_config_ep()
1427 ep_index = xhci_last_valid_endpoint(add_flags) - 1; in xhci_handle_cmd_config_ep()
1429 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, ep_index); in xhci_handle_cmd_config_ep()
1438 if (xhci->quirks & XHCI_RESET_EP_QUIRK && in xhci_handle_cmd_config_ep()
1439 ep_index != (unsigned int) -1 && in xhci_handle_cmd_config_ep()
1440 add_flags - SLOT_FLAG == drop_flags) { in xhci_handle_cmd_config_ep()
1441 ep_state = virt_dev->eps[ep_index].ep_state; in xhci_handle_cmd_config_ep()
1444 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_config_ep()
1445 "Completed config ep cmd - " in xhci_handle_cmd_config_ep()
1449 virt_dev->eps[ep_index].ep_state &= ~EP_HALTED; in xhci_handle_cmd_config_ep()
1450 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_config_ep()
1456 static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_addr_dev() argument
1461 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_addr_dev()
1462 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_addr_dev()
1466 static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_dev() argument
1472 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_dev()
1473 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_reset_dev()
1476 xhci_dbg(xhci, "Completed reset device command.\n"); in xhci_handle_cmd_reset_dev()
1477 if (!xhci->devs[slot_id]) in xhci_handle_cmd_reset_dev()
1478 xhci_warn(xhci, "Reset device command completion " in xhci_handle_cmd_reset_dev()
1482 static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, in xhci_handle_cmd_nec_get_fw() argument
1485 if (!(xhci->quirks & XHCI_NEC_HOST)) { in xhci_handle_cmd_nec_get_fw()
1486 xhci_warn(xhci, "WARN NEC_GET_FW command on non-NEC host\n"); in xhci_handle_cmd_nec_get_fw()
1489 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_nec_get_fw()
1491 NEC_FW_MAJOR(le32_to_cpu(event->status)), in xhci_handle_cmd_nec_get_fw()
1492 NEC_FW_MINOR(le32_to_cpu(event->status))); in xhci_handle_cmd_nec_get_fw()
1497 list_del(&cmd->cmd_list); in xhci_complete_del_and_free_cmd()
1499 if (cmd->completion) { in xhci_complete_del_and_free_cmd()
1500 cmd->status = status; in xhci_complete_del_and_free_cmd()
1501 complete(cmd->completion); in xhci_complete_del_and_free_cmd()
1507 void xhci_cleanup_command_queue(struct xhci_hcd *xhci) in xhci_cleanup_command_queue() argument
1510 xhci->current_cmd = NULL; in xhci_cleanup_command_queue()
1511 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) in xhci_cleanup_command_queue()
1517 struct xhci_hcd *xhci; in xhci_handle_command_timeout() local
1521 xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer); in xhci_handle_command_timeout()
1523 spin_lock_irqsave(&xhci->lock, flags); in xhci_handle_command_timeout()
1529 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { in xhci_handle_command_timeout()
1530 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1534 xhci->current_cmd->status = COMP_COMMAND_ABORTED; in xhci_handle_command_timeout()
1537 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_handle_command_timeout()
1539 xhci_hc_died(xhci); in xhci_handle_command_timeout()
1543 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && in xhci_handle_command_timeout()
1546 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; in xhci_handle_command_timeout()
1547 xhci_dbg(xhci, "Command timeout\n"); in xhci_handle_command_timeout()
1548 xhci_abort_cmd_ring(xhci, flags); in xhci_handle_command_timeout()
1553 if (xhci->xhc_state & XHCI_STATE_REMOVING) { in xhci_handle_command_timeout()
1554 xhci_dbg(xhci, "host removed, ring start fail?\n"); in xhci_handle_command_timeout()
1555 xhci_cleanup_command_queue(xhci); in xhci_handle_command_timeout()
1561 xhci_dbg(xhci, "Command timeout on stopped ring\n"); in xhci_handle_command_timeout()
1562 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); in xhci_handle_command_timeout()
1565 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1569 static void handle_cmd_completion(struct xhci_hcd *xhci, in handle_cmd_completion() argument
1572 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); in handle_cmd_completion()
1580 cmd_dma = le64_to_cpu(event->cmd_trb); in handle_cmd_completion()
1581 cmd_trb = xhci->cmd_ring->dequeue; in handle_cmd_completion()
1583 trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic); in handle_cmd_completion()
1585 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in handle_cmd_completion()
1592 xhci_warn(xhci, in handle_cmd_completion()
1597 cmd = list_first_entry(&xhci->cmd_list, struct xhci_command, cmd_list); in handle_cmd_completion()
1599 cancel_delayed_work(&xhci->cmd_timer); in handle_cmd_completion()
1601 cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status)); in handle_cmd_completion()
1605 complete_all(&xhci->cmd_ring_stop_completion); in handle_cmd_completion()
1609 if (cmd->command_trb != xhci->cmd_ring->dequeue) { in handle_cmd_completion()
1610 xhci_err(xhci, in handle_cmd_completion()
1622 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in handle_cmd_completion()
1623 if (cmd->status == COMP_COMMAND_ABORTED) { in handle_cmd_completion()
1624 if (xhci->current_cmd == cmd) in handle_cmd_completion()
1625 xhci->current_cmd = NULL; in handle_cmd_completion()
1630 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); in handle_cmd_completion()
1633 xhci_handle_cmd_enable_slot(xhci, slot_id, cmd, cmd_comp_code); in handle_cmd_completion()
1636 xhci_handle_cmd_disable_slot(xhci, slot_id); in handle_cmd_completion()
1639 if (!cmd->completion) in handle_cmd_completion()
1640 xhci_handle_cmd_config_ep(xhci, slot_id, event, in handle_cmd_completion()
1646 xhci_handle_cmd_addr_dev(xhci, slot_id); in handle_cmd_completion()
1650 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1651 if (!cmd->completion) in handle_cmd_completion()
1652 xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, event); in handle_cmd_completion()
1656 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1657 xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1660 /* Is this an aborted command turned to NO-OP? */ in handle_cmd_completion()
1661 if (cmd->status == COMP_COMMAND_RING_STOPPED) in handle_cmd_completion()
1666 le32_to_cpu(cmd_trb->generic.field[3]))); in handle_cmd_completion()
1667 xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1671 * Use the SLOT_ID from the command TRB instead (xhci 4.6.11) in handle_cmd_completion()
1674 le32_to_cpu(cmd_trb->generic.field[3])); in handle_cmd_completion()
1675 xhci_handle_cmd_reset_dev(xhci, slot_id, event); in handle_cmd_completion()
1678 xhci_handle_cmd_nec_get_fw(xhci, event); in handle_cmd_completion()
1682 xhci_info(xhci, "INFO unknown command type %d\n", cmd_type); in handle_cmd_completion()
1687 if (!list_is_singular(&xhci->cmd_list)) { in handle_cmd_completion()
1688 xhci->current_cmd = list_first_entry(&cmd->cmd_list, in handle_cmd_completion()
1690 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in handle_cmd_completion()
1691 } else if (xhci->current_cmd == cmd) { in handle_cmd_completion()
1692 xhci->current_cmd = NULL; in handle_cmd_completion()
1698 inc_deq(xhci, xhci->cmd_ring); in handle_cmd_completion()
1701 static void handle_vendor_event(struct xhci_hcd *xhci, in handle_vendor_event() argument
1706 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(event->generic.field[3])); in handle_vendor_event()
1707 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type); in handle_vendor_event()
1708 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) in handle_vendor_event()
1709 handle_cmd_completion(xhci, &event->event_cmd); in handle_vendor_event()
1712 static void handle_device_notification(struct xhci_hcd *xhci, in handle_device_notification() argument
1718 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->generic.field[3])); in handle_device_notification()
1719 if (!xhci->devs[slot_id]) { in handle_device_notification()
1720 xhci_warn(xhci, "Device Notification event for " in handle_device_notification()
1725 xhci_dbg(xhci, "Device Wake Notification event for slot ID %u\n", in handle_device_notification()
1727 udev = xhci->devs[slot_id]->udev; in handle_device_notification()
1728 if (udev && udev->parent) in handle_device_notification()
1729 usb_wakeup_notification(udev->parent, udev->portnum); in handle_device_notification()
1733 * Quirk hanlder for errata seen on Cavium ThunderX2 processor XHCI
1735 * As per ThunderX2errata-129 USB 2 device may come up as USB 1
1744 static void xhci_cavium_reset_phy_quirk(struct xhci_hcd *xhci) in xhci_cavium_reset_phy_quirk() argument
1746 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_cavium_reset_phy_quirk()
1752 writel(0x6F, hcd->regs + 0x1048); in xhci_cavium_reset_phy_quirk()
1754 /* De-assert the PHY reset */ in xhci_cavium_reset_phy_quirk()
1755 writel(0x7F, hcd->regs + 0x1048); in xhci_cavium_reset_phy_quirk()
1757 pll_lock_check = readl(hcd->regs + 0x1070); in xhci_cavium_reset_phy_quirk()
1758 } while (!(pll_lock_check & 0x1) && --retry_count); in xhci_cavium_reset_phy_quirk()
1761 static void handle_port_status(struct xhci_hcd *xhci, in handle_port_status() argument
1775 if (GET_COMP_CODE(le32_to_cpu(event->generic.field[2])) != COMP_SUCCESS) in handle_port_status()
1776 xhci_warn(xhci, in handle_port_status()
1779 port_id = GET_PORT_ID(le32_to_cpu(event->generic.field[0])); in handle_port_status()
1780 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); in handle_port_status()
1783 xhci_warn(xhci, "Port change event with invalid port ID %d\n", in handle_port_status()
1785 inc_deq(xhci, xhci->event_ring); in handle_port_status()
1789 port = &xhci->hw_ports[port_id - 1]; in handle_port_status()
1790 if (!port || !port->rhub || port->hcd_portnum == DUPLICATE_ENTRY) { in handle_port_status()
1791 xhci_warn(xhci, "Port change event, no port for port ID %u\n", in handle_port_status()
1798 if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) { in handle_port_status()
1799 xhci_dbg(xhci, "ignore port event for removed USB3 hcd\n"); in handle_port_status()
1804 hcd = port->rhub->hcd; in handle_port_status()
1805 bus_state = &port->rhub->bus_state; in handle_port_status()
1806 hcd_portnum = port->hcd_portnum; in handle_port_status()
1807 portsc = readl(port->addr); in handle_port_status()
1809 xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n", in handle_port_status()
1810 hcd->self.busnum, hcd_portnum + 1, port_id, portsc); in handle_port_status()
1814 if (hcd->state == HC_STATE_SUSPENDED) { in handle_port_status()
1815 xhci_dbg(xhci, "resume root hub\n"); in handle_port_status()
1819 if (hcd->speed >= HCD_USB3 && in handle_port_status()
1821 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
1822 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
1823 xhci->devs[slot_id]->flags |= VDEV_PORT_ERROR; in handle_port_status()
1827 xhci_dbg(xhci, "port resume event for port %d\n", port_id); in handle_port_status()
1829 cmd_reg = readl(&xhci->op_regs->command); in handle_port_status()
1831 xhci_warn(xhci, "xHC is not running.\n"); in handle_port_status()
1836 xhci_dbg(xhci, "remote wake SS port %d\n", port_id); in handle_port_status()
1841 bus_state->port_remote_wakeup |= 1 << hcd_portnum; in handle_port_status()
1842 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1843 usb_hcd_start_port_resume(&hcd->self, hcd_portnum); in handle_port_status()
1844 xhci_set_link_state(xhci, port, XDEV_U0); in handle_port_status()
1850 } else if (!test_bit(hcd_portnum, &bus_state->resuming_ports)) { in handle_port_status()
1851 xhci_dbg(xhci, "resume HS port %d\n", port_id); in handle_port_status()
1852 port->resume_timestamp = jiffies + in handle_port_status()
1854 set_bit(hcd_portnum, &bus_state->resuming_ports); in handle_port_status()
1857 * usb device auto-resume latency around ~40ms. in handle_port_status()
1859 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in handle_port_status()
1860 mod_timer(&hcd->rh_timer, in handle_port_status()
1861 port->resume_timestamp); in handle_port_status()
1862 usb_hcd_start_port_resume(&hcd->self, hcd_portnum); in handle_port_status()
1872 xhci_dbg(xhci, "resume SS port %d finished\n", port_id); in handle_port_status()
1873 complete(&port->u3exit_done); in handle_port_status()
1876 * U3Exit state after a host-initiated resume. If it's a device in handle_port_status()
1881 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
1882 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
1883 xhci_ring_device(xhci, slot_id); in handle_port_status()
1884 if (bus_state->port_remote_wakeup & (1 << hcd_portnum)) { in handle_port_status()
1885 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1886 usb_wakeup_notification(hcd->self.root_hub, in handle_port_status()
1894 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or in handle_port_status()
1898 if (hcd->speed < HCD_USB3 && port->rexit_active) { in handle_port_status()
1899 complete(&port->rexit_done); in handle_port_status()
1900 port->rexit_active = false; in handle_port_status()
1905 if (hcd->speed < HCD_USB3) { in handle_port_status()
1906 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1907 if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) && in handle_port_status()
1909 xhci_cavium_reset_phy_quirk(xhci); in handle_port_status()
1914 inc_deq(xhci, xhci->event_ring); in handle_port_status()
1924 * xHCI port-status-change events occur when the "or" of all the in handle_port_status()
1925 * status-change bits in the portsc register changes from 0 to 1. in handle_port_status()
1930 xhci_dbg(xhci, "%s: starting port polling.\n", __func__); in handle_port_status()
1931 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in handle_port_status()
1932 spin_unlock(&xhci->lock); in handle_port_status()
1935 spin_lock(&xhci->lock); in handle_port_status()
1944 struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, in trb_in_td() argument
1964 &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); in trb_in_td()
1969 xhci_warn(xhci, in trb_in_td()
1970 …"Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx… in trb_in_td()
1974 (unsigned long long)cur_seg->dma, in trb_in_td()
1988 (suspect_dma >= cur_seg->dma && in trb_in_td()
1998 cur_seg = cur_seg->next; in trb_in_td()
1999 start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]); in trb_in_td()
2005 static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_clear_hub_tt_buffer() argument
2009 * As part of low/full-speed endpoint-halt processing in xhci_clear_hub_tt_buffer()
2012 if (td->urb->dev->tt && !usb_pipeint(td->urb->pipe) && in xhci_clear_hub_tt_buffer()
2013 (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && in xhci_clear_hub_tt_buffer()
2014 !(ep->ep_state & EP_CLEARING_TT)) { in xhci_clear_hub_tt_buffer()
2015 ep->ep_state |= EP_CLEARING_TT; in xhci_clear_hub_tt_buffer()
2016 td->urb->ep->hcpriv = td->urb->dev; in xhci_clear_hub_tt_buffer()
2017 if (usb_hub_clear_tt_buffer(td->urb)) in xhci_clear_hub_tt_buffer()
2018 ep->ep_state &= ~EP_CLEARING_TT; in xhci_clear_hub_tt_buffer()
2023 * cleanup the halt for a non-default control endpoint if we indicate a stall.
2028 static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci, in xhci_requires_manual_halt_cleanup() argument
2048 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) in xhci_is_vendor_info_code() argument
2052 * treat as not-an-error. in xhci_is_vendor_info_code()
2054 xhci_dbg(xhci, "Vendor defined info completion code %u\n", in xhci_is_vendor_info_code()
2056 xhci_dbg(xhci, "Treating code as success.\n"); in xhci_is_vendor_info_code()
2062 static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in finish_td() argument
2068 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in finish_td()
2080 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in finish_td()
2083 * xhci internal endpoint state will go to a "halt" state for in finish_td()
2092 if ((ep->ep_index != 0) || (trb_comp_code != COMP_STALL_ERROR)) in finish_td()
2093 xhci_clear_hub_tt_buffer(xhci, td, ep); in finish_td()
2095 xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td, in finish_td()
2099 ep_ring->dequeue = td->last_trb; in finish_td()
2100 ep_ring->deq_seg = td->last_trb_seg; in finish_td()
2101 ep_ring->num_trbs_free += td->num_trbs - 1; in finish_td()
2102 inc_deq(xhci, ep_ring); in finish_td()
2105 return xhci_td_cleanup(xhci, td, ep_ring, td->status); in finish_td()
2109 static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring, in sum_trb_lengths() argument
2113 union xhci_trb *trb = ring->dequeue; in sum_trb_lengths()
2114 struct xhci_segment *seg = ring->deq_seg; in sum_trb_lengths()
2116 for (sum = 0; trb != stop_trb; next_trb(xhci, ring, &seg, &trb)) { in sum_trb_lengths()
2118 sum += TRB_LEN(le32_to_cpu(trb->generic.field[2])); in sum_trb_lengths()
2126 static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_ctrl_td() argument
2135 trb_type = TRB_FIELD_TO_TYPE(le32_to_cpu(ep_trb->generic.field[3])); in process_ctrl_td()
2136 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in process_ctrl_td()
2137 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_ctrl_td()
2138 requested = td->urb->transfer_buffer_length; in process_ctrl_td()
2139 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_ctrl_td()
2144 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n", in process_ctrl_td()
2146 td->status = -ESHUTDOWN; in process_ctrl_td()
2149 td->status = 0; in process_ctrl_td()
2152 td->status = 0; in process_ctrl_td()
2156 td->urb->actual_length = remaining; in process_ctrl_td()
2158 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); in process_ctrl_td()
2163 td->urb->actual_length = 0; in process_ctrl_td()
2167 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2170 td->urb->actual_length = requested; in process_ctrl_td()
2173 xhci_warn(xhci, "WARN: unexpected TRB Type %d\n", in process_ctrl_td()
2180 if (!xhci_requires_manual_halt_cleanup(xhci, in process_ctrl_td()
2183 xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n", in process_ctrl_td()
2184 trb_comp_code, ep->ep_index); in process_ctrl_td()
2189 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2190 else if (!td->urb_length_set) in process_ctrl_td()
2191 td->urb->actual_length = 0; in process_ctrl_td()
2205 td->urb_length_set = true; in process_ctrl_td()
2206 td->urb->actual_length = requested - remaining; in process_ctrl_td()
2207 xhci_dbg(xhci, "Waiting for status stage event\n"); in process_ctrl_td()
2212 if (!td->urb_length_set) in process_ctrl_td()
2213 td->urb->actual_length = requested; in process_ctrl_td()
2216 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_ctrl_td()
2222 static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_isoc_td() argument
2234 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_isoc_td()
2235 urb_priv = td->urb->hcpriv; in process_isoc_td()
2236 idx = urb_priv->num_tds_done; in process_isoc_td()
2237 frame = &td->urb->iso_frame_desc[idx]; in process_isoc_td()
2238 requested = frame->length; in process_isoc_td()
2239 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_isoc_td()
2240 ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2])); in process_isoc_td()
2241 short_framestatus = td->urb->transfer_flags & URB_SHORT_NOT_OK ? in process_isoc_td()
2242 -EREMOTEIO : 0; in process_isoc_td()
2247 /* Don't overwrite status if TD had an error, see xHCI 4.9.1 */ in process_isoc_td()
2248 if (td->error_mid_td) in process_isoc_td()
2251 frame->status = short_framestatus; in process_isoc_td()
2252 if (xhci->quirks & XHCI_TRUST_TX_LENGTH) in process_isoc_td()
2256 frame->status = 0; in process_isoc_td()
2259 frame->status = short_framestatus; in process_isoc_td()
2263 frame->status = -ECOMM; in process_isoc_td()
2269 frame->status = -EOVERFLOW; in process_isoc_td()
2270 if (ep_trb != td->last_trb) in process_isoc_td()
2271 td->error_mid_td = true; in process_isoc_td()
2275 frame->status = -EPROTO; in process_isoc_td()
2278 frame->status = -EPROTO; in process_isoc_td()
2280 if (ep_trb != td->last_trb) in process_isoc_td()
2281 td->error_mid_td = true; in process_isoc_td()
2288 frame->status = short_framestatus; in process_isoc_td()
2297 frame->status = -1; in process_isoc_td()
2301 if (td->urb_length_set) in process_isoc_td()
2305 frame->actual_length = sum_trb_lengths(xhci, ep->ring, ep_trb) + in process_isoc_td()
2306 ep_trb_len - remaining; in process_isoc_td()
2308 frame->actual_length = requested; in process_isoc_td()
2310 td->urb->actual_length += frame->actual_length; in process_isoc_td()
2314 if (td->error_mid_td && ep_trb != td->last_trb) { in process_isoc_td()
2315 xhci_dbg(xhci, "Error mid isoc TD, wait for final completion event\n"); in process_isoc_td()
2316 td->urb_length_set = true; in process_isoc_td()
2320 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_isoc_td()
2323 static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, in skip_isoc_td() argument
2330 urb_priv = td->urb->hcpriv; in skip_isoc_td()
2331 idx = urb_priv->num_tds_done; in skip_isoc_td()
2332 frame = &td->urb->iso_frame_desc[idx]; in skip_isoc_td()
2335 frame->status = -EXDEV; in skip_isoc_td()
2338 frame->actual_length = 0; in skip_isoc_td()
2341 ep->ring->dequeue = td->last_trb; in skip_isoc_td()
2342 ep->ring->deq_seg = td->last_trb_seg; in skip_isoc_td()
2343 ep->ring->num_trbs_free += td->num_trbs - 1; in skip_isoc_td()
2344 inc_deq(xhci, ep->ring); in skip_isoc_td()
2346 return xhci_td_cleanup(xhci, td, ep->ring, status); in skip_isoc_td()
2352 static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_bulk_intr_td() argument
2360 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in process_bulk_intr_td()
2361 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in process_bulk_intr_td()
2362 remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); in process_bulk_intr_td()
2363 ep_trb_len = TRB_LEN(le32_to_cpu(ep_trb->generic.field[2])); in process_bulk_intr_td()
2364 requested = td->urb->transfer_buffer_length; in process_bulk_intr_td()
2368 ep->err_count = 0; in process_bulk_intr_td()
2370 if (ep_trb != td->last_trb || remaining) { in process_bulk_intr_td()
2371 xhci_warn(xhci, "WARN Successful completion on short TX\n"); in process_bulk_intr_td()
2372 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2373 td->urb->ep->desc.bEndpointAddress, in process_bulk_intr_td()
2376 td->status = 0; in process_bulk_intr_td()
2379 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2380 td->urb->ep->desc.bEndpointAddress, in process_bulk_intr_td()
2382 td->status = 0; in process_bulk_intr_td()
2385 td->urb->actual_length = remaining; in process_bulk_intr_td()
2393 if (xhci->quirks & XHCI_NO_SOFT_RETRY || in process_bulk_intr_td()
2394 (ep->err_count++ > MAX_SOFT_RETRY) || in process_bulk_intr_td()
2395 le32_to_cpu(slot_ctx->tt_info) & TT_SLOT) in process_bulk_intr_td()
2398 td->status = 0; in process_bulk_intr_td()
2400 xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td, in process_bulk_intr_td()
2408 if (ep_trb == td->last_trb) in process_bulk_intr_td()
2409 td->urb->actual_length = requested - remaining; in process_bulk_intr_td()
2411 td->urb->actual_length = in process_bulk_intr_td()
2412 sum_trb_lengths(xhci, ep_ring, ep_trb) + in process_bulk_intr_td()
2413 ep_trb_len - remaining; in process_bulk_intr_td()
2416 xhci_warn(xhci, "bad transfer trb length %d in event trb\n", in process_bulk_intr_td()
2418 td->urb->actual_length = 0; in process_bulk_intr_td()
2421 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_bulk_intr_td()
2429 static int handle_tx_event(struct xhci_hcd *xhci, in handle_tx_event() argument
2441 int status = -EINPROGRESS; in handle_tx_event()
2448 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); in handle_tx_event()
2449 ep_index = TRB_TO_EP_ID(le32_to_cpu(event->flags)) - 1; in handle_tx_event()
2450 trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); in handle_tx_event()
2451 ep_trb_dma = le64_to_cpu(event->buffer); in handle_tx_event()
2453 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in handle_tx_event()
2455 xhci_err(xhci, "ERROR Invalid Transfer event\n"); in handle_tx_event()
2459 xdev = xhci->devs[slot_id]; in handle_tx_event()
2461 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in handle_tx_event()
2464 xhci_err(xhci, in handle_tx_event()
2470 /* Some transfer events don't always point to a trb, see xhci 4.17.4 */ in handle_tx_event()
2477 xhci_dbg(xhci, "Stream transaction error ep %u no id\n", in handle_tx_event()
2479 if (ep->err_count++ > MAX_SOFT_RETRY) in handle_tx_event()
2480 xhci_handle_halted_endpoint(xhci, ep, 0, NULL, in handle_tx_event()
2483 xhci_handle_halted_endpoint(xhci, ep, 0, NULL, in handle_tx_event()
2491 xhci_err(xhci, "ERROR Transfer event for unknown stream ring slot %u ep %u\n", in handle_tx_event()
2497 /* Count current td numbers if ep->skip is set */ in handle_tx_event()
2498 if (ep->skip) { in handle_tx_event()
2499 list_for_each(tmp, &ep_ring->td_list) in handle_tx_event()
2509 if (EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) in handle_tx_event()
2511 if (xhci->quirks & XHCI_TRUST_TX_LENGTH || in handle_tx_event()
2512 ep_ring->last_td_was_short) in handle_tx_event()
2515 xhci_warn_ratelimited(xhci, in handle_tx_event()
2522 xhci_dbg(xhci, "Stopped on Transfer TRB for slot %u ep %u\n", in handle_tx_event()
2526 xhci_dbg(xhci, in handle_tx_event()
2527 "Stopped on No-op or Link TRB for slot %u ep %u\n", in handle_tx_event()
2531 xhci_dbg(xhci, in handle_tx_event()
2537 xhci_dbg(xhci, "Stalled endpoint for slot %u ep %u\n", slot_id, in handle_tx_event()
2539 ep->ep_state |= EP_HALTED; in handle_tx_event()
2540 status = -EPIPE; in handle_tx_event()
2543 xhci_dbg(xhci, "Split transaction error for slot %u ep %u\n", in handle_tx_event()
2545 status = -EPROTO; in handle_tx_event()
2548 xhci_dbg(xhci, "Transfer error for slot %u ep %u on endpoint\n", in handle_tx_event()
2550 status = -EPROTO; in handle_tx_event()
2553 xhci_dbg(xhci, "Babble error for slot %u ep %u on endpoint\n", in handle_tx_event()
2555 status = -EOVERFLOW; in handle_tx_event()
2559 xhci_warn(xhci, in handle_tx_event()
2562 status = -EILSEQ; in handle_tx_event()
2566 xhci_warn(xhci, in handle_tx_event()
2569 status = -ENOSR; in handle_tx_event()
2572 xhci_warn(xhci, in handle_tx_event()
2577 xhci_warn(xhci, in handle_tx_event()
2587 xhci_dbg(xhci, "underrun event on endpoint\n"); in handle_tx_event()
2588 if (!list_empty(&ep_ring->td_list)) in handle_tx_event()
2589 xhci_dbg(xhci, "Underrun Event for slot %d ep %d " in handle_tx_event()
2591 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)), in handle_tx_event()
2595 xhci_dbg(xhci, "overrun event on endpoint\n"); in handle_tx_event()
2596 if (!list_empty(&ep_ring->td_list)) in handle_tx_event()
2597 xhci_dbg(xhci, "Overrun Event for slot %d ep %d " in handle_tx_event()
2599 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)), in handle_tx_event()
2609 ep->skip = true; in handle_tx_event()
2610 xhci_dbg(xhci, in handle_tx_event()
2615 ep->skip = true; in handle_tx_event()
2616 xhci_dbg(xhci, in handle_tx_event()
2623 xhci_warn(xhci, in handle_tx_event()
2626 status = -EPROTO; in handle_tx_event()
2629 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { in handle_tx_event()
2633 xhci_warn(xhci, in handle_tx_event()
2643 if (list_empty(&ep_ring->td_list)) { in handle_tx_event()
2654 ep_ring->last_td_was_short)) { in handle_tx_event()
2655 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n", in handle_tx_event()
2656 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)), in handle_tx_event()
2659 if (ep->skip) { in handle_tx_event()
2660 ep->skip = false; in handle_tx_event()
2661 xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2665 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
2667 xhci_handle_halted_endpoint(xhci, ep, in handle_tx_event()
2668 ep_ring->stream_id, in handle_tx_event()
2675 /* We've skipped all the TDs on the ep ring when ep->skip set */ in handle_tx_event()
2676 if (ep->skip && td_num == 0) { in handle_tx_event()
2677 ep->skip = false; in handle_tx_event()
2678 xhci_dbg(xhci, "All tds on the ep_ring skipped. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2683 td = list_first_entry(&ep_ring->td_list, struct xhci_td, in handle_tx_event()
2685 if (ep->skip) in handle_tx_event()
2686 td_num--; in handle_tx_event()
2689 ep_seg = trb_in_td(xhci, ep_ring->deq_seg, ep_ring->dequeue, in handle_tx_event()
2690 td->last_trb, ep_trb_dma, false); in handle_tx_event()
2694 * is not in the current TD pointed by ep_ring->dequeue because in handle_tx_event()
2707 if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { in handle_tx_event()
2708 skip_isoc_td(xhci, td, ep, status); in handle_tx_event()
2716 if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && in handle_tx_event()
2717 ep_ring->last_td_was_short) { in handle_tx_event()
2718 ep_ring->last_td_was_short = false; in handle_tx_event()
2723 * xhci 4.10.2 states isoc endpoints should continue in handle_tx_event()
2727 * xhci 4.9.1 states that if there are errors in mult-TRB in handle_tx_event()
2733 if (td->error_mid_td && in handle_tx_event()
2734 !list_is_last(&td->td_list, &ep_ring->td_list)) { in handle_tx_event()
2737 ep_seg = trb_in_td(xhci, td_next->start_seg, td_next->first_trb, in handle_tx_event()
2738 td_next->last_trb, ep_trb_dma, false); in handle_tx_event()
2741 xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); in handle_tx_event()
2742 ep_ring->dequeue = td->last_trb; in handle_tx_event()
2743 ep_ring->deq_seg = td->last_trb_seg; in handle_tx_event()
2744 inc_deq(xhci, ep_ring); in handle_tx_event()
2745 xhci_td_cleanup(xhci, td, ep_ring, td->status); in handle_tx_event()
2752 xhci_err(xhci, in handle_tx_event()
2757 trb_in_td(xhci, ep_ring->deq_seg, in handle_tx_event()
2758 ep_ring->dequeue, td->last_trb, in handle_tx_event()
2760 return -ESHUTDOWN; in handle_tx_event()
2764 ep_ring->last_td_was_short = true; in handle_tx_event()
2766 ep_ring->last_td_was_short = false; in handle_tx_event()
2768 if (ep->skip) { in handle_tx_event()
2769 xhci_dbg(xhci, in handle_tx_event()
2772 ep->skip = false; in handle_tx_event()
2775 ep_trb = &ep_seg->trbs[(ep_trb_dma - ep_seg->dma) / in handle_tx_event()
2782 * No-op TRB could trigger interrupts in a case where in handle_tx_event()
2791 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
2793 xhci_handle_halted_endpoint(xhci, ep, in handle_tx_event()
2794 ep_ring->stream_id, in handle_tx_event()
2799 td->status = status; in handle_tx_event()
2802 if (usb_endpoint_xfer_control(&td->urb->ep->desc)) in handle_tx_event()
2803 process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2804 else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) in handle_tx_event()
2805 process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2807 process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2809 handling_skipped_tds = ep->skip && in handle_tx_event()
2818 inc_deq(xhci, xhci->event_ring); in handle_tx_event()
2821 * If ep->skip is set, it means there are missed tds on the in handle_tx_event()
2831 xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n", in handle_tx_event()
2833 xhci->event_ring->deq_seg, in handle_tx_event()
2834 xhci->event_ring->dequeue), in handle_tx_event()
2835 lower_32_bits(le64_to_cpu(event->buffer)), in handle_tx_event()
2836 upper_32_bits(le64_to_cpu(event->buffer)), in handle_tx_event()
2837 le32_to_cpu(event->transfer_len), in handle_tx_event()
2838 le32_to_cpu(event->flags)); in handle_tx_event()
2839 return -ENODEV; in handle_tx_event()
2843 * This function handles all OS-owned events on the event ring. It may drop
2844 * xhci->lock between event processing (e.g. to pass up port status changes).
2848 static int xhci_handle_event(struct xhci_hcd *xhci) in xhci_handle_event() argument
2855 if (!xhci->event_ring || !xhci->event_ring->dequeue) { in xhci_handle_event()
2856 xhci_err(xhci, "ERROR event ring not ready\n"); in xhci_handle_event()
2857 return -ENOMEM; in xhci_handle_event()
2860 event = xhci->event_ring->dequeue; in xhci_handle_event()
2862 if ((le32_to_cpu(event->event_cmd.flags) & TRB_CYCLE) != in xhci_handle_event()
2863 xhci->event_ring->cycle_state) in xhci_handle_event()
2866 trace_xhci_handle_event(xhci->event_ring, &event->generic); in xhci_handle_event()
2874 switch (le32_to_cpu(event->event_cmd.flags) & TRB_TYPE_BITMASK) { in xhci_handle_event()
2876 handle_cmd_completion(xhci, &event->event_cmd); in xhci_handle_event()
2879 handle_port_status(xhci, event); in xhci_handle_event()
2883 ret = handle_tx_event(xhci, &event->trans_event); in xhci_handle_event()
2888 handle_device_notification(xhci, event); in xhci_handle_event()
2891 if ((le32_to_cpu(event->event_cmd.flags) & TRB_TYPE_BITMASK) >= in xhci_handle_event()
2893 handle_vendor_event(xhci, event); in xhci_handle_event()
2895 xhci_warn(xhci, "ERROR unknown event type %d\n", in xhci_handle_event()
2897 le32_to_cpu(event->event_cmd.flags))); in xhci_handle_event()
2899 /* Any of the above functions may drop and re-acquire the lock, so check in xhci_handle_event()
2900 * to make sure a watchdog timer didn't mark the host as non-responsive. in xhci_handle_event()
2902 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_handle_event()
2903 xhci_dbg(xhci, "xHCI host dying, returning from " in xhci_handle_event()
2910 inc_deq(xhci, xhci->event_ring); in xhci_handle_event()
2920 * - When all events have finished
2921 * - To avoid "Event Ring Full Error" condition
2923 static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, in xhci_update_erst_dequeue() argument
2929 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
2931 if (event_ring_deq != xhci->event_ring->dequeue) { in xhci_update_erst_dequeue()
2932 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, in xhci_update_erst_dequeue()
2933 xhci->event_ring->dequeue); in xhci_update_erst_dequeue()
2935 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); in xhci_update_erst_dequeue()
2951 xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
2955 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
2961 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_irq() local
2969 spin_lock_irqsave(&xhci->lock, flags); in xhci_irq()
2971 status = readl(&xhci->op_regs->status); in xhci_irq()
2973 xhci_hc_died(xhci); in xhci_irq()
2982 xhci_warn(xhci, "WARNING: Host System Error\n"); in xhci_irq()
2983 xhci_halt(xhci); in xhci_irq()
2990 * so we can receive interrupts from other MSI-X interrupters. in xhci_irq()
2994 writel(status, &xhci->op_regs->status); in xhci_irq()
2996 if (!hcd->msi_enabled) { in xhci_irq()
2998 irq_pending = readl(&xhci->ir_set->irq_pending); in xhci_irq()
3000 writel(irq_pending, &xhci->ir_set->irq_pending); in xhci_irq()
3003 if (xhci->xhc_state & XHCI_STATE_DYING || in xhci_irq()
3004 xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_irq()
3005 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " in xhci_irq()
3010 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_irq()
3011 xhci_write_64(xhci, temp_64 | ERST_EHB, in xhci_irq()
3012 &xhci->ir_set->erst_dequeue); in xhci_irq()
3017 event_ring_deq = xhci->event_ring->dequeue; in xhci_irq()
3021 while (xhci_handle_event(xhci) > 0) { in xhci_irq()
3024 xhci_update_erst_dequeue(xhci, event_ring_deq); in xhci_irq()
3025 event_ring_deq = xhci->event_ring->dequeue; in xhci_irq()
3030 xhci_update_erst_dequeue(xhci, event_ring_deq); in xhci_irq()
3034 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_irq()
3047 * Generic function for queueing a TRB on a ring.
3053 static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, in queue_trb() argument
3059 trb = &ring->enqueue->generic; in queue_trb()
3060 trb->field[0] = cpu_to_le32(field1); in queue_trb()
3061 trb->field[1] = cpu_to_le32(field2); in queue_trb()
3062 trb->field[2] = cpu_to_le32(field3); in queue_trb()
3065 trb->field[3] = cpu_to_le32(field4); in queue_trb()
3069 inc_enq(xhci, ring, more_trbs_coming); in queue_trb()
3076 static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in prepare_ring() argument
3088 xhci_warn(xhci, "WARN urb submitted to disabled ep\n"); in prepare_ring()
3089 return -ENOENT; in prepare_ring()
3091 xhci_warn(xhci, "WARN waiting for error on ep to be cleared\n"); in prepare_ring()
3093 /* XXX not sure if this should be -ENOENT or not */ in prepare_ring()
3094 return -EINVAL; in prepare_ring()
3096 xhci_dbg(xhci, "WARN halted endpoint, queueing URB anyway.\n"); in prepare_ring()
3101 xhci_err(xhci, "ERROR unknown endpoint state for ep\n"); in prepare_ring()
3106 return -EINVAL; in prepare_ring()
3110 if (room_on_ring(xhci, ep_ring, num_trbs)) in prepare_ring()
3113 if (ep_ring == xhci->cmd_ring) { in prepare_ring()
3114 xhci_err(xhci, "Do not support expand command ring\n"); in prepare_ring()
3115 return -ENOMEM; in prepare_ring()
3118 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, in prepare_ring()
3120 num_trbs_needed = num_trbs - ep_ring->num_trbs_free; in prepare_ring()
3121 if (xhci_ring_expansion(xhci, ep_ring, num_trbs_needed, in prepare_ring()
3123 xhci_err(xhci, "Ring expansion failed\n"); in prepare_ring()
3124 return -ENOMEM; in prepare_ring()
3128 while (trb_is_link(ep_ring->enqueue)) { in prepare_ring()
3132 if (!xhci_link_trb_quirk(xhci) && in prepare_ring()
3133 !(ep_ring->type == TYPE_ISOC && in prepare_ring()
3134 (xhci->quirks & XHCI_AMD_0x96_HOST))) in prepare_ring()
3135 ep_ring->enqueue->link.control &= in prepare_ring()
3138 ep_ring->enqueue->link.control |= in prepare_ring()
3142 ep_ring->enqueue->link.control ^= cpu_to_le32(TRB_CYCLE); in prepare_ring()
3145 if (link_trb_toggles_cycle(ep_ring->enqueue)) in prepare_ring()
3146 ep_ring->cycle_state ^= 1; in prepare_ring()
3148 ep_ring->enq_seg = ep_ring->enq_seg->next; in prepare_ring()
3149 ep_ring->enqueue = ep_ring->enq_seg->trbs; in prepare_ring()
3154 static int prepare_transfer(struct xhci_hcd *xhci, in prepare_transfer() argument
3167 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in prepare_transfer()
3171 xhci_dbg(xhci, "Can't prepare ring for bad stream ID %u\n", in prepare_transfer()
3173 return -EINVAL; in prepare_transfer()
3176 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in prepare_transfer()
3181 urb_priv = urb->hcpriv; in prepare_transfer()
3182 td = &urb_priv->td[td_index]; in prepare_transfer()
3184 INIT_LIST_HEAD(&td->td_list); in prepare_transfer()
3185 INIT_LIST_HEAD(&td->cancelled_td_list); in prepare_transfer()
3188 ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb); in prepare_transfer()
3193 td->urb = urb; in prepare_transfer()
3195 list_add_tail(&td->td_list, &ep_ring->td_list); in prepare_transfer()
3196 td->start_seg = ep_ring->enq_seg; in prepare_transfer()
3197 td->first_trb = ep_ring->enqueue; in prepare_transfer()
3206 num_trbs = DIV_ROUND_UP(len + (addr & (TRB_MAX_BUFF_SIZE - 1)), in count_trbs()
3216 return count_trbs(urb->transfer_dma, urb->transfer_buffer_length); in count_trbs_needed()
3224 full_len = urb->transfer_buffer_length; in count_sg_trbs_needed()
3226 for_each_sg(urb->sg, sg, urb->num_mapped_sgs, i) { in count_sg_trbs_needed()
3230 full_len -= len; in count_sg_trbs_needed()
3242 addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset); in count_isoc_trbs_needed()
3243 len = urb->iso_frame_desc[i].length; in count_isoc_trbs_needed()
3250 if (unlikely(running_total != urb->transfer_buffer_length)) in check_trb_math()
3251 dev_err(&urb->dev->dev, "%s - ep %#x - Miscalculated tx length, " in check_trb_math()
3254 urb->ep->desc.bEndpointAddress, in check_trb_math()
3256 urb->transfer_buffer_length, in check_trb_math()
3257 urb->transfer_buffer_length); in check_trb_math()
3260 static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, in giveback_first_trb() argument
3270 start_trb->field[3] |= cpu_to_le32(start_cycle); in giveback_first_trb()
3272 start_trb->field[3] &= cpu_to_le32(~TRB_CYCLE); in giveback_first_trb()
3273 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); in giveback_first_trb()
3276 static void check_interval(struct xhci_hcd *xhci, struct urb *urb, in check_interval() argument
3282 xhci_interval = EP_INTERVAL_TO_UFRAMES(le32_to_cpu(ep_ctx->ep_info)); in check_interval()
3283 ep_interval = urb->interval; in check_interval()
3286 if (urb->dev->speed == USB_SPEED_LOW || in check_interval()
3287 urb->dev->speed == USB_SPEED_FULL) in check_interval()
3294 dev_dbg_ratelimited(&urb->dev->dev, in check_interval()
3295 "Driver uses different interval (%d microframe%s) than xHCI (%d microframe%s)\n", in check_interval()
3298 urb->interval = xhci_interval; in check_interval()
3300 if (urb->dev->speed == USB_SPEED_LOW || in check_interval()
3301 urb->dev->speed == USB_SPEED_FULL) in check_interval()
3302 urb->interval /= 8; in check_interval()
3307 * xHCI uses normal TRBs for both bulk and interrupt. When the interrupt
3312 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_intr_tx() argument
3317 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); in xhci_queue_intr_tx()
3318 check_interval(xhci, urb, ep_ctx); in xhci_queue_intr_tx()
3320 return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_intr_tx()
3324 * For xHCI 1.0 host controllers, TD size is the number of max packet sized
3333 * TD size = total_packet_count - packets_transferred
3335 * For xHCI 0.96 and older, TD size field should be the remaining bytes
3343 static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, in xhci_td_remainder() argument
3349 /* MTK xHCI 0.96 contains some features from 1.0 */ in xhci_td_remainder()
3350 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) in xhci_td_remainder()
3351 return ((td_total_len - transferred) >> 10); in xhci_td_remainder()
3353 /* One TRB with a zero-length data packet. */ in xhci_td_remainder()
3358 /* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */ in xhci_td_remainder()
3359 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) in xhci_td_remainder()
3362 maxp = usb_endpoint_maxp(&urb->ep->desc); in xhci_td_remainder()
3366 return (total_packet_count - ((transferred + trb_buff_len) / maxp)); in xhci_td_remainder()
3370 static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len, in xhci_align_td() argument
3373 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_align_td()
3379 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_align_td()
3386 xhci_dbg(xhci, "Unaligned %d bytes, buff len %d\n", in xhci_align_td()
3391 *trb_buff_len -= unalign; in xhci_align_td()
3392 xhci_dbg(xhci, "split align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3401 new_buff_len = max_pkt - (enqd_len % max_pkt); in xhci_align_td()
3403 if (new_buff_len > (urb->transfer_buffer_length - enqd_len)) in xhci_align_td()
3404 new_buff_len = (urb->transfer_buffer_length - enqd_len); in xhci_align_td()
3408 if (urb->num_sgs) { in xhci_align_td()
3409 len = sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_align_td()
3410 seg->bounce_buf, new_buff_len, enqd_len); in xhci_align_td()
3412 xhci_warn(xhci, "WARN Wrong bounce buffer write length: %zu != %d\n", in xhci_align_td()
3415 memcpy(seg->bounce_buf, urb->transfer_buffer + enqd_len, new_buff_len); in xhci_align_td()
3418 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, in xhci_align_td()
3421 seg->bounce_dma = dma_map_single(dev, seg->bounce_buf, in xhci_align_td()
3425 if (dma_mapping_error(dev, seg->bounce_dma)) { in xhci_align_td()
3427 xhci_warn(xhci, "Failed mapping bounce buffer, not aligning\n"); in xhci_align_td()
3431 seg->bounce_len = new_buff_len; in xhci_align_td()
3432 seg->bounce_offs = enqd_len; in xhci_align_td()
3434 xhci_dbg(xhci, "Bounce align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3439 /* This is very similar to what ehci-q.c qtd_fill() does */
3440 int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_bulk_tx() argument
3458 ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_bulk_tx()
3460 return -EINVAL; in xhci_queue_bulk_tx()
3462 full_len = urb->transfer_buffer_length; in xhci_queue_bulk_tx()
3464 if (urb->num_sgs) { in xhci_queue_bulk_tx()
3465 num_sgs = urb->num_mapped_sgs; in xhci_queue_bulk_tx()
3466 sg = urb->sg; in xhci_queue_bulk_tx()
3472 addr = (u64) urb->transfer_dma; in xhci_queue_bulk_tx()
3475 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3476 ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3481 urb_priv = urb->hcpriv; in xhci_queue_bulk_tx()
3483 /* Deal with URB_ZERO_PACKET - need one more td/trb */ in xhci_queue_bulk_tx()
3484 if (urb->transfer_flags & URB_ZERO_PACKET && urb_priv->num_tds > 1) in xhci_queue_bulk_tx()
3487 td = &urb_priv->td[0]; in xhci_queue_bulk_tx()
3494 start_trb = &ring->enqueue->generic; in xhci_queue_bulk_tx()
3495 start_cycle = ring->cycle_state; in xhci_queue_bulk_tx()
3498 /* Queue the TRBs, even if they are zero-length */ in xhci_queue_bulk_tx()
3508 trb_buff_len = full_len - enqd_len; in xhci_queue_bulk_tx()
3516 field |= ring->cycle_state; in xhci_queue_bulk_tx()
3523 if (trb_is_link(ring->enqueue + 1)) { in xhci_queue_bulk_tx()
3524 if (xhci_align_td(xhci, urb, enqd_len, in xhci_queue_bulk_tx()
3526 ring->enq_seg)) { in xhci_queue_bulk_tx()
3527 send_addr = ring->enq_seg->bounce_dma; in xhci_queue_bulk_tx()
3529 td->bounce_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3537 td->last_trb = ring->enqueue; in xhci_queue_bulk_tx()
3538 td->last_trb_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3540 memcpy(&send_addr, urb->transfer_buffer, in xhci_queue_bulk_tx()
3552 remainder = xhci_td_remainder(xhci, enqd_len, trb_buff_len, in xhci_queue_bulk_tx()
3559 queue_trb(xhci, ring, more_trbs_coming | need_zero_pkt, in xhci_queue_bulk_tx()
3564 td->num_trbs++; in xhci_queue_bulk_tx()
3570 --num_sgs; in xhci_queue_bulk_tx()
3571 sent_len -= block_len; in xhci_queue_bulk_tx()
3579 block_len -= sent_len; in xhci_queue_bulk_tx()
3584 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3585 ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3587 urb_priv->td[1].last_trb = ring->enqueue; in xhci_queue_bulk_tx()
3588 urb_priv->td[1].last_trb_seg = ring->enq_seg; in xhci_queue_bulk_tx()
3589 field = TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; in xhci_queue_bulk_tx()
3590 queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); in xhci_queue_bulk_tx()
3591 urb_priv->td[1].num_trbs++; in xhci_queue_bulk_tx()
3595 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3600 /* Caller must have locked xhci->lock */
3601 int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_ctrl_tx() argument
3614 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_ctrl_tx()
3616 return -EINVAL; in xhci_queue_ctrl_tx()
3622 if (!urb->setup_packet) in xhci_queue_ctrl_tx()
3623 return -EINVAL; in xhci_queue_ctrl_tx()
3632 if (urb->transfer_buffer_length > 0) in xhci_queue_ctrl_tx()
3634 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_ctrl_tx()
3635 ep_index, urb->stream_id, in xhci_queue_ctrl_tx()
3640 urb_priv = urb->hcpriv; in xhci_queue_ctrl_tx()
3641 td = &urb_priv->td[0]; in xhci_queue_ctrl_tx()
3642 td->num_trbs = num_trbs; in xhci_queue_ctrl_tx()
3649 start_trb = &ep_ring->enqueue->generic; in xhci_queue_ctrl_tx()
3650 start_cycle = ep_ring->cycle_state; in xhci_queue_ctrl_tx()
3652 /* Queue setup TRB - see section 6.4.1.2.1 */ in xhci_queue_ctrl_tx()
3654 setup = (struct usb_ctrlrequest *) urb->setup_packet; in xhci_queue_ctrl_tx()
3660 /* xHCI 1.0/1.1 6.4.1.2.1: Transfer Type field */ in xhci_queue_ctrl_tx()
3661 if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { in xhci_queue_ctrl_tx()
3662 if (urb->transfer_buffer_length > 0) { in xhci_queue_ctrl_tx()
3663 if (setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3670 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3671 setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16, in xhci_queue_ctrl_tx()
3672 le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16, in xhci_queue_ctrl_tx()
3684 if (urb->transfer_buffer_length > 0) { in xhci_queue_ctrl_tx()
3689 memcpy(&addr, urb->transfer_buffer, in xhci_queue_ctrl_tx()
3690 urb->transfer_buffer_length); in xhci_queue_ctrl_tx()
3694 addr = (u64) urb->transfer_dma; in xhci_queue_ctrl_tx()
3697 remainder = xhci_td_remainder(xhci, 0, in xhci_queue_ctrl_tx()
3698 urb->transfer_buffer_length, in xhci_queue_ctrl_tx()
3699 urb->transfer_buffer_length, in xhci_queue_ctrl_tx()
3701 length_field = TRB_LEN(urb->transfer_buffer_length) | in xhci_queue_ctrl_tx()
3704 if (setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3706 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3710 field | ep_ring->cycle_state); in xhci_queue_ctrl_tx()
3714 td->last_trb = ep_ring->enqueue; in xhci_queue_ctrl_tx()
3715 td->last_trb_seg = ep_ring->enq_seg; in xhci_queue_ctrl_tx()
3717 /* Queue status TRB - see Table 7 and sections 4.11.2.2 and 6.4.1.2.3 */ in xhci_queue_ctrl_tx()
3719 if (urb->transfer_buffer_length > 0 && setup->bRequestType & USB_DIR_IN) in xhci_queue_ctrl_tx()
3723 queue_trb(xhci, ep_ring, false, in xhci_queue_ctrl_tx()
3728 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state); in xhci_queue_ctrl_tx()
3730 giveback_first_trb(xhci, slot_id, ep_index, 0, in xhci_queue_ctrl_tx()
3741 * zero. Only xHCI 1.0 host controllers support this field.
3743 static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci, in xhci_get_burst_count() argument
3748 if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER) in xhci_get_burst_count()
3751 max_burst = urb->ep->ss_ep_comp.bMaxBurst; in xhci_get_burst_count()
3752 return DIV_ROUND_UP(total_packet_count, max_burst + 1) - 1; in xhci_get_burst_count()
3763 static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci, in xhci_get_last_burst_packet_count() argument
3769 if (xhci->hci_version < 0x100) in xhci_get_last_burst_packet_count()
3772 if (urb->dev->speed >= USB_SPEED_SUPER) { in xhci_get_last_burst_packet_count()
3774 max_burst = urb->ep->ss_ep_comp.bMaxBurst; in xhci_get_last_burst_packet_count()
3777 * number of packets, but the TLBPC field is zero-based. in xhci_get_last_burst_packet_count()
3781 return residue - 1; in xhci_get_last_burst_packet_count()
3785 return total_packet_count - 1; in xhci_get_last_burst_packet_count()
3795 static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci, in xhci_get_isoc_frame_id() argument
3801 if (urb->dev->speed == USB_SPEED_LOW || in xhci_get_isoc_frame_id()
3802 urb->dev->speed == USB_SPEED_FULL) in xhci_get_isoc_frame_id()
3803 start_frame = urb->start_frame + index * urb->interval; in xhci_get_isoc_frame_id()
3805 start_frame = (urb->start_frame + index * urb->interval) >> 3; in xhci_get_isoc_frame_id()
3815 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_get_isoc_frame_id()
3816 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_get_isoc_frame_id()
3832 current_frame_id = readl(&xhci->run_regs->microframe_index); in xhci_get_isoc_frame_id()
3840 xhci_dbg(xhci, "%s: index %d, reg 0x%x start_frame_id 0x%x, end_frame_id 0x%x, start_frame 0x%x\n", in xhci_get_isoc_frame_id()
3841 __func__, index, readl(&xhci->run_regs->microframe_index), in xhci_get_isoc_frame_id()
3847 ret = -EINVAL; in xhci_get_isoc_frame_id()
3851 ret = -EINVAL; in xhci_get_isoc_frame_id()
3853 ret = -EINVAL; in xhci_get_isoc_frame_id()
3857 if (ret == -EINVAL || start_frame == start_frame_id) { in xhci_get_isoc_frame_id()
3859 if (urb->dev->speed == USB_SPEED_LOW || in xhci_get_isoc_frame_id()
3860 urb->dev->speed == USB_SPEED_FULL) in xhci_get_isoc_frame_id()
3861 urb->start_frame = start_frame; in xhci_get_isoc_frame_id()
3863 urb->start_frame = start_frame << 3; in xhci_get_isoc_frame_id()
3869 xhci_warn(xhci, "Frame ID %d (reg %d, index %d) beyond range (%d, %d)\n", in xhci_get_isoc_frame_id()
3872 xhci_warn(xhci, "Ignore frame ID field, use SIA bit instead\n"); in xhci_get_isoc_frame_id()
3880 static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) in trb_block_event_intr() argument
3882 if (xhci->hci_version < 0x100) in trb_block_event_intr()
3885 if (i == num_tds - 1) in trb_block_event_intr()
3891 if (i && xhci->quirks & XHCI_AVOID_BEI) in trb_block_event_intr()
3898 static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx() argument
3916 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx()
3917 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; in xhci_queue_isoc_tx()
3919 num_tds = urb->number_of_packets; in xhci_queue_isoc_tx()
3921 xhci_dbg(xhci, "Isoc URB with zero packets?\n"); in xhci_queue_isoc_tx()
3922 return -EINVAL; in xhci_queue_isoc_tx()
3924 start_addr = (u64) urb->transfer_dma; in xhci_queue_isoc_tx()
3925 start_trb = &ep_ring->enqueue->generic; in xhci_queue_isoc_tx()
3926 start_cycle = ep_ring->cycle_state; in xhci_queue_isoc_tx()
3928 urb_priv = urb->hcpriv; in xhci_queue_isoc_tx()
3929 /* Queue the TRBs for each TD, even if they are zero-length */ in xhci_queue_isoc_tx()
3937 addr = start_addr + urb->iso_frame_desc[i].offset; in xhci_queue_isoc_tx()
3938 td_len = urb->iso_frame_desc[i].length; in xhci_queue_isoc_tx()
3940 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_queue_isoc_tx()
3943 /* A zero-length transfer still involves at least one packet. */ in xhci_queue_isoc_tx()
3946 burst_count = xhci_get_burst_count(xhci, urb, total_pkt_count); in xhci_queue_isoc_tx()
3947 last_burst_pkt_count = xhci_get_last_burst_packet_count(xhci, in xhci_queue_isoc_tx()
3952 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, in xhci_queue_isoc_tx()
3953 urb->stream_id, trbs_per_td, urb, i, mem_flags); in xhci_queue_isoc_tx()
3959 td = &urb_priv->td[i]; in xhci_queue_isoc_tx()
3960 td->num_trbs = trbs_per_td; in xhci_queue_isoc_tx()
3963 if (!(urb->transfer_flags & URB_ISO_ASAP) && in xhci_queue_isoc_tx()
3964 HCC_CFC(xhci->hcc_params)) { in xhci_queue_isoc_tx()
3965 frame_id = xhci_get_isoc_frame_id(xhci, urb, i); in xhci_queue_isoc_tx()
3977 (i ? ep_ring->cycle_state : !start_cycle); in xhci_queue_isoc_tx()
3979 /* xhci 1.1 with ETE uses TD_Size field for TBC, old is Rsvdz */ in xhci_queue_isoc_tx()
3980 if (!xep->use_extended_tbc) in xhci_queue_isoc_tx()
3990 ep_ring->cycle_state; in xhci_queue_isoc_tx()
3997 if (j < trbs_per_td - 1) { in xhci_queue_isoc_tx()
4002 td->last_trb = ep_ring->enqueue; in xhci_queue_isoc_tx()
4003 td->last_trb_seg = ep_ring->enq_seg; in xhci_queue_isoc_tx()
4005 if (trb_block_event_intr(xhci, num_tds, i)) in xhci_queue_isoc_tx()
4014 remainder = xhci_td_remainder(xhci, running_total, in xhci_queue_isoc_tx()
4021 /* xhci 1.1 with ETE uses TD Size field for TBC */ in xhci_queue_isoc_tx()
4022 if (first_trb && xep->use_extended_tbc) in xhci_queue_isoc_tx()
4028 queue_trb(xhci, ep_ring, more_trbs_coming, in xhci_queue_isoc_tx()
4036 td_remain_len -= trb_buff_len; in xhci_queue_isoc_tx()
4041 xhci_err(xhci, "ISOC TD length unmatch\n"); in xhci_queue_isoc_tx()
4042 ret = -EINVAL; in xhci_queue_isoc_tx()
4048 if (HCC_CFC(xhci->hcc_params)) in xhci_queue_isoc_tx()
4049 xep->next_frame_id = urb->start_frame + num_tds * urb->interval; in xhci_queue_isoc_tx()
4051 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_queue_isoc_tx()
4052 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_queue_isoc_tx()
4055 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; in xhci_queue_isoc_tx()
4057 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_isoc_tx()
4063 for (i--; i >= 0; i--) in xhci_queue_isoc_tx()
4064 list_del_init(&urb_priv->td[i].td_list); in xhci_queue_isoc_tx()
4067 * into No-ops with a software-owned cycle bit. That way the hardware in xhci_queue_isoc_tx()
4069 * overwrite them. td->first_trb and td->start_seg are already set. in xhci_queue_isoc_tx()
4071 urb_priv->td[0].last_trb = ep_ring->enqueue; in xhci_queue_isoc_tx()
4073 td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); in xhci_queue_isoc_tx()
4076 ep_ring->enqueue = urb_priv->td[0].first_trb; in xhci_queue_isoc_tx()
4077 ep_ring->enq_seg = urb_priv->td[0].start_seg; in xhci_queue_isoc_tx()
4078 ep_ring->cycle_state = start_cycle; in xhci_queue_isoc_tx()
4079 ep_ring->num_trbs_free = ep_ring->num_trbs_free_temp; in xhci_queue_isoc_tx()
4080 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb); in xhci_queue_isoc_tx()
4087 * Update interval as xhci_queue_intr_tx does. Use xhci frame_index to
4088 * update urb->start_frame if URB_ISO_ASAP is set in transfer_flags or
4091 int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx_prepare() argument
4103 xdev = xhci->devs[slot_id]; in xhci_queue_isoc_tx_prepare()
4104 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx_prepare()
4105 ep_ring = xdev->eps[ep_index].ring; in xhci_queue_isoc_tx_prepare()
4106 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in xhci_queue_isoc_tx_prepare()
4109 num_tds = urb->number_of_packets; in xhci_queue_isoc_tx_prepare()
4116 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in xhci_queue_isoc_tx_prepare()
4125 check_interval(xhci, urb, ep_ctx); in xhci_queue_isoc_tx_prepare()
4127 /* Calculate the start frame and put it in urb->start_frame. */ in xhci_queue_isoc_tx_prepare()
4128 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { in xhci_queue_isoc_tx_prepare()
4130 urb->start_frame = xep->next_frame_id; in xhci_queue_isoc_tx_prepare()
4135 start_frame = readl(&xhci->run_regs->microframe_index); in xhci_queue_isoc_tx_prepare()
4141 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_queue_isoc_tx_prepare()
4142 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_queue_isoc_tx_prepare()
4151 if (urb->dev->speed == USB_SPEED_LOW || in xhci_queue_isoc_tx_prepare()
4152 urb->dev->speed == USB_SPEED_FULL) { in xhci_queue_isoc_tx_prepare()
4153 start_frame = roundup(start_frame, urb->interval << 3); in xhci_queue_isoc_tx_prepare()
4154 urb->start_frame = start_frame >> 3; in xhci_queue_isoc_tx_prepare()
4156 start_frame = roundup(start_frame, urb->interval); in xhci_queue_isoc_tx_prepare()
4157 urb->start_frame = start_frame; in xhci_queue_isoc_tx_prepare()
4161 ep_ring->num_trbs_free_temp = ep_ring->num_trbs_free; in xhci_queue_isoc_tx_prepare()
4163 return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_isoc_tx_prepare()
4168 /* Generic function for queueing a command TRB on the command ring.
4173 * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
4176 static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in queue_command() argument
4180 int reserved_trbs = xhci->cmd_ring_reserved_trbs; in queue_command()
4183 if ((xhci->xhc_state & XHCI_STATE_DYING) || in queue_command()
4184 (xhci->xhc_state & XHCI_STATE_HALTED)) { in queue_command()
4185 xhci_dbg(xhci, "xHCI dying or halted, can't queue_command\n"); in queue_command()
4186 return -ESHUTDOWN; in queue_command()
4192 ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, in queue_command()
4195 xhci_err(xhci, "ERR: No room for command on command ring\n"); in queue_command()
4197 xhci_err(xhci, "ERR: Reserved TRB counting for " in queue_command()
4202 cmd->command_trb = xhci->cmd_ring->enqueue; in queue_command()
4205 if (list_empty(&xhci->cmd_list)) { in queue_command()
4206 xhci->current_cmd = cmd; in queue_command()
4207 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in queue_command()
4210 list_add_tail(&cmd->cmd_list, &xhci->cmd_list); in queue_command()
4212 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, in queue_command()
4213 field4 | xhci->cmd_ring->cycle_state); in queue_command()
4218 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_slot_control() argument
4221 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_slot_control()
4226 int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_address_device() argument
4229 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_address_device()
4235 int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_vendor_command() argument
4238 return queue_command(xhci, cmd, field1, field2, field3, field4, false); in xhci_queue_vendor_command()
4242 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_device() argument
4245 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_device()
4251 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, in xhci_queue_configure_endpoint() argument
4255 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_configure_endpoint()
4262 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_evaluate_context() argument
4265 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_evaluate_context()
4275 int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_stop_endpoint() argument
4283 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_stop_endpoint()
4288 void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, in xhci_queue_new_dequeue_state() argument
4295 u32 trb_stream_id = STREAM_ID_FOR_TRB(deq_state->stream_id); in xhci_queue_new_dequeue_state()
4302 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_queue_new_dequeue_state()
4304 deq_state->new_deq_seg, in xhci_queue_new_dequeue_state()
4305 (unsigned long long)deq_state->new_deq_seg->dma, in xhci_queue_new_dequeue_state()
4306 deq_state->new_deq_ptr, in xhci_queue_new_dequeue_state()
4308 deq_state->new_deq_seg, deq_state->new_deq_ptr), in xhci_queue_new_dequeue_state()
4309 deq_state->new_cycle_state); in xhci_queue_new_dequeue_state()
4311 addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg, in xhci_queue_new_dequeue_state()
4312 deq_state->new_deq_ptr); in xhci_queue_new_dequeue_state()
4314 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); in xhci_queue_new_dequeue_state()
4315 xhci_warn(xhci, "WARN deq seg = %p, deq pt = %p\n", in xhci_queue_new_dequeue_state()
4316 deq_state->new_deq_seg, deq_state->new_deq_ptr); in xhci_queue_new_dequeue_state()
4319 ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_new_dequeue_state()
4320 if ((ep->ep_state & SET_DEQ_PENDING)) { in xhci_queue_new_dequeue_state()
4321 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); in xhci_queue_new_dequeue_state()
4322 xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n"); in xhci_queue_new_dequeue_state()
4327 cmd = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_queue_new_dequeue_state()
4331 ep->queued_deq_seg = deq_state->new_deq_seg; in xhci_queue_new_dequeue_state()
4332 ep->queued_deq_ptr = deq_state->new_deq_ptr; in xhci_queue_new_dequeue_state()
4333 if (deq_state->stream_id) in xhci_queue_new_dequeue_state()
4335 ret = queue_command(xhci, cmd, in xhci_queue_new_dequeue_state()
4336 lower_32_bits(addr) | trb_sct | deq_state->new_cycle_state, in xhci_queue_new_dequeue_state()
4340 xhci_free_command(xhci, cmd); in xhci_queue_new_dequeue_state()
4349 ep->ep_state |= SET_DEQ_PENDING; in xhci_queue_new_dequeue_state()
4352 int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_ep() argument
4363 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_ep()