• Home
  • Raw
  • Download

Lines Matching full:xhci

3  * xHCI host controller driver
58 #include "xhci.h"
59 #include "xhci-trace.h"
60 #include "xhci-mtk.h"
139 static void next_trb(struct xhci_hcd *xhci, in next_trb() argument
156 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring) in inc_deq() argument
199 * xHCI hardware can't handle the chain bit being cleared on a link TRB.
204 static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, in inc_enq() argument
234 (xhci->quirks & XHCI_AMD_0x96_HOST)) && in inc_enq()
235 !xhci_link_trb_quirk(xhci)) { in inc_enq()
259 static inline int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring, in room_on_ring() argument
277 void xhci_ring_cmd_db(struct xhci_hcd *xhci) in xhci_ring_cmd_db() argument
279 if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) in xhci_ring_cmd_db()
282 xhci_dbg(xhci, "// Ding dong!\n"); in xhci_ring_cmd_db()
286 writel(DB_VALUE_HOST, &xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
288 readl(&xhci->dba->doorbell[0]); in xhci_ring_cmd_db()
291 static bool xhci_mod_cmd_timer(struct xhci_hcd *xhci, unsigned long delay) in xhci_mod_cmd_timer() argument
293 return mod_delayed_work(system_wq, &xhci->cmd_timer, delay); in xhci_mod_cmd_timer()
296 static struct xhci_command *xhci_next_queued_cmd(struct xhci_hcd *xhci) in xhci_next_queued_cmd() argument
298 return list_first_entry_or_null(&xhci->cmd_list, struct xhci_command, in xhci_next_queued_cmd()
305 * This must be called with command ring stopped and xhci->lock held.
307 static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci, in xhci_handle_stopped_cmd_ring() argument
313 list_for_each_entry(i_cmd, &xhci->cmd_list, cmd_list) { in xhci_handle_stopped_cmd_ring()
320 xhci_dbg(xhci, "Turn aborted command %p to no-op\n", in xhci_handle_stopped_cmd_ring()
331 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_handle_stopped_cmd_ring()
334 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && in xhci_handle_stopped_cmd_ring()
335 !(xhci->xhc_state & XHCI_STATE_DYING)) { in xhci_handle_stopped_cmd_ring()
336 xhci->current_cmd = cur_cmd; in xhci_handle_stopped_cmd_ring()
337 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in xhci_handle_stopped_cmd_ring()
338 xhci_ring_cmd_db(xhci); in xhci_handle_stopped_cmd_ring()
342 /* Must be called with xhci->lock held, releases and aquires lock back */
343 static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) in xhci_abort_cmd_ring() argument
345 struct xhci_segment *new_seg = xhci->cmd_ring->deq_seg; in xhci_abort_cmd_ring()
346 union xhci_trb *new_deq = xhci->cmd_ring->dequeue; in xhci_abort_cmd_ring()
350 xhci_dbg(xhci, "Abort command ring\n"); in xhci_abort_cmd_ring()
352 reinit_completion(&xhci->cmd_ring_stop_completion); in xhci_abort_cmd_ring()
362 next_trb(xhci, NULL, &new_seg, &new_deq); in xhci_abort_cmd_ring()
364 next_trb(xhci, NULL, &new_seg, &new_deq); in xhci_abort_cmd_ring()
367 xhci_write_64(xhci, crcr | CMD_RING_ABORT, &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
369 /* Section 4.6.1.2 of xHCI 1.0 spec says software should also time the in xhci_abort_cmd_ring()
375 ret = xhci_handshake(&xhci->op_regs->cmd_ring, in xhci_abort_cmd_ring()
378 xhci_err(xhci, "Abort failed to stop command ring: %d\n", ret); in xhci_abort_cmd_ring()
379 xhci_halt(xhci); in xhci_abort_cmd_ring()
380 xhci_hc_died(xhci); in xhci_abort_cmd_ring()
389 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_abort_cmd_ring()
390 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, in xhci_abort_cmd_ring()
392 spin_lock_irqsave(&xhci->lock, flags); in xhci_abort_cmd_ring()
394 xhci_dbg(xhci, "No stop event for abort, ring start fail?\n"); in xhci_abort_cmd_ring()
395 xhci_cleanup_command_queue(xhci); in xhci_abort_cmd_ring()
397 xhci_handle_stopped_cmd_ring(xhci, xhci_next_queued_cmd(xhci)); in xhci_abort_cmd_ring()
402 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, in xhci_ring_ep_doorbell() argument
407 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; in xhci_ring_ep_doorbell()
408 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_ring_ep_doorbell()
430 static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in ring_doorbell_for_active_rings() argument
437 ep = &xhci->devs[slot_id]->eps[ep_index]; in ring_doorbell_for_active_rings()
442 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, 0); in ring_doorbell_for_active_rings()
450 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, in ring_doorbell_for_active_rings()
455 void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in xhci_ring_doorbell_for_active_rings() argument
459 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_ring_doorbell_for_active_rings()
462 static struct xhci_virt_ep *xhci_get_virt_ep(struct xhci_hcd *xhci, in xhci_get_virt_ep() argument
467 xhci_warn(xhci, "Invalid slot_id %u\n", slot_id); in xhci_get_virt_ep()
471 xhci_warn(xhci, "Invalid endpoint index %u\n", ep_index); in xhci_get_virt_ep()
474 if (!xhci->devs[slot_id]) { in xhci_get_virt_ep()
475 xhci_warn(xhci, "No xhci virt device for slot_id %u\n", slot_id); in xhci_get_virt_ep()
479 return &xhci->devs[slot_id]->eps[ep_index]; in xhci_get_virt_ep()
486 struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, in xhci_triad_to_transfer_ring() argument
492 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_triad_to_transfer_ring()
501 xhci_warn(xhci, in xhci_triad_to_transfer_ring()
511 xhci_warn(xhci, in xhci_triad_to_transfer_ring()
528 static u64 xhci_get_hw_deq(struct xhci_hcd *xhci, struct xhci_virt_device *vdev, in xhci_get_hw_deq() argument
541 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_get_hw_deq()
563 void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, in xhci_find_new_dequeue_state() argument
568 struct xhci_virt_device *dev = xhci->devs[slot_id]; in xhci_find_new_dequeue_state()
581 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id, in xhci_find_new_dequeue_state()
584 xhci_warn(xhci, "WARN can't find new dequeue state " in xhci_find_new_dequeue_state()
601 xhci_warn(xhci, "Can't find new dequeue state, missing cur_td\n"); in xhci_find_new_dequeue_state()
607 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
610 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); in xhci_find_new_dequeue_state()
619 if (xhci->quirks & XHCI_EP_CTX_BROKEN_DCS && in xhci_find_new_dequeue_state()
621 halted_seg = trb_in_td(xhci, cur_td->start_seg, in xhci_find_new_dequeue_state()
629 xhci_dbg(xhci, "Endpoint DCS = %d TRB index = %d cycle = %d\n", in xhci_find_new_dequeue_state()
657 next_trb(xhci, ep_ring, &new_seg, &new_deq); in xhci_find_new_dequeue_state()
661 xhci_err(xhci, "Error: Failed finding new dequeue state\n"); in xhci_find_new_dequeue_state()
674 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
677 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
681 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
690 static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in td_to_noop() argument
706 next_trb(xhci, ep_ring, &seg, &trb); in td_to_noop()
710 static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, in xhci_stop_watchdog_timer_in_irq() argument
719 * Must be called with xhci->lock held in interrupt context,
720 * releases and re-acquires xhci->lock
722 static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, in xhci_giveback_urb_in_irq() argument
730 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; in xhci_giveback_urb_in_irq()
731 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_giveback_urb_in_irq()
732 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_giveback_urb_in_irq()
742 static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, in xhci_unmap_td_bounce_buffer() argument
745 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_unmap_td_bounce_buffer()
766 xhci_warn(xhci, "WARN Wrong bounce buffer read length: %zu != %d\n", in xhci_unmap_td_bounce_buffer()
776 static int xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_td_cleanup() argument
785 xhci_unmap_td_bounce_buffer(xhci, ep_ring, td); in xhci_td_cleanup()
793 xhci_warn(xhci, "URB req %u and actual %u transfer length mismatch\n", in xhci_td_cleanup()
809 xhci_dbg(xhci, "Giveback URB %p, len = %d, expected = %d, status = %d\n", in xhci_td_cleanup()
816 xhci_giveback_urb_in_irq(xhci, td, status); in xhci_td_cleanup()
822 static int xhci_reset_halted_ep(struct xhci_hcd *xhci, unsigned int slot_id, in xhci_reset_halted_ep() argument
828 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_reset_halted_ep()
834 ret = xhci_queue_reset_ep(xhci, command, slot_id, ep_index, reset_type); in xhci_reset_halted_ep()
837 xhci_err(xhci, "ERROR queuing reset endpoint for slot %d ep_index %d, %d\n", in xhci_reset_halted_ep()
842 static void xhci_handle_halted_endpoint(struct xhci_hcd *xhci, in xhci_handle_halted_endpoint() argument
859 err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type); in xhci_handle_halted_endpoint()
865 xhci_cleanup_stalled_ring(xhci, slot_id, ep->ep_index, stream_id, in xhci_handle_halted_endpoint()
868 xhci_ring_cmd_db(xhci); in xhci_handle_halted_endpoint()
873 * We have the xHCI lock, so nothing can modify this list until we drop it.
881 struct xhci_hcd *xhci; in xhci_invalidate_cancelled_tds() local
887 xhci = ep->xhci; in xhci_invalidate_cancelled_tds()
890 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_invalidate_cancelled_tds()
895 ring = xhci_urb_to_transfer_ring(xhci, td->urb); in xhci_invalidate_cancelled_tds()
897 xhci_warn(xhci, "WARN Cancelled URB %p has invalid stream ID %u.\n", in xhci_invalidate_cancelled_tds()
905 hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index, in xhci_invalidate_cancelled_tds()
909 if (trb_in_td(xhci, td->start_seg, td->first_trb, in xhci_invalidate_cancelled_tds()
911 xhci_find_new_dequeue_state(xhci, ep->vdev->slot_id, in xhci_invalidate_cancelled_tds()
916 td_to_noop(xhci, ring, td, false); in xhci_invalidate_cancelled_tds()
933 static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_stop_ep() argument
946 if (!xhci->devs[slot_id]) in xhci_handle_cmd_stop_ep()
947 xhci_warn(xhci, "Stop endpoint command " in xhci_handle_cmd_stop_ep()
956 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
960 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_stop_ep()
961 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_handle_cmd_stop_ep()
968 xhci_stop_watchdog_timer_in_irq(xhci, ep); in xhci_handle_cmd_stop_ep()
969 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
975 xhci_stop_watchdog_timer_in_irq(xhci, ep); in xhci_handle_cmd_stop_ep()
979 xhci_queue_new_dequeue_state(xhci, slot_id, ep_index, in xhci_handle_cmd_stop_ep()
981 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_stop_ep()
984 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
1002 ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb); in xhci_handle_cmd_stop_ep()
1003 xhci_unmap_td_bounce_buffer(xhci, ep_ring, cur_td); in xhci_handle_cmd_stop_ep()
1006 xhci_giveback_urb_in_irq(xhci, cur_td, 0); in xhci_handle_cmd_stop_ep()
1011 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_handle_cmd_stop_ep()
1015 /* Return to the event handler with xhci->lock re-acquired */ in xhci_handle_cmd_stop_ep()
1018 static void xhci_kill_ring_urbs(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_kill_ring_urbs() argument
1029 xhci_unmap_td_bounce_buffer(xhci, ring, cur_td); in xhci_kill_ring_urbs()
1033 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_ring_urbs()
1037 static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, in xhci_kill_endpoint_urbs() argument
1045 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_kill_endpoint_urbs()
1059 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1062 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1068 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
1071 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
1080 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_endpoint_urbs()
1090 * Call with xhci->lock held.
1093 void xhci_hc_died(struct xhci_hcd *xhci) in xhci_hc_died() argument
1097 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_hc_died()
1100 xhci_err(xhci, "xHCI host controller not responding, assume dead\n"); in xhci_hc_died()
1101 xhci->xhc_state |= XHCI_STATE_DYING; in xhci_hc_died()
1103 xhci_cleanup_command_queue(xhci); in xhci_hc_died()
1106 for (i = 0; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_hc_died()
1107 if (!xhci->devs[i]) in xhci_hc_died()
1110 xhci_kill_endpoint_urbs(xhci, i, j); in xhci_hc_died()
1114 if (!(xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_hc_died()
1115 usb_hc_died(xhci_to_hcd(xhci)); in xhci_hc_died()
1122 * through xhci->state.
1138 struct xhci_hcd *xhci = ep->xhci; in xhci_stop_endpoint_command_watchdog() local
1143 spin_lock_irqsave(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
1148 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
1149 xhci_dbg(xhci, "Stop EP timer raced with cmd completion, exit"); in xhci_stop_endpoint_command_watchdog()
1152 usbsts = readl(&xhci->op_regs->status); in xhci_stop_endpoint_command_watchdog()
1154 xhci_warn(xhci, "xHCI host not responding to stop endpoint command.\n"); in xhci_stop_endpoint_command_watchdog()
1155 xhci_warn(xhci, "USBSTS:%s\n", xhci_decode_usbsts(str, usbsts)); in xhci_stop_endpoint_command_watchdog()
1159 xhci_halt(xhci); in xhci_stop_endpoint_command_watchdog()
1166 xhci_hc_died(xhci); in xhci_stop_endpoint_command_watchdog()
1168 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
1169 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_stop_endpoint_command_watchdog()
1170 "xHCI host controller is dead."); in xhci_stop_endpoint_command_watchdog()
1173 static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci, in update_ring_for_set_deq_completion() argument
1214 xhci_dbg(xhci, "Unable to find new dequeue pointer\n"); in update_ring_for_set_deq_completion()
1226 static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_set_deq() argument
1239 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1243 dev = xhci->devs[slot_id]; in xhci_handle_cmd_set_deq()
1246 xhci_warn(xhci, "WARN Set TR deq ptr command for freed stream ID %u\n", in xhci_handle_cmd_set_deq()
1252 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); in xhci_handle_cmd_set_deq()
1253 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); in xhci_handle_cmd_set_deq()
1263 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because of stream ID configuration\n"); in xhci_handle_cmd_set_deq()
1266 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.\n"); in xhci_handle_cmd_set_deq()
1270 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1275 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed because slot %u was not enabled.\n", in xhci_handle_cmd_set_deq()
1279 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown completion code of %u.\n", in xhci_handle_cmd_set_deq()
1299 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1306 update_ring_for_set_deq_completion(xhci, dev, in xhci_handle_cmd_set_deq()
1309 xhci_warn(xhci, "Mismatch between completed Set TR Deq Ptr command & xHCI internal state.\n"); in xhci_handle_cmd_set_deq()
1310 xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n", in xhci_handle_cmd_set_deq()
1320 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1323 static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_ep() argument
1332 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1336 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_ep()
1337 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_handle_cmd_reset_ep()
1343 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, in xhci_handle_cmd_reset_ep()
1350 if (xhci->quirks & XHCI_RESET_EP_QUIRK) { in xhci_handle_cmd_reset_ep()
1353 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_handle_cmd_reset_ep()
1357 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_reset_ep()
1359 xhci_queue_configure_endpoint(xhci, command, in xhci_handle_cmd_reset_ep()
1360 xhci->devs[slot_id]->in_ctx->dma, slot_id, in xhci_handle_cmd_reset_ep()
1362 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_reset_ep()
1370 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1373 static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_enable_slot() argument
1382 static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_disable_slot() argument
1387 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_disable_slot()
1391 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_handle_cmd_disable_slot()
1394 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) in xhci_handle_cmd_disable_slot()
1396 xhci_free_device_endpoint_resources(xhci, virt_dev, true); in xhci_handle_cmd_disable_slot()
1399 static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_config_ep() argument
1414 * If the command was for a halted endpoint, the xHCI driver in xhci_handle_cmd_config_ep()
1417 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_config_ep()
1420 xhci_warn(xhci, "Could not get input context, bad type.\n"); in xhci_handle_cmd_config_ep()
1429 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, ep_index); in xhci_handle_cmd_config_ep()
1438 if (xhci->quirks & XHCI_RESET_EP_QUIRK && in xhci_handle_cmd_config_ep()
1444 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_config_ep()
1450 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_config_ep()
1456 static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_addr_dev() argument
1461 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_addr_dev()
1462 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_addr_dev()
1466 static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_dev() argument
1472 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_dev()
1473 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_reset_dev()
1476 xhci_dbg(xhci, "Completed reset device command.\n"); in xhci_handle_cmd_reset_dev()
1477 if (!xhci->devs[slot_id]) in xhci_handle_cmd_reset_dev()
1478 xhci_warn(xhci, "Reset device command completion " in xhci_handle_cmd_reset_dev()
1482 static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, in xhci_handle_cmd_nec_get_fw() argument
1485 if (!(xhci->quirks & XHCI_NEC_HOST)) { in xhci_handle_cmd_nec_get_fw()
1486 xhci_warn(xhci, "WARN NEC_GET_FW command on non-NEC host\n"); in xhci_handle_cmd_nec_get_fw()
1489 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_nec_get_fw()
1507 void xhci_cleanup_command_queue(struct xhci_hcd *xhci) in xhci_cleanup_command_queue() argument
1510 xhci->current_cmd = NULL; in xhci_cleanup_command_queue()
1511 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) in xhci_cleanup_command_queue()
1517 struct xhci_hcd *xhci; in xhci_handle_command_timeout() local
1521 xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer); in xhci_handle_command_timeout()
1523 spin_lock_irqsave(&xhci->lock, flags); in xhci_handle_command_timeout()
1529 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { in xhci_handle_command_timeout()
1530 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1534 xhci->current_cmd->status = COMP_COMMAND_ABORTED; in xhci_handle_command_timeout()
1537 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_handle_command_timeout()
1539 xhci_hc_died(xhci); in xhci_handle_command_timeout()
1543 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && in xhci_handle_command_timeout()
1546 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; in xhci_handle_command_timeout()
1547 xhci_dbg(xhci, "Command timeout\n"); in xhci_handle_command_timeout()
1548 xhci_abort_cmd_ring(xhci, flags); in xhci_handle_command_timeout()
1553 if (xhci->xhc_state & XHCI_STATE_REMOVING) { in xhci_handle_command_timeout()
1554 xhci_dbg(xhci, "host removed, ring start fail?\n"); in xhci_handle_command_timeout()
1555 xhci_cleanup_command_queue(xhci); in xhci_handle_command_timeout()
1561 xhci_dbg(xhci, "Command timeout on stopped ring\n"); in xhci_handle_command_timeout()
1562 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); in xhci_handle_command_timeout()
1565 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1569 static void handle_cmd_completion(struct xhci_hcd *xhci, in handle_cmd_completion() argument
1581 cmd_trb = xhci->cmd_ring->dequeue; in handle_cmd_completion()
1583 trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic); in handle_cmd_completion()
1585 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in handle_cmd_completion()
1592 xhci_warn(xhci, in handle_cmd_completion()
1597 cmd = list_first_entry(&xhci->cmd_list, struct xhci_command, cmd_list); in handle_cmd_completion()
1599 cancel_delayed_work(&xhci->cmd_timer); in handle_cmd_completion()
1605 complete_all(&xhci->cmd_ring_stop_completion); in handle_cmd_completion()
1609 if (cmd->command_trb != xhci->cmd_ring->dequeue) { in handle_cmd_completion()
1610 xhci_err(xhci, in handle_cmd_completion()
1622 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in handle_cmd_completion()
1624 if (xhci->current_cmd == cmd) in handle_cmd_completion()
1625 xhci->current_cmd = NULL; in handle_cmd_completion()
1633 xhci_handle_cmd_enable_slot(xhci, slot_id, cmd, cmd_comp_code); in handle_cmd_completion()
1636 xhci_handle_cmd_disable_slot(xhci, slot_id); in handle_cmd_completion()
1640 xhci_handle_cmd_config_ep(xhci, slot_id, event, in handle_cmd_completion()
1646 xhci_handle_cmd_addr_dev(xhci, slot_id); in handle_cmd_completion()
1652 xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, event); in handle_cmd_completion()
1657 xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1667 xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1671 * Use the SLOT_ID from the command TRB instead (xhci 4.6.11) in handle_cmd_completion()
1675 xhci_handle_cmd_reset_dev(xhci, slot_id, event); in handle_cmd_completion()
1678 xhci_handle_cmd_nec_get_fw(xhci, event); in handle_cmd_completion()
1682 xhci_info(xhci, "INFO unknown command type %d\n", cmd_type); in handle_cmd_completion()
1687 if (!list_is_singular(&xhci->cmd_list)) { in handle_cmd_completion()
1688 xhci->current_cmd = list_first_entry(&cmd->cmd_list, in handle_cmd_completion()
1690 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in handle_cmd_completion()
1691 } else if (xhci->current_cmd == cmd) { in handle_cmd_completion()
1692 xhci->current_cmd = NULL; in handle_cmd_completion()
1698 inc_deq(xhci, xhci->cmd_ring); in handle_cmd_completion()
1701 static void handle_vendor_event(struct xhci_hcd *xhci, in handle_vendor_event() argument
1707 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type); in handle_vendor_event()
1708 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) in handle_vendor_event()
1709 handle_cmd_completion(xhci, &event->event_cmd); in handle_vendor_event()
1712 static void handle_device_notification(struct xhci_hcd *xhci, in handle_device_notification() argument
1719 if (!xhci->devs[slot_id]) { in handle_device_notification()
1720 xhci_warn(xhci, "Device Notification event for " in handle_device_notification()
1725 xhci_dbg(xhci, "Device Wake Notification event for slot ID %u\n", in handle_device_notification()
1727 udev = xhci->devs[slot_id]->udev; in handle_device_notification()
1733 * Quirk hanlder for errata seen on Cavium ThunderX2 processor XHCI
1744 static void xhci_cavium_reset_phy_quirk(struct xhci_hcd *xhci) in xhci_cavium_reset_phy_quirk() argument
1746 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_cavium_reset_phy_quirk()
1761 static void handle_port_status(struct xhci_hcd *xhci, in handle_port_status() argument
1776 xhci_warn(xhci, in handle_port_status()
1780 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); in handle_port_status()
1783 xhci_warn(xhci, "Port change event with invalid port ID %d\n", in handle_port_status()
1785 inc_deq(xhci, xhci->event_ring); in handle_port_status()
1789 port = &xhci->hw_ports[port_id - 1]; in handle_port_status()
1791 xhci_warn(xhci, "Port change event, no port for port ID %u\n", in handle_port_status()
1798 if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) { in handle_port_status()
1799 xhci_dbg(xhci, "ignore port event for removed USB3 hcd\n"); in handle_port_status()
1809 xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n", in handle_port_status()
1815 xhci_dbg(xhci, "resume root hub\n"); in handle_port_status()
1821 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
1822 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
1823 xhci->devs[slot_id]->flags |= VDEV_PORT_ERROR; in handle_port_status()
1827 xhci_dbg(xhci, "port resume event for port %d\n", port_id); in handle_port_status()
1829 cmd_reg = readl(&xhci->op_regs->command); in handle_port_status()
1831 xhci_warn(xhci, "xHC is not running.\n"); in handle_port_status()
1836 xhci_dbg(xhci, "remote wake SS port %d\n", port_id); in handle_port_status()
1842 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1844 xhci_set_link_state(xhci, port, XDEV_U0); in handle_port_status()
1851 xhci_dbg(xhci, "resume HS port %d\n", port_id); in handle_port_status()
1872 xhci_dbg(xhci, "resume SS port %d finished\n", port_id); in handle_port_status()
1881 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
1882 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
1883 xhci_ring_device(xhci, slot_id); in handle_port_status()
1885 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1894 * Check to see if xhci-hub.c is waiting on RExit to U0 transition (or in handle_port_status()
1906 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1907 if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) && in handle_port_status()
1909 xhci_cavium_reset_phy_quirk(xhci); in handle_port_status()
1914 inc_deq(xhci, xhci->event_ring); in handle_port_status()
1924 * xHCI port-status-change events occur when the "or" of all the in handle_port_status()
1930 xhci_dbg(xhci, "%s: starting port polling.\n", __func__); in handle_port_status()
1932 spin_unlock(&xhci->lock); in handle_port_status()
1935 spin_lock(&xhci->lock); in handle_port_status()
1944 struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, in trb_in_td() argument
1969 xhci_warn(xhci, in trb_in_td()
2005 static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_clear_hub_tt_buffer() argument
2013 (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && in xhci_clear_hub_tt_buffer()
2028 static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci, in xhci_requires_manual_halt_cleanup() argument
2048 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) in xhci_is_vendor_info_code() argument
2054 xhci_dbg(xhci, "Vendor defined info completion code %u\n", in xhci_is_vendor_info_code()
2056 xhci_dbg(xhci, "Treating code as success.\n"); in xhci_is_vendor_info_code()
2062 static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in finish_td() argument
2068 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in finish_td()
2080 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in finish_td()
2083 * xhci internal endpoint state will go to a "halt" state for in finish_td()
2093 xhci_clear_hub_tt_buffer(xhci, td, ep); in finish_td()
2095 xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td, in finish_td()
2102 inc_deq(xhci, ep_ring); in finish_td()
2105 return xhci_td_cleanup(xhci, td, ep_ring, td->status); in finish_td()
2109 static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring, in sum_trb_lengths() argument
2116 for (sum = 0; trb != stop_trb; next_trb(xhci, ring, &seg, &trb)) { in sum_trb_lengths()
2126 static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_ctrl_td() argument
2136 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); in process_ctrl_td()
2144 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n", in process_ctrl_td()
2158 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); in process_ctrl_td()
2173 xhci_warn(xhci, "WARN: unexpected TRB Type %d\n", in process_ctrl_td()
2180 if (!xhci_requires_manual_halt_cleanup(xhci, in process_ctrl_td()
2183 xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n", in process_ctrl_td()
2207 xhci_dbg(xhci, "Waiting for status stage event\n"); in process_ctrl_td()
2216 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_ctrl_td()
2222 static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_isoc_td() argument
2247 /* Don't overwrite status if TD had an error, see xHCI 4.9.1 */ in process_isoc_td()
2252 if (xhci->quirks & XHCI_TRUST_TX_LENGTH) in process_isoc_td()
2305 frame->actual_length = sum_trb_lengths(xhci, ep->ring, ep_trb) + in process_isoc_td()
2315 xhci_dbg(xhci, "Error mid isoc TD, wait for final completion event\n"); in process_isoc_td()
2320 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_isoc_td()
2323 static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, in skip_isoc_td() argument
2344 inc_deq(xhci, ep->ring); in skip_isoc_td()
2346 return xhci_td_cleanup(xhci, td, ep->ring, status); in skip_isoc_td()
2352 static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, in process_bulk_intr_td() argument
2360 slot_ctx = xhci_get_slot_ctx(xhci, ep->vdev->out_ctx); in process_bulk_intr_td()
2371 xhci_warn(xhci, "WARN Successful completion on short TX\n"); in process_bulk_intr_td()
2372 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2379 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2393 if (xhci->quirks & XHCI_NO_SOFT_RETRY || in process_bulk_intr_td()
2400 xhci_handle_halted_endpoint(xhci, ep, ep_ring->stream_id, td, in process_bulk_intr_td()
2412 sum_trb_lengths(xhci, ep_ring, ep_trb) + in process_bulk_intr_td()
2416 xhci_warn(xhci, "bad transfer trb length %d in event trb\n", in process_bulk_intr_td()
2421 return finish_td(xhci, ep, ep_ring, td, trb_comp_code); in process_bulk_intr_td()
2429 static int handle_tx_event(struct xhci_hcd *xhci, in handle_tx_event() argument
2453 ep = xhci_get_virt_ep(xhci, slot_id, ep_index); in handle_tx_event()
2455 xhci_err(xhci, "ERROR Invalid Transfer event\n"); in handle_tx_event()
2459 xdev = xhci->devs[slot_id]; in handle_tx_event()
2461 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in handle_tx_event()
2464 xhci_err(xhci, in handle_tx_event()
2470 /* Some transfer events don't always point to a trb, see xhci 4.17.4 */ in handle_tx_event()
2477 xhci_dbg(xhci, "Stream transaction error ep %u no id\n", in handle_tx_event()
2480 xhci_handle_halted_endpoint(xhci, ep, 0, NULL, in handle_tx_event()
2483 xhci_handle_halted_endpoint(xhci, ep, 0, NULL, in handle_tx_event()
2491 xhci_err(xhci, "ERROR Transfer event for unknown stream ring slot %u ep %u\n", in handle_tx_event()
2511 if (xhci->quirks & XHCI_TRUST_TX_LENGTH || in handle_tx_event()
2515 xhci_warn_ratelimited(xhci, in handle_tx_event()
2522 xhci_dbg(xhci, "Stopped on Transfer TRB for slot %u ep %u\n", in handle_tx_event()
2526 xhci_dbg(xhci, in handle_tx_event()
2531 xhci_dbg(xhci, in handle_tx_event()
2537 xhci_dbg(xhci, "Stalled endpoint for slot %u ep %u\n", slot_id, in handle_tx_event()
2543 xhci_dbg(xhci, "Split transaction error for slot %u ep %u\n", in handle_tx_event()
2548 xhci_dbg(xhci, "Transfer error for slot %u ep %u on endpoint\n", in handle_tx_event()
2553 xhci_dbg(xhci, "Babble error for slot %u ep %u on endpoint\n", in handle_tx_event()
2559 xhci_warn(xhci, in handle_tx_event()
2566 xhci_warn(xhci, in handle_tx_event()
2572 xhci_warn(xhci, in handle_tx_event()
2577 xhci_warn(xhci, in handle_tx_event()
2587 xhci_dbg(xhci, "underrun event on endpoint\n"); in handle_tx_event()
2589 xhci_dbg(xhci, "Underrun Event for slot %d ep %d " in handle_tx_event()
2595 xhci_dbg(xhci, "overrun event on endpoint\n"); in handle_tx_event()
2597 xhci_dbg(xhci, "Overrun Event for slot %d ep %d " in handle_tx_event()
2610 xhci_dbg(xhci, in handle_tx_event()
2616 xhci_dbg(xhci, in handle_tx_event()
2623 xhci_warn(xhci, in handle_tx_event()
2629 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { in handle_tx_event()
2633 xhci_warn(xhci, in handle_tx_event()
2655 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n", in handle_tx_event()
2661 xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2665 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
2667 xhci_handle_halted_endpoint(xhci, ep, in handle_tx_event()
2678 xhci_dbg(xhci, "All tds on the ep_ring skipped. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2689 ep_seg = trb_in_td(xhci, ep_ring->deq_seg, ep_ring->dequeue, in handle_tx_event()
2708 skip_isoc_td(xhci, td, ep, status); in handle_tx_event()
2716 if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && in handle_tx_event()
2723 * xhci 4.10.2 states isoc endpoints should continue in handle_tx_event()
2727 * xhci 4.9.1 states that if there are errors in mult-TRB in handle_tx_event()
2737 ep_seg = trb_in_td(xhci, td_next->start_seg, td_next->first_trb, in handle_tx_event()
2741 xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); in handle_tx_event()
2744 inc_deq(xhci, ep_ring); in handle_tx_event()
2745 xhci_td_cleanup(xhci, td, ep_ring, td->status); in handle_tx_event()
2752 xhci_err(xhci, in handle_tx_event()
2757 trb_in_td(xhci, ep_ring->deq_seg, in handle_tx_event()
2769 xhci_dbg(xhci, in handle_tx_event()
2791 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
2793 xhci_handle_halted_endpoint(xhci, ep, in handle_tx_event()
2803 process_ctrl_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2805 process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2807 process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event); in handle_tx_event()
2818 inc_deq(xhci, xhci->event_ring); in handle_tx_event()
2831 xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n", in handle_tx_event()
2833 xhci->event_ring->deq_seg, in handle_tx_event()
2834 xhci->event_ring->dequeue), in handle_tx_event()
2844 * xhci->lock between event processing (e.g. to pass up port status changes).
2848 static int xhci_handle_event(struct xhci_hcd *xhci) in xhci_handle_event() argument
2855 if (!xhci->event_ring || !xhci->event_ring->dequeue) { in xhci_handle_event()
2856 xhci_err(xhci, "ERROR event ring not ready\n"); in xhci_handle_event()
2860 event = xhci->event_ring->dequeue; in xhci_handle_event()
2863 xhci->event_ring->cycle_state) in xhci_handle_event()
2866 trace_xhci_handle_event(xhci->event_ring, &event->generic); in xhci_handle_event()
2876 handle_cmd_completion(xhci, &event->event_cmd); in xhci_handle_event()
2879 handle_port_status(xhci, event); in xhci_handle_event()
2883 ret = handle_tx_event(xhci, &event->trans_event); in xhci_handle_event()
2888 handle_device_notification(xhci, event); in xhci_handle_event()
2893 handle_vendor_event(xhci, event); in xhci_handle_event()
2895 xhci_warn(xhci, "ERROR unknown event type %d\n", in xhci_handle_event()
2902 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_handle_event()
2903 xhci_dbg(xhci, "xHCI host dying, returning from " in xhci_handle_event()
2910 inc_deq(xhci, xhci->event_ring); in xhci_handle_event()
2923 static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, in xhci_update_erst_dequeue() argument
2929 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
2931 if (event_ring_deq != xhci->event_ring->dequeue) { in xhci_update_erst_dequeue()
2932 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, in xhci_update_erst_dequeue()
2933 xhci->event_ring->dequeue); in xhci_update_erst_dequeue()
2935 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); in xhci_update_erst_dequeue()
2951 xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
2955 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
2961 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_irq() local
2969 spin_lock_irqsave(&xhci->lock, flags); in xhci_irq()
2971 status = readl(&xhci->op_regs->status); in xhci_irq()
2973 xhci_hc_died(xhci); in xhci_irq()
2982 xhci_warn(xhci, "WARNING: Host System Error\n"); in xhci_irq()
2983 xhci_halt(xhci); in xhci_irq()
2994 writel(status, &xhci->op_regs->status); in xhci_irq()
2998 irq_pending = readl(&xhci->ir_set->irq_pending); in xhci_irq()
3000 writel(irq_pending, &xhci->ir_set->irq_pending); in xhci_irq()
3003 if (xhci->xhc_state & XHCI_STATE_DYING || in xhci_irq()
3004 xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_irq()
3005 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " in xhci_irq()
3010 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_irq()
3011 xhci_write_64(xhci, temp_64 | ERST_EHB, in xhci_irq()
3012 &xhci->ir_set->erst_dequeue); in xhci_irq()
3017 event_ring_deq = xhci->event_ring->dequeue; in xhci_irq()
3021 while (xhci_handle_event(xhci) > 0) { in xhci_irq()
3024 xhci_update_erst_dequeue(xhci, event_ring_deq); in xhci_irq()
3025 event_ring_deq = xhci->event_ring->dequeue; in xhci_irq()
3030 xhci_update_erst_dequeue(xhci, event_ring_deq); in xhci_irq()
3034 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_irq()
3053 static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, in queue_trb() argument
3069 inc_enq(xhci, ring, more_trbs_coming); in queue_trb()
3076 static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in prepare_ring() argument
3088 xhci_warn(xhci, "WARN urb submitted to disabled ep\n"); in prepare_ring()
3091 xhci_warn(xhci, "WARN waiting for error on ep to be cleared\n"); in prepare_ring()
3096 xhci_dbg(xhci, "WARN halted endpoint, queueing URB anyway.\n"); in prepare_ring()
3101 xhci_err(xhci, "ERROR unknown endpoint state for ep\n"); in prepare_ring()
3110 if (room_on_ring(xhci, ep_ring, num_trbs)) in prepare_ring()
3113 if (ep_ring == xhci->cmd_ring) { in prepare_ring()
3114 xhci_err(xhci, "Do not support expand command ring\n"); in prepare_ring()
3118 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, in prepare_ring()
3121 if (xhci_ring_expansion(xhci, ep_ring, num_trbs_needed, in prepare_ring()
3123 xhci_err(xhci, "Ring expansion failed\n"); in prepare_ring()
3132 if (!xhci_link_trb_quirk(xhci) && in prepare_ring()
3134 (xhci->quirks & XHCI_AMD_0x96_HOST))) in prepare_ring()
3154 static int prepare_transfer(struct xhci_hcd *xhci, in prepare_transfer() argument
3167 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in prepare_transfer()
3171 xhci_dbg(xhci, "Can't prepare ring for bad stream ID %u\n", in prepare_transfer()
3176 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in prepare_transfer()
3260 static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, in giveback_first_trb() argument
3273 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); in giveback_first_trb()
3276 static void check_interval(struct xhci_hcd *xhci, struct urb *urb, in check_interval() argument
3295 "Driver uses different interval (%d microframe%s) than xHCI (%d microframe%s)\n", in check_interval()
3307 * xHCI uses normal TRBs for both bulk and interrupt. When the interrupt
3312 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_intr_tx() argument
3317 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); in xhci_queue_intr_tx()
3318 check_interval(xhci, urb, ep_ctx); in xhci_queue_intr_tx()
3320 return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_intr_tx()
3324 * For xHCI 1.0 host controllers, TD size is the number of max packet sized
3335 * For xHCI 0.96 and older, TD size field should be the remaining bytes
3343 static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, in xhci_td_remainder() argument
3349 /* MTK xHCI 0.96 contains some features from 1.0 */ in xhci_td_remainder()
3350 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) in xhci_td_remainder()
3358 /* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */ in xhci_td_remainder()
3359 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) in xhci_td_remainder()
3370 static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len, in xhci_align_td() argument
3373 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_align_td()
3386 xhci_dbg(xhci, "Unaligned %d bytes, buff len %d\n", in xhci_align_td()
3392 xhci_dbg(xhci, "split align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3412 xhci_warn(xhci, "WARN Wrong bounce buffer write length: %zu != %d\n", in xhci_align_td()
3427 xhci_warn(xhci, "Failed mapping bounce buffer, not aligning\n"); in xhci_align_td()
3434 xhci_dbg(xhci, "Bounce align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3440 int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_bulk_tx() argument
3458 ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_bulk_tx()
3475 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3524 if (xhci_align_td(xhci, urb, enqd_len, in xhci_queue_bulk_tx()
3552 remainder = xhci_td_remainder(xhci, enqd_len, trb_buff_len, in xhci_queue_bulk_tx()
3559 queue_trb(xhci, ring, more_trbs_coming | need_zero_pkt, in xhci_queue_bulk_tx()
3584 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3590 queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); in xhci_queue_bulk_tx()
3595 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3600 /* Caller must have locked xhci->lock */
3601 int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_ctrl_tx() argument
3614 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_ctrl_tx()
3634 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_ctrl_tx()
3660 /* xHCI 1.0/1.1 6.4.1.2.1: Transfer Type field */ in xhci_queue_ctrl_tx()
3661 if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { in xhci_queue_ctrl_tx()
3670 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3697 remainder = xhci_td_remainder(xhci, 0, in xhci_queue_ctrl_tx()
3706 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3723 queue_trb(xhci, ep_ring, false, in xhci_queue_ctrl_tx()
3730 giveback_first_trb(xhci, slot_id, ep_index, 0, in xhci_queue_ctrl_tx()
3741 * zero. Only xHCI 1.0 host controllers support this field.
3743 static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci, in xhci_get_burst_count() argument
3748 if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER) in xhci_get_burst_count()
3763 static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci, in xhci_get_last_burst_packet_count() argument
3769 if (xhci->hci_version < 0x100) in xhci_get_last_burst_packet_count()
3795 static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci, in xhci_get_isoc_frame_id() argument
3815 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_get_isoc_frame_id()
3816 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_get_isoc_frame_id()
3832 current_frame_id = readl(&xhci->run_regs->microframe_index); in xhci_get_isoc_frame_id()
3840 xhci_dbg(xhci, "%s: index %d, reg 0x%x start_frame_id 0x%x, end_frame_id 0x%x, start_frame 0x%x\n", in xhci_get_isoc_frame_id()
3841 __func__, index, readl(&xhci->run_regs->microframe_index), in xhci_get_isoc_frame_id()
3869 xhci_warn(xhci, "Frame ID %d (reg %d, index %d) beyond range (%d, %d)\n", in xhci_get_isoc_frame_id()
3872 xhci_warn(xhci, "Ignore frame ID field, use SIA bit instead\n"); in xhci_get_isoc_frame_id()
3880 static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) in trb_block_event_intr() argument
3882 if (xhci->hci_version < 0x100) in trb_block_event_intr()
3891 if (i && xhci->quirks & XHCI_AVOID_BEI) in trb_block_event_intr()
3898 static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx() argument
3916 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx()
3917 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; in xhci_queue_isoc_tx()
3921 xhci_dbg(xhci, "Isoc URB with zero packets?\n"); in xhci_queue_isoc_tx()
3946 burst_count = xhci_get_burst_count(xhci, urb, total_pkt_count); in xhci_queue_isoc_tx()
3947 last_burst_pkt_count = xhci_get_last_burst_packet_count(xhci, in xhci_queue_isoc_tx()
3952 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, in xhci_queue_isoc_tx()
3964 HCC_CFC(xhci->hcc_params)) { in xhci_queue_isoc_tx()
3965 frame_id = xhci_get_isoc_frame_id(xhci, urb, i); in xhci_queue_isoc_tx()
3979 /* xhci 1.1 with ETE uses TD_Size field for TBC, old is Rsvdz */ in xhci_queue_isoc_tx()
4005 if (trb_block_event_intr(xhci, num_tds, i)) in xhci_queue_isoc_tx()
4014 remainder = xhci_td_remainder(xhci, running_total, in xhci_queue_isoc_tx()
4021 /* xhci 1.1 with ETE uses TD Size field for TBC */ in xhci_queue_isoc_tx()
4028 queue_trb(xhci, ep_ring, more_trbs_coming, in xhci_queue_isoc_tx()
4041 xhci_err(xhci, "ISOC TD length unmatch\n"); in xhci_queue_isoc_tx()
4048 if (HCC_CFC(xhci->hcc_params)) in xhci_queue_isoc_tx()
4051 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_queue_isoc_tx()
4052 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_queue_isoc_tx()
4055 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; in xhci_queue_isoc_tx()
4057 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_isoc_tx()
4073 td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); in xhci_queue_isoc_tx()
4087 * Update interval as xhci_queue_intr_tx does. Use xhci frame_index to
4091 int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx_prepare() argument
4103 xdev = xhci->devs[slot_id]; in xhci_queue_isoc_tx_prepare()
4104 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx_prepare()
4106 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in xhci_queue_isoc_tx_prepare()
4116 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in xhci_queue_isoc_tx_prepare()
4125 check_interval(xhci, urb, ep_ctx); in xhci_queue_isoc_tx_prepare()
4128 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { in xhci_queue_isoc_tx_prepare()
4135 start_frame = readl(&xhci->run_regs->microframe_index); in xhci_queue_isoc_tx_prepare()
4141 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_queue_isoc_tx_prepare()
4142 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_queue_isoc_tx_prepare()
4163 return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_isoc_tx_prepare()
4173 * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
4176 static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in queue_command() argument
4180 int reserved_trbs = xhci->cmd_ring_reserved_trbs; in queue_command()
4183 if ((xhci->xhc_state & XHCI_STATE_DYING) || in queue_command()
4184 (xhci->xhc_state & XHCI_STATE_HALTED)) { in queue_command()
4185 xhci_dbg(xhci, "xHCI dying or halted, can't queue_command\n"); in queue_command()
4192 ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, in queue_command()
4195 xhci_err(xhci, "ERR: No room for command on command ring\n"); in queue_command()
4197 xhci_err(xhci, "ERR: Reserved TRB counting for " in queue_command()
4202 cmd->command_trb = xhci->cmd_ring->enqueue; in queue_command()
4205 if (list_empty(&xhci->cmd_list)) { in queue_command()
4206 xhci->current_cmd = cmd; in queue_command()
4207 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in queue_command()
4210 list_add_tail(&cmd->cmd_list, &xhci->cmd_list); in queue_command()
4212 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, in queue_command()
4213 field4 | xhci->cmd_ring->cycle_state); in queue_command()
4218 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_slot_control() argument
4221 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_slot_control()
4226 int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_address_device() argument
4229 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_address_device()
4235 int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_vendor_command() argument
4238 return queue_command(xhci, cmd, field1, field2, field3, field4, false); in xhci_queue_vendor_command()
4242 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_device() argument
4245 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_device()
4251 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, in xhci_queue_configure_endpoint() argument
4255 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_configure_endpoint()
4262 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_evaluate_context() argument
4265 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_evaluate_context()
4275 int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_stop_endpoint() argument
4283 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_stop_endpoint()
4288 void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, in xhci_queue_new_dequeue_state() argument
4302 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_queue_new_dequeue_state()
4314 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); in xhci_queue_new_dequeue_state()
4315 xhci_warn(xhci, "WARN deq seg = %p, deq pt = %p\n", in xhci_queue_new_dequeue_state()
4319 ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_new_dequeue_state()
4321 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); in xhci_queue_new_dequeue_state()
4322 xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n"); in xhci_queue_new_dequeue_state()
4327 cmd = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_queue_new_dequeue_state()
4335 ret = queue_command(xhci, cmd, in xhci_queue_new_dequeue_state()
4340 xhci_free_command(xhci, cmd); in xhci_queue_new_dequeue_state()
4352 int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_ep() argument
4363 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_ep()