Lines Matching full:xhci
3 * xHCI host controller driver
59 #include "xhci.h"
60 #include "xhci-trace.h"
62 static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd,
143 static void next_trb(struct xhci_hcd *xhci, in next_trb() argument
159 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) in inc_deq() argument
179 xhci_warn(xhci, "Missing link TRB at end of segment\n"); in inc_deq()
189 xhci_warn(xhci, "Ring is an endless link TRB loop\n"); in inc_deq()
210 * xHCI hardware can't handle the chain bit being cleared on a link TRB.
215 static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, in inc_enq() argument
225 xhci_err(xhci, "Tried to move enqueue past ring segment\n"); in inc_enq()
249 (xhci->quirks & XHCI_AMD_0x96_HOST)) && in inc_enq()
250 !xhci_link_trb_quirk(xhci)) { in inc_enq()
267 xhci_warn(xhci, "%s: Ring link TRB loop\n", __func__); in inc_enq()
281 static unsigned int xhci_num_trbs_free(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_num_trbs_free() argument
317 static unsigned int xhci_ring_expansion_needed(struct xhci_hcd *xhci, struct xhci_ring *ring, in xhci_ring_expansion_needed() argument
349 xhci_dbg(xhci, "Ring expansion by %d segments needed\n", in xhci_ring_expansion_needed()
351 xhci_dbg(xhci, "Adding %d trbs moves enq %d trbs into deq seg\n", in xhci_ring_expansion_needed()
362 void xhci_ring_cmd_db(struct xhci_hcd *xhci) in xhci_ring_cmd_db() argument
364 if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) in xhci_ring_cmd_db()
367 xhci_dbg(xhci, "// Ding dong!\n"); in xhci_ring_cmd_db()
371 writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
373 readl(&xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
376 static bool xhci_mod_cmd_timer(struct xhci_hcd *xhci) in xhci_mod_cmd_timer() argument
378 return mod_delayed_work(system_wq, &xhci->cmd_timer, in xhci_mod_cmd_timer()
379 msecs_to_jiffies(xhci->current_cmd->timeout_ms)); in xhci_mod_cmd_timer()
382 static struct xhci_command *xhci_next_queued_cmd(struct xhci_hcd *xhci) in xhci_next_queued_cmd() argument
384 return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command, in xhci_next_queued_cmd()
391 * This must be called with command ring stopped and xhci->lock held.
393 static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci, in xhci_handle_stopped_cmd_ring() argument
399 list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) { in xhci_handle_stopped_cmd_ring()
406 xhci_dbg(xhci, "Turn aborted command %p to no-op\n", in xhci_handle_stopped_cmd_ring()
417 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_handle_stopped_cmd_ring()
420 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && in xhci_handle_stopped_cmd_ring()
421 !(xhci->xhc_state & XHCI_STATE_DYING)) { in xhci_handle_stopped_cmd_ring()
422 xhci->current_cmd = cur_cmd; in xhci_handle_stopped_cmd_ring()
424 xhci_mod_cmd_timer(xhci); in xhci_handle_stopped_cmd_ring()
425 xhci_ring_cmd_db(xhci); in xhci_handle_stopped_cmd_ring()
429 /* Must be called with xhci->lock held, releases and aquires lock back */
430 static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) in xhci_abort_cmd_ring() argument
432 struct xhci_segment *new_seg = xhci->cmd_ring->deq_seg; in xhci_abort_cmd_ring()
433 union xhci_trb *new_deq = xhci->cmd_ring->dequeue; in xhci_abort_cmd_ring()
437 xhci_dbg(xhci, "Abort command ring\n"); in xhci_abort_cmd_ring()
439 reinit_completion(&xhci->cmd_ring_stop_completion); in xhci_abort_cmd_ring()
449 next_trb(xhci, NULL, &new_seg, &new_deq); in xhci_abort_cmd_ring()
451 next_trb(xhci, NULL, &new_seg, &new_deq); in xhci_abort_cmd_ring()
454 xhci_write_64(xhci, crcr | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
456 /* Section 4.6.1.2 of xHCI 1.0 spec says software should also time the in xhci_abort_cmd_ring()
462 ret = xhci_handshake(&xhci->op_regs->cmd_ring, in xhci_abort_cmd_ring()
465 xhci_err(xhci, "Abort failed to stop command ring: %d\n", ret); in xhci_abort_cmd_ring()
466 xhci_halt(xhci); in xhci_abort_cmd_ring()
467 xhci_hc_died(xhci); in xhci_abort_cmd_ring()
476 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_abort_cmd_ring()
477 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, in xhci_abort_cmd_ring()
479 spin_lock_irqsave(&xhci->lock, flags); in xhci_abort_cmd_ring()
481 xhci_dbg(xhci, "No stop event for abort, ring start fail?\n"); in xhci_abort_cmd_ring()
482 xhci_cleanup_command_queue(xhci); in xhci_abort_cmd_ring()
484 xhci_handle_stopped_cmd_ring(xhci, xhci_next_queued_cmd(xhci)); in xhci_abort_cmd_ring()
489 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, in xhci_ring_ep_doorbell() argument
494 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; in xhci_ring_ep_doorbell()
495 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_ring_ep_doorbell()
516 static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in ring_doorbell_for_active_rings() argument
523 ep = &xhci->devs[slot_id]->eps[ep_index]; in ring_doorbell_for_active_rings()
528 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, 0); in ring_doorbell_for_active_rings()
536 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, in ring_doorbell_for_active_rings()
541 void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in xhci_ring_doorbell_for_active_rings() argument
545 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_ring_doorbell_for_active_rings()
548 static struct xhci_virt_ep *xhci_get_virt_ep(struct xhci_hcd *xhci, in xhci_get_virt_ep() argument
553 xhci_warn(xhci, "Invalid slot_id %u\n", slot_id); in xhci_get_virt_ep()
557 xhci_warn(xhci, "Invalid endpoint index %u\n", ep_index); in xhci_get_virt_ep()
560 if (!xhci->devs[slot_id]) { in xhci_get_virt_ep()
561 xhci_warn(xhci, "No xhci virt device for slot_id %u\n", slot_id); in xhci_get_virt_ep()
565 return &xhci->devs[slot_id]->eps[ep_index]; in xhci_get_virt_ep()
568 static struct xhci_ring *xhci_virt_ep_to_ring(struct xhci_hcd *xhci, in xhci_virt_ep_to_ring() argument
580 xhci_warn(xhci, "Invalid stream_id %u request for slot_id %u ep_index %u\n", in xhci_virt_ep_to_ring()
592 struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, in xhci_triad_to_transfer_ring() argument
598 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_triad_to_transfer_ring()
602 return xhci_virt_ep_to_ring(xhci, ep, stream_id); in xhci_triad_to_transfer_ring()
612 static u64 xhci_get_hw_deq(struct xhci_hcd *xhci, struct xhci_virt_device *vdev, in xhci_get_hw_deq() argument
625 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_get_hw_deq()
629 static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, in xhci_move_dequeue_past_td() argument
633 struct xhci_virt_device *dev = xhci->devs[slot_id]; in xhci_move_dequeue_past_td()
647 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id, in xhci_move_dequeue_past_td()
650 xhci_warn(xhci, "WARN can't find new dequeue, invalid stream ID %u\n", in xhci_move_dequeue_past_td()
666 xhci_dbg(xhci, "ep ring empty, Set new dequeue = enqueue"); in xhci_move_dequeue_past_td()
669 xhci_warn(xhci, "Can't find new dequeue state, missing td\n"); in xhci_move_dequeue_past_td()
674 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); in xhci_move_dequeue_past_td()
699 next_trb(xhci, ep_ring, &new_seg, &new_deq); in xhci_move_dequeue_past_td()
703 xhci_err(xhci, "Error: Failed finding new dequeue state\n"); in xhci_move_dequeue_past_td()
714 xhci_warn(xhci, "Can't find dma of new dequeue ptr\n"); in xhci_move_dequeue_past_td()
715 xhci_warn(xhci, "deq seg = %p, deq ptr = %p\n", new_seg, new_deq); in xhci_move_dequeue_past_td()
720 xhci_warn(xhci, "Set TR Deq already pending, don't submit for 0x%pad\n", in xhci_move_dequeue_past_td()
726 cmd = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_move_dequeue_past_td()
728 xhci_warn(xhci, "Can't alloc Set TR Deq cmd 0x%pad\n", &addr); in xhci_move_dequeue_past_td()
734 ret = queue_command(xhci, cmd, in xhci_move_dequeue_past_td()
740 xhci_free_command(xhci, cmd); in xhci_move_dequeue_past_td()
746 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_move_dequeue_past_td()
755 xhci_ring_cmd_db(xhci); in xhci_move_dequeue_past_td()
763 static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in td_to_noop() argument
779 next_trb(xhci, ep_ring, &seg, &trb); in td_to_noop()
784 * Must be called with xhci->lock held in interrupt context,
785 * releases and re-acquires xhci->lock
787 static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, in xhci_giveback_urb_in_irq() argument
795 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; in xhci_giveback_urb_in_irq()
796 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_giveback_urb_in_irq()
797 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_giveback_urb_in_irq()
807 static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, in xhci_unmap_td_bounce_buffer() argument
810 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_unmap_td_bounce_buffer()
831 xhci_warn(xhci, "WARN Wrong bounce buffer read length: %zu != %d\n", in xhci_unmap_td_bounce_buffer()
841 static int xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_td_cleanup() argument
850 xhci_unmap_td_bounce_buffer(xhci, ep_ring, td); in xhci_td_cleanup()
858 xhci_warn(xhci, "URB req %u and actual %u transfer length mismatch\n", in xhci_td_cleanup()
876 xhci_dbg(xhci, "Giveback URB %p, len = %d, expected = %d, status = %d\n", in xhci_td_cleanup()
883 xhci_giveback_urb_in_irq(xhci, td, status); in xhci_td_cleanup()
899 ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_giveback_invalidated_tds()
902 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_giveback_invalidated_tds()
904 xhci_td_cleanup(ep->xhci, td, ring, td->status); in xhci_giveback_invalidated_tds()
906 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_giveback_invalidated_tds()
909 if (ep->xhci->xhc_state & XHCI_STATE_DYING) in xhci_giveback_invalidated_tds()
914 static int xhci_reset_halted_ep(struct xhci_hcd *xhci, unsigned int slot_id, in xhci_reset_halted_ep() argument
920 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_reset_halted_ep()
926 xhci_dbg(xhci, "%s-reset ep %u, slot %u\n", in xhci_reset_halted_ep()
930 ret = xhci_queue_reset_ep(xhci, command, slot_id, ep_index, reset_type); in xhci_reset_halted_ep()
933 xhci_err(xhci, "ERROR queuing reset endpoint for slot %d ep_index %d, %d\n", in xhci_reset_halted_ep()
938 static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci, in xhci_handle_halted_endpoint() argument
963 xhci_dbg(xhci, "Reset ep command for ep_index %d already pending\n", in xhci_handle_halted_endpoint()
968 err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type); in xhci_handle_halted_endpoint()
974 xhci_ring_cmd_db(xhci); in xhci_handle_halted_endpoint()
981 * We have the xHCI lock, so nothing can modify this list until we drop it.
990 struct xhci_hcd *xhci; in xhci_invalidate_cancelled_tds() local
1006 xhci = ep->xhci; in xhci_invalidate_cancelled_tds()
1009 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_invalidate_cancelled_tds()
1015 ring = xhci_urb_to_transfer_ring(xhci, td->urb); in xhci_invalidate_cancelled_tds()
1017 xhci_warn(xhci, "WARN Cancelled URB %p has invalid stream ID %u.\n", in xhci_invalidate_cancelled_tds()
1027 hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index, in xhci_invalidate_cancelled_tds()
1032 trb_in_td(xhci, td->start_seg, td->first_trb, td->last_trb, hw_deq, false)) { in xhci_invalidate_cancelled_tds()
1043 xhci_dbg(xhci, in xhci_invalidate_cancelled_tds()
1051 xhci_warn(xhci, in xhci_invalidate_cancelled_tds()
1055 td_to_noop(xhci, ring, cached_td, false); in xhci_invalidate_cancelled_tds()
1058 td_to_noop(xhci, ring, td, false); in xhci_invalidate_cancelled_tds()
1064 td_to_noop(xhci, ring, td, false); in xhci_invalidate_cancelled_tds()
1073 err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index, in xhci_invalidate_cancelled_tds()
1087 xhci_warn(xhci, "Failed to clear cancelled cached URB %p, mark clear anyway\n", in xhci_invalidate_cancelled_tds()
1089 td_to_noop(xhci, ring, td, false); in xhci_invalidate_cancelled_tds()
1101 * Call under xhci->lock on a stopped endpoint.
1119 hw_deq = xhci_get_hw_deq(ep->xhci, ep->vdev, ep->ep_index, 0); in find_halted_td()
1122 if (trb_in_td(ep->xhci, td->start_seg, td->first_trb, in find_halted_td()
1139 static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_stop_ep() argument
1151 if (!xhci->devs[slot_id]) in xhci_handle_cmd_stop_ep()
1152 xhci_warn(xhci, "Stop endpoint command completion for disabled slot %u\n", in xhci_handle_cmd_stop_ep()
1158 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
1162 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_stop_ep()
1183 xhci_dbg(xhci, "Stop ep completion raced with stall, reset ep\n"); in xhci_handle_cmd_stop_ep()
1193 err = xhci_handle_halted_endpoint(xhci, ep, td, reset_type); in xhci_handle_cmd_stop_ep()
1200 * Per xHCI 4.6.9, Stop Endpoint command on a Stopped in xhci_handle_cmd_stop_ep()
1225 xhci_dbg(xhci, "Stop ep completion ctx error, ctx_state %d\n", in xhci_handle_cmd_stop_ep()
1228 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_handle_cmd_stop_ep()
1233 xhci_queue_stop_endpoint(xhci, command, slot_id, ep_index, 0); in xhci_handle_cmd_stop_ep()
1234 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_stop_ep()
1248 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
1251 static void xhci_kill_ring_urbs(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_kill_ring_urbs() argument
1262 xhci_unmap_td_bounce_buffer(xhci, ring, cur_td); in xhci_kill_ring_urbs()
1266 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_ring_urbs()
1270 static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, in xhci_kill_endpoint_urbs() argument
1278 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_kill_endpoint_urbs()
1292 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1295 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1301 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1304 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1313 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_endpoint_urbs()
1323 * Call with xhci->lock held.
1326 void xhci_hc_died(struct xhci_hcd *xhci) in xhci_hc_died() argument
1330 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_hc_died()
1333 xhci_err(xhci, "xHCI host controller not responding, assume dead\n"); in xhci_hc_died()
1334 xhci->xhc_state |= XHCI_STATE_DYING; in xhci_hc_died()
1336 xhci_cleanup_command_queue(xhci); in xhci_hc_died()
1339 for (i = 0; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_hc_died()
1340 if (!xhci->devs[i]) in xhci_hc_died()
1343 xhci_kill_endpoint_urbs(xhci, i, j); in xhci_hc_died()
1347 if (!(xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_hc_died()
1348 usb_hc_died(xhci_to_hcd(xhci)); in xhci_hc_died()
1351 static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci, in update_ring_for_set_deq_completion() argument
1382 xhci_dbg(xhci, "Unable to find new dequeue pointer\n"); in update_ring_for_set_deq_completion()
1395 static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_set_deq() argument
1408 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1412 ep_ring = xhci_virt_ep_to_ring(xhci, ep, stream_id); in xhci_handle_cmd_set_deq()
1414 xhci_warn(xhci, "WARN Set TR deq ptr command for freed stream ID %u\n", in xhci_handle_cmd_set_deq()
1420 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_set_deq()
1421 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in xhci_handle_cmd_set_deq()
1431 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because of stream ID configuration\n"); in xhci_handle_cmd_set_deq()
1434 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.\n"); in xhci_handle_cmd_set_deq()
1438 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1443 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed because slot %u was not enabled.\n", in xhci_handle_cmd_set_deq()
1447 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown completion code of %u.\n", in xhci_handle_cmd_set_deq()
1466 * Cadence xHCI controllers store some endpoint state in xhci_handle_cmd_set_deq()
1474 if (xhci->quirks & XHCI_CDNS_SCTX_QUIRK) { in xhci_handle_cmd_set_deq()
1481 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1488 update_ring_for_set_deq_completion(xhci, ep->vdev, in xhci_handle_cmd_set_deq()
1491 xhci_warn(xhci, "Mismatch between completed Set TR Deq Ptr command & xHCI internal state.\n"); in xhci_handle_cmd_set_deq()
1492 xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n", in xhci_handle_cmd_set_deq()
1499 ep_ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_handle_cmd_set_deq()
1502 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_handle_cmd_set_deq()
1504 xhci_td_cleanup(ep->xhci, td, ep_ring, td->status); in xhci_handle_cmd_set_deq()
1506 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_handle_cmd_set_deq()
1517 xhci_dbg(ep->xhci, "%s: Pending TDs to clear, continuing with invalidation\n", in xhci_handle_cmd_set_deq()
1521 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1526 xhci_dbg(ep->xhci, "%s: All TDs cleared, ring doorbell\n", __func__); in xhci_handle_cmd_set_deq()
1527 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1531 static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_ep() argument
1539 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1543 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_reset_ep()
1549 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, in xhci_handle_cmd_reset_ep()
1562 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1565 static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_enable_slot() argument
1574 static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_disable_slot() argument
1579 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_disable_slot()
1583 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_handle_cmd_disable_slot()
1586 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) in xhci_handle_cmd_disable_slot()
1588 xhci_free_device_endpoint_resources(xhci, virt_dev, true); in xhci_handle_cmd_disable_slot()
1591 static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_config_ep() argument
1605 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_config_ep()
1610 xhci_warn(xhci, "Could not get input context, bad type.\n"); in xhci_handle_cmd_config_ep()
1619 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, ep_index); in xhci_handle_cmd_config_ep()
1625 static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_addr_dev() argument
1630 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_addr_dev()
1633 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_addr_dev()
1637 static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_reset_dev() argument
1642 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_dev()
1644 xhci_warn(xhci, "Reset device command completion for disabled slot %u\n", in xhci_handle_cmd_reset_dev()
1648 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_reset_dev()
1651 xhci_dbg(xhci, "Completed reset device command.\n"); in xhci_handle_cmd_reset_dev()
1654 static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, in xhci_handle_cmd_nec_get_fw() argument
1657 if (!(xhci->quirks & XHCI_NEC_HOST)) { in xhci_handle_cmd_nec_get_fw()
1658 xhci_warn(xhci, "WARN NEC_GET_FW command on non-NEC host\n"); in xhci_handle_cmd_nec_get_fw()
1661 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_nec_get_fw()
1679 void xhci_cleanup_command_queue(struct xhci_hcd *xhci) in xhci_cleanup_command_queue() argument
1682 xhci->current_cmd = NULL; in xhci_cleanup_command_queue()
1683 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) in xhci_cleanup_command_queue()
1689 struct xhci_hcd *xhci; in xhci_handle_command_timeout() local
1696 xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer); in xhci_handle_command_timeout()
1698 spin_lock_irqsave(&xhci->lock, flags); in xhci_handle_command_timeout()
1704 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { in xhci_handle_command_timeout()
1705 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1709 cmd_field3 = le32_to_cpu(xhci->current_cmd->command_trb->generic.field[3]); in xhci_handle_command_timeout()
1710 usbsts = readl(&xhci->op_regs->status); in xhci_handle_command_timeout()
1711 xhci_dbg(xhci, "Command timeout, USBSTS:%s\n", xhci_decode_usbsts(str, usbsts)); in xhci_handle_command_timeout()
1713 /* Bail out and tear down xhci if a stop endpoint command failed */ in xhci_handle_command_timeout()
1717 xhci_warn(xhci, "xHCI host not responding to stop endpoint command\n"); in xhci_handle_command_timeout()
1719 ep = xhci_get_virt_ep(xhci, TRB_TO_SLOT_ID(cmd_field3), in xhci_handle_command_timeout()
1724 xhci_halt(xhci); in xhci_handle_command_timeout()
1725 xhci_hc_died(xhci); in xhci_handle_command_timeout()
1730 xhci->current_cmd->status = COMP_COMMAND_ABORTED; in xhci_handle_command_timeout()
1733 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_handle_command_timeout()
1735 xhci_hc_died(xhci); in xhci_handle_command_timeout()
1739 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && in xhci_handle_command_timeout()
1742 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; in xhci_handle_command_timeout()
1743 xhci_dbg(xhci, "Command timeout\n"); in xhci_handle_command_timeout()
1744 xhci_abort_cmd_ring(xhci, flags); in xhci_handle_command_timeout()
1749 if (xhci->xhc_state & XHCI_STATE_REMOVING) { in xhci_handle_command_timeout()
1750 xhci_dbg(xhci, "host removed, ring start fail?\n"); in xhci_handle_command_timeout()
1751 xhci_cleanup_command_queue(xhci); in xhci_handle_command_timeout()
1757 xhci_dbg(xhci, "Command timeout on stopped ring\n"); in xhci_handle_command_timeout()
1758 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); in xhci_handle_command_timeout()
1761 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1765 static void handle_cmd_completion(struct xhci_hcd *xhci, in handle_cmd_completion() argument
1777 xhci_warn(xhci, "Invalid slot_id %u\n", slot_id); in handle_cmd_completion()
1782 cmd_trb = xhci->cmd_ring->dequeue; in handle_cmd_completion()
1784 trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic); in handle_cmd_completion()
1790 complete_all(&xhci->cmd_ring_stop_completion); in handle_cmd_completion()
1794 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in handle_cmd_completion()
1801 xhci_warn(xhci, in handle_cmd_completion()
1806 cmd = list_first_entry(&xhci->cmd_list, struct xhci_command, cmd_list); in handle_cmd_completion()
1808 cancel_delayed_work(&xhci->cmd_timer); in handle_cmd_completion()
1810 if (cmd->command_trb != xhci->cmd_ring->dequeue) { in handle_cmd_completion()
1811 xhci_err(xhci, in handle_cmd_completion()
1823 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in handle_cmd_completion()
1825 if (xhci->current_cmd == cmd) in handle_cmd_completion()
1826 xhci->current_cmd = NULL; in handle_cmd_completion()
1834 xhci_handle_cmd_enable_slot(xhci, slot_id, cmd, cmd_comp_code); in handle_cmd_completion()
1837 xhci_handle_cmd_disable_slot(xhci, slot_id); in handle_cmd_completion()
1841 xhci_handle_cmd_config_ep(xhci, slot_id, cmd_comp_code); in handle_cmd_completion()
1846 xhci_handle_cmd_addr_dev(xhci, slot_id); in handle_cmd_completion()
1852 xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, in handle_cmd_completion()
1858 xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1868 xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1872 * Use the SLOT_ID from the command TRB instead (xhci 4.6.11) in handle_cmd_completion()
1876 xhci_handle_cmd_reset_dev(xhci, slot_id); in handle_cmd_completion()
1879 xhci_handle_cmd_nec_get_fw(xhci, event); in handle_cmd_completion()
1883 xhci_info(xhci, "INFO unknown command type %d\n", cmd_type); in handle_cmd_completion()
1888 if (!list_is_singular(&xhci->cmd_list)) { in handle_cmd_completion()
1889 xhci->current_cmd = list_first_entry(&cmd->cmd_list, in handle_cmd_completion()
1891 xhci_mod_cmd_timer(xhci); in handle_cmd_completion()
1892 } else if (xhci->current_cmd == cmd) { in handle_cmd_completion()
1893 xhci->current_cmd = NULL; in handle_cmd_completion()
1899 inc_deq(xhci, xhci->cmd_ring); in handle_cmd_completion()
1902 static void handle_vendor_event(struct xhci_hcd *xhci, in handle_vendor_event() argument
1905 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type); in handle_vendor_event()
1906 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) in handle_vendor_event()
1907 handle_cmd_completion(xhci, &event->event_cmd); in handle_vendor_event()
1910 static void handle_device_notification(struct xhci_hcd *xhci, in handle_device_notification() argument
1917 if (!xhci->devs[slot_id]) { in handle_device_notification()
1918 xhci_warn(xhci, "Device Notification event for " in handle_device_notification()
1923 xhci_dbg(xhci, "Device Wake Notification event for slot ID %u\n", in handle_device_notification()
1925 udev = xhci->devs[slot_id]->udev; in handle_device_notification()
1931 * Quirk hanlder for errata seen on Cavium ThunderX2 processor XHCI
1942 static void xhci_cavium_reset_phy_quirk(struct xhci_hcd *xhci) in xhci_cavium_reset_phy_quirk() argument
1944 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_cavium_reset_phy_quirk()
1959 static void handle_port_status(struct xhci_hcd *xhci, in handle_port_status() argument
1975 xhci_warn(xhci, in handle_port_status()
1979 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); in handle_port_status()
1982 xhci_warn(xhci, "Port change event with invalid port ID %d\n", in handle_port_status()
1984 inc_deq(xhci, ir->event_ring); in handle_port_status()
1988 port = &xhci->hw_ports[port_id - 1]; in handle_port_status()
1990 xhci_warn(xhci, "Port change event, no port for port ID %u\n", in handle_port_status()
1997 if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) { in handle_port_status()
1998 xhci_dbg(xhci, "ignore port event for removed USB3 hcd\n"); in handle_port_status()
2008 xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n", in handle_port_status()
2014 xhci_dbg(xhci, "resume root hub\n"); in handle_port_status()
2020 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
2021 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
2022 xhci->devs[slot_id]->flags |= VDEV_PORT_ERROR; in handle_port_status()
2026 xhci_dbg(xhci, "port resume event for port %d\n", port_id); in handle_port_status()
2028 cmd_reg = readl(&xhci->op_regs->command); in handle_port_status()
2030 xhci_warn(xhci, "xHC is not running.\n"); in handle_port_status()
2035 xhci_dbg(xhci, "remote wake SS port %d\n", port_id); in handle_port_status()
2041 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
2043 xhci_set_link_state(xhci, port, XDEV_U0); in handle_port_status()
2050 xhci_dbg(xhci, "resume HS port %d\n", port_id); in handle_port_status()
2071 xhci_dbg(xhci, "resume SS port %d finished\n", port_id); in handle_port_status()
2080 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
2081 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
2082 xhci_ring_device(xhci, slot_id); in handle_port_status()
2084 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
2093 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or in handle_port_status()
2105 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
2106 if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) && in handle_port_status()
2108 xhci_cavium_reset_phy_quirk(xhci); in handle_port_status()
2113 inc_deq(xhci, ir->event_ring); in handle_port_status()
2123 * xHCI port-status-change events occur when the "or" of all the in handle_port_status()
2129 xhci_dbg(xhci, "%s: starting usb%d port polling.\n", in handle_port_status()
2132 spin_unlock(&xhci->lock); in handle_port_status()
2135 spin_lock(&xhci->lock); in handle_port_status()
2144 struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, in trb_in_td() argument
2169 xhci_warn(xhci, in trb_in_td()
2205 static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_clear_hub_tt_buffer() argument
2213 (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && in xhci_clear_hub_tt_buffer()
2228 static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci, in xhci_requires_manual_halt_cleanup() argument
2248 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) in xhci_is_vendor_info_code() argument
2254 xhci_dbg(xhci, "Vendor defined info completion code %u\n", in xhci_is_vendor_info_code()
2256 xhci_dbg(xhci, "Treating code as success.\n"); in xhci_is_vendor_info_code()
2262 static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in finish_td() argument
2268 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in finish_td()
2302 xhci_dbg(xhci, "Already resolving halted ep for 0x%llx\n", in finish_td()
2311 xhci_clear_hub_tt_buffer(xhci, td, ep); in finish_td()
2312 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); in finish_td()
2316 * xhci internal endpoint state will go to a "halt" state for in finish_td()
2326 xhci_clear_hub_tt_buffer(xhci, td, ep); in finish_td()
2328 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); in finish_td()
2338 inc_deq(xhci, ep_ring); in finish_td()
2340 return xhci_td_cleanup(xhci, td, ep_ring, td->status); in finish_td()
2344 static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring, in sum_trb_lengths() argument
2351 for (sum = 0; trb != stop_trb; next_trb(xhci, ring, &seg, &trb)) { in sum_trb_lengths()
2361 static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_ctrl_td() argument
2371 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in process_ctrl_td()
2379 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n", in process_ctrl_td()
2393 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); in process_ctrl_td()
2408 xhci_warn(xhci, "WARN: unexpected TRB Type %d\n", in process_ctrl_td()
2415 if (!xhci_requires_manual_halt_cleanup(xhci, in process_ctrl_td()
2418 xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n", in process_ctrl_td()
2442 xhci_dbg(xhci, "Waiting for status stage event\n"); in process_ctrl_td()
2451 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_ctrl_td()
2457 static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_isoc_td() argument
2482 /* Don't overwrite status if TD had an error, see xHCI 4.9.1 */ in process_isoc_td()
2539 frame->actual_length = sum_trb_lengths(xhci, ep->ring, ep_trb) + in process_isoc_td()
2549 xhci_dbg(xhci, "Error mid isoc TD, wait for final completion event\n"); in process_isoc_td()
2554 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_isoc_td()
2557 static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, in skip_isoc_td() argument
2577 inc_deq(xhci, ep->ring); in skip_isoc_td()
2579 return xhci_td_cleanup(xhci, td, ep->ring, status); in skip_isoc_td()
2585 static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_bulk_intr_td() argument
2593 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in process_bulk_intr_td()
2604 xhci_warn(xhci, "WARN Successful completion on short TX\n"); in process_bulk_intr_td()
2605 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2612 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2622 td->urb->actual_length = sum_trb_lengths(xhci, ep_ring, ep_trb); in process_bulk_intr_td()
2625 if (xhci->quirks & XHCI_NO_SOFT_RETRY || in process_bulk_intr_td()
2632 xhci_handle_halted_endpoint(xhci, ep, td, EP_SOFT_RESET); in process_bulk_intr_td()
2643 sum_trb_lengths(xhci, ep_ring, ep_trb) + in process_bulk_intr_td()
2647 xhci_warn(xhci, "bad transfer trb length %d in event trb\n", in process_bulk_intr_td()
2652 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_bulk_intr_td()
2660 static int handle_tx_event(struct xhci_hcd *xhci, in handle_tx_event() argument
2683 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in handle_tx_event()
2685 xhci_err(xhci, "ERROR Invalid Transfer event\n"); in handle_tx_event()
2690 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in handle_tx_event()
2693 xhci_err(xhci, in handle_tx_event()
2699 /* Some transfer events don't always point to a trb, see xhci 4.17.4 */ in handle_tx_event()
2706 xhci_dbg(xhci, "Stream transaction error ep %u no id\n", in handle_tx_event()
2709 xhci_handle_halted_endpoint(xhci, ep, NULL, in handle_tx_event()
2712 xhci_handle_halted_endpoint(xhci, ep, NULL, in handle_tx_event()
2720 xhci_err(xhci, "ERROR Transfer event for unknown stream ring slot %u ep %u\n", in handle_tx_event()
2738 xhci_dbg(xhci, "Successful completion on short TX for slot %u ep %u with last td short %d\n", in handle_tx_event()
2746 xhci_dbg(xhci, "Stopped on Transfer TRB for slot %u ep %u\n", in handle_tx_event()
2750 xhci_dbg(xhci, in handle_tx_event()
2755 xhci_dbg(xhci, in handle_tx_event()
2761 xhci_dbg(xhci, "Stalled endpoint for slot %u ep %u\n", slot_id, in handle_tx_event()
2766 xhci_dbg(xhci, "Split transaction error for slot %u ep %u\n", in handle_tx_event()
2771 xhci_dbg(xhci, "Transfer error for slot %u ep %u on endpoint\n", in handle_tx_event()
2776 xhci_dbg(xhci, "Babble error for slot %u ep %u on endpoint\n", in handle_tx_event()
2782 xhci_warn(xhci, in handle_tx_event()
2789 xhci_warn(xhci, in handle_tx_event()
2795 xhci_warn(xhci, in handle_tx_event()
2800 xhci_warn(xhci, in handle_tx_event()
2810 xhci_dbg(xhci, "underrun event on endpoint\n"); in handle_tx_event()
2812 xhci_dbg(xhci, "Underrun Event for slot %d ep %d " in handle_tx_event()
2818 xhci_dbg(xhci, "overrun event on endpoint\n"); in handle_tx_event()
2820 xhci_dbg(xhci, "Overrun Event for slot %d ep %d " in handle_tx_event()
2833 xhci_dbg(xhci, in handle_tx_event()
2839 xhci_dbg(xhci, in handle_tx_event()
2846 xhci_warn(xhci, in handle_tx_event()
2852 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { in handle_tx_event()
2856 xhci_warn(xhci, in handle_tx_event()
2878 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n", in handle_tx_event()
2884 xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2888 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
2890 xhci_handle_halted_endpoint(xhci, ep, NULL, in handle_tx_event()
2899 xhci_dbg(xhci, "All tds on the ep_ring skipped. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2910 ep_seg = trb_in_td(xhci, ep_ring->deq_seg, ep_ring->dequeue, in handle_tx_event()
2929 skip_isoc_td(xhci, td, ep, status); in handle_tx_event()
2937 if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && in handle_tx_event()
2944 * xhci 4.10.2 states isoc endpoints should continue in handle_tx_event()
2948 * xhci 4.9.1 states that if there are errors in mult-TRB in handle_tx_event()
2958 ep_seg = trb_in_td(xhci, td_next->start_seg, td_next->first_trb, in handle_tx_event()
2962 xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); in handle_tx_event()
2965 inc_deq(xhci, ep_ring); in handle_tx_event()
2966 xhci_td_cleanup(xhci, td, ep_ring, td->status); in handle_tx_event()
2973 xhci_err(xhci, in handle_tx_event()
2978 trb_in_td(xhci, ep_ring->deq_seg, in handle_tx_event()
2990 xhci_dbg(xhci, in handle_tx_event()
3012 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
3014 xhci_handle_halted_endpoint(xhci, ep, td, in handle_tx_event()
3023 process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
3025 process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
3027 process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
3038 inc_deq(xhci, ir->event_ring); in handle_tx_event()
3051 xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n", in handle_tx_event()
3064 * xhci->lock between event processing (e.g. to pass up port status changes).
3068 static int xhci_handle_event(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_handle_event() argument
3077 xhci_err(xhci, "ERROR interrupter not ready\n"); in xhci_handle_event()
3099 handle_cmd_completion(xhci, &event->event_cmd); in xhci_handle_event()
3102 handle_port_status(xhci, ir, event); in xhci_handle_event()
3106 ret = handle_tx_event(xhci, ir, &event->trans_event); in xhci_handle_event()
3111 handle_device_notification(xhci, event); in xhci_handle_event()
3115 handle_vendor_event(xhci, event, trb_type); in xhci_handle_event()
3117 xhci_warn(xhci, "ERROR unknown event type %d\n", trb_type); in xhci_handle_event()
3122 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_handle_event()
3123 xhci_dbg(xhci, "xHCI host dying, returning from " in xhci_handle_event()
3130 inc_deq(xhci, ir->event_ring); in xhci_handle_event()
3143 static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, in xhci_update_erst_dequeue() argument
3151 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
3157 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); in xhci_update_erst_dequeue()
3174 xhci_write_64(xhci, temp_64, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
3178 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
3184 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_irq() local
3192 spin_lock(&xhci->lock); in xhci_irq()
3194 status = readl(&xhci->op_regs->status); in xhci_irq()
3196 xhci_hc_died(xhci); in xhci_irq()
3205 xhci_warn(xhci, "WARNING: Host Controller Error\n"); in xhci_irq()
3210 xhci_warn(xhci, "WARNING: Host System Error\n"); in xhci_irq()
3211 xhci_halt(xhci); in xhci_irq()
3222 writel(status, &xhci->op_regs->status); in xhci_irq()
3225 ir = xhci->interrupter; in xhci_irq()
3233 if (xhci->xhc_state & XHCI_STATE_DYING || in xhci_irq()
3234 xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_irq()
3235 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " in xhci_irq()
3240 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_irq()
3241 xhci_write_64(xhci, temp_64 | ERST_EHB, in xhci_irq()
3251 while (xhci_handle_event(xhci, ir) > 0) { in xhci_irq()
3254 xhci_update_erst_dequeue(xhci, ir, event_ring_deq, false); in xhci_irq()
3258 if (xhci->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) in xhci_irq()
3259 xhci->isoc_bei_interval = xhci->isoc_bei_interval / 2; in xhci_irq()
3264 xhci_update_erst_dequeue(xhci, ir, event_ring_deq, true); in xhci_irq()
3268 spin_unlock(&xhci->lock); in xhci_irq()
3288 static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, in queue_trb() argument
3304 inc_enq(xhci, ring, more_trbs_coming); in queue_trb()
3311 static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in prepare_ring() argument
3324 xhci_warn(xhci, "WARN urb submitted to disabled ep\n"); in prepare_ring()
3327 xhci_warn(xhci, "WARN waiting for error on ep to be cleared\n"); in prepare_ring()
3332 xhci_dbg(xhci, "WARN halted endpoint, queueing URB anyway.\n"); in prepare_ring()
3338 xhci_err(xhci, "ERROR unknown endpoint state for ep\n"); in prepare_ring()
3346 if (ep_ring != xhci->cmd_ring) { in prepare_ring()
3347 new_segs = xhci_ring_expansion_needed(xhci, ep_ring, num_trbs); in prepare_ring()
3348 } else if (xhci_num_trbs_free(xhci, ep_ring) <= num_trbs) { in prepare_ring()
3349 xhci_err(xhci, "Do not support expand command ring\n"); in prepare_ring()
3354 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, in prepare_ring()
3356 if (xhci_ring_expansion(xhci, ep_ring, new_segs, mem_flags)) { in prepare_ring()
3357 xhci_err(xhci, "Ring expansion failed\n"); in prepare_ring()
3366 if (!xhci_link_trb_quirk(xhci) && in prepare_ring()
3368 (xhci->quirks & XHCI_AMD_0x96_HOST))) in prepare_ring()
3387 xhci_warn(xhci, "Ring is an endless link TRB loop\n"); in prepare_ring()
3393 xhci_warn(xhci, "Missing link TRB at end of ring segment\n"); in prepare_ring()
3400 static int prepare_transfer(struct xhci_hcd *xhci, in prepare_transfer() argument
3413 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in prepare_transfer()
3415 ep_ring = xhci_triad_to_transfer_ring(xhci, xdev->slot_id, ep_index, in prepare_transfer()
3418 xhci_dbg(xhci, "Can't prepare ring for bad stream ID %u\n", in prepare_transfer()
3423 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in prepare_transfer()
3507 static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, in giveback_first_trb() argument
3520 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); in giveback_first_trb()
3523 static void check_interval(struct xhci_hcd *xhci, struct urb *urb, in check_interval() argument
3542 "Driver uses different interval (%d microframe%s) than xHCI (%d microframe%s)\n", in check_interval()
3554 * xHCI uses normal TRBs for both bulk and interrupt. When the interrupt
3559 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_intr_tx() argument
3564 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); in xhci_queue_intr_tx()
3565 check_interval(xhci, urb, ep_ctx); in xhci_queue_intr_tx()
3567 return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_intr_tx()
3571 * For xHCI 1.0 host controllers, TD size is the number of max packet sized
3582 * For xHCI 0.96 and older, TD size field should be the remaining bytes
3590 static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, in xhci_td_remainder() argument
3596 /* MTK xHCI 0.96 contains some features from 1.0 */ in xhci_td_remainder()
3597 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) in xhci_td_remainder()
3605 /* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */ in xhci_td_remainder()
3606 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) in xhci_td_remainder()
3617 static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len, in xhci_align_td() argument
3620 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_align_td()
3633 xhci_dbg(xhci, "Unaligned %d bytes, buff len %d\n", in xhci_align_td()
3639 xhci_dbg(xhci, "split align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3659 xhci_warn(xhci, "WARN Wrong bounce buffer write length: %zu != %d\n", in xhci_align_td()
3674 xhci_warn(xhci, "Failed mapping bounce buffer, not aligning\n"); in xhci_align_td()
3681 xhci_dbg(xhci, "Bounce align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3687 int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_bulk_tx() argument
3705 ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_bulk_tx()
3722 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3771 if (xhci_align_td(xhci, urb, enqd_len, in xhci_queue_bulk_tx()
3799 remainder = xhci_td_remainder(xhci, enqd_len, trb_buff_len, in xhci_queue_bulk_tx()
3806 queue_trb(xhci, ring, more_trbs_coming | need_zero_pkt, in xhci_queue_bulk_tx()
3831 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3837 queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); in xhci_queue_bulk_tx()
3842 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3847 /* Caller must have locked xhci->lock */
3848 int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_ctrl_tx() argument
3861 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_ctrl_tx()
3872 if ((xhci->quirks & XHCI_ETRON_HOST) && in xhci_queue_ctrl_tx()
3881 queue_trb(xhci, ep_ring, false, 0, 0, in xhci_queue_ctrl_tx()
3895 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_ctrl_tx()
3921 /* xHCI 1.0/1.1 6.4.1.2.1: Transfer Type field */ in xhci_queue_ctrl_tx()
3922 if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { in xhci_queue_ctrl_tx()
3931 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3958 remainder = xhci_td_remainder(xhci, 0, in xhci_queue_ctrl_tx()
3967 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3984 queue_trb(xhci, ep_ring, false, in xhci_queue_ctrl_tx()
3991 giveback_first_trb(xhci, slot_id, ep_index, 0, in xhci_queue_ctrl_tx()
4002 * zero. Only xHCI 1.0 host controllers support this field.
4004 static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci, in xhci_get_burst_count() argument
4009 if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER) in xhci_get_burst_count()
4024 static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci, in xhci_get_last_burst_packet_count() argument
4030 if (xhci->hci_version < 0x100) in xhci_get_last_burst_packet_count()
4056 static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci, in xhci_get_isoc_frame_id() argument
4076 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_get_isoc_frame_id()
4077 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_get_isoc_frame_id()
4093 current_frame_id = readl(&xhci->run_regs->microframe_index); in xhci_get_isoc_frame_id()
4101 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()
4102 __func__, index, readl(&xhci->run_regs->microframe_index), in xhci_get_isoc_frame_id()
4130 xhci_warn(xhci, "Frame ID %d (reg %d, index %d) beyond range (%d, %d)\n", in xhci_get_isoc_frame_id()
4133 xhci_warn(xhci, "Ignore frame ID field, use SIA bit instead\n"); in xhci_get_isoc_frame_id()
4141 static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) in trb_block_event_intr() argument
4143 if (xhci->hci_version < 0x100) in trb_block_event_intr()
4152 if (i && xhci->quirks & XHCI_AVOID_BEI) in trb_block_event_intr()
4153 return !!(i % xhci->isoc_bei_interval); in trb_block_event_intr()
4159 static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx() argument
4177 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx()
4178 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; in xhci_queue_isoc_tx()
4182 xhci_dbg(xhci, "Isoc URB with zero packets?\n"); in xhci_queue_isoc_tx()
4207 burst_count = xhci_get_burst_count(xhci, urb, total_pkt_count); in xhci_queue_isoc_tx()
4208 last_burst_pkt_count = xhci_get_last_burst_packet_count(xhci, in xhci_queue_isoc_tx()
4213 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, in xhci_queue_isoc_tx()
4225 HCC_CFC(xhci->hcc_params)) { in xhci_queue_isoc_tx()
4226 frame_id = xhci_get_isoc_frame_id(xhci, urb, i); in xhci_queue_isoc_tx()
4240 /* xhci 1.1 with ETE uses TD_Size field for TBC, old is Rsvdz */ in xhci_queue_isoc_tx()
4266 if (trb_block_event_intr(xhci, num_tds, i)) in xhci_queue_isoc_tx()
4275 remainder = xhci_td_remainder(xhci, running_total, in xhci_queue_isoc_tx()
4282 /* xhci 1.1 with ETE uses TD Size field for TBC */ in xhci_queue_isoc_tx()
4289 queue_trb(xhci, ep_ring, more_trbs_coming, in xhci_queue_isoc_tx()
4302 xhci_err(xhci, "ISOC TD length unmatch\n"); in xhci_queue_isoc_tx()
4309 if (HCC_CFC(xhci->hcc_params)) in xhci_queue_isoc_tx()
4312 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_queue_isoc_tx()
4313 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_queue_isoc_tx()
4316 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; in xhci_queue_isoc_tx()
4318 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_isoc_tx()
4334 td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); in xhci_queue_isoc_tx()
4347 * Update interval as xhci_queue_intr_tx does. Use xhci frame_index to
4351 int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx_prepare() argument
4363 xdev = xhci->devs[slot_id]; in xhci_queue_isoc_tx_prepare()
4364 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx_prepare()
4366 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in xhci_queue_isoc_tx_prepare()
4376 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in xhci_queue_isoc_tx_prepare()
4385 check_interval(xhci, urb, ep_ctx); in xhci_queue_isoc_tx_prepare()
4388 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { in xhci_queue_isoc_tx_prepare()
4395 start_frame = readl(&xhci->run_regs->microframe_index); in xhci_queue_isoc_tx_prepare()
4401 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_queue_isoc_tx_prepare()
4402 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_queue_isoc_tx_prepare()
4422 return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_isoc_tx_prepare()
4432 * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
4435 static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in queue_command() argument
4439 int reserved_trbs = xhci->cmd_ring_reserved_trbs; in queue_command()
4442 if ((xhci->xhc_state & XHCI_STATE_DYING) || in queue_command()
4443 (xhci->xhc_state & XHCI_STATE_HALTED)) { in queue_command()
4444 xhci_dbg(xhci, "xHCI dying or halted, can't queue_command\n"); in queue_command()
4451 ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, in queue_command()
4454 xhci_err(xhci, "ERR: No room for command on command ring\n"); in queue_command()
4456 xhci_err(xhci, "ERR: Reserved TRB counting for " in queue_command()
4461 cmd->command_trb = xhci->cmd_ring->enqueue; in queue_command()
4464 if (list_empty(&xhci->cmd_list)) { in queue_command()
4465 xhci->current_cmd = cmd; in queue_command()
4466 xhci_mod_cmd_timer(xhci); in queue_command()
4469 list_add_tail(&cmd->cmd_list, &xhci->cmd_list); in queue_command()
4471 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, in queue_command()
4472 field4 | xhci->cmd_ring->cycle_state); in queue_command()
4477 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_slot_control() argument
4480 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_slot_control()
4485 int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_address_device() argument
4488 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_address_device()
4494 int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_vendor_command() argument
4497 return queue_command(xhci, cmd, field1, field2, field3, field4, false); in xhci_queue_vendor_command()
4501 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_device() argument
4504 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_device()
4510 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, in xhci_queue_configure_endpoint() argument
4514 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_configure_endpoint()
4521 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_evaluate_context() argument
4524 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_evaluate_context()
4534 int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_stop_endpoint() argument
4542 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_stop_endpoint()
4546 int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_ep() argument
4557 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_ep()