Lines Matching refs:xhci
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
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()
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()
343 static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags) in xhci_abort_cmd_ring() argument
348 xhci_dbg(xhci, "Abort command ring\n"); in xhci_abort_cmd_ring()
350 reinit_completion(&xhci->cmd_ring_stop_completion); in xhci_abort_cmd_ring()
352 temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
353 xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, in xhci_abort_cmd_ring()
354 &xhci->op_regs->cmd_ring); in xhci_abort_cmd_ring()
362 ret = xhci_handshake(&xhci->op_regs->cmd_ring, in xhci_abort_cmd_ring()
365 xhci_err(xhci, "Abort failed to stop command ring: %d\n", ret); in xhci_abort_cmd_ring()
366 xhci_halt(xhci); in xhci_abort_cmd_ring()
367 xhci_hc_died(xhci); in xhci_abort_cmd_ring()
376 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_abort_cmd_ring()
377 ret = wait_for_completion_timeout(&xhci->cmd_ring_stop_completion, in xhci_abort_cmd_ring()
379 spin_lock_irqsave(&xhci->lock, flags); in xhci_abort_cmd_ring()
381 xhci_dbg(xhci, "No stop event for abort, ring start fail?\n"); in xhci_abort_cmd_ring()
382 xhci_cleanup_command_queue(xhci); in xhci_abort_cmd_ring()
384 xhci_handle_stopped_cmd_ring(xhci, xhci_next_queued_cmd(xhci)); in xhci_abort_cmd_ring()
389 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, in xhci_ring_ep_doorbell() argument
394 __le32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; in xhci_ring_ep_doorbell()
395 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_ring_ep_doorbell()
417 static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in ring_doorbell_for_active_rings() argument
424 ep = &xhci->devs[slot_id]->eps[ep_index]; in ring_doorbell_for_active_rings()
429 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, 0); in ring_doorbell_for_active_rings()
437 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, in ring_doorbell_for_active_rings()
442 void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci, in xhci_ring_doorbell_for_active_rings() argument
446 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_ring_doorbell_for_active_rings()
453 struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, in xhci_triad_to_transfer_ring() argument
459 ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_triad_to_transfer_ring()
465 xhci_warn(xhci, in xhci_triad_to_transfer_ring()
475 xhci_warn(xhci, in xhci_triad_to_transfer_ring()
492 static u64 xhci_get_hw_deq(struct xhci_hcd *xhci, struct xhci_virt_device *vdev, in xhci_get_hw_deq() argument
505 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_get_hw_deq()
527 void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, in xhci_find_new_dequeue_state() argument
532 struct xhci_virt_device *dev = xhci->devs[slot_id]; in xhci_find_new_dequeue_state()
542 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id, in xhci_find_new_dequeue_state()
545 xhci_warn(xhci, "WARN can't find new dequeue state " in xhci_find_new_dequeue_state()
562 xhci_warn(xhci, "Can't find new dequeue state, missing cur_td\n"); in xhci_find_new_dequeue_state()
568 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
571 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); in xhci_find_new_dequeue_state()
597 next_trb(xhci, ep_ring, &new_seg, &new_deq); in xhci_find_new_dequeue_state()
601 xhci_err(xhci, "Error: Failed finding new dequeue state\n"); in xhci_find_new_dequeue_state()
614 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
617 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
621 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_find_new_dequeue_state()
630 static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in td_to_noop() argument
646 next_trb(xhci, ep_ring, &seg, &trb); in td_to_noop()
650 static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, in xhci_stop_watchdog_timer_in_irq() argument
662 static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, in xhci_giveback_urb_in_irq() argument
670 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; in xhci_giveback_urb_in_irq()
671 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_giveback_urb_in_irq()
672 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_giveback_urb_in_irq()
682 static void xhci_unmap_td_bounce_buffer(struct xhci_hcd *xhci, in xhci_unmap_td_bounce_buffer() argument
685 struct device *dev = xhci_to_hcd(xhci)->self.controller; in xhci_unmap_td_bounce_buffer()
705 xhci_warn(xhci, "WARN Wrong bounce buffer read length: %zu != %d\n", in xhci_unmap_td_bounce_buffer()
721 static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_stop_ep() argument
735 if (!xhci->devs[slot_id]) in xhci_handle_cmd_stop_ep()
736 xhci_warn(xhci, "Stop endpoint command " in xhci_handle_cmd_stop_ep()
745 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_stop_ep()
746 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_handle_cmd_stop_ep()
749 ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_handle_cmd_stop_ep()
754 xhci_stop_watchdog_timer_in_irq(xhci, ep); in xhci_handle_cmd_stop_ep()
755 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
765 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_stop_ep()
769 ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb); in xhci_handle_cmd_stop_ep()
782 xhci_warn(xhci, "WARN Cancelled URB %p " in xhci_handle_cmd_stop_ep()
792 hw_deq = xhci_get_hw_deq(xhci, vdev, ep_index, in xhci_handle_cmd_stop_ep()
796 if (trb_in_td(xhci, cur_td->start_seg, cur_td->first_trb, in xhci_handle_cmd_stop_ep()
798 xhci_find_new_dequeue_state(xhci, slot_id, ep_index, in xhci_handle_cmd_stop_ep()
802 td_to_noop(xhci, ep_ring, cur_td, false); in xhci_handle_cmd_stop_ep()
814 xhci_stop_watchdog_timer_in_irq(xhci, ep); in xhci_handle_cmd_stop_ep()
818 xhci_queue_new_dequeue_state(xhci, slot_id, ep_index, in xhci_handle_cmd_stop_ep()
820 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_stop_ep()
823 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_stop_ep()
841 ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb); in xhci_handle_cmd_stop_ep()
842 xhci_unmap_td_bounce_buffer(xhci, ep_ring, cur_td); in xhci_handle_cmd_stop_ep()
845 xhci_giveback_urb_in_irq(xhci, cur_td, 0); in xhci_handle_cmd_stop_ep()
850 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_handle_cmd_stop_ep()
857 static void xhci_kill_ring_urbs(struct xhci_hcd *xhci, struct xhci_ring *ring) in xhci_kill_ring_urbs() argument
868 xhci_unmap_td_bounce_buffer(xhci, ring, cur_td); in xhci_kill_ring_urbs()
872 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_ring_urbs()
876 static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, in xhci_kill_endpoint_urbs() argument
884 ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_kill_endpoint_urbs()
895 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
898 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
904 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_kill_endpoint_urbs()
907 xhci_kill_ring_urbs(xhci, ring); in xhci_kill_endpoint_urbs()
916 xhci_giveback_urb_in_irq(xhci, cur_td, -ESHUTDOWN); in xhci_kill_endpoint_urbs()
929 void xhci_hc_died(struct xhci_hcd *xhci) in xhci_hc_died() argument
933 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_hc_died()
936 xhci_err(xhci, "xHCI host controller not responding, assume dead\n"); in xhci_hc_died()
937 xhci->xhc_state |= XHCI_STATE_DYING; in xhci_hc_died()
939 xhci_cleanup_command_queue(xhci); in xhci_hc_died()
942 for (i = 0; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) { in xhci_hc_died()
943 if (!xhci->devs[i]) in xhci_hc_died()
946 xhci_kill_endpoint_urbs(xhci, i, j); in xhci_hc_died()
950 if (!(xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_hc_died()
951 usb_hc_died(xhci_to_hcd(xhci)); in xhci_hc_died()
974 struct xhci_hcd *xhci = ep->xhci; in xhci_stop_endpoint_command_watchdog() local
978 spin_lock_irqsave(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
983 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
984 xhci_dbg(xhci, "Stop EP timer raced with cmd completion, exit"); in xhci_stop_endpoint_command_watchdog()
987 usbsts = readl(&xhci->op_regs->status); in xhci_stop_endpoint_command_watchdog()
989 xhci_warn(xhci, "xHCI host not responding to stop endpoint command.\n"); in xhci_stop_endpoint_command_watchdog()
990 xhci_warn(xhci, "USBSTS:%s\n", xhci_decode_usbsts(usbsts)); in xhci_stop_endpoint_command_watchdog()
994 xhci_halt(xhci); in xhci_stop_endpoint_command_watchdog()
1001 xhci_hc_died(xhci); in xhci_stop_endpoint_command_watchdog()
1003 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_command_watchdog()
1004 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_stop_endpoint_command_watchdog()
1008 static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci, in update_ring_for_set_deq_completion() argument
1049 xhci_dbg(xhci, "Unable to find new dequeue pointer\n"); in update_ring_for_set_deq_completion()
1061 static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_set_deq() argument
1074 dev = xhci->devs[slot_id]; in xhci_handle_cmd_set_deq()
1079 xhci_warn(xhci, "WARN Set TR deq ptr command for freed stream ID %u\n", in xhci_handle_cmd_set_deq()
1085 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); in xhci_handle_cmd_set_deq()
1086 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); in xhci_handle_cmd_set_deq()
1096 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because of stream ID configuration\n"); in xhci_handle_cmd_set_deq()
1099 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.\n"); in xhci_handle_cmd_set_deq()
1103 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1108 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd failed because slot %u was not enabled.\n", in xhci_handle_cmd_set_deq()
1112 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown completion code of %u.\n", in xhci_handle_cmd_set_deq()
1132 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_handle_cmd_set_deq()
1139 update_ring_for_set_deq_completion(xhci, dev, in xhci_handle_cmd_set_deq()
1142 xhci_warn(xhci, "Mismatch between completed Set TR Deq Ptr command & xHCI internal state.\n"); in xhci_handle_cmd_set_deq()
1143 xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n", in xhci_handle_cmd_set_deq()
1153 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_set_deq()
1156 static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_ep() argument
1164 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_ep()
1165 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, ep_index); in xhci_handle_cmd_reset_ep()
1171 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, in xhci_handle_cmd_reset_ep()
1178 if (xhci->quirks & XHCI_RESET_EP_QUIRK) { in xhci_handle_cmd_reset_ep()
1181 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_handle_cmd_reset_ep()
1185 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_reset_ep()
1187 xhci_queue_configure_endpoint(xhci, command, in xhci_handle_cmd_reset_ep()
1188 xhci->devs[slot_id]->in_ctx->dma, slot_id, in xhci_handle_cmd_reset_ep()
1190 xhci_ring_cmd_db(xhci); in xhci_handle_cmd_reset_ep()
1193 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED; in xhci_handle_cmd_reset_ep()
1198 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_reset_ep()
1201 static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_enable_slot() argument
1210 static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_disable_slot() argument
1215 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_disable_slot()
1219 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_handle_cmd_disable_slot()
1222 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) in xhci_handle_cmd_disable_slot()
1224 xhci_free_device_endpoint_resources(xhci, virt_dev, true); in xhci_handle_cmd_disable_slot()
1225 xhci_free_virt_device(xhci, slot_id); in xhci_handle_cmd_disable_slot()
1228 static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_config_ep() argument
1246 virt_dev = xhci->devs[slot_id]; in xhci_handle_cmd_config_ep()
1249 xhci_warn(xhci, "Could not get input context, bad type.\n"); in xhci_handle_cmd_config_ep()
1258 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->out_ctx, ep_index); in xhci_handle_cmd_config_ep()
1267 if (xhci->quirks & XHCI_RESET_EP_QUIRK && in xhci_handle_cmd_config_ep()
1273 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_config_ep()
1279 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_handle_cmd_config_ep()
1285 static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id) in xhci_handle_cmd_addr_dev() argument
1290 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_addr_dev()
1291 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_addr_dev()
1295 static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id, in xhci_handle_cmd_reset_dev() argument
1301 vdev = xhci->devs[slot_id]; in xhci_handle_cmd_reset_dev()
1302 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_handle_cmd_reset_dev()
1305 xhci_dbg(xhci, "Completed reset device command.\n"); in xhci_handle_cmd_reset_dev()
1306 if (!xhci->devs[slot_id]) in xhci_handle_cmd_reset_dev()
1307 xhci_warn(xhci, "Reset device command completion " in xhci_handle_cmd_reset_dev()
1311 static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, in xhci_handle_cmd_nec_get_fw() argument
1314 if (!(xhci->quirks & XHCI_NEC_HOST)) { in xhci_handle_cmd_nec_get_fw()
1315 xhci_warn(xhci, "WARN NEC_GET_FW command on non-NEC host\n"); in xhci_handle_cmd_nec_get_fw()
1318 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_handle_cmd_nec_get_fw()
1336 void xhci_cleanup_command_queue(struct xhci_hcd *xhci) in xhci_cleanup_command_queue() argument
1339 xhci->current_cmd = NULL; in xhci_cleanup_command_queue()
1340 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) in xhci_cleanup_command_queue()
1346 struct xhci_hcd *xhci; in xhci_handle_command_timeout() local
1350 xhci = container_of(to_delayed_work(work), struct xhci_hcd, cmd_timer); in xhci_handle_command_timeout()
1352 spin_lock_irqsave(&xhci->lock, flags); in xhci_handle_command_timeout()
1358 if (!xhci->current_cmd || delayed_work_pending(&xhci->cmd_timer)) { in xhci_handle_command_timeout()
1359 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1363 xhci->current_cmd->status = COMP_COMMAND_ABORTED; in xhci_handle_command_timeout()
1366 hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_handle_command_timeout()
1368 xhci_hc_died(xhci); in xhci_handle_command_timeout()
1372 if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && in xhci_handle_command_timeout()
1375 xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; in xhci_handle_command_timeout()
1376 xhci_dbg(xhci, "Command timeout\n"); in xhci_handle_command_timeout()
1377 xhci_abort_cmd_ring(xhci, flags); in xhci_handle_command_timeout()
1382 if (xhci->xhc_state & XHCI_STATE_REMOVING) { in xhci_handle_command_timeout()
1383 xhci_dbg(xhci, "host removed, ring start fail?\n"); in xhci_handle_command_timeout()
1384 xhci_cleanup_command_queue(xhci); in xhci_handle_command_timeout()
1390 xhci_dbg(xhci, "Command timeout on stopped ring\n"); in xhci_handle_command_timeout()
1391 xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); in xhci_handle_command_timeout()
1394 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_handle_command_timeout()
1398 static void handle_cmd_completion(struct xhci_hcd *xhci, in handle_cmd_completion() argument
1410 cmd_trb = xhci->cmd_ring->dequeue; in handle_cmd_completion()
1412 trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic); in handle_cmd_completion()
1414 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in handle_cmd_completion()
1421 xhci_warn(xhci, in handle_cmd_completion()
1426 cmd = list_first_entry(&xhci->cmd_list, struct xhci_command, cmd_list); in handle_cmd_completion()
1428 cancel_delayed_work(&xhci->cmd_timer); in handle_cmd_completion()
1434 complete_all(&xhci->cmd_ring_stop_completion); in handle_cmd_completion()
1438 if (cmd->command_trb != xhci->cmd_ring->dequeue) { in handle_cmd_completion()
1439 xhci_err(xhci, in handle_cmd_completion()
1451 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in handle_cmd_completion()
1453 if (xhci->current_cmd == cmd) in handle_cmd_completion()
1454 xhci->current_cmd = NULL; in handle_cmd_completion()
1462 xhci_handle_cmd_enable_slot(xhci, slot_id, cmd, cmd_comp_code); in handle_cmd_completion()
1465 xhci_handle_cmd_disable_slot(xhci, slot_id); in handle_cmd_completion()
1469 xhci_handle_cmd_config_ep(xhci, slot_id, event, in handle_cmd_completion()
1475 xhci_handle_cmd_addr_dev(xhci, slot_id); in handle_cmd_completion()
1481 xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, event); in handle_cmd_completion()
1486 xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1496 xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code); in handle_cmd_completion()
1504 xhci_handle_cmd_reset_dev(xhci, slot_id, event); in handle_cmd_completion()
1507 xhci_handle_cmd_nec_get_fw(xhci, event); in handle_cmd_completion()
1511 xhci_info(xhci, "INFO unknown command type %d\n", cmd_type); in handle_cmd_completion()
1516 if (!list_is_singular(&xhci->cmd_list)) { in handle_cmd_completion()
1517 xhci->current_cmd = list_first_entry(&cmd->cmd_list, in handle_cmd_completion()
1519 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in handle_cmd_completion()
1520 } else if (xhci->current_cmd == cmd) { in handle_cmd_completion()
1521 xhci->current_cmd = NULL; in handle_cmd_completion()
1527 inc_deq(xhci, xhci->cmd_ring); in handle_cmd_completion()
1530 static void handle_vendor_event(struct xhci_hcd *xhci, in handle_vendor_event() argument
1536 xhci_dbg(xhci, "Vendor specific event TRB type = %u\n", trb_type); in handle_vendor_event()
1537 if (trb_type == TRB_NEC_CMD_COMP && (xhci->quirks & XHCI_NEC_HOST)) in handle_vendor_event()
1538 handle_cmd_completion(xhci, &event->event_cmd); in handle_vendor_event()
1541 static void handle_device_notification(struct xhci_hcd *xhci, in handle_device_notification() argument
1548 if (!xhci->devs[slot_id]) { in handle_device_notification()
1549 xhci_warn(xhci, "Device Notification event for " in handle_device_notification()
1554 xhci_dbg(xhci, "Device Wake Notification event for slot ID %u\n", in handle_device_notification()
1556 udev = xhci->devs[slot_id]->udev; in handle_device_notification()
1573 static void xhci_cavium_reset_phy_quirk(struct xhci_hcd *xhci) in xhci_cavium_reset_phy_quirk() argument
1575 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_cavium_reset_phy_quirk()
1590 static void handle_port_status(struct xhci_hcd *xhci, in handle_port_status() argument
1605 xhci_warn(xhci, in handle_port_status()
1609 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); in handle_port_status()
1612 xhci_warn(xhci, "Port change event with invalid port ID %d\n", in handle_port_status()
1614 inc_deq(xhci, xhci->event_ring); in handle_port_status()
1618 port = &xhci->hw_ports[port_id - 1]; in handle_port_status()
1620 xhci_warn(xhci, "Port change event, no port for port ID %u\n", in handle_port_status()
1627 if (port->rhub == &xhci->usb3_rhub && xhci->shared_hcd == NULL) { in handle_port_status()
1628 xhci_dbg(xhci, "ignore port event for removed USB3 hcd\n"); in handle_port_status()
1638 xhci_dbg(xhci, "Port change event, %d-%d, id %d, portsc: 0x%x\n", in handle_port_status()
1644 xhci_dbg(xhci, "resume root hub\n"); in handle_port_status()
1650 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
1651 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
1652 xhci->devs[slot_id]->flags |= VDEV_PORT_ERROR; in handle_port_status()
1656 xhci_dbg(xhci, "port resume event for port %d\n", port_id); in handle_port_status()
1658 cmd_reg = readl(&xhci->op_regs->command); in handle_port_status()
1660 xhci_warn(xhci, "xHC is not running.\n"); in handle_port_status()
1665 xhci_dbg(xhci, "remote wake SS port %d\n", port_id); in handle_port_status()
1671 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1673 xhci_set_link_state(xhci, port, XDEV_U0); in handle_port_status()
1680 xhci_dbg(xhci, "resume HS port %d\n", port_id); in handle_port_status()
1701 xhci_dbg(xhci, "resume SS port %d finished\n", port_id); in handle_port_status()
1710 slot_id = xhci_find_slot_id_by_port(hcd, xhci, hcd_portnum + 1); in handle_port_status()
1711 if (slot_id && xhci->devs[slot_id]) in handle_port_status()
1712 xhci_ring_device(xhci, slot_id); in handle_port_status()
1714 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1736 xhci_test_and_clear_bit(xhci, port, PORT_PLC); in handle_port_status()
1737 if ((xhci->quirks & XHCI_RESET_PLL_ON_DISCONNECT) && in handle_port_status()
1739 xhci_cavium_reset_phy_quirk(xhci); in handle_port_status()
1744 inc_deq(xhci, xhci->event_ring); in handle_port_status()
1760 xhci_dbg(xhci, "%s: starting port polling.\n", __func__); in handle_port_status()
1762 spin_unlock(&xhci->lock); in handle_port_status()
1765 spin_lock(&xhci->lock); in handle_port_status()
1774 struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, in trb_in_td() argument
1799 xhci_warn(xhci, in trb_in_td()
1835 static void xhci_clear_hub_tt_buffer(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_clear_hub_tt_buffer() argument
1843 (td->urb->dev->tt->hub != xhci_to_hcd(xhci)->self.root_hub) && in xhci_clear_hub_tt_buffer()
1852 static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci, in xhci_cleanup_halted_endpoint() argument
1857 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_cleanup_halted_endpoint()
1864 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) in xhci_cleanup_halted_endpoint()
1867 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_cleanup_halted_endpoint()
1873 xhci_queue_reset_ep(xhci, command, slot_id, ep_index, reset_type); in xhci_cleanup_halted_endpoint()
1877 xhci_cleanup_stalled_ring(xhci, slot_id, ep_index, stream_id, in xhci_cleanup_halted_endpoint()
1880 xhci_ring_cmd_db(xhci); in xhci_cleanup_halted_endpoint()
1889 static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci, in xhci_requires_manual_halt_cleanup() argument
1909 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code) in xhci_is_vendor_info_code() argument
1915 xhci_dbg(xhci, "Vendor defined info completion code %u\n", in xhci_is_vendor_info_code()
1917 xhci_dbg(xhci, "Treating code as success.\n"); in xhci_is_vendor_info_code()
1923 static int xhci_td_cleanup(struct xhci_hcd *xhci, struct xhci_td *td, in xhci_td_cleanup() argument
1932 xhci_unmap_td_bounce_buffer(xhci, ep_ring, td); in xhci_td_cleanup()
1940 xhci_warn(xhci, "URB req %u and actual %u transfer length mismatch\n", in xhci_td_cleanup()
1956 xhci_dbg(xhci, "Giveback URB %p, len = %d, expected = %d, status = %d\n", in xhci_td_cleanup()
1963 xhci_giveback_urb_in_irq(xhci, td, *status); in xhci_td_cleanup()
1969 static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td, in finish_td() argument
1981 xdev = xhci->devs[slot_id]; in finish_td()
1984 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in finish_td()
1997 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in finish_td()
2010 xhci_clear_hub_tt_buffer(xhci, td, ep); in finish_td()
2011 xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index, in finish_td()
2016 inc_deq(xhci, ep_ring); in finish_td()
2017 inc_deq(xhci, ep_ring); in finish_td()
2020 return xhci_td_cleanup(xhci, td, ep_ring, status); in finish_td()
2024 static int sum_trb_lengths(struct xhci_hcd *xhci, struct xhci_ring *ring, in sum_trb_lengths() argument
2031 for (sum = 0; trb != stop_trb; next_trb(xhci, ring, &seg, &trb)) { in sum_trb_lengths()
2041 static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td, in process_ctrl_td() argument
2055 xdev = xhci->devs[slot_id]; in process_ctrl_td()
2057 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in process_ctrl_td()
2065 xhci_warn(xhci, "WARN: Success on ctrl %s TRB without IOC set?\n", in process_ctrl_td()
2079 xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl setup or status TRB\n"); in process_ctrl_td()
2094 xhci_warn(xhci, "WARN: unexpected TRB Type %d\n", in process_ctrl_td()
2101 if (!xhci_requires_manual_halt_cleanup(xhci, in process_ctrl_td()
2104 xhci_dbg(xhci, "TRB error %u, halted endpoint index = %u\n", in process_ctrl_td()
2128 xhci_dbg(xhci, "Waiting for status stage event\n"); in process_ctrl_td()
2137 return finish_td(xhci, td, event, ep, status); in process_ctrl_td()
2143 static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, in process_isoc_td() argument
2172 if (xhci->quirks & XHCI_TRUST_TX_LENGTH) in process_isoc_td()
2217 frame->actual_length = sum_trb_lengths(xhci, ep_ring, ep_trb) + in process_isoc_td()
2224 return finish_td(xhci, td, event, ep, status); in process_isoc_td()
2227 static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, in skip_isoc_td() argument
2249 inc_deq(xhci, ep_ring); in skip_isoc_td()
2250 inc_deq(xhci, ep_ring); in skip_isoc_td()
2252 return xhci_td_cleanup(xhci, td, ep_ring, status); in skip_isoc_td()
2258 static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td, in process_bulk_intr_td() argument
2270 slot_ctx = xhci_get_slot_ctx(xhci, xhci->devs[slot_id]->out_ctx); in process_bulk_intr_td()
2283 xhci_warn(xhci, "WARN Successful completion on short TX\n"); in process_bulk_intr_td()
2284 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2291 xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", in process_bulk_intr_td()
2309 xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index, in process_bulk_intr_td()
2321 sum_trb_lengths(xhci, ep_ring, ep_trb) + in process_bulk_intr_td()
2325 xhci_warn(xhci, "bad transfer trb length %d in event trb\n", in process_bulk_intr_td()
2329 return finish_td(xhci, td, event, ep, status); in process_bulk_intr_td()
2337 static int handle_tx_event(struct xhci_hcd *xhci, in handle_tx_event() argument
2361 xdev = xhci->devs[slot_id]; in handle_tx_event()
2363 xhci_err(xhci, "ERROR Transfer event pointed to bad slot %u\n", in handle_tx_event()
2370 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in handle_tx_event()
2373 xhci_err(xhci, in handle_tx_event()
2386 xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index, 0, in handle_tx_event()
2394 xhci_err(xhci, "ERROR Transfer event for unknown stream ring slot %u ep %u\n", in handle_tx_event()
2414 if (xhci->quirks & XHCI_TRUST_TX_LENGTH || in handle_tx_event()
2418 xhci_warn_ratelimited(xhci, in handle_tx_event()
2425 xhci_dbg(xhci, "Stopped on Transfer TRB for slot %u ep %u\n", in handle_tx_event()
2429 xhci_dbg(xhci, in handle_tx_event()
2434 xhci_dbg(xhci, in handle_tx_event()
2440 xhci_dbg(xhci, "Stalled endpoint for slot %u ep %u\n", slot_id, in handle_tx_event()
2446 xhci_dbg(xhci, "Split transaction error for slot %u ep %u\n", in handle_tx_event()
2451 xhci_dbg(xhci, "Transfer error for slot %u ep %u on endpoint\n", in handle_tx_event()
2456 xhci_dbg(xhci, "Babble error for slot %u ep %u on endpoint\n", in handle_tx_event()
2462 xhci_warn(xhci, in handle_tx_event()
2469 xhci_warn(xhci, in handle_tx_event()
2475 xhci_warn(xhci, in handle_tx_event()
2480 xhci_warn(xhci, in handle_tx_event()
2490 xhci_dbg(xhci, "underrun event on endpoint\n"); in handle_tx_event()
2492 xhci_dbg(xhci, "Underrun Event for slot %d ep %d " in handle_tx_event()
2498 xhci_dbg(xhci, "overrun event on endpoint\n"); in handle_tx_event()
2500 xhci_dbg(xhci, "Overrun Event for slot %d ep %d " in handle_tx_event()
2513 xhci_dbg(xhci, in handle_tx_event()
2519 xhci_dbg(xhci, in handle_tx_event()
2526 xhci_warn(xhci, in handle_tx_event()
2532 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { in handle_tx_event()
2536 xhci_warn(xhci, in handle_tx_event()
2558 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n", in handle_tx_event()
2564 xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2568 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
2570 xhci_cleanup_halted_endpoint(xhci, slot_id, in handle_tx_event()
2582 xhci_dbg(xhci, "All tds on the ep_ring skipped. Clear skip flag for slot %u ep %u.\n", in handle_tx_event()
2593 ep_seg = trb_in_td(xhci, ep_ring->deq_seg, ep_ring->dequeue, in handle_tx_event()
2616 if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && in handle_tx_event()
2622 xhci_err(xhci, in handle_tx_event()
2627 trb_in_td(xhci, ep_ring->deq_seg, in handle_tx_event()
2633 skip_isoc_td(xhci, td, event, ep, &status); in handle_tx_event()
2642 xhci_dbg(xhci, in handle_tx_event()
2663 xhci_requires_manual_halt_cleanup(xhci, ep_ctx, in handle_tx_event()
2665 xhci_cleanup_halted_endpoint(xhci, slot_id, in handle_tx_event()
2674 process_ctrl_td(xhci, td, ep_trb, event, ep, &status); in handle_tx_event()
2676 process_isoc_td(xhci, td, ep_trb, event, ep, &status); in handle_tx_event()
2678 process_bulk_intr_td(xhci, td, ep_trb, event, ep, in handle_tx_event()
2690 inc_deq(xhci, xhci->event_ring); in handle_tx_event()
2703 xhci_err(xhci, "@%016llx %08x %08x %08x %08x\n", in handle_tx_event()
2705 xhci->event_ring->deq_seg, in handle_tx_event()
2706 xhci->event_ring->dequeue), in handle_tx_event()
2720 static int xhci_handle_event(struct xhci_hcd *xhci) in xhci_handle_event() argument
2727 if (!xhci->event_ring || !xhci->event_ring->dequeue) { in xhci_handle_event()
2728 xhci_err(xhci, "ERROR event ring not ready\n"); in xhci_handle_event()
2732 event = xhci->event_ring->dequeue; in xhci_handle_event()
2735 xhci->event_ring->cycle_state) in xhci_handle_event()
2738 trace_xhci_handle_event(xhci->event_ring, &event->generic); in xhci_handle_event()
2748 handle_cmd_completion(xhci, &event->event_cmd); in xhci_handle_event()
2751 handle_port_status(xhci, event); in xhci_handle_event()
2755 ret = handle_tx_event(xhci, &event->trans_event); in xhci_handle_event()
2760 handle_device_notification(xhci, event); in xhci_handle_event()
2765 handle_vendor_event(xhci, event); in xhci_handle_event()
2767 xhci_warn(xhci, "ERROR unknown event type %d\n", in xhci_handle_event()
2774 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_handle_event()
2775 xhci_dbg(xhci, "xHCI host dying, returning from " in xhci_handle_event()
2782 inc_deq(xhci, xhci->event_ring); in xhci_handle_event()
2795 static void xhci_update_erst_dequeue(struct xhci_hcd *xhci, in xhci_update_erst_dequeue() argument
2801 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
2803 if (event_ring_deq != xhci->event_ring->dequeue) { in xhci_update_erst_dequeue()
2804 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, in xhci_update_erst_dequeue()
2805 xhci->event_ring->dequeue); in xhci_update_erst_dequeue()
2807 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr\n"); in xhci_update_erst_dequeue()
2823 xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue); in xhci_update_erst_dequeue()
2833 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_irq() local
2841 spin_lock_irqsave(&xhci->lock, flags); in xhci_irq()
2843 status = readl(&xhci->op_regs->status); in xhci_irq()
2845 xhci_hc_died(xhci); in xhci_irq()
2854 xhci_warn(xhci, "WARNING: Host System Error\n"); in xhci_irq()
2855 xhci_halt(xhci); in xhci_irq()
2866 writel(status, &xhci->op_regs->status); in xhci_irq()
2870 irq_pending = readl(&xhci->ir_set->irq_pending); in xhci_irq()
2872 writel(irq_pending, &xhci->ir_set->irq_pending); in xhci_irq()
2875 if (xhci->xhc_state & XHCI_STATE_DYING || in xhci_irq()
2876 xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_irq()
2877 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " in xhci_irq()
2882 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_irq()
2883 xhci_write_64(xhci, temp_64 | ERST_EHB, in xhci_irq()
2884 &xhci->ir_set->erst_dequeue); in xhci_irq()
2889 event_ring_deq = xhci->event_ring->dequeue; in xhci_irq()
2893 while (xhci_handle_event(xhci) > 0) { in xhci_irq()
2896 xhci_update_erst_dequeue(xhci, event_ring_deq); in xhci_irq()
2900 xhci_update_erst_dequeue(xhci, event_ring_deq); in xhci_irq()
2904 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_irq()
2923 static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, in queue_trb() argument
2937 inc_enq(xhci, ring, more_trbs_coming); in queue_trb()
2944 static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, in prepare_ring() argument
2956 xhci_warn(xhci, "WARN urb submitted to disabled ep\n"); in prepare_ring()
2959 xhci_warn(xhci, "WARN waiting for error on ep to be cleared\n"); in prepare_ring()
2964 xhci_dbg(xhci, "WARN halted endpoint, queueing URB anyway.\n"); in prepare_ring()
2969 xhci_err(xhci, "ERROR unknown endpoint state for ep\n"); in prepare_ring()
2978 if (room_on_ring(xhci, ep_ring, num_trbs)) in prepare_ring()
2981 if (ep_ring == xhci->cmd_ring) { in prepare_ring()
2982 xhci_err(xhci, "Do not support expand command ring\n"); in prepare_ring()
2986 xhci_dbg_trace(xhci, trace_xhci_dbg_ring_expansion, in prepare_ring()
2989 if (xhci_ring_expansion(xhci, ep_ring, num_trbs_needed, in prepare_ring()
2991 xhci_err(xhci, "Ring expansion failed\n"); in prepare_ring()
3000 if (!xhci_link_trb_quirk(xhci) && in prepare_ring()
3002 (xhci->quirks & XHCI_AMD_0x96_HOST))) in prepare_ring()
3022 static int prepare_transfer(struct xhci_hcd *xhci, in prepare_transfer() argument
3035 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in prepare_transfer()
3039 xhci_dbg(xhci, "Can't prepare ring for bad stream ID %u\n", in prepare_transfer()
3044 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in prepare_transfer()
3128 static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, in giveback_first_trb() argument
3141 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); in giveback_first_trb()
3144 static void check_interval(struct xhci_hcd *xhci, struct urb *urb, in check_interval() argument
3180 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_intr_tx() argument
3185 ep_ctx = xhci_get_ep_ctx(xhci, xhci->devs[slot_id]->out_ctx, ep_index); in xhci_queue_intr_tx()
3186 check_interval(xhci, urb, ep_ctx); in xhci_queue_intr_tx()
3188 return xhci_queue_bulk_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_intr_tx()
3211 static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, in xhci_td_remainder() argument
3218 if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) in xhci_td_remainder()
3227 if ((xhci->quirks & XHCI_MTK_HOST) && (xhci->hci_version < 0x100)) in xhci_td_remainder()
3238 static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len, in xhci_align_td() argument
3241 struct device *dev = xhci_to_hcd(xhci)->self.controller; in xhci_align_td()
3254 xhci_dbg(xhci, "Unaligned %d bytes, buff len %d\n", in xhci_align_td()
3260 xhci_dbg(xhci, "split align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3279 xhci_warn(xhci, in xhci_align_td()
3291 xhci_warn(xhci, "Failed mapping bounce buffer, not aligning\n"); in xhci_align_td()
3298 xhci_dbg(xhci, "Bounce align, new buff len %d\n", *trb_buff_len); in xhci_align_td()
3304 int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_bulk_tx() argument
3322 ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_bulk_tx()
3339 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3388 if (xhci_align_td(xhci, urb, enqd_len, in xhci_queue_bulk_tx()
3416 remainder = xhci_td_remainder(xhci, enqd_len, trb_buff_len, in xhci_queue_bulk_tx()
3423 queue_trb(xhci, ring, more_trbs_coming | need_zero_pkt, in xhci_queue_bulk_tx()
3448 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_bulk_tx()
3453 queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); in xhci_queue_bulk_tx()
3457 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_bulk_tx()
3463 int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_ctrl_tx() argument
3476 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_queue_ctrl_tx()
3496 ret = prepare_transfer(xhci, xhci->devs[slot_id], in xhci_queue_ctrl_tx()
3522 if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { in xhci_queue_ctrl_tx()
3531 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3558 remainder = xhci_td_remainder(xhci, 0, in xhci_queue_ctrl_tx()
3567 queue_trb(xhci, ep_ring, true, in xhci_queue_ctrl_tx()
3583 queue_trb(xhci, ep_ring, false, in xhci_queue_ctrl_tx()
3590 giveback_first_trb(xhci, slot_id, ep_index, 0, in xhci_queue_ctrl_tx()
3603 static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci, in xhci_get_burst_count() argument
3608 if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER) in xhci_get_burst_count()
3623 static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci, in xhci_get_last_burst_packet_count() argument
3629 if (xhci->hci_version < 0x100) in xhci_get_last_burst_packet_count()
3655 static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci, in xhci_get_isoc_frame_id() argument
3675 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_get_isoc_frame_id()
3676 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_get_isoc_frame_id()
3692 current_frame_id = readl(&xhci->run_regs->microframe_index); in xhci_get_isoc_frame_id()
3700 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()
3701 __func__, index, readl(&xhci->run_regs->microframe_index), in xhci_get_isoc_frame_id()
3729 xhci_warn(xhci, "Frame ID %d (reg %d, index %d) beyond range (%d, %d)\n", in xhci_get_isoc_frame_id()
3732 xhci_warn(xhci, "Ignore frame ID field, use SIA bit instead\n"); in xhci_get_isoc_frame_id()
3740 static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) in trb_block_event_intr() argument
3742 if (xhci->hci_version < 0x100) in trb_block_event_intr()
3751 if (i && xhci->quirks & XHCI_AVOID_BEI) in trb_block_event_intr()
3758 static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx() argument
3776 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx()
3777 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; in xhci_queue_isoc_tx()
3781 xhci_dbg(xhci, "Isoc URB with zero packets?\n"); in xhci_queue_isoc_tx()
3806 burst_count = xhci_get_burst_count(xhci, urb, total_pkt_count); in xhci_queue_isoc_tx()
3807 last_burst_pkt_count = xhci_get_last_burst_packet_count(xhci, in xhci_queue_isoc_tx()
3812 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, in xhci_queue_isoc_tx()
3824 HCC_CFC(xhci->hcc_params)) { in xhci_queue_isoc_tx()
3825 frame_id = xhci_get_isoc_frame_id(xhci, urb, i); in xhci_queue_isoc_tx()
3864 if (trb_block_event_intr(xhci, num_tds, i)) in xhci_queue_isoc_tx()
3873 remainder = xhci_td_remainder(xhci, running_total, in xhci_queue_isoc_tx()
3887 queue_trb(xhci, ep_ring, more_trbs_coming, in xhci_queue_isoc_tx()
3900 xhci_err(xhci, "ISOC TD length unmatch\n"); in xhci_queue_isoc_tx()
3907 if (HCC_CFC(xhci->hcc_params)) in xhci_queue_isoc_tx()
3910 if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { in xhci_queue_isoc_tx()
3911 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_queue_isoc_tx()
3914 xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; in xhci_queue_isoc_tx()
3916 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, in xhci_queue_isoc_tx()
3932 td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); in xhci_queue_isoc_tx()
3950 int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, in xhci_queue_isoc_tx_prepare() argument
3962 xdev = xhci->devs[slot_id]; in xhci_queue_isoc_tx_prepare()
3963 xep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_isoc_tx_prepare()
3965 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); in xhci_queue_isoc_tx_prepare()
3975 ret = prepare_ring(xhci, ep_ring, GET_EP_CTX_STATE(ep_ctx), in xhci_queue_isoc_tx_prepare()
3984 check_interval(xhci, urb, ep_ctx); in xhci_queue_isoc_tx_prepare()
3987 if (HCC_CFC(xhci->hcc_params) && !list_empty(&ep_ring->td_list)) { in xhci_queue_isoc_tx_prepare()
3994 start_frame = readl(&xhci->run_regs->microframe_index); in xhci_queue_isoc_tx_prepare()
4000 ist = HCS_IST(xhci->hcs_params2) & 0x7; in xhci_queue_isoc_tx_prepare()
4001 if (HCS_IST(xhci->hcs_params2) & (1 << 3)) in xhci_queue_isoc_tx_prepare()
4022 return xhci_queue_isoc_tx(xhci, mem_flags, urb, slot_id, ep_index); in xhci_queue_isoc_tx_prepare()
4035 static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in queue_command() argument
4039 int reserved_trbs = xhci->cmd_ring_reserved_trbs; in queue_command()
4042 if ((xhci->xhc_state & XHCI_STATE_DYING) || in queue_command()
4043 (xhci->xhc_state & XHCI_STATE_HALTED)) { in queue_command()
4044 xhci_dbg(xhci, "xHCI dying or halted, can't queue_command\n"); in queue_command()
4051 ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, in queue_command()
4054 xhci_err(xhci, "ERR: No room for command on command ring\n"); in queue_command()
4056 xhci_err(xhci, "ERR: Reserved TRB counting for " in queue_command()
4061 cmd->command_trb = xhci->cmd_ring->enqueue; in queue_command()
4064 if (list_empty(&xhci->cmd_list)) { in queue_command()
4065 xhci->current_cmd = cmd; in queue_command()
4066 xhci_mod_cmd_timer(xhci, XHCI_CMD_DEFAULT_TIMEOUT); in queue_command()
4069 list_add_tail(&cmd->cmd_list, &xhci->cmd_list); in queue_command()
4071 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, in queue_command()
4072 field4 | xhci->cmd_ring->cycle_state); in queue_command()
4077 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_slot_control() argument
4080 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_slot_control()
4085 int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_address_device() argument
4088 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_address_device()
4094 int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_vendor_command() argument
4097 return queue_command(xhci, cmd, field1, field2, field3, field4, false); in xhci_queue_vendor_command()
4101 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_device() argument
4104 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_device()
4110 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, in xhci_queue_configure_endpoint() argument
4114 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_configure_endpoint()
4121 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_evaluate_context() argument
4124 return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), in xhci_queue_evaluate_context()
4134 int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_stop_endpoint() argument
4142 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_stop_endpoint()
4147 void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, in xhci_queue_new_dequeue_state() argument
4161 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_queue_new_dequeue_state()
4173 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); in xhci_queue_new_dequeue_state()
4174 xhci_warn(xhci, "WARN deq seg = %p, deq pt = %p\n", in xhci_queue_new_dequeue_state()
4178 ep = &xhci->devs[slot_id]->eps[ep_index]; in xhci_queue_new_dequeue_state()
4180 xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); in xhci_queue_new_dequeue_state()
4181 xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n"); in xhci_queue_new_dequeue_state()
4186 cmd = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_queue_new_dequeue_state()
4194 ret = queue_command(xhci, cmd, in xhci_queue_new_dequeue_state()
4199 xhci_free_command(xhci, cmd); in xhci_queue_new_dequeue_state()
4211 int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, in xhci_queue_reset_ep() argument
4222 return queue_command(xhci, cmd, 0, 0, 0, in xhci_queue_reset_ep()