Lines Matching full:xhci
3 * xHCI host controller driver
23 #include "xhci.h"
24 #include "xhci-trace.h"
25 #include "xhci-debugfs.h"
26 #include "xhci-dbgcap.h"
86 * Disable interrupts and begin the xHCI halting process.
88 void xhci_quiesce(struct xhci_hcd *xhci) in xhci_quiesce() argument
95 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
99 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
101 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
112 int xhci_halt(struct xhci_hcd *xhci) in xhci_halt() argument
116 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC"); in xhci_halt()
117 xhci_quiesce(xhci); in xhci_halt()
119 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
122 xhci_warn(xhci, "Host halt failed, %d\n", ret); in xhci_halt()
126 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
127 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
135 int xhci_start(struct xhci_hcd *xhci) in xhci_start() argument
140 temp = readl(&xhci->op_regs->command); in xhci_start()
142 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.", in xhci_start()
144 writel(temp, &xhci->op_regs->command); in xhci_start()
150 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
153 xhci_err(xhci, "Host took too long to start, " in xhci_start()
158 xhci->xhc_state = 0; in xhci_start()
159 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
172 int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us) in xhci_reset() argument
178 state = readl(&xhci->op_regs->status); in xhci_reset()
181 xhci_warn(xhci, "Host not accessible, reset failed.\n"); in xhci_reset()
186 xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); in xhci_reset()
190 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); in xhci_reset()
191 command = readl(&xhci->op_regs->command); in xhci_reset()
193 writel(command, &xhci->op_regs->command); in xhci_reset()
195 /* Existing Intel xHCI controllers require a delay of 1 mS, in xhci_reset()
202 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
205 ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us); in xhci_reset()
209 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
210 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
212 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_reset()
215 * xHCI cannot write to any doorbells or operational registers other in xhci_reset()
218 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
220 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
221 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
222 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
223 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
224 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
225 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
230 static void xhci_zero_64b_regs(struct xhci_hcd *xhci) in xhci_zero_64b_regs() argument
232 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
253 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
257 xhci_info(xhci, "Zeroing 64bit base registers, expecting fault\n"); in xhci_zero_64b_regs()
260 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
262 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
265 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
267 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
270 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
272 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
273 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
275 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
277 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
278 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
283 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
284 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
286 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
287 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
289 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
293 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
297 xhci_info(xhci, "Fault detected\n"); in xhci_zero_64b_regs()
345 struct xhci_hcd *xhci; in compliance_mode_recovery() local
351 xhci = from_timer(xhci, t, comp_mode_recovery_timer); in compliance_mode_recovery()
352 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
365 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
368 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
378 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
379 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
390 * status event is generated when entering compliance mode (per xhci spec),
393 static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci) in compliance_mode_recovery_timer_init() argument
395 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
396 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
398 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
401 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
402 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery_timer_init()
433 static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) in xhci_all_ports_seen_u0() argument
435 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
448 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_init() local
451 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); in xhci_init()
452 spin_lock_init(&xhci->lock); in xhci_init()
453 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_init()
454 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_init()
456 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_init()
458 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_init()
459 "xHCI doesn't need link TRB QUIRK"); in xhci_init()
461 retval = xhci_mem_init(xhci, GFP_KERNEL); in xhci_init()
462 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init"); in xhci_init()
466 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
467 compliance_mode_recovery_timer_init(xhci); in xhci_init()
475 static int xhci_run_finished(struct xhci_hcd *xhci) in xhci_run_finished() argument
477 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run_finished()
482 * Enable interrupts before starting the host (xhci 4.2 and 5.5.2). in xhci_run_finished()
485 spin_lock_irqsave(&xhci->lock, flags); in xhci_run_finished()
487 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable interrupts"); in xhci_run_finished()
488 temp = readl(&xhci->op_regs->command); in xhci_run_finished()
490 writel(temp, &xhci->op_regs->command); in xhci_run_finished()
492 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable primary interrupter"); in xhci_run_finished()
495 if (xhci_start(xhci)) { in xhci_run_finished()
496 xhci_halt(xhci); in xhci_run_finished()
497 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
501 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
503 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
504 xhci_ring_cmd_db(xhci); in xhci_run_finished()
506 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
527 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_run() local
528 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run()
529 /* Start the xHCI host controller running only after the USB 2.0 roothub in xhci_run()
535 return xhci_run_finished(xhci); in xhci_run()
537 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_run"); in xhci_run()
539 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_run()
541 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
544 xhci_set_interrupter_moderation(ir, xhci->imod_interval); in xhci_run()
546 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
549 command = xhci_alloc_command(xhci, false, GFP_KERNEL); in xhci_run()
553 ret = xhci_queue_vendor_command(xhci, command, 0, 0, 0, in xhci_run()
556 xhci_free_command(xhci, command); in xhci_run()
558 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
561 xhci_create_dbc_dev(xhci); in xhci_run()
563 xhci_debugfs_init(xhci); in xhci_run()
565 if (xhci_has_one_roothub(xhci)) in xhci_run()
566 return xhci_run_finished(xhci); in xhci_run()
575 * Stop xHCI driver.
586 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_stop() local
587 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_stop()
589 mutex_lock(&xhci->mutex); in xhci_stop()
593 mutex_unlock(&xhci->mutex); in xhci_stop()
597 xhci_remove_dbc_dev(xhci); in xhci_stop()
599 spin_lock_irq(&xhci->lock); in xhci_stop()
600 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
601 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
602 xhci_halt(xhci); in xhci_stop()
603 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_stop()
604 spin_unlock_irq(&xhci->lock); in xhci_stop()
607 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
608 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_stop()
609 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
610 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_stop()
615 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
618 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
620 temp = readl(&xhci->op_regs->status); in xhci_stop()
621 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
624 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); in xhci_stop()
625 xhci_mem_cleanup(xhci); in xhci_stop()
626 xhci_debugfs_exit(xhci); in xhci_stop()
627 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
629 readl(&xhci->op_regs->status)); in xhci_stop()
630 mutex_unlock(&xhci->mutex); in xhci_stop()
645 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_shutdown() local
647 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
651 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_shutdown()
656 if (xhci->shared_hcd) { in xhci_shutdown()
657 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
658 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
661 spin_lock_irq(&xhci->lock); in xhci_shutdown()
662 xhci_halt(xhci); in xhci_shutdown()
668 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
669 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
670 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_shutdown()
672 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
674 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_shutdown()
676 readl(&xhci->op_regs->status)); in xhci_shutdown()
681 static void xhci_save_registers(struct xhci_hcd *xhci) in xhci_save_registers() argument
686 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
687 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
688 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
689 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
693 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_save_registers()
694 ir = xhci->interrupters[i]; in xhci_save_registers()
699 ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_save_registers()
700 ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_save_registers()
706 static void xhci_restore_registers(struct xhci_hcd *xhci) in xhci_restore_registers() argument
711 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
712 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
713 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
714 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
717 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_restore_registers()
718 ir = xhci->interrupters[i]; in xhci_restore_registers()
723 xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); in xhci_restore_registers()
724 xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); in xhci_restore_registers()
730 static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) in xhci_set_cmd_ring_deq() argument
735 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
737 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
738 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
740 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
741 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_set_cmd_ring_deq()
744 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
756 static void xhci_clear_command_ring(struct xhci_hcd *xhci) in xhci_clear_command_ring() argument
761 ring = xhci->cmd_ring; in xhci_clear_command_ring()
791 xhci_set_cmd_ring_deq(xhci); in xhci_clear_command_ring()
799 * Internal wake causes immediate xHCI wake after suspend. PORT_CSC write done
803 static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci, in xhci_disable_hub_port_wake() argument
811 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
828 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
832 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
835 static bool xhci_pending_portevent(struct xhci_hcd *xhci) in xhci_pending_portevent() argument
842 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
848 * being written to the Event Ring. See note in xhci 1.1 section 4.19.2. in xhci_pending_portevent()
851 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
852 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
859 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
860 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
876 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) in xhci_suspend() argument
880 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_suspend()
888 (xhci->shared_hcd && xhci->shared_hcd->state != HC_STATE_SUSPENDED)) in xhci_suspend()
892 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
893 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
898 xhci_dbc_suspend(xhci); in xhci_suspend()
901 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_suspend()
905 if (xhci->shared_hcd) { in xhci_suspend()
906 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
907 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
910 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
913 spin_lock_irq(&xhci->lock); in xhci_suspend()
915 if (xhci->shared_hcd) in xhci_suspend()
916 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
921 command = readl(&xhci->op_regs->command); in xhci_suspend()
923 writel(command, &xhci->op_regs->command); in xhci_suspend()
926 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
928 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
930 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); in xhci_suspend()
931 spin_unlock_irq(&xhci->lock); in xhci_suspend()
934 xhci_clear_command_ring(xhci); in xhci_suspend()
937 xhci_save_registers(xhci); in xhci_suspend()
940 command = readl(&xhci->op_regs->command); in xhci_suspend()
942 writel(command, &xhci->op_regs->command); in xhci_suspend()
943 xhci->broken_suspend = 0; in xhci_suspend()
944 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
952 * if SRE and HCE bits are not set (as per xhci in xhci_suspend()
955 res = readl(&xhci->op_regs->status); in xhci_suspend()
956 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
959 xhci->broken_suspend = 1; in xhci_suspend()
961 xhci_warn(xhci, "WARN: xHC save state timeout\n"); in xhci_suspend()
962 spin_unlock_irq(&xhci->lock); in xhci_suspend()
966 spin_unlock_irq(&xhci->lock); in xhci_suspend()
969 * Deleting Compliance Mode Recovery Timer because the xHCI Host in xhci_suspend()
972 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
973 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_suspend()
974 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
975 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_suspend()
990 int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg) in xhci_resume() argument
994 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_resume()
1008 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
1009 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
1013 if (xhci->shared_hcd) in xhci_resume()
1014 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
1016 spin_lock_irq(&xhci->lock); in xhci_resume()
1018 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
1026 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1029 xhci_warn(xhci, "Controller not ready at resume %d\n", in xhci_resume()
1031 spin_unlock_irq(&xhci->lock); in xhci_resume()
1035 xhci_restore_registers(xhci); in xhci_resume()
1037 xhci_set_cmd_ring_deq(xhci); in xhci_resume()
1040 command = readl(&xhci->op_regs->command); in xhci_resume()
1042 writel(command, &xhci->op_regs->command); in xhci_resume()
1045 * restore so setting the timeout to 100ms. Xhci specification in xhci_resume()
1048 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1050 xhci_warn(xhci, "WARN: xHC restore state timeout\n"); in xhci_resume()
1051 spin_unlock_irq(&xhci->lock); in xhci_resume()
1056 temp = readl(&xhci->op_regs->status); in xhci_resume()
1060 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1062 if (!xhci->broken_suspend) in xhci_resume()
1063 xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); in xhci_resume()
1067 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1068 !(xhci_all_ports_seen_u0(xhci))) { in xhci_resume()
1069 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1070 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_resume()
1075 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1076 if (xhci->shared_hcd) in xhci_resume()
1077 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1079 xhci_dbg(xhci, "Stop HCD\n"); in xhci_resume()
1080 xhci_halt(xhci); in xhci_resume()
1081 xhci_zero_64b_regs(xhci); in xhci_resume()
1082 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_resume()
1083 spin_unlock_irq(&xhci->lock); in xhci_resume()
1087 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); in xhci_resume()
1088 temp = readl(&xhci->op_regs->status); in xhci_resume()
1089 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1090 xhci_disable_interrupter(xhci->interrupters[0]); in xhci_resume()
1092 xhci_dbg(xhci, "cleaning up memory\n"); in xhci_resume()
1093 xhci_mem_cleanup(xhci); in xhci_resume()
1094 xhci_debugfs_exit(xhci); in xhci_resume()
1095 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1096 readl(&xhci->op_regs->status)); in xhci_resume()
1102 xhci_dbg(xhci, "Initialize the xhci_hcd\n"); in xhci_resume()
1108 xhci_dbg(xhci, "Start the primary HCD\n"); in xhci_resume()
1110 if (!retval && xhci->shared_hcd) { in xhci_resume()
1111 xhci_dbg(xhci, "Start the secondary HCD\n"); in xhci_resume()
1112 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1122 if (xhci->shared_hcd) { in xhci_resume()
1123 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1124 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1132 command = readl(&xhci->op_regs->command); in xhci_resume()
1134 writel(command, &xhci->op_regs->command); in xhci_resume()
1135 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1147 spin_unlock_irq(&xhci->lock); in xhci_resume()
1149 xhci_dbc_resume(xhci); in xhci_resume()
1158 if (xhci->usb3_rhub.bus_state.suspended_ports || in xhci_resume()
1159 xhci->usb3_rhub.bus_state.bus_suspended) in xhci_resume()
1162 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1167 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1171 if (xhci->shared_hcd) in xhci_resume()
1172 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1183 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1184 compliance_mode_recovery_timer_init(xhci); in xhci_resume()
1186 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1190 xhci_dbg(xhci, "%s: starting usb%d port polling.\n", in xhci_resume()
1192 if (xhci->shared_hcd) { in xhci_resume()
1193 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1194 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1324 struct xhci_hcd *xhci; in xhci_map_urb_for_dma() local
1326 xhci = hcd_to_xhci(hcd); in xhci_map_urb_for_dma()
1331 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1340 struct xhci_hcd *xhci; in xhci_unmap_urb_for_dma() local
1343 xhci = hcd_to_xhci(hcd); in xhci_unmap_urb_for_dma()
1348 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1377 * address from the XHCI endpoint index.
1412 struct xhci_hcd *xhci; in xhci_check_args() local
1416 pr_debug("xHCI %s called with invalid args\n", func); in xhci_check_args()
1420 pr_debug("xHCI %s called for root hub\n", func); in xhci_check_args()
1424 xhci = hcd_to_xhci(hcd); in xhci_check_args()
1426 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1427 xhci_dbg(xhci, "xHCI %s called with unaddressed device\n", in xhci_check_args()
1432 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1434 xhci_dbg(xhci, "xHCI %s called with udev and " in xhci_check_args()
1440 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1446 static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1456 static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, in xhci_check_maxpacket() argument
1467 out_ctx = xhci->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
1468 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_check_maxpacket()
1472 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1474 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1477 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1478 "Max packet size in xHCI HW = %d", in xhci_check_maxpacket()
1480 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1488 command = xhci_alloc_command(xhci, true, mem_flags); in xhci_check_maxpacket()
1492 command->in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
1495 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_maxpacket()
1501 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
1502 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
1504 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_check_maxpacket()
1512 ret = xhci_configure_endpoint(xhci, urb->dev, command, in xhci_check_maxpacket()
1532 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_urb_enqueue() local
1549 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1554 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1555 xhci_dbg(xhci, "Can't queue urb, port error, link inactive\n"); in xhci_urb_enqueue()
1584 ret = xhci_check_maxpacket(xhci, slot_id, in xhci_urb_enqueue()
1594 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1596 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1597 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1603 xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams transition state %x\n", in xhci_urb_enqueue()
1609 xhci_warn(xhci, "Can't enqueue URB while manually clearing toggle\n"); in xhci_urb_enqueue()
1617 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1621 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1625 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1629 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1638 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1660 * endpoint command, as noted in the xHCI 0.95 errata.
1678 struct xhci_hcd *xhci; in xhci_urb_dequeue() local
1687 xhci = hcd_to_xhci(hcd); in xhci_urb_dequeue()
1688 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1698 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1705 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_urb_dequeue()
1710 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1711 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1712 xhci_hc_died(xhci); in xhci_urb_dequeue()
1722 xhci_err(xhci, "Canceled URB td not found on endpoint ring"); in xhci_urb_dequeue()
1731 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1732 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1748 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1769 xhci_dbg(xhci, "Not queuing Stop Endpoint on slot %d ep %d in state 0x%x\n", in xhci_urb_dequeue()
1777 xhci_dbg(xhci, "Invalidating TDs instantly on slot %d ep %d in state 0x%x\n", in xhci_urb_dequeue()
1782 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_urb_dequeue()
1789 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1791 xhci_ring_cmd_db(xhci); in xhci_urb_dequeue()
1794 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1801 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1817 * the xhci->devs[slot_id] structure.
1822 struct xhci_hcd *xhci; in xhci_drop_endpoint() local
1834 xhci = hcd_to_xhci(hcd); in xhci_drop_endpoint()
1835 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1838 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_drop_endpoint()
1841 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1846 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1847 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1850 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_drop_endpoint()
1856 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_drop_endpoint()
1864 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1865 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", in xhci_drop_endpoint()
1876 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1878 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1880 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_drop_endpoint()
1900 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1905 struct xhci_hcd *xhci; in xhci_add_endpoint() local
1921 xhci = hcd_to_xhci(hcd); in xhci_add_endpoint()
1922 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1931 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1936 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1940 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_add_endpoint()
1951 xhci_warn(xhci, "Trying to add endpoint 0x%x " in xhci_add_endpoint()
1961 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", in xhci_add_endpoint()
1971 if (xhci_endpoint_init(xhci, virt_dev, udev, ep, GFP_NOIO) < 0) { in xhci_add_endpoint()
1991 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1994 xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_add_endpoint()
2003 static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev) in xhci_zero_in_ctx() argument
2012 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_zero_in_ctx()
2024 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
2029 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
2037 static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, in xhci_configure_endpoint_result() argument
2045 xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); in xhci_configure_endpoint_result()
2074 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint_result()
2079 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_configure_endpoint_result()
2087 static int xhci_evaluate_context_result(struct xhci_hcd *xhci, in xhci_evaluate_context_result() argument
2095 xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); in xhci_evaluate_context_result()
2100 "WARN: xHCI driver setup invalid evaluate context command.\n"); in xhci_evaluate_context_result()
2124 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_evaluate_context_result()
2129 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_evaluate_context_result()
2137 static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, in xhci_count_num_new_endpoints() argument
2158 static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci, in xhci_count_num_dropped_endpoints() argument
2182 * Must be called with xhci->lock held.
2184 static int xhci_reserve_host_resources(struct xhci_hcd *xhci, in xhci_reserve_host_resources() argument
2189 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_reserve_host_resources()
2190 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2191 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2194 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2195 xhci->limit_active_eps); in xhci_reserve_host_resources()
2198 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2199 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2201 xhci->num_active_eps); in xhci_reserve_host_resources()
2209 * Must be called with xhci->lock held.
2211 static void xhci_free_host_resources(struct xhci_hcd *xhci, in xhci_free_host_resources() argument
2216 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_free_host_resources()
2217 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2218 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_host_resources()
2221 xhci->num_active_eps); in xhci_free_host_resources()
2228 * Must be called with xhci->lock held.
2230 static void xhci_finish_resource_reservation(struct xhci_hcd *xhci, in xhci_finish_resource_reservation() argument
2235 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx); in xhci_finish_resource_reservation()
2236 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2238 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_finish_resource_reservation()
2241 xhci->num_active_eps); in xhci_finish_resource_reservation()
2276 static int xhci_check_tt_bw_table(struct xhci_hcd *xhci, in xhci_check_tt_bw_table() argument
2284 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2306 static int xhci_check_ss_bw(struct xhci_hcd *xhci, in xhci_check_ss_bw() argument
2363 static int xhci_check_bw_table(struct xhci_hcd *xhci, in xhci_check_bw_table() argument
2379 return xhci_check_ss_bw(xhci, virt_dev); in xhci_check_bw_table()
2400 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2403 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_check_bw_table()
2404 xhci_warn(xhci, "Not enough bandwidth on HS bus for " in xhci_check_bw_table()
2408 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2413 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2496 xhci_warn(xhci, "Not enough bandwidth. " in xhci_check_bw_table()
2519 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2522 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2531 xhci_warn(xhci, "Not enough bandwidth. Proposed: %u, Max: %u\n", in xhci_check_bw_table()
2566 static void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci, in xhci_drop_ep_from_interval_table() argument
2581 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2584 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2627 static void xhci_add_ep_to_interval_table(struct xhci_hcd *xhci, in xhci_add_ep_to_interval_table() argument
2643 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2646 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2698 void xhci_update_tt_active_eps(struct xhci_hcd *xhci, in xhci_update_tt_active_eps() argument
2706 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2718 static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, in xhci_reserve_bandwidth() argument
2732 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_reserve_bandwidth()
2748 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2756 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2760 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2768 if (!xhci_check_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_reserve_bandwidth()
2772 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_reserve_bandwidth()
2785 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2797 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2811 static int xhci_configure_endpoint(struct xhci_hcd *xhci, in xhci_configure_endpoint() argument
2825 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2827 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2828 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2832 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2836 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2837 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_configure_endpoint()
2842 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2843 xhci_reserve_host_resources(xhci, ctrl_ctx)) { in xhci_configure_endpoint()
2844 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2845 xhci_warn(xhci, "Not enough host resources, " in xhci_configure_endpoint()
2847 xhci->num_active_eps); in xhci_configure_endpoint()
2850 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && !ctx_change && in xhci_configure_endpoint()
2851 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2852 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2853 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2854 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2855 xhci_warn(xhci, "Not enough bandwidth\n"); in xhci_configure_endpoint()
2859 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2865 ret = xhci_queue_configure_endpoint(xhci, command, in xhci_configure_endpoint()
2869 ret = xhci_queue_evaluate_context(xhci, command, in xhci_configure_endpoint()
2873 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2874 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2875 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2876 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint()
2880 xhci_ring_cmd_db(xhci); in xhci_configure_endpoint()
2881 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2887 ret = xhci_configure_endpoint_result(xhci, udev, in xhci_configure_endpoint()
2890 ret = xhci_evaluate_context_result(xhci, udev, in xhci_configure_endpoint()
2893 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2894 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2899 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2901 xhci_finish_resource_reservation(xhci, ctrl_ctx); in xhci_configure_endpoint()
2902 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2907 static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci, in xhci_check_bw_drop_ep_streams() argument
2913 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on set_interface, freeing streams.\n", in xhci_check_bw_drop_ep_streams()
2915 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2928 * else should be touching the xhci->devs[slot_id] structure, so we
2929 * don't need to take the xhci->lock for manipulating that.
2935 struct xhci_hcd *xhci; in xhci_check_bandwidth() local
2944 xhci = hcd_to_xhci(hcd); in xhci_check_bandwidth()
2945 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2946 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2949 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_check_bandwidth()
2950 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2952 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_bandwidth()
2961 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_bandwidth()
2977 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
2989 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_check_bandwidth()
2999 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
3000 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
3003 xhci_zero_in_ctx(xhci, virt_dev); in xhci_check_bandwidth()
3015 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
3017 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
3020 xhci_debugfs_create_endpoint(xhci, virt_dev, i); in xhci_check_bandwidth()
3032 struct xhci_hcd *xhci; in xhci_reset_bandwidth() local
3039 xhci = hcd_to_xhci(hcd); in xhci_reset_bandwidth()
3041 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_reset_bandwidth()
3042 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
3046 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_reset_bandwidth()
3047 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3051 xhci_zero_in_ctx(xhci, virt_dev); in xhci_reset_bandwidth()
3055 static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, in xhci_setup_input_ctx_for_config_ep() argument
3063 xhci_slot_copy(xhci, in_ctx, out_ctx); in xhci_setup_input_ctx_for_config_ep()
3070 struct xhci_hcd *xhci; in xhci_endpoint_disable() local
3077 xhci = hcd_to_xhci(hcd); in xhci_endpoint_disable()
3079 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3085 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3094 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3100 xhci_dbg(xhci, "endpoint disable with ep_state 0x%x\n", in xhci_endpoint_disable()
3104 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3116 * endpoint. Refer to the additional note in xhci spcification section 4.6.8.
3122 struct xhci_hcd *xhci; in xhci_endpoint_reset() local
3133 xhci = hcd_to_xhci(hcd); in xhci_endpoint_reset()
3137 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3150 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3153 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3156 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3167 stop_cmd = xhci_alloc_command(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3171 cfg_cmd = xhci_alloc_command_with_ctx(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3175 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3188 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3189 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3193 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3196 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3197 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3198 xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ", in xhci_endpoint_reset()
3203 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3204 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3208 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3213 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3214 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3215 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_endpoint_reset()
3220 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3222 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3224 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3227 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3228 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3229 xhci_dbg(xhci, "%s: Failed to queue config ep command, %d ", in xhci_endpoint_reset()
3234 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3235 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3239 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3241 xhci_free_command(xhci, stop_cmd); in xhci_endpoint_reset()
3242 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3245 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3248 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, in xhci_check_streams_endpoint() argument
3258 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__); in xhci_check_streams_endpoint()
3262 xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion" in xhci_check_streams_endpoint()
3269 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3272 xhci_warn(xhci, "WARN: SuperSpeed bulk endpoint 0x%x " in xhci_check_streams_endpoint()
3275 xhci_warn(xhci, "Send email to xHCI maintainer and ask for " in xhci_check_streams_endpoint()
3279 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3280 xhci_warn(xhci, "Cannot setup streams for SuperSpeed bulk " in xhci_check_streams_endpoint()
3288 static void xhci_calculate_streams_entries(struct xhci_hcd *xhci, in xhci_calculate_streams_entries() argument
3298 * level page entries), but that's an optional feature for xHCI host in xhci_calculate_streams_entries()
3301 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3303 xhci_dbg(xhci, "xHCI HW only supports %u stream ctx entries.\n", in xhci_calculate_streams_entries()
3314 static int xhci_calculate_streams_and_bitmask(struct xhci_hcd *xhci, in xhci_calculate_streams_and_bitmask() argument
3325 ret = xhci_check_streams_endpoint(xhci, udev, in xhci_calculate_streams_and_bitmask()
3332 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n", in xhci_calculate_streams_and_bitmask()
3346 static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci, in xhci_calculate_no_streams_bitmask() argument
3357 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3362 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3365 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3374 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3378 xhci_warn(xhci, "WARN xhci_free_streams() called " in xhci_calculate_no_streams_bitmask()
3408 struct xhci_hcd *xhci; in xhci_alloc_streams() local
3422 * stream 0 that is reserved for xHCI usage. in xhci_alloc_streams()
3425 xhci = hcd_to_xhci(hcd); in xhci_alloc_streams()
3426 xhci_dbg(xhci, "Driver wants %u stream IDs (including stream 0).\n", in xhci_alloc_streams()
3430 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3431 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3432 xhci_dbg(xhci, "xHCI controller does not support streams.\n"); in xhci_alloc_streams()
3436 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_alloc_streams()
3442 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_alloc_streams()
3444 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3452 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3453 ret = xhci_calculate_streams_and_bitmask(xhci, udev, eps, in xhci_alloc_streams()
3456 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3457 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3461 xhci_warn(xhci, "WARN: endpoints can't handle " in xhci_alloc_streams()
3463 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3464 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3467 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3475 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3481 xhci_calculate_streams_entries(xhci, &num_streams, &num_stream_ctxs); in xhci_alloc_streams()
3482 xhci_dbg(xhci, "Need %u stream ctx entries for %u stream IDs.\n", in xhci_alloc_streams()
3488 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3504 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3506 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3508 xhci_setup_streams_ep_input_ctx(xhci, ep_ctx, in xhci_alloc_streams()
3514 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3519 ret = xhci_configure_endpoint(xhci, udev, config_cmd, in xhci_alloc_streams()
3529 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3533 xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n", in xhci_alloc_streams()
3537 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3538 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3542 xhci_debugfs_create_stream_files(xhci, vdev, ep_index); in xhci_alloc_streams()
3551 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3558 xhci_endpoint_zero(xhci, vdev, eps[i]); in xhci_alloc_streams()
3560 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3575 struct xhci_hcd *xhci; in xhci_free_streams() local
3583 xhci = hcd_to_xhci(hcd); in xhci_free_streams()
3584 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3587 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3588 changed_ep_bitmask = xhci_calculate_no_streams_bitmask(xhci, in xhci_free_streams()
3591 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3603 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3604 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_free_streams()
3613 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3614 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3617 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3622 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3625 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3630 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_free_streams()
3639 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3642 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3650 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3660 * Must be called with xhci->lock held.
3662 void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, in xhci_free_device_endpoint_resources() argument
3675 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3677 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_device_endpoint_resources()
3681 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3709 struct xhci_hcd *xhci; in xhci_discover_or_reset_device() local
3719 xhci = hcd_to_xhci(hcd); in xhci_discover_or_reset_device()
3721 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3723 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3740 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3751 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3756 if (xhci->quirks & XHCI_ETRON_HOST) { in xhci_discover_or_reset_device()
3758 * Obtaining a new device slot to inform the xHCI host that in xhci_discover_or_reset_device()
3761 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_discover_or_reset_device()
3762 xhci_free_virt_device(xhci, udev->slot_id); in xhci_discover_or_reset_device()
3775 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); in xhci_discover_or_reset_device()
3782 reset_device_cmd = xhci_alloc_command(xhci, true, GFP_NOIO); in xhci_discover_or_reset_device()
3784 xhci_dbg(xhci, "Couldn't allocate command structure.\n"); in xhci_discover_or_reset_device()
3789 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3791 ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id); in xhci_discover_or_reset_device()
3793 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_discover_or_reset_device()
3794 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3797 xhci_ring_cmd_db(xhci); in xhci_discover_or_reset_device()
3798 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3811 xhci_warn(xhci, "Timeout waiting for reset device command\n"); in xhci_discover_or_reset_device()
3816 xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n", in xhci_discover_or_reset_device()
3818 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3819 xhci_dbg(xhci, "Not freeing device rings.\n"); in xhci_discover_or_reset_device()
3824 xhci_dbg(xhci, "Successful reset device command.\n"); in xhci_discover_or_reset_device()
3827 if (xhci_is_vendor_info_code(xhci, ret)) in xhci_discover_or_reset_device()
3829 xhci_warn(xhci, "Unknown completion code %u for " in xhci_discover_or_reset_device()
3836 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3837 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3839 xhci_free_device_endpoint_resources(xhci, virt_dev, false); in xhci_discover_or_reset_device()
3840 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3848 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on device reset, freeing streams.\n", in xhci_discover_or_reset_device()
3850 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3856 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3857 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3860 xhci_drop_ep_from_interval_table(xhci, in xhci_discover_or_reset_device()
3869 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_discover_or_reset_device()
3874 xhci_free_command(xhci, reset_device_cmd); in xhci_discover_or_reset_device()
3885 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_free_dev() local
3896 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3906 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3907 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3914 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3916 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3917 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3918 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3922 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id) in xhci_disable_slot() argument
3929 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_disable_slot()
3933 xhci_debugfs_remove_slot(xhci, slot_id); in xhci_disable_slot()
3935 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3937 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3938 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3939 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3940 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3945 ret = xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, in xhci_disable_slot()
3948 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3952 xhci_ring_cmd_db(xhci); in xhci_disable_slot()
3953 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3958 xhci_warn(xhci, "Unsuccessful disable slot %u command, status %d\n", in xhci_disable_slot()
3961 xhci_free_command(xhci, command); in xhci_disable_slot()
3970 * Must be called with xhci->lock held.
3972 static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci) in xhci_reserve_host_control_ep_resources() argument
3974 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
3975 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
3978 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
3981 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
3982 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
3984 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
3995 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_alloc_dev() local
4002 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_alloc_dev()
4006 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4007 ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0); in xhci_alloc_dev()
4009 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4010 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_alloc_dev()
4011 xhci_free_command(xhci, command); in xhci_alloc_dev()
4014 xhci_ring_cmd_db(xhci); in xhci_alloc_dev()
4015 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4021 xhci_err(xhci, "Error while assigning device slot ID: %s\n", in xhci_alloc_dev()
4023 xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", in xhci_alloc_dev()
4025 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
4026 xhci_free_command(xhci, command); in xhci_alloc_dev()
4030 xhci_free_command(xhci, command); in xhci_alloc_dev()
4032 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
4033 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4034 ret = xhci_reserve_host_control_ep_resources(xhci); in xhci_alloc_dev()
4036 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4037 xhci_warn(xhci, "Not enough host resources, " in xhci_alloc_dev()
4039 xhci->num_active_eps); in xhci_alloc_dev()
4042 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4048 if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO)) { in xhci_alloc_dev()
4049 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); in xhci_alloc_dev()
4052 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
4053 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
4058 xhci_debugfs_create_slot(xhci, slot_id); in xhci_alloc_dev()
4064 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4072 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4073 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4095 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_setup_device() local
4101 mutex_lock(&xhci->mutex); in xhci_setup_device()
4103 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4109 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4115 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4123 xhci_warn(xhci, "Virt dev invalid for slot_id 0x%x!\n", in xhci_setup_device()
4128 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4134 xhci_dbg(xhci, "Slot already in default state\n"); in xhci_setup_device()
4139 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_setup_device()
4148 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4151 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_setup_device()
4158 * virt_device realloaction after a resume with an xHCI power loss, in xhci_setup_device()
4162 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4165 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); in xhci_setup_device()
4169 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4173 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4175 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4178 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4179 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4183 xhci_ring_cmd_db(xhci); in xhci_setup_device()
4184 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4196 xhci_warn(xhci, "Timeout while waiting for setup device command\n"); in xhci_setup_device()
4201 xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", in xhci_setup_device()
4208 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4209 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4210 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4213 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4224 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4228 xhci_err(xhci, in xhci_setup_device()
4231 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4237 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4238 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4240 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4243 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4245 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4246 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4249 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4255 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4260 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4263 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4267 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4305 static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, in xhci_change_max_exit_latency() argument
4315 command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL); in xhci_change_max_exit_latency()
4319 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4321 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4326 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4330 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4331 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4338 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4339 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4340 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_change_max_exit_latency()
4345 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4346 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4349 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4354 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_change_max_exit_latency()
4358 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_change_max_exit_latency()
4362 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4364 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4367 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4379 static int xhci_calculate_hird_besl(struct xhci_hcd *xhci, in xhci_calculate_hird_besl() argument
4386 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4423 /* xHCI l1 is set in steps of 256us, xHCI 1.0 section 5.4.11.2 */ in xhci_calculate_usb2_hw_lpm_params()
4438 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_set_usb2_hardware_lpm() local
4447 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4450 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4461 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4463 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4469 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", in xhci_set_usb2_hardware_lpm()
4477 * systems. See XHCI_DEFAULT_BESL definition in xhci.h in xhci_set_usb2_hardware_lpm()
4487 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4489 ret = xhci_change_max_exit_latency(xhci, udev, in xhci_set_usb2_hardware_lpm()
4493 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4500 hird = xhci_calculate_hird_besl(xhci, udev); in xhci_set_usb2_hardware_lpm()
4517 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4518 xhci_change_max_exit_latency(xhci, udev, 0); in xhci_set_usb2_hardware_lpm()
4526 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4534 static int xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int port, in xhci_check_usb2_port_capability() argument
4540 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4541 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4543 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4544 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4555 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_device() local
4566 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4568 xhci, portnum, XHCI_HLC)) { in xhci_update_device()
4572 if (xhci_check_usb2_port_capability(xhci, portnum, in xhci_update_device()
4677 static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci, in xhci_calculate_u1_timeout() argument
4691 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4741 static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci, in xhci_calculate_u2_timeout() argument
4755 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4772 static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_call_host_update_timeout_for_endpoint() argument
4779 return xhci_calculate_u1_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4781 return xhci_calculate_u2_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4786 static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_update_timeout_for_endpoint() argument
4794 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_endpoint()
4811 static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci, in xhci_update_timeout_for_interface() argument
4820 if (xhci_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_interface()
4827 static int xhci_check_tier_policy(struct xhci_hcd *xhci, in xhci_check_tier_policy() argument
4839 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
4841 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
4859 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_calculate_lpm_timeout() local
4878 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4912 if (xhci_update_timeout_for_interface(xhci, udev, in xhci_calculate_lpm_timeout()
4954 /* xHCI host controller max exit latency field is only 16 bits wide. */ in calculate_max_exit_latency()
4967 struct xhci_hcd *xhci; in xhci_enable_usb3_lpm_timeout() local
4973 xhci = hcd_to_xhci(hcd); in xhci_enable_usb3_lpm_timeout()
4978 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
4979 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
4982 if (xhci_check_tier_policy(xhci, udev, state) < 0) in xhci_enable_usb3_lpm_timeout()
4987 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
5000 ret = xhci_change_max_exit_latency(xhci, udev, mel); in xhci_enable_usb3_lpm_timeout()
5009 struct xhci_hcd *xhci; in xhci_disable_usb3_lpm_timeout() local
5012 xhci = hcd_to_xhci(hcd); in xhci_disable_usb3_lpm_timeout()
5013 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
5014 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
5018 return xhci_change_max_exit_latency(xhci, udev, mel); in xhci_disable_usb3_lpm_timeout()
5054 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_hub_device() local
5067 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
5069 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n"); in xhci_update_hub_device()
5073 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_update_hub_device()
5079 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_update_hub_device()
5081 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5085 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5087 xhci_alloc_tt_info(xhci, vdev, hdev, tt, GFP_ATOMIC)) { in xhci_update_hub_device()
5088 xhci_dbg(xhci, "Could not allocate xHCI TT structure.\n"); in xhci_update_hub_device()
5089 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5090 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5094 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5096 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5100 * but it may be already set to 1 when setup an xHCI virtual in xhci_update_hub_device()
5108 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5109 xhci_dbg(xhci, "xHCI version %x needs hub " in xhci_update_hub_device()
5111 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5117 * xHCI 1.0: this field shall be 0 if the device is not a in xhci_update_hub_device()
5123 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5127 xhci_dbg(xhci, "xHCI version %x doesn't need hub " in xhci_update_hub_device()
5129 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5132 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5134 xhci_dbg(xhci, "Set up %s for hub device.\n", in xhci_update_hub_device()
5135 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5141 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5142 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5145 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5148 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5155 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_get_frame() local
5157 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5160 static void xhci_hcd_init_usb2_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb2_data() argument
5162 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5166 * USB 2.0 roothub under xHCI has an integrated TT, in xhci_hcd_init_usb2_data()
5173 static void xhci_hcd_init_usb3_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb3_data() argument
5178 * Early xHCI 1.1 spec did not mention USB 3.1 capable hosts in xhci_hcd_init_usb3_data()
5181 * This was later clarified in xHCI 1.2. in xhci_hcd_init_usb3_data()
5186 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5189 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5205 xhci_info(xhci, "Host supports USB 3.%x %sSuperSpeed\n", in xhci_hcd_init_usb3_data()
5208 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5213 struct xhci_hcd *xhci; in xhci_gen_setup() local
5227 /* XHCI controllers don't stop the ep queue on short packets :| */ in xhci_gen_setup()
5230 xhci = hcd_to_xhci(hcd); in xhci_gen_setup()
5233 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5237 mutex_init(&xhci->mutex); in xhci_gen_setup()
5238 xhci->main_hcd = hcd; in xhci_gen_setup()
5239 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5240 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5241 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5242 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5243 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5245 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5246 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5247 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5248 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5249 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5250 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5251 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5253 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5254 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5255 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5256 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5258 xhci->quirks |= quirks; in xhci_gen_setup()
5261 get_quirks(dev, xhci); in xhci_gen_setup()
5263 /* In xhci controllers which follow xhci 1.0 spec gives a spurious in xhci_gen_setup()
5267 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5268 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5271 retval = xhci_halt(xhci); in xhci_gen_setup()
5275 xhci_zero_64b_regs(xhci); in xhci_gen_setup()
5277 xhci_dbg(xhci, "Resetting HCD\n"); in xhci_gen_setup()
5279 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_gen_setup()
5282 xhci_dbg(xhci, "Reset complete\n"); in xhci_gen_setup()
5285 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5288 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5291 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5292 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5296 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5298 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5308 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5312 xhci_dbg(xhci, "Calling HCD init\n"); in xhci_gen_setup()
5317 xhci_dbg(xhci, "Called HCD init\n"); in xhci_gen_setup()
5320 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5322 xhci_hcd_init_usb2_data(xhci, hcd); in xhci_gen_setup()
5324 xhci_info(xhci, "hcc params 0x%08x hci version 0x%x quirks 0x%016llx\n", in xhci_gen_setup()
5325 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5334 struct xhci_hcd *xhci; in xhci_clear_tt_buffer_complete() local
5340 xhci = hcd_to_xhci(hcd); in xhci_clear_tt_buffer_complete()
5342 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5347 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5348 xhci_ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_clear_tt_buffer_complete()
5349 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5353 .description = "xhci-hcd",
5354 .product_desc = "xHCI Host Controller",