Lines Matching full:xhci

3  * xHCI host controller driver
60 #include "xhci.h"
61 #include "xhci-trace.h"
63 static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd,
164 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) in inc_deq() argument
187 xhci_warn(xhci, "Missing link TRB at end of segment\n"); in inc_deq()
199 xhci_warn(xhci, "Ring is an endless link TRB loop\n"); in inc_deq()
217 * xHCI hardware can't handle the chain bit being cleared on a link TRB.
222 static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, in inc_enq() argument
232 xhci_err(xhci, "Tried to move enqueue past ring segment\n"); in inc_enq()
255 if (!xhci_link_chain_quirk(xhci, ring->type)) { in inc_enq()
274 xhci_warn(xhci, "%s: Ring link TRB loop\n", __func__); in inc_enq()
322 static unsigned int xhci_ring_expansion_needed(struct xhci_hcd *xhci, struct xhci_ring *ring, in xhci_ring_expansion_needed() argument
354 xhci_dbg(xhci, "Adding %d trbs requires expanding ring by %d segments\n", in xhci_ring_expansion_needed()
365 void xhci_ring_cmd_db(struct xhci_hcd *xhci) in xhci_ring_cmd_db() argument
367 if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) in xhci_ring_cmd_db()
370 xhci_dbg(xhci, "// Ding dong!\n"); in xhci_ring_cmd_db()
374 writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
376 readl(&xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
379 static bool xhci_mod_cmd_timer(struct xhci_hcd *xhci) in xhci_mod_cmd_timer() argument
381 return mod_delayed_work(system_wq, &xhci->cmd_timer, in xhci_mod_cmd_timer()
382 msecs_to_jiffies(xhci->current_cmd->timeout_ms)); in xhci_mod_cmd_timer()
385 static struct xhci_command *xhci_next_queued_cmd(struct xhci_hcd *xhci) in xhci_next_queued_cmd() argument
387 return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command, in xhci_next_queued_cmd()
394 * This must be called with command ring stopped and xhci->lock held.
396 static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci, in xhci_handle_stopped_cmd_ring() argument
402 list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) { in xhci_handle_stopped_cmd_ring()
409 xhci_dbg(xhci, "Turn aborted command %p to no-op\n", in xhci_handle_stopped_cmd_ring()
420 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_handle_stopped_cmd_ring()
423 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && in xhci_handle_stopped_cmd_ring()
424 !(xhci->xhc_state & XHCI_STATE_DYING)) { in xhci_handle_stopped_cmd_ring()
425 xhci->current_cmd = cur_cmd; in xhci_handle_stopped_cmd_ring()
427 xhci_mod_cmd_timer(xhci); in xhci_handle_stopped_cmd_ring()
428 xhci_ring_cmd_db(xhci); in xhci_handle_stopped_cmd_ring()
432 /* Must be called with xhci->lock held, releases and acquires lock back */
433 static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) in xhci_abort_cmd_ring() argument
435 struct xhci_segment *new_seg = xhci->cmd_ring->deq_seg; in xhci_abort_cmd_ring()
436 union xhci_trb *new_deq = xhci->cmd_ring->dequeue; in xhci_abort_cmd_ring()
440 xhci_dbg(xhci, "Abort command ring\n"); in xhci_abort_cmd_ring()
442 reinit_completion(&xhci->cmd_ring_stop_completion); in xhci_abort_cmd_ring()
457 xhci_write_64(xhci, crcr | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
459 /* Section 4.6.1.2 of xHCI 1.0 spec says software should also time the in xhci_abort_cmd_ring()
465 ret = xhci_handshake_check_state(xhci, &xhci->op_regs->cmd_ring, in xhci_abort_cmd_ring()
469 xhci_err(xhci, "Abort failed to stop command ring: %d\n", ret); in xhci_abort_cmd_ring()
470 xhci_halt(xhci); in xhci_abort_cmd_ring()
471 xhci_hc_died(xhci); in xhci_abort_cmd_ring()
480 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_abort_cmd_ring()
481 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, in xhci_abort_cmd_ring()
483 spin_lock_irqsave(&xhci->lock, flags); in xhci_abort_cmd_ring()
485 xhci_dbg(xhci, "No stop event for abort, ring start fail?\n"); in xhci_abort_cmd_ring()
486 xhci_cleanup_command_queue(xhci); in xhci_abort_cmd_ring()
488 xhci_handle_stopped_cmd_ring(xhci, xhci_next_queued_cmd(xhci)); in xhci_abort_cmd_ring()
493 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, in xhci_ring_ep_doorbell() argument
498 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; in xhci_ring_ep_doorbell()
499 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_ring_ep_doorbell()
520 static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in ring_doorbell_for_active_rings() argument
527 ep = &xhci->devs[slot_id]->eps[ep_index]; in ring_doorbell_for_active_rings()
532 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, 0); in ring_doorbell_for_active_rings()
540 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, in ring_doorbell_for_active_rings()
545 void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in xhci_ring_doorbell_for_active_rings() argument
549 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_ring_doorbell_for_active_rings()
552 static struct xhci_virt_ep *xhci_get_virt_ep(struct xhci_hcd *xhci, in xhci_get_virt_ep() argument
557 xhci_warn(xhci, "Invalid slot_id %u\n", slot_id); in xhci_get_virt_ep()
561 xhci_warn(xhci, "Invalid endpoint index %u\n", ep_index); in xhci_get_virt_ep()
564 if (!xhci->devs[slot_id]) { in xhci_get_virt_ep()
565 xhci_warn(xhci, "No xhci virt device for slot_id %u\n", slot_id); in xhci_get_virt_ep()
569 return &xhci->devs[slot_id]->eps[ep_index]; in xhci_get_virt_ep()
572 static struct xhci_ring *xhci_virt_ep_to_ring(struct xhci_hcd *xhci, in xhci_virt_ep_to_ring() argument
584 xhci_warn(xhci, "Invalid stream_id %u request for slot_id %u ep_index %u\n", in xhci_virt_ep_to_ring()
596 struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, in xhci_triad_to_transfer_ring() argument
602 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_triad_to_transfer_ring()
606 return xhci_virt_ep_to_ring(xhci, ep, stream_id); in xhci_triad_to_transfer_ring()
616 static u64 xhci_get_hw_deq(struct xhci_hcd *xhci, struct xhci_virt_device *vdev, in xhci_get_hw_deq() argument
629 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_get_hw_deq()
633 static int xhci_move_dequeue_past_td(struct xhci_hcd *xhci, in xhci_move_dequeue_past_td() argument
637 struct xhci_virt_device *dev = xhci->devs[slot_id]; in xhci_move_dequeue_past_td()
651 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id, in xhci_move_dequeue_past_td()
654 xhci_warn(xhci, "WARN can't find new dequeue, invalid stream ID %u\n", in xhci_move_dequeue_past_td()
659 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); in xhci_move_dequeue_past_td()
688 xhci_err(xhci, "Error: Failed finding new dequeue state\n"); in xhci_move_dequeue_past_td()
697 xhci_warn(xhci, "Can't find dma of new dequeue ptr\n"); in xhci_move_dequeue_past_td()
698 xhci_warn(xhci, "deq seg = %p, deq ptr = %p\n", new_seg, new_deq); in xhci_move_dequeue_past_td()
703 xhci_warn(xhci, "Set TR Deq already pending, don't submit for 0x%pad\n", in xhci_move_dequeue_past_td()
709 cmd = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_move_dequeue_past_td()
711 xhci_warn(xhci, "Can't alloc Set TR Deq cmd 0x%pad\n", &addr); in xhci_move_dequeue_past_td()
717 ret = queue_command(xhci, cmd, in xhci_move_dequeue_past_td()
723 xhci_free_command(xhci, cmd); in xhci_move_dequeue_past_td()
729 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_move_dequeue_past_td()
738 xhci_ring_cmd_db(xhci); in xhci_move_dequeue_past_td()
765 static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, in xhci_giveback_urb_in_irq() argument
773 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; in xhci_giveback_urb_in_irq()
774 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_giveback_urb_in_irq()
775 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_giveback_urb_in_irq()
785 static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, in xhci_unmap_td_bounce_buffer() argument
788 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_unmap_td_bounce_buffer()
809 xhci_warn(xhci, "WARN Wrong bounce buffer read length: %zu != %d\n", in xhci_unmap_td_bounce_buffer()
819 static void xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_td_cleanup() argument
828 xhci_unmap_td_bounce_buffer(xhci, ep_ring, td); in xhci_td_cleanup()
836 xhci_warn(xhci, "URB req %u and actual %u transfer length mismatch\n", in xhci_td_cleanup()
854 xhci_dbg(xhci, "Giveback URB %p, len = %d, expected = %d, status = %d\n", in xhci_td_cleanup()
861 xhci_giveback_urb_in_irq(xhci, td, status); in xhci_td_cleanup()
866 static void xhci_dequeue_td(struct xhci_hcd *xhci, struct xhci_td *td, struct xhci_ring *ring, in xhci_dequeue_td() argument
871 inc_deq(xhci, ring); in xhci_dequeue_td()
873 xhci_td_cleanup(xhci, td, ring, status); in xhci_dequeue_td()
885 ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_giveback_invalidated_tds()
888 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_giveback_invalidated_tds()
890 xhci_td_cleanup(ep->xhci, td, ring, td->status); in xhci_giveback_invalidated_tds()
892 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_giveback_invalidated_tds()
895 if (ep->xhci->xhc_state & XHCI_STATE_DYING) in xhci_giveback_invalidated_tds()
900 static int xhci_reset_halted_ep(struct xhci_hcd *xhci, unsigned int slot_id, in xhci_reset_halted_ep() argument
906 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_reset_halted_ep()
912 xhci_dbg(xhci, "%s-reset ep %u, slot %u\n", in xhci_reset_halted_ep()
916 ret = xhci_queue_reset_ep(xhci, command, slot_id, ep_index, reset_type); in xhci_reset_halted_ep()
919 xhci_err(xhci, "ERROR queuing reset endpoint for slot %d ep_index %d, %d\n", in xhci_reset_halted_ep()
924 static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci, in xhci_handle_halted_endpoint() argument
949 xhci_dbg(xhci, "Reset ep command for ep_index %d already pending\n", in xhci_handle_halted_endpoint()
954 err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type); in xhci_handle_halted_endpoint()
960 xhci_ring_cmd_db(xhci); in xhci_handle_halted_endpoint()
967 * We have the xHCI lock, so nothing can modify this list until we drop it.
976 struct xhci_hcd *xhci; in xhci_invalidate_cancelled_tds() local
992 xhci = ep->xhci; in xhci_invalidate_cancelled_tds()
995 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_invalidate_cancelled_tds()
1001 ring = xhci_urb_to_transfer_ring(xhci, td->urb); in xhci_invalidate_cancelled_tds()
1003 xhci_warn(xhci, "WARN Cancelled URB %p has invalid stream ID %u.\n", in xhci_invalidate_cancelled_tds()
1013 hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index, in xhci_invalidate_cancelled_tds()
1017 if (td->cancel_status == TD_HALTED || trb_in_td(xhci, td, hw_deq, false)) { in xhci_invalidate_cancelled_tds()
1028 xhci_dbg(xhci, in xhci_invalidate_cancelled_tds()
1036 xhci_warn(xhci, in xhci_invalidate_cancelled_tds()
1058 err = xhci_move_dequeue_past_td(xhci, slot_id, ep->ep_index, in xhci_invalidate_cancelled_tds()
1072 xhci_warn(xhci, "Failed to clear cancelled cached URB %p, mark clear anyway\n", in xhci_invalidate_cancelled_tds()
1086 * Call under xhci->lock on a stopped endpoint.
1104 hw_deq = xhci_get_hw_deq(ep->xhci, ep->vdev, ep->ep_index, 0); in find_halted_td()
1107 if (trb_in_td(ep->xhci, td, hw_deq, false)) in find_halted_td()
1123 static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_stop_ep() argument
1135 if (!xhci->devs[slot_id]) in xhci_handle_cmd_stop_ep()
1136 xhci_warn(xhci, "Stop endpoint command completion for disabled slot %u\n", in xhci_handle_cmd_stop_ep()
1142 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
1146 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_stop_ep()
1167 xhci_dbg(xhci, "Stop ep completion raced with stall, reset ep\n"); in xhci_handle_cmd_stop_ep()
1177 err = xhci_handle_halted_endpoint(xhci, ep, td, reset_type); in xhci_handle_cmd_stop_ep()
1184 * Per xHCI 4.6.9, Stop Endpoint command on a Stopped in xhci_handle_cmd_stop_ep()
1209 xhci_dbg(xhci, "Stop ep completion ctx error, ctx_state %d\n", in xhci_handle_cmd_stop_ep()
1212 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_handle_cmd_stop_ep()
1217 xhci_queue_stop_endpoint(xhci, command, slot_id, ep_index, 0); in xhci_handle_cmd_stop_ep()
1218 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_stop_ep()
1232 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
1235 static void xhci_kill_ring_urbs(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_kill_ring_urbs() argument
1246 xhci_unmap_td_bounce_buffer(xhci, ring, cur_td); in xhci_kill_ring_urbs()
1250 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_ring_urbs()
1254 static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, in xhci_kill_endpoint_urbs() argument
1262 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_kill_endpoint_urbs()
1276 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1279 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1285 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1288 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1297 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_endpoint_urbs()
1307 * Call with xhci->lock held.
1310 void xhci_hc_died(struct xhci_hcd *xhci) in xhci_hc_died() argument
1314 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_hc_died()
1317 xhci_err(xhci, "xHCI host controller not responding, assume dead\n"); in xhci_hc_died()
1318 xhci->xhc_state |= XHCI_STATE_DYING; in xhci_hc_died()
1320 xhci_cleanup_command_queue(xhci); in xhci_hc_died()
1323 for (i = 0; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_hc_died()
1324 if (!xhci->devs[i]) in xhci_hc_died()
1327 xhci_kill_endpoint_urbs(xhci, i, j); in xhci_hc_died()
1331 if (!(xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_hc_died()
1332 usb_hc_died(xhci_to_hcd(xhci)); in xhci_hc_died()
1335 static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci, in update_ring_for_set_deq_completion() argument
1366 xhci_dbg(xhci, "Unable to find new dequeue pointer\n"); in update_ring_for_set_deq_completion()
1379 static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_set_deq() argument
1393 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1397 ep_ring = xhci_virt_ep_to_ring(xhci, ep, stream_id); in xhci_handle_cmd_set_deq()
1399 xhci_warn(xhci, "WARN Set TR deq ptr command for freed stream ID %u\n", in xhci_handle_cmd_set_deq()
1405 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_set_deq()
1406 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in xhci_handle_cmd_set_deq()
1421 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because of stream ID configuration\n"); in xhci_handle_cmd_set_deq()
1424 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.\n"); in xhci_handle_cmd_set_deq()
1428 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1433 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed because slot %u was not enabled.\n", in xhci_handle_cmd_set_deq()
1437 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown completion code of %u.\n", in xhci_handle_cmd_set_deq()
1454 * Cadence xHCI controllers store some endpoint state in xhci_handle_cmd_set_deq()
1462 if (xhci->quirks & XHCI_CDNS_SCTX_QUIRK) { in xhci_handle_cmd_set_deq()
1469 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1476 update_ring_for_set_deq_completion(xhci, ep->vdev, in xhci_handle_cmd_set_deq()
1479 xhci_warn(xhci, "Mismatch between completed Set TR Deq Ptr command & xHCI internal state.\n"); in xhci_handle_cmd_set_deq()
1480 xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n", in xhci_handle_cmd_set_deq()
1487 ep_ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb); in xhci_handle_cmd_set_deq()
1490 xhci_dbg(ep->xhci, "%s: Giveback cancelled URB %p TD\n", in xhci_handle_cmd_set_deq()
1492 xhci_td_cleanup(ep->xhci, td, ep_ring, td->status); in xhci_handle_cmd_set_deq()
1494 xhci_dbg(ep->xhci, "%s: Keep cancelled URB %p TD as cancel_status is %d\n", in xhci_handle_cmd_set_deq()
1505 xhci_dbg(ep->xhci, "%s: Pending TDs to clear, continuing with invalidation\n", in xhci_handle_cmd_set_deq()
1509 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1514 xhci_dbg(ep->xhci, "%s: All TDs cleared, ring doorbell\n", __func__); in xhci_handle_cmd_set_deq()
1515 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1519 static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_ep() argument
1527 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1531 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in xhci_handle_cmd_reset_ep()
1537 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, in xhci_handle_cmd_reset_ep()
1550 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1562 static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_disable_slot() argument
1567 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_disable_slot()
1571 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_handle_cmd_disable_slot()
1574 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) in xhci_handle_cmd_disable_slot()
1576 xhci_free_device_endpoint_resources(xhci, virt_dev, true); in xhci_handle_cmd_disable_slot()
1579 static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_config_ep() argument
1592 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_config_ep()
1597 xhci_warn(xhci, "Could not get input context, bad type.\n"); in xhci_handle_cmd_config_ep()
1606 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, ep_index); in xhci_handle_cmd_config_ep()
1612 static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_addr_dev() argument
1617 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_addr_dev()
1620 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_addr_dev()
1624 static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_reset_dev() argument
1629 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_dev()
1631 xhci_warn(xhci, "Reset device command completion for disabled slot %u\n", in xhci_handle_cmd_reset_dev()
1635 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_reset_dev()
1638 xhci_dbg(xhci, "Completed reset device command.\n"); in xhci_handle_cmd_reset_dev()
1641 static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, in xhci_handle_cmd_nec_get_fw() argument
1644 if (!(xhci->quirks & XHCI_NEC_HOST)) { in xhci_handle_cmd_nec_get_fw()
1645 xhci_warn(xhci, "WARN NEC_GET_FW command on non-NEC host\n"); in xhci_handle_cmd_nec_get_fw()
1648 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_nec_get_fw()
1667 void xhci_cleanup_command_queue(struct xhci_hcd *xhci) in xhci_cleanup_command_queue() argument
1670 xhci->current_cmd = NULL; in xhci_cleanup_command_queue()
1671 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) in xhci_cleanup_command_queue()
1677 struct xhci_hcd *xhci; in xhci_handle_command_timeout() local
1684 xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer); in xhci_handle_command_timeout()
1686 spin_lock_irqsave(&xhci->lock, flags); in xhci_handle_command_timeout()
1692 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { in xhci_handle_command_timeout()
1693 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1697 cmd_field3 = le32_to_cpu(xhci->current_cmd->command_trb->generic.field[3]); in xhci_handle_command_timeout()
1698 usbsts = readl(&xhci->op_regs->status); in xhci_handle_command_timeout()
1699 xhci_dbg(xhci, "Command timeout, USBSTS:%s\n", xhci_decode_usbsts(str, usbsts)); in xhci_handle_command_timeout()
1701 /* Bail out and tear down xhci if a stop endpoint command failed */ in xhci_handle_command_timeout()
1705 xhci_warn(xhci, "xHCI host not responding to stop endpoint command\n"); in xhci_handle_command_timeout()
1707 ep = xhci_get_virt_ep(xhci, TRB_TO_SLOT_ID(cmd_field3), in xhci_handle_command_timeout()
1712 xhci_halt(xhci); in xhci_handle_command_timeout()
1713 xhci_hc_died(xhci); in xhci_handle_command_timeout()
1718 xhci->current_cmd->status = COMP_COMMAND_ABORTED; in xhci_handle_command_timeout()
1721 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_handle_command_timeout()
1723 xhci_hc_died(xhci); in xhci_handle_command_timeout()
1727 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && in xhci_handle_command_timeout()
1730 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; in xhci_handle_command_timeout()
1731 xhci_dbg(xhci, "Command timeout\n"); in xhci_handle_command_timeout()
1732 xhci_abort_cmd_ring(xhci, flags); in xhci_handle_command_timeout()
1737 if (xhci->xhc_state & XHCI_STATE_REMOVING) { in xhci_handle_command_timeout()
1738 xhci_dbg(xhci, "host removed, ring start fail?\n"); in xhci_handle_command_timeout()
1739 xhci_cleanup_command_queue(xhci); in xhci_handle_command_timeout()
1745 xhci_dbg(xhci, "Command timeout on stopped ring\n"); in xhci_handle_command_timeout()
1746 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); in xhci_handle_command_timeout()
1749 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1753 static void handle_cmd_completion(struct xhci_hcd *xhci, in handle_cmd_completion() argument
1766 xhci_warn(xhci, "Invalid slot_id %u\n", slot_id); in handle_cmd_completion()
1771 cmd_trb = xhci->cmd_ring->dequeue; in handle_cmd_completion()
1773 trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic, cmd_dma); in handle_cmd_completion()
1779 complete_all(&xhci->cmd_ring_stop_completion); in handle_cmd_completion()
1783 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in handle_cmd_completion()
1790 xhci_warn(xhci, in handle_cmd_completion()
1795 cmd = list_first_entry(&xhci->cmd_list, struct xhci_command, cmd_list); in handle_cmd_completion()
1797 cancel_delayed_work(&xhci->cmd_timer); in handle_cmd_completion()
1799 if (cmd->command_trb != xhci->cmd_ring->dequeue) { in handle_cmd_completion()
1800 xhci_err(xhci, in handle_cmd_completion()
1812 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in handle_cmd_completion()
1814 if (xhci->current_cmd == cmd) in handle_cmd_completion()
1815 xhci->current_cmd = NULL; in handle_cmd_completion()
1826 xhci_handle_cmd_disable_slot(xhci, slot_id); in handle_cmd_completion()
1830 xhci_handle_cmd_config_ep(xhci, slot_id); in handle_cmd_completion()
1835 xhci_handle_cmd_addr_dev(xhci, slot_id); in handle_cmd_completion()
1841 xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, in handle_cmd_completion()
1847 xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1857 xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1861 * Use the SLOT_ID from the command TRB instead (xhci 4.6.11) in handle_cmd_completion()
1865 xhci_handle_cmd_reset_dev(xhci, slot_id); in handle_cmd_completion()
1868 xhci_handle_cmd_nec_get_fw(xhci, event); in handle_cmd_completion()
1872 xhci_info(xhci, "INFO unknown command type %d\n", cmd_type); in handle_cmd_completion()
1877 if (!list_is_singular(&xhci->cmd_list)) { in handle_cmd_completion()
1878 xhci->current_cmd = list_first_entry(&cmd->cmd_list, in handle_cmd_completion()
1880 xhci_mod_cmd_timer(xhci); in handle_cmd_completion()
1881 } else if (xhci->current_cmd == cmd) { in handle_cmd_completion()
1882 xhci->current_cmd = NULL; in handle_cmd_completion()
1888 inc_deq(xhci, xhci->cmd_ring); in handle_cmd_completion()
1891 static void handle_vendor_event(struct xhci_hcd *xhci, in handle_vendor_event() argument
1894 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type); in handle_vendor_event()
1895 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) in handle_vendor_event()
1896 handle_cmd_completion(xhci, &event->event_cmd); in handle_vendor_event()
1899 static void handle_device_notification(struct xhci_hcd *xhci, in handle_device_notification() argument
1906 if (!xhci->devs[slot_id]) { in handle_device_notification()
1907 xhci_warn(xhci, "Device Notification event for " in handle_device_notification()
1912 xhci_dbg(xhci, "Device Wake Notification event for slot ID %u\n", in handle_device_notification()
1914 udev = xhci->devs[slot_id]->udev; in handle_device_notification()
1920 * Quirk hanlder for errata seen on Cavium ThunderX2 processor XHCI
1931 static void xhci_cavium_reset_phy_quirk(struct xhci_hcd *xhci) in xhci_cavium_reset_phy_quirk() argument
1933 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_cavium_reset_phy_quirk()
1948 static void handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event) in handle_port_status() argument
1961 xhci_warn(xhci, in handle_port_status()
1965 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); in handle_port_status()
1968 xhci_warn(xhci, "Port change event with invalid port ID %d\n", in handle_port_status()
1973 port = &xhci->hw_ports[port_id - 1]; in handle_port_status()
1975 xhci_warn(xhci, "Port change event, no port for port ID %u\n", in handle_port_status()
1982 if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) { in handle_port_status()
1983 xhci_dbg(xhci, "ignore port event for removed USB3 hcd\n"); in handle_port_status()
1993 xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n", in handle_port_status()
1999 xhci_dbg(xhci, "resume root hub\n"); in handle_port_status()
2005 if (port->slot_id && xhci->devs[port->slot_id]) in handle_port_status()
2006 xhci->devs[port->slot_id]->flags |= VDEV_PORT_ERROR; in handle_port_status()
2010 xhci_dbg(xhci, "port resume event for port %d\n", port_id); in handle_port_status()
2012 cmd_reg = readl(&xhci->op_regs->command); in handle_port_status()
2014 xhci_warn(xhci, "xHC is not running.\n"); in handle_port_status()
2019 xhci_dbg(xhci, "remote wake SS port %d\n", port_id); in handle_port_status()
2025 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
2027 xhci_set_link_state(xhci, port, XDEV_U0); in handle_port_status()
2034 xhci_dbg(xhci, "resume HS port %d\n", port_id); in handle_port_status()
2055 xhci_dbg(xhci, "resume SS port %d finished\n", port_id); in handle_port_status()
2064 if (port->slot_id && xhci->devs[port->slot_id]) in handle_port_status()
2065 xhci_ring_device(xhci, port->slot_id); in handle_port_status()
2067 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
2076 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or in handle_port_status()
2088 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
2089 if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) && in handle_port_status()
2091 xhci_cavium_reset_phy_quirk(xhci); in handle_port_status()
2104 * xHCI port-status-change events occur when the "or" of all the in handle_port_status()
2110 xhci_dbg(xhci, "%s: starting usb%d port polling.\n", in handle_port_status()
2113 spin_unlock(&xhci->lock); in handle_port_status()
2116 spin_lock(&xhci->lock); in handle_port_status()
2123 struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, struct xhci_td *td, dma_addr_t suspect_dma, in trb_in_td() argument
2144 xhci_warn(xhci, in trb_in_td()
2180 static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_clear_hub_tt_buffer() argument
2188 (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && in xhci_clear_hub_tt_buffer()
2198 * Check if xhci internal endpoint state has gone to a "halt" state due to an
2227 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) in xhci_is_vendor_info_code() argument
2233 xhci_dbg(xhci, "Vendor defined info completion code %u\n", in xhci_is_vendor_info_code()
2235 xhci_dbg(xhci, "Treating code as success.\n"); in xhci_is_vendor_info_code()
2241 static void finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in finish_td() argument
2247 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in finish_td()
2281 xhci_dbg(xhci, "Already resolving halted ep for 0x%llx\n", in finish_td()
2290 xhci_clear_hub_tt_buffer(xhci, td, ep); in finish_td()
2291 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); in finish_td()
2295 * xhci internal endpoint state will go to a "halt" state for in finish_td()
2305 xhci_clear_hub_tt_buffer(xhci, td, ep); in finish_td()
2307 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); in finish_td()
2314 xhci_dequeue_td(xhci, td, ep_ring, td->status); in finish_td()
2334 static void process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_ctrl_td() argument
2344 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in process_ctrl_td()
2352 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n", in process_ctrl_td()
2366 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); in process_ctrl_td()
2381 xhci_warn(xhci, "WARN: unexpected TRB Type %d\n", in process_ctrl_td()
2390 xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n", in process_ctrl_td()
2414 xhci_dbg(xhci, "Waiting for status stage event\n"); in process_ctrl_td()
2423 finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_ctrl_td()
2429 static void process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_isoc_td() argument
2454 /* Don't overwrite status if TD had an error, see xHCI 4.9.1 */ in process_isoc_td()
2523 xhci_dbg(xhci, "Error mid isoc TD, wait for final completion event\n"); in process_isoc_td()
2527 finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_isoc_td()
2530 static void skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, in skip_isoc_td() argument
2547 xhci_dequeue_td(xhci, td, ep->ring, status); in skip_isoc_td()
2553 static void process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_bulk_intr_td() argument
2561 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in process_bulk_intr_td()
2572 xhci_warn(xhci, "WARN Successful completion on short TX\n"); in process_bulk_intr_td()
2573 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2590 if (xhci->quirks & XHCI_NO_SOFT_RETRY || in process_bulk_intr_td()
2597 xhci_handle_halted_endpoint(xhci, ep, td, EP_SOFT_RESET); in process_bulk_intr_td()
2612 xhci_warn(xhci, "bad transfer trb length %d in event trb\n", in process_bulk_intr_td()
2617 finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_bulk_intr_td()
2620 /* Transfer events which don't point to a transfer TRB, see xhci 4.17.4 */
2621 static int handle_transferless_tx_event(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in handle_transferless_tx_event() argument
2629 xhci_dbg(xhci, "Stream transaction error ep %u no id\n", ep->ep_index); in handle_transferless_tx_event()
2631 xhci_handle_halted_endpoint(xhci, ep, NULL, EP_HARD_RESET); in handle_transferless_tx_event()
2633 xhci_handle_halted_endpoint(xhci, ep, NULL, EP_SOFT_RESET); in handle_transferless_tx_event()
2640 xhci_err(xhci, "Transfer event %u for unknown stream ring slot %u ep %u\n", in handle_transferless_tx_event()
2652 static int handle_tx_event(struct xhci_hcd *xhci, in handle_tx_event() argument
2673 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in handle_tx_event()
2675 xhci_err(xhci, "ERROR Invalid Transfer event\n"); in handle_tx_event()
2680 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep_index); in handle_tx_event()
2683 xhci_err(xhci, in handle_tx_event()
2690 return handle_transferless_tx_event(xhci, ep, trb_comp_code); in handle_tx_event()
2700 xhci_dbg(xhci, "Successful completion on short TX for slot %u ep %u with last td short %d\n", in handle_tx_event()
2708 xhci_dbg(xhci, "Stopped on Transfer TRB for slot %u ep %u\n", in handle_tx_event()
2712 xhci_dbg(xhci, in handle_tx_event()
2717 xhci_dbg(xhci, in handle_tx_event()
2723 xhci_dbg(xhci, "Stalled endpoint for slot %u ep %u\n", slot_id, in handle_tx_event()
2728 xhci_dbg(xhci, "Split transaction error for slot %u ep %u\n", in handle_tx_event()
2733 xhci_dbg(xhci, "Transfer error for slot %u ep %u on endpoint\n", in handle_tx_event()
2738 xhci_dbg(xhci, "Babble error for slot %u ep %u on endpoint\n", in handle_tx_event()
2744 xhci_warn(xhci, in handle_tx_event()
2751 xhci_warn(xhci, in handle_tx_event()
2757 xhci_warn(xhci, in handle_tx_event()
2762 xhci_warn(xhci, in handle_tx_event()
2772 xhci_dbg(xhci, "Underrun event on slot %u ep %u\n", slot_id, ep_index); in handle_tx_event()
2777 xhci_dbg(xhci, "Overrun event on slot %u ep %u\n", slot_id, ep_index); in handle_tx_event()
2789 xhci_dbg(xhci, in handle_tx_event()
2795 xhci_dbg(xhci, in handle_tx_event()
2802 xhci_warn(xhci, in handle_tx_event()
2808 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { in handle_tx_event()
2812 xhci_warn(xhci, in handle_tx_event()
2821 * xhci 4.10.2 states isoc endpoints should continue in handle_tx_event()
2825 * xhci 4.9.1 states that if there are errors in mult-TRB in handle_tx_event()
2835 if (td && td->error_mid_td && !trb_in_td(xhci, td, ep_trb_dma, false)) { in handle_tx_event()
2836 xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); in handle_tx_event()
2837 xhci_dequeue_td(xhci, td, ep_ring, td->status); in handle_tx_event()
2850 xhci_warn(xhci, "Event TRB for slot %u ep %u with no TDs queued\n", in handle_tx_event()
2863 ep_seg = trb_in_td(xhci, td, ep_trb_dma, false); in handle_tx_event()
2872 skip_isoc_td(xhci, td, ep, status); in handle_tx_event()
2876 xhci_dbg(xhci, "All TDs skipped for slot %u ep %u. Clear skip flag.\n", in handle_tx_event()
2899 if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && in handle_tx_event()
2906 xhci_err(xhci, in handle_tx_event()
2909 trb_in_td(xhci, td, ep_trb_dma, true); in handle_tx_event()
2915 xhci_dbg(xhci, in handle_tx_event()
2951 process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2953 process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2955 process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2960 xhci_handle_halted_endpoint(xhci, ep, td, EP_HARD_RESET); in handle_tx_event()
2965 xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n", in handle_tx_event()
2978 * xhci->lock between event processing (e.g. to pass up port status changes).
2980 static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interrupter *ir, in xhci_handle_event_trb() argument
2999 handle_cmd_completion(xhci, &event->event_cmd); in xhci_handle_event_trb()
3002 handle_port_status(xhci, event); in xhci_handle_event_trb()
3005 handle_tx_event(xhci, ir, &event->trans_event); in xhci_handle_event_trb()
3008 handle_device_notification(xhci, event); in xhci_handle_event_trb()
3012 handle_vendor_event(xhci, event, trb_type); in xhci_handle_event_trb()
3014 xhci_warn(xhci, "ERROR unknown event type %d\n", trb_type); in xhci_handle_event_trb()
3019 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_handle_event_trb()
3020 xhci_dbg(xhci, "xHCI host dying, returning from event handler.\n"); in xhci_handle_event_trb()
3032 static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, in xhci_update_erst_dequeue() argument
3039 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
3043 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); in xhci_update_erst_dequeue()
3058 xhci_write_64(xhci, temp_64, &ir->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
3075 * and reaquire xhci->lock between event processing.
3077 static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_handle_events() argument
3087 xhci_err(xhci, "ERROR interrupter event ring not ready\n"); in xhci_handle_events()
3091 if (xhci->xhc_state & XHCI_STATE_DYING || in xhci_handle_events()
3092 xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_handle_events()
3093 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?\n"); in xhci_handle_events()
3096 temp = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_handle_events()
3097 xhci_write_64(xhci, temp | ERST_EHB, &ir->ir_set->erst_dequeue); in xhci_handle_events()
3103 err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue); in xhci_handle_events()
3110 xhci_update_erst_dequeue(xhci, ir, false); in xhci_handle_events()
3119 inc_deq(xhci, ir->event_ring); in xhci_handle_events()
3125 xhci_update_erst_dequeue(xhci, ir, true); in xhci_handle_events()
3131 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
3137 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_irq() local
3141 spin_lock(&xhci->lock); in xhci_irq()
3143 status = readl(&xhci->op_regs->status); in xhci_irq()
3145 xhci_hc_died(xhci); in xhci_irq()
3155 xhci_warn(xhci, "WARNING: Host Controller Error\n"); in xhci_irq()
3160 xhci_warn(xhci, "WARNING: Host System Error\n"); in xhci_irq()
3161 xhci_halt(xhci); in xhci_irq()
3171 writel(status, &xhci->op_regs->status); in xhci_irq()
3174 xhci_handle_events(xhci, xhci->interrupters[0]); in xhci_irq()
3176 spin_unlock(&xhci->lock); in xhci_irq()
3196 static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, in queue_trb() argument
3213 inc_enq(xhci, ring, more_trbs_coming); in queue_trb()
3220 static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in prepare_ring() argument
3233 xhci_warn(xhci, "WARN urb submitted to disabled ep\n"); in prepare_ring()
3236 xhci_warn(xhci, "WARN waiting for error on ep to be cleared\n"); in prepare_ring()
3241 xhci_dbg(xhci, "WARN halted endpoint, queueing URB anyway.\n"); in prepare_ring()
3247 xhci_err(xhci, "ERROR unknown endpoint state for ep\n"); in prepare_ring()
3255 if (ep_ring != xhci->cmd_ring) { in prepare_ring()
3256 new_segs = xhci_ring_expansion_needed(xhci, ep_ring, num_trbs); in prepare_ring()
3258 xhci_err(xhci, "Do not support expand command ring\n"); in prepare_ring()
3263 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, in prepare_ring()
3265 if (xhci_ring_expansion(xhci, ep_ring, new_segs, mem_flags)) { in prepare_ring()
3266 xhci_err(xhci, "Ring expansion failed\n"); in prepare_ring()
3275 if (!xhci_link_chain_quirk(xhci, ep_ring->type)) in prepare_ring()
3294 xhci_warn(xhci, "Ring is an endless link TRB loop\n"); in prepare_ring()
3300 xhci_warn(xhci, "Missing link TRB at end of ring segment\n"); in prepare_ring()
3307 static int prepare_transfer(struct xhci_hcd *xhci, in prepare_transfer() argument
3320 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in prepare_transfer()
3322 ep_ring = xhci_triad_to_transfer_ring(xhci, xdev->slot_id, ep_index, in prepare_transfer()
3325 xhci_dbg(xhci, "Can't prepare ring for bad stream ID %u\n", in prepare_transfer()
3330 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in prepare_transfer()
3414 static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, in giveback_first_trb() argument
3427 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); in giveback_first_trb()
3448 "Driver uses different interval (%d microframe%s) than xHCI (%d microframe%s)\n", in check_interval()
3460 * xHCI uses normal TRBs for both bulk and interrupt. When the interrupt
3465 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_intr_tx() argument
3470 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); in xhci_queue_intr_tx()
3473 return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_intr_tx()
3477 * For xHCI 1.0 host controllers, TD size is the number of max packet sized
3488 * For xHCI 0.96 and older, TD size field should be the remaining bytes
3496 static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, in xhci_td_remainder() argument
3502 /* MTK xHCI 0.96 contains some features from 1.0 */ in xhci_td_remainder()
3503 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) in xhci_td_remainder()
3511 /* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */ in xhci_td_remainder()
3512 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) in xhci_td_remainder()
3523 static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len, in xhci_align_td() argument
3526 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_align_td()
3539 xhci_dbg(xhci, "Unaligned %d bytes, buff len %d\n", in xhci_align_td()
3545 xhci_dbg(xhci, "split align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3565 xhci_warn(xhci, "WARN Wrong bounce buffer write length: %zu != %d\n", in xhci_align_td()
3580 xhci_warn(xhci, "Failed mapping bounce buffer, not aligning\n"); in xhci_align_td()
3587 xhci_dbg(xhci, "Bounce align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3593 int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_bulk_tx() argument
3611 ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_bulk_tx()
3628 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3677 if (xhci_align_td(xhci, urb, enqd_len, in xhci_queue_bulk_tx()
3705 remainder = xhci_td_remainder(xhci, enqd_len, trb_buff_len, in xhci_queue_bulk_tx()
3712 queue_trb(xhci, ring, more_trbs_coming | need_zero_pkt, in xhci_queue_bulk_tx()
3736 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3742 queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); in xhci_queue_bulk_tx()
3746 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3751 /* Caller must have locked xhci->lock */
3752 int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_ctrl_tx() argument
3765 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_ctrl_tx()
3776 if ((xhci->quirks & XHCI_ETRON_HOST) && in xhci_queue_ctrl_tx()
3785 queue_trb(xhci, ep_ring, false, 0, 0, in xhci_queue_ctrl_tx()
3799 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_ctrl_tx()
3824 /* xHCI 1.0/1.1 6.4.1.2.1: Transfer Type field */ in xhci_queue_ctrl_tx()
3825 if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { in xhci_queue_ctrl_tx()
3834 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3861 remainder = xhci_td_remainder(xhci, 0, in xhci_queue_ctrl_tx()
3870 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3887 queue_trb(xhci, ep_ring, false, in xhci_queue_ctrl_tx()
3894 giveback_first_trb(xhci, slot_id, ep_index, 0, in xhci_queue_ctrl_tx()
3905 * zero. Only xHCI 1.0 host controllers support this field.
3907 static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci, in xhci_get_burst_count() argument
3912 if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER) in xhci_get_burst_count()
3927 static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci, in xhci_get_last_burst_packet_count() argument
3933 if (xhci->hci_version < 0x100) in xhci_get_last_burst_packet_count()
3959 static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci, in xhci_get_isoc_frame_id() argument
3979 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_get_isoc_frame_id()
3980 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_get_isoc_frame_id()
3996 current_frame_id = readl(&xhci->run_regs->microframe_index); in xhci_get_isoc_frame_id()
4029 xhci_warn(xhci, "Frame ID %d (reg %d, index %d) beyond range (%d, %d)\n", in xhci_get_isoc_frame_id()
4032 xhci_warn(xhci, "Ignore frame ID field, use SIA bit instead\n"); in xhci_get_isoc_frame_id()
4040 static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i, in trb_block_event_intr() argument
4043 if (xhci->hci_version < 0x100) in trb_block_event_intr()
4052 if (i && ir->isoc_bei_interval && xhci->quirks & XHCI_AVOID_BEI) in trb_block_event_intr()
4059 static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx() argument
4078 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx()
4079 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; in xhci_queue_isoc_tx()
4080 ir = xhci->interrupters[0]; in xhci_queue_isoc_tx()
4084 xhci_dbg(xhci, "Isoc URB with zero packets?\n"); in xhci_queue_isoc_tx()
4109 burst_count = xhci_get_burst_count(xhci, urb, total_pkt_count); in xhci_queue_isoc_tx()
4110 last_burst_pkt_count = xhci_get_last_burst_packet_count(xhci, in xhci_queue_isoc_tx()
4115 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, in xhci_queue_isoc_tx()
4126 HCC_CFC(xhci->hcc_params)) { in xhci_queue_isoc_tx()
4127 frame_id = xhci_get_isoc_frame_id(xhci, urb, i); in xhci_queue_isoc_tx()
4141 /* xhci 1.1 with ETE uses TD_Size field for TBC, old is Rsvdz */ in xhci_queue_isoc_tx()
4167 if (trb_block_event_intr(xhci, num_tds, i, ir)) in xhci_queue_isoc_tx()
4176 remainder = xhci_td_remainder(xhci, running_total, in xhci_queue_isoc_tx()
4183 /* xhci 1.1 with ETE uses TD Size field for TBC */ in xhci_queue_isoc_tx()
4190 queue_trb(xhci, ep_ring, more_trbs_coming, in xhci_queue_isoc_tx()
4203 xhci_err(xhci, "ISOC TD length unmatch\n"); in xhci_queue_isoc_tx()
4210 if (HCC_CFC(xhci->hcc_params)) in xhci_queue_isoc_tx()
4213 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_queue_isoc_tx()
4214 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_queue_isoc_tx()
4217 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; in xhci_queue_isoc_tx()
4219 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_isoc_tx()
4248 * Update interval as xhci_queue_intr_tx does. Use xhci frame_index to
4252 int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx_prepare() argument
4264 xdev = xhci->devs[slot_id]; in xhci_queue_isoc_tx_prepare()
4265 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx_prepare()
4267 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in xhci_queue_isoc_tx_prepare()
4277 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in xhci_queue_isoc_tx_prepare()
4289 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { in xhci_queue_isoc_tx_prepare()
4296 start_frame = readl(&xhci->run_regs->microframe_index); in xhci_queue_isoc_tx_prepare()
4302 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_queue_isoc_tx_prepare()
4303 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_queue_isoc_tx_prepare()
4323 return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_isoc_tx_prepare()
4333 * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
4336 static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in queue_command() argument
4340 int reserved_trbs = xhci->cmd_ring_reserved_trbs; in queue_command()
4343 if ((xhci->xhc_state & XHCI_STATE_DYING) || in queue_command()
4344 (xhci->xhc_state & XHCI_STATE_HALTED)) { in queue_command()
4345 xhci_dbg(xhci, "xHCI dying or halted, can't queue_command\n"); in queue_command()
4352 ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, in queue_command()
4355 xhci_err(xhci, "ERR: No room for command on command ring\n"); in queue_command()
4357 xhci_err(xhci, "ERR: Reserved TRB counting for " in queue_command()
4362 cmd->command_trb = xhci->cmd_ring->enqueue; in queue_command()
4365 if (list_empty(&xhci->cmd_list)) { in queue_command()
4366 xhci->current_cmd = cmd; in queue_command()
4367 xhci_mod_cmd_timer(xhci); in queue_command()
4370 list_add_tail(&cmd->cmd_list, &xhci->cmd_list); in queue_command()
4372 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, in queue_command()
4373 field4 | xhci->cmd_ring->cycle_state); in queue_command()
4378 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_slot_control() argument
4381 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_slot_control()
4386 int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_address_device() argument
4389 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_address_device()
4395 int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_vendor_command() argument
4398 return queue_command(xhci, cmd, field1, field2, field3, field4, false); in xhci_queue_vendor_command()
4402 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_device() argument
4405 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_device()
4411 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, in xhci_queue_configure_endpoint() argument
4415 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_configure_endpoint()
4422 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_evaluate_context() argument
4425 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_evaluate_context()
4435 int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_stop_endpoint() argument
4443 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_stop_endpoint()
4447 int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_ep() argument
4458 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_ep()