Lines Matching full:xhci

3  * xHCI host controller driver
22 #include "xhci.h"
23 #include "xhci-trace.h"
24 #include "xhci-debugfs.h"
25 #include "xhci-dbgcap.h"
89 int xhci_handshake_check_state(struct xhci_hcd *xhci, void __iomem *ptr, in xhci_handshake_check_state() argument
98 xhci->xhc_state & exit_state, in xhci_handshake_check_state()
101 if (result == U32_MAX || xhci->xhc_state & exit_state) in xhci_handshake_check_state()
108 * Disable interrupts and begin the xHCI halting process.
110 void xhci_quiesce(struct xhci_hcd *xhci) in xhci_quiesce() argument
117 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
121 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
123 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
134 int xhci_halt(struct xhci_hcd *xhci) in xhci_halt() argument
138 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC"); in xhci_halt()
139 xhci_quiesce(xhci); in xhci_halt()
141 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
144 xhci_warn(xhci, "Host halt failed, %d\n", ret); in xhci_halt()
148 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
149 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
157 int xhci_start(struct xhci_hcd *xhci) in xhci_start() argument
162 temp = readl(&xhci->op_regs->command); in xhci_start()
164 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.", in xhci_start()
166 writel(temp, &xhci->op_regs->command); in xhci_start()
172 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
175 xhci_err(xhci, "Host took too long to start, " in xhci_start()
180 xhci->xhc_state = 0; in xhci_start()
181 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
194 int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us) in xhci_reset() argument
200 state = readl(&xhci->op_regs->status); in xhci_reset()
203 xhci_warn(xhci, "Host not accessible, reset failed.\n"); in xhci_reset()
208 xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); in xhci_reset()
212 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); in xhci_reset()
213 command = readl(&xhci->op_regs->command); in xhci_reset()
215 writel(command, &xhci->op_regs->command); in xhci_reset()
217 /* Existing Intel xHCI controllers require a delay of 1 mS, in xhci_reset()
224 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
227 ret = xhci_handshake_check_state(xhci, &xhci->op_regs->command, in xhci_reset()
232 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
233 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
235 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_reset()
238 * xHCI cannot write to any doorbells or operational registers other in xhci_reset()
241 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
243 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
244 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
245 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
246 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
247 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
248 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
253 static void xhci_zero_64b_regs(struct xhci_hcd *xhci) in xhci_zero_64b_regs() argument
255 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
276 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
280 xhci_info(xhci, "Zeroing 64bit base registers, expecting fault\n"); in xhci_zero_64b_regs()
283 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
285 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
288 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
290 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
293 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
295 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
296 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
298 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
300 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
301 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
306 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
307 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
309 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
310 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
312 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
316 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
320 xhci_info(xhci, "Fault detected\n"); in xhci_zero_64b_regs()
351 struct xhci_hcd *xhci; in compliance_mode_recovery() local
357 xhci = from_timer(xhci, t, comp_mode_recovery_timer); in compliance_mode_recovery()
358 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
371 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
374 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
384 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
385 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
396 * status event is generated when entering compliance mode (per xhci spec),
399 static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci) in compliance_mode_recovery_timer_init() argument
401 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
402 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
404 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
407 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
408 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery_timer_init()
439 static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) in xhci_all_ports_seen_u0() argument
441 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
454 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_init() local
457 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); in xhci_init()
458 spin_lock_init(&xhci->lock); in xhci_init()
459 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_init()
460 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_init()
462 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_init()
464 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_init()
465 "xHCI doesn't need link TRB QUIRK"); in xhci_init()
467 retval = xhci_mem_init(xhci, GFP_KERNEL); in xhci_init()
468 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init"); in xhci_init()
472 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
473 compliance_mode_recovery_timer_init(xhci); in xhci_init()
481 static int xhci_run_finished(struct xhci_hcd *xhci) in xhci_run_finished() argument
483 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run_finished()
488 * Enable interrupts before starting the host (xhci 4.2 and 5.5.2). in xhci_run_finished()
491 spin_lock_irqsave(&xhci->lock, flags); in xhci_run_finished()
493 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable interrupts"); in xhci_run_finished()
494 temp = readl(&xhci->op_regs->command); in xhci_run_finished()
496 writel(temp, &xhci->op_regs->command); in xhci_run_finished()
498 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable primary interrupter"); in xhci_run_finished()
501 if (xhci_start(xhci)) { in xhci_run_finished()
502 xhci_halt(xhci); in xhci_run_finished()
503 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
507 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
509 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
510 xhci_ring_cmd_db(xhci); in xhci_run_finished()
512 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
534 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_run() local
535 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run()
536 /* Start the xHCI host controller running only after the USB 2.0 roothub in xhci_run()
542 return xhci_run_finished(xhci); in xhci_run()
544 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_run"); in xhci_run()
546 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_run()
548 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
551 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
555 temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; in xhci_run()
558 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
561 command = xhci_alloc_command(xhci, false, GFP_KERNEL); in xhci_run()
565 ret = xhci_queue_vendor_command(xhci, command, 0, 0, 0, in xhci_run()
568 xhci_free_command(xhci, command); in xhci_run()
570 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
573 xhci_create_dbc_dev(xhci); in xhci_run()
575 xhci_debugfs_init(xhci); in xhci_run()
577 if (xhci_has_one_roothub(xhci)) in xhci_run()
578 return xhci_run_finished(xhci); in xhci_run()
587 * Stop xHCI driver.
598 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_stop() local
599 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_stop()
601 mutex_lock(&xhci->mutex); in xhci_stop()
605 mutex_unlock(&xhci->mutex); in xhci_stop()
609 xhci_remove_dbc_dev(xhci); in xhci_stop()
611 spin_lock_irq(&xhci->lock); in xhci_stop()
612 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
613 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
614 xhci_halt(xhci); in xhci_stop()
615 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_stop()
616 spin_unlock_irq(&xhci->lock); in xhci_stop()
619 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
620 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_stop()
621 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
622 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_stop()
627 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
630 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
632 temp = readl(&xhci->op_regs->status); in xhci_stop()
633 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
636 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); in xhci_stop()
637 xhci_mem_cleanup(xhci); in xhci_stop()
638 xhci_debugfs_exit(xhci); in xhci_stop()
639 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
641 readl(&xhci->op_regs->status)); in xhci_stop()
642 mutex_unlock(&xhci->mutex); in xhci_stop()
657 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_shutdown() local
659 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
663 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_shutdown()
668 if (xhci->shared_hcd) { in xhci_shutdown()
669 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
670 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
673 spin_lock_irq(&xhci->lock); in xhci_shutdown()
674 xhci_halt(xhci); in xhci_shutdown()
680 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
681 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
682 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_shutdown()
684 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
686 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_shutdown()
688 readl(&xhci->op_regs->status)); in xhci_shutdown()
693 static void xhci_save_registers(struct xhci_hcd *xhci) in xhci_save_registers() argument
698 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
699 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
700 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
701 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
705 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_save_registers()
706 ir = xhci->interrupters[i]; in xhci_save_registers()
711 ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_save_registers()
712 ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_save_registers()
718 static void xhci_restore_registers(struct xhci_hcd *xhci) in xhci_restore_registers() argument
723 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
724 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
725 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
726 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
729 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_restore_registers()
730 ir = xhci->interrupters[i]; in xhci_restore_registers()
735 xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); in xhci_restore_registers()
736 xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); in xhci_restore_registers()
742 static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) in xhci_set_cmd_ring_deq() argument
747 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
749 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
750 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
752 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
753 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_set_cmd_ring_deq()
756 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
768 static void xhci_clear_command_ring(struct xhci_hcd *xhci) in xhci_clear_command_ring() argument
773 ring = xhci->cmd_ring; in xhci_clear_command_ring()
803 xhci_set_cmd_ring_deq(xhci); in xhci_clear_command_ring()
811 * Internal wake causes immediate xHCI wake after suspend. PORT_CSC write done
815 static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci, in xhci_disable_hub_port_wake() argument
823 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
840 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
844 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
847 static bool xhci_pending_portevent(struct xhci_hcd *xhci) in xhci_pending_portevent() argument
854 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
860 * being written to the Event Ring. See note in xhci 1.1 section 4.19.2. in xhci_pending_portevent()
863 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
864 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
871 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
872 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
888 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) in xhci_suspend() argument
892 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_suspend()
900 (xhci->shared_hcd && xhci->shared_hcd->state != HC_STATE_SUSPENDED)) in xhci_suspend()
904 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
905 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
910 xhci_dbc_suspend(xhci); in xhci_suspend()
913 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_suspend()
917 if (xhci->shared_hcd) { in xhci_suspend()
918 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
919 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
922 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
925 spin_lock_irq(&xhci->lock); in xhci_suspend()
927 if (xhci->shared_hcd) in xhci_suspend()
928 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
933 command = readl(&xhci->op_regs->command); in xhci_suspend()
935 writel(command, &xhci->op_regs->command); in xhci_suspend()
938 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
940 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
942 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); in xhci_suspend()
943 spin_unlock_irq(&xhci->lock); in xhci_suspend()
946 xhci_clear_command_ring(xhci); in xhci_suspend()
949 xhci_save_registers(xhci); in xhci_suspend()
952 command = readl(&xhci->op_regs->command); in xhci_suspend()
954 writel(command, &xhci->op_regs->command); in xhci_suspend()
955 xhci->broken_suspend = 0; in xhci_suspend()
956 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
964 * if SRE and HCE bits are not set (as per xhci in xhci_suspend()
967 res = readl(&xhci->op_regs->status); in xhci_suspend()
968 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
971 xhci->broken_suspend = 1; in xhci_suspend()
973 xhci_warn(xhci, "WARN: xHC save state timeout\n"); in xhci_suspend()
974 spin_unlock_irq(&xhci->lock); in xhci_suspend()
978 spin_unlock_irq(&xhci->lock); in xhci_suspend()
981 * Deleting Compliance Mode Recovery Timer because the xHCI Host in xhci_suspend()
984 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
985 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_suspend()
986 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
987 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_suspend()
1002 int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg) in xhci_resume() argument
1006 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_resume()
1020 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
1021 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
1025 if (xhci->shared_hcd) in xhci_resume()
1026 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
1028 spin_lock_irq(&xhci->lock); in xhci_resume()
1030 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
1038 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1041 xhci_warn(xhci, "Controller not ready at resume %d\n", in xhci_resume()
1043 spin_unlock_irq(&xhci->lock); in xhci_resume()
1047 xhci_restore_registers(xhci); in xhci_resume()
1049 xhci_set_cmd_ring_deq(xhci); in xhci_resume()
1052 command = readl(&xhci->op_regs->command); in xhci_resume()
1054 writel(command, &xhci->op_regs->command); in xhci_resume()
1057 * restore so setting the timeout to 100ms. Xhci specification in xhci_resume()
1060 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1062 xhci_warn(xhci, "WARN: xHC restore state timeout\n"); in xhci_resume()
1063 spin_unlock_irq(&xhci->lock); in xhci_resume()
1068 temp = readl(&xhci->op_regs->status); in xhci_resume()
1072 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1074 if (!xhci->broken_suspend) in xhci_resume()
1075 xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); in xhci_resume()
1079 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1080 !(xhci_all_ports_seen_u0(xhci))) { in xhci_resume()
1081 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1082 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_resume()
1087 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1088 if (xhci->shared_hcd) in xhci_resume()
1089 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1091 xhci_dbg(xhci, "Stop HCD\n"); in xhci_resume()
1092 xhci_halt(xhci); in xhci_resume()
1093 xhci_zero_64b_regs(xhci); in xhci_resume()
1094 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_resume()
1095 spin_unlock_irq(&xhci->lock); in xhci_resume()
1099 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); in xhci_resume()
1100 temp = readl(&xhci->op_regs->status); in xhci_resume()
1101 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1102 xhci_disable_interrupter(xhci->interrupters[0]); in xhci_resume()
1104 xhci_dbg(xhci, "cleaning up memory\n"); in xhci_resume()
1105 xhci_mem_cleanup(xhci); in xhci_resume()
1106 xhci_debugfs_exit(xhci); in xhci_resume()
1107 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1108 readl(&xhci->op_regs->status)); in xhci_resume()
1114 xhci_dbg(xhci, "Initialize the xhci_hcd\n"); in xhci_resume()
1120 xhci_dbg(xhci, "Start the primary HCD\n"); in xhci_resume()
1122 if (!retval && xhci->shared_hcd) { in xhci_resume()
1123 xhci_dbg(xhci, "Start the secondary HCD\n"); in xhci_resume()
1124 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1128 if (xhci->shared_hcd) in xhci_resume()
1129 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1134 command = readl(&xhci->op_regs->command); in xhci_resume()
1136 writel(command, &xhci->op_regs->command); in xhci_resume()
1137 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1149 spin_unlock_irq(&xhci->lock); in xhci_resume()
1151 xhci_dbc_resume(xhci); in xhci_resume()
1161 if (xhci->usb3_rhub.bus_state.suspended_ports || in xhci_resume()
1162 xhci->usb3_rhub.bus_state.bus_suspended) in xhci_resume()
1165 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1170 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1174 if (xhci->shared_hcd) in xhci_resume()
1175 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1185 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1186 compliance_mode_recovery_timer_init(xhci); in xhci_resume()
1188 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1192 xhci_dbg(xhci, "%s: starting usb%d port polling.\n", in xhci_resume()
1194 if (xhci->shared_hcd) { in xhci_resume()
1195 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1196 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_ep0_maxpacket(struct xhci_hcd *xhci, struct xhci_virt_device *vdev) in xhci_check_ep0_maxpacket() argument
1465 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, 0); in xhci_check_ep0_maxpacket()
1474 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1476 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1479 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1480 "Max packet size in xHCI HW = %d", in xhci_check_ep0_maxpacket()
1482 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1485 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_ep0_maxpacket()
1492 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_ep0_maxpacket()
1498 xhci_endpoint_copy(xhci, vdev->in_ctx, vdev->out_ctx, 0); in xhci_check_ep0_maxpacket()
1500 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, 0); in xhci_check_ep0_maxpacket()
1508 ret = xhci_configure_endpoint(xhci, vdev->udev, command, in xhci_check_ep0_maxpacket()
1531 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_urb_enqueue() local
1561 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1577 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1578 xhci_dbg(xhci, "Can't queue urb, port error, link inactive\n"); in xhci_urb_enqueue()
1583 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1584 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1590 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1593 xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams transition state %x\n", in xhci_urb_enqueue()
1599 xhci_warn(xhci, "Can't enqueue URB while manually clearing toggle\n"); in xhci_urb_enqueue()
1607 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1611 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1615 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1619 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1628 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1650 * endpoint command, as noted in the xHCI 0.95 errata.
1668 struct xhci_hcd *xhci; in xhci_urb_dequeue() local
1677 xhci = hcd_to_xhci(hcd); in xhci_urb_dequeue()
1678 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1688 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1695 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_urb_dequeue()
1700 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1701 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1702 xhci_hc_died(xhci); in xhci_urb_dequeue()
1712 xhci_err(xhci, "Canceled URB td not found on endpoint ring"); in xhci_urb_dequeue()
1721 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1722 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1738 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1761 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_urb_dequeue()
1767 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1769 xhci_ring_cmd_db(xhci); in xhci_urb_dequeue()
1772 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1779 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1795 * the xhci->devs[slot_id] structure.
1800 struct xhci_hcd *xhci; in xhci_drop_endpoint() local
1812 xhci = hcd_to_xhci(hcd); in xhci_drop_endpoint()
1813 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1816 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_drop_endpoint()
1819 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1824 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1825 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1828 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_drop_endpoint()
1834 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_drop_endpoint()
1842 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1843 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", in xhci_drop_endpoint()
1854 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1856 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1858 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_drop_endpoint()
1878 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1883 struct xhci_hcd *xhci; in xhci_add_endpoint() local
1899 xhci = hcd_to_xhci(hcd); in xhci_add_endpoint()
1900 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1909 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1914 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1918 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_add_endpoint()
1929 xhci_warn(xhci, "Trying to add endpoint 0x%x " in xhci_add_endpoint()
1939 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", in xhci_add_endpoint()
1949 if (xhci_endpoint_init(xhci, virt_dev, udev, ep, GFP_NOIO) < 0) { in xhci_add_endpoint()
1969 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1972 xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_add_endpoint()
1981 static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev) in xhci_zero_in_ctx() argument
1990 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_zero_in_ctx()
2002 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
2007 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
2015 static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, in xhci_configure_endpoint_result() argument
2023 xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); in xhci_configure_endpoint_result()
2052 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint_result()
2057 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_configure_endpoint_result()
2065 static int xhci_evaluate_context_result(struct xhci_hcd *xhci, in xhci_evaluate_context_result() argument
2073 xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); in xhci_evaluate_context_result()
2078 "WARN: xHCI driver setup invalid evaluate context command.\n"); in xhci_evaluate_context_result()
2102 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_evaluate_context_result()
2107 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_evaluate_context_result()
2115 static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, in xhci_count_num_new_endpoints() argument
2136 static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci, in xhci_count_num_dropped_endpoints() argument
2160 * Must be called with xhci->lock held.
2162 static int xhci_reserve_host_resources(struct xhci_hcd *xhci, in xhci_reserve_host_resources() argument
2167 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_reserve_host_resources()
2168 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2169 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2172 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2173 xhci->limit_active_eps); in xhci_reserve_host_resources()
2176 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2177 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2179 xhci->num_active_eps); in xhci_reserve_host_resources()
2187 * Must be called with xhci->lock held.
2189 static void xhci_free_host_resources(struct xhci_hcd *xhci, in xhci_free_host_resources() argument
2194 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_free_host_resources()
2195 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2196 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_host_resources()
2199 xhci->num_active_eps); in xhci_free_host_resources()
2206 * Must be called with xhci->lock held.
2208 static void xhci_finish_resource_reservation(struct xhci_hcd *xhci, in xhci_finish_resource_reservation() argument
2213 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx); in xhci_finish_resource_reservation()
2214 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2216 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_finish_resource_reservation()
2219 xhci->num_active_eps); in xhci_finish_resource_reservation()
2254 static int xhci_check_tt_bw_table(struct xhci_hcd *xhci, in xhci_check_tt_bw_table() argument
2262 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2284 static int xhci_check_ss_bw(struct xhci_hcd *xhci, in xhci_check_ss_bw() argument
2341 static int xhci_check_bw_table(struct xhci_hcd *xhci, in xhci_check_bw_table() argument
2357 return xhci_check_ss_bw(xhci, virt_dev); in xhci_check_bw_table()
2378 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2381 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_check_bw_table()
2382 xhci_warn(xhci, "Not enough bandwidth on HS bus for " in xhci_check_bw_table()
2386 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2391 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2474 xhci_warn(xhci, "Not enough bandwidth. " in xhci_check_bw_table()
2497 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2500 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2509 xhci_warn(xhci, "Not enough bandwidth. Proposed: %u, Max: %u\n", in xhci_check_bw_table()
2544 static void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci, in xhci_drop_ep_from_interval_table() argument
2559 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2562 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2605 static void xhci_add_ep_to_interval_table(struct xhci_hcd *xhci, in xhci_add_ep_to_interval_table() argument
2621 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2624 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2676 void xhci_update_tt_active_eps(struct xhci_hcd *xhci, in xhci_update_tt_active_eps() argument
2684 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2696 static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, in xhci_reserve_bandwidth() argument
2710 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_reserve_bandwidth()
2726 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2734 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2738 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2746 if (!xhci_check_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_reserve_bandwidth()
2750 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_reserve_bandwidth()
2763 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2775 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2789 static int xhci_configure_endpoint(struct xhci_hcd *xhci, in xhci_configure_endpoint() argument
2803 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2805 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2806 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2810 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2814 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2815 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_configure_endpoint()
2820 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2821 xhci_reserve_host_resources(xhci, ctrl_ctx)) { in xhci_configure_endpoint()
2822 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2823 xhci_warn(xhci, "Not enough host resources, " in xhci_configure_endpoint()
2825 xhci->num_active_eps); in xhci_configure_endpoint()
2828 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && in xhci_configure_endpoint()
2829 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2830 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2831 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2832 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2833 xhci_warn(xhci, "Not enough bandwidth\n"); in xhci_configure_endpoint()
2837 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2843 ret = xhci_queue_configure_endpoint(xhci, command, in xhci_configure_endpoint()
2847 ret = xhci_queue_evaluate_context(xhci, command, in xhci_configure_endpoint()
2851 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2852 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2853 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2854 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint()
2858 xhci_ring_cmd_db(xhci); in xhci_configure_endpoint()
2859 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2865 ret = xhci_configure_endpoint_result(xhci, udev, in xhci_configure_endpoint()
2868 ret = xhci_evaluate_context_result(xhci, udev, in xhci_configure_endpoint()
2871 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2872 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2877 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2879 xhci_finish_resource_reservation(xhci, ctrl_ctx); in xhci_configure_endpoint()
2880 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2885 static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci, in xhci_check_bw_drop_ep_streams() argument
2891 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on set_interface, freeing streams.\n", in xhci_check_bw_drop_ep_streams()
2893 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2906 * else should be touching the xhci->devs[slot_id] structure, so we
2907 * don't need to take the xhci->lock for manipulating that.
2913 struct xhci_hcd *xhci; in xhci_check_bandwidth() local
2922 xhci = hcd_to_xhci(hcd); in xhci_check_bandwidth()
2923 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2924 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2927 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_check_bandwidth()
2928 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2930 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_bandwidth()
2939 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_bandwidth()
2955 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
2967 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_check_bandwidth()
2977 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
2978 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
2981 xhci_zero_in_ctx(xhci, virt_dev); in xhci_check_bandwidth()
2993 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
2995 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
2998 xhci_debugfs_create_endpoint(xhci, virt_dev, i); in xhci_check_bandwidth()
3010 struct xhci_hcd *xhci; in xhci_reset_bandwidth() local
3017 xhci = hcd_to_xhci(hcd); in xhci_reset_bandwidth()
3019 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_reset_bandwidth()
3020 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
3024 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_reset_bandwidth()
3025 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3029 xhci_zero_in_ctx(xhci, virt_dev); in xhci_reset_bandwidth()
3033 static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, in xhci_setup_input_ctx_for_config_ep() argument
3041 xhci_slot_copy(xhci, in_ctx, out_ctx); in xhci_setup_input_ctx_for_config_ep()
3048 struct xhci_hcd *xhci; in xhci_endpoint_disable() local
3055 xhci = hcd_to_xhci(hcd); in xhci_endpoint_disable()
3057 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3063 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3072 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3078 xhci_dbg(xhci, "endpoint disable with ep_state 0x%x\n", in xhci_endpoint_disable()
3082 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3094 * endpoint. Refer to the additional note in xhci spcification section 4.6.8.
3103 struct xhci_hcd *xhci; in xhci_endpoint_reset() local
3114 xhci = hcd_to_xhci(hcd); in xhci_endpoint_reset()
3120 * mismatch. Reconfigure the xhci ep0 endpoint context here in that case in xhci_endpoint_reset()
3128 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3132 xhci_check_ep0_maxpacket(xhci, vdev); in xhci_endpoint_reset()
3141 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3149 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3152 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3155 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3166 stop_cmd = xhci_alloc_command(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3170 cfg_cmd = xhci_alloc_command_with_ctx(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3174 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3187 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3188 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3192 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3195 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3196 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3197 xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ", in xhci_endpoint_reset()
3202 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3203 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3207 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3212 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3213 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3214 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_endpoint_reset()
3219 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3221 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3223 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3226 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3227 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3228 xhci_dbg(xhci, "%s: Failed to queue config ep command, %d ", in xhci_endpoint_reset()
3233 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3234 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3238 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3240 xhci_free_command(xhci, stop_cmd); in xhci_endpoint_reset()
3241 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3244 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3247 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, in xhci_check_streams_endpoint() argument
3257 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__); in xhci_check_streams_endpoint()
3261 xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion" in xhci_check_streams_endpoint()
3268 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3271 xhci_warn(xhci, "WARN: SuperSpeed bulk endpoint 0x%x " in xhci_check_streams_endpoint()
3274 xhci_warn(xhci, "Send email to xHCI maintainer and ask for " in xhci_check_streams_endpoint()
3278 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3279 xhci_warn(xhci, "Cannot setup streams for SuperSpeed bulk " in xhci_check_streams_endpoint()
3287 static void xhci_calculate_streams_entries(struct xhci_hcd *xhci, in xhci_calculate_streams_entries() argument
3297 * level page entries), but that's an optional feature for xHCI host in xhci_calculate_streams_entries()
3300 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3302 xhci_dbg(xhci, "xHCI HW only supports %u stream ctx entries.\n", in xhci_calculate_streams_entries()
3313 static int xhci_calculate_streams_and_bitmask(struct xhci_hcd *xhci, in xhci_calculate_streams_and_bitmask() argument
3324 ret = xhci_check_streams_endpoint(xhci, udev, in xhci_calculate_streams_and_bitmask()
3331 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n", in xhci_calculate_streams_and_bitmask()
3345 static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci, in xhci_calculate_no_streams_bitmask() argument
3356 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3361 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3364 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3373 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3377 xhci_warn(xhci, "WARN xhci_free_streams() called " in xhci_calculate_no_streams_bitmask()
3407 struct xhci_hcd *xhci; in xhci_alloc_streams() local
3421 * stream 0 that is reserved for xHCI usage. in xhci_alloc_streams()
3424 xhci = hcd_to_xhci(hcd); in xhci_alloc_streams()
3425 xhci_dbg(xhci, "Driver wants %u stream IDs (including stream 0).\n", in xhci_alloc_streams()
3429 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3430 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3431 xhci_dbg(xhci, "xHCI controller does not support streams.\n"); in xhci_alloc_streams()
3435 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_alloc_streams()
3441 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_alloc_streams()
3443 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3451 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3452 ret = xhci_calculate_streams_and_bitmask(xhci, udev, eps, in xhci_alloc_streams()
3455 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3456 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3460 xhci_warn(xhci, "WARN: endpoints can't handle " in xhci_alloc_streams()
3462 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3463 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3466 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3474 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3480 xhci_calculate_streams_entries(xhci, &num_streams, &num_stream_ctxs); in xhci_alloc_streams()
3481 xhci_dbg(xhci, "Need %u stream ctx entries for %u stream IDs.\n", in xhci_alloc_streams()
3487 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3503 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3505 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3507 xhci_setup_streams_ep_input_ctx(xhci, ep_ctx, in xhci_alloc_streams()
3513 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3518 ret = xhci_configure_endpoint(xhci, udev, config_cmd, in xhci_alloc_streams()
3528 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3532 xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n", in xhci_alloc_streams()
3536 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3537 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3541 xhci_debugfs_create_stream_files(xhci, vdev, ep_index); in xhci_alloc_streams()
3550 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3557 xhci_endpoint_zero(xhci, vdev, eps[i]); in xhci_alloc_streams()
3559 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3574 struct xhci_hcd *xhci; in xhci_free_streams() local
3582 xhci = hcd_to_xhci(hcd); in xhci_free_streams()
3583 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3586 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3587 changed_ep_bitmask = xhci_calculate_no_streams_bitmask(xhci, in xhci_free_streams()
3590 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3602 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3603 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_free_streams()
3612 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3613 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3616 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3621 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3624 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3629 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_free_streams()
3638 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3641 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3649 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3659 * Must be called with xhci->lock held.
3661 void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, in xhci_free_device_endpoint_resources() argument
3674 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3676 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_device_endpoint_resources()
3680 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3706 struct xhci_hcd *xhci; in xhci_discover_or_reset_device() local
3716 xhci = hcd_to_xhci(hcd); in xhci_discover_or_reset_device()
3718 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3720 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3737 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3748 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3755 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); in xhci_discover_or_reset_device()
3762 reset_device_cmd = xhci_alloc_command(xhci, true, GFP_NOIO); in xhci_discover_or_reset_device()
3764 xhci_dbg(xhci, "Couldn't allocate command structure.\n"); in xhci_discover_or_reset_device()
3769 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3771 ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id); in xhci_discover_or_reset_device()
3773 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_discover_or_reset_device()
3774 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3777 xhci_ring_cmd_db(xhci); in xhci_discover_or_reset_device()
3778 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3791 xhci_warn(xhci, "Timeout waiting for reset device command\n"); in xhci_discover_or_reset_device()
3796 xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n", in xhci_discover_or_reset_device()
3798 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3799 xhci_dbg(xhci, "Not freeing device rings.\n"); in xhci_discover_or_reset_device()
3804 xhci_dbg(xhci, "Successful reset device command.\n"); in xhci_discover_or_reset_device()
3807 if (xhci_is_vendor_info_code(xhci, ret)) in xhci_discover_or_reset_device()
3809 xhci_warn(xhci, "Unknown completion code %u for " in xhci_discover_or_reset_device()
3816 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3817 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3819 xhci_free_device_endpoint_resources(xhci, virt_dev, false); in xhci_discover_or_reset_device()
3820 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3828 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on device reset, freeing streams.\n", in xhci_discover_or_reset_device()
3830 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3836 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3837 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3840 xhci_drop_ep_from_interval_table(xhci, in xhci_discover_or_reset_device()
3849 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_discover_or_reset_device()
3854 xhci_free_command(xhci, reset_device_cmd); in xhci_discover_or_reset_device()
3865 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_free_dev() local
3876 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3886 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3887 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3894 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3896 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3897 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3898 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3902 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id) in xhci_disable_slot() argument
3909 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_disable_slot()
3913 xhci_debugfs_remove_slot(xhci, slot_id); in xhci_disable_slot()
3915 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3917 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3918 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3919 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3920 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3925 ret = xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, in xhci_disable_slot()
3928 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3932 xhci_ring_cmd_db(xhci); in xhci_disable_slot()
3933 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3938 xhci_warn(xhci, "Unsuccessful disable slot %u command, status %d\n", in xhci_disable_slot()
3941 xhci_free_command(xhci, command); in xhci_disable_slot()
3950 * Must be called with xhci->lock held.
3952 static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci) in xhci_reserve_host_control_ep_resources() argument
3954 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
3955 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
3958 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
3961 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
3962 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
3964 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
3975 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_alloc_dev() local
3982 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_alloc_dev()
3986 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3987 ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0); in xhci_alloc_dev()
3989 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3990 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_alloc_dev()
3991 xhci_free_command(xhci, command); in xhci_alloc_dev()
3994 xhci_ring_cmd_db(xhci); in xhci_alloc_dev()
3995 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4001 xhci_err(xhci, "Error while assigning device slot ID: %s\n", in xhci_alloc_dev()
4003 xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", in xhci_alloc_dev()
4005 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
4006 xhci_free_command(xhci, command); in xhci_alloc_dev()
4010 xhci_free_command(xhci, command); in xhci_alloc_dev()
4012 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
4013 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4014 ret = xhci_reserve_host_control_ep_resources(xhci); in xhci_alloc_dev()
4016 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4017 xhci_warn(xhci, "Not enough host resources, " in xhci_alloc_dev()
4019 xhci->num_active_eps); in xhci_alloc_dev()
4022 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4028 if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO)) { in xhci_alloc_dev()
4029 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); in xhci_alloc_dev()
4032 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
4033 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
4038 xhci_debugfs_create_slot(xhci, slot_id); in xhci_alloc_dev()
4044 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4052 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4053 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4075 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_setup_device() local
4081 mutex_lock(&xhci->mutex); in xhci_setup_device()
4083 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4089 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4095 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4103 xhci_warn(xhci, "Virt dev invalid for slot_id 0x%x!\n", in xhci_setup_device()
4108 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4114 xhci_dbg(xhci, "Slot already in default state\n"); in xhci_setup_device()
4119 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_setup_device()
4128 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4131 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_setup_device()
4138 * virt_device realloaction after a resume with an xHCI power loss, in xhci_setup_device()
4142 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4145 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); in xhci_setup_device()
4149 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4153 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4155 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4158 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4159 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4163 xhci_ring_cmd_db(xhci); in xhci_setup_device()
4164 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4176 xhci_warn(xhci, "Timeout while waiting for setup device command\n"); in xhci_setup_device()
4181 xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", in xhci_setup_device()
4188 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4189 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4190 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4202 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4206 xhci_err(xhci, in xhci_setup_device()
4209 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4215 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4216 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4218 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4221 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4223 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4224 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4227 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4233 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4238 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4241 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4245 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4283 static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, in xhci_change_max_exit_latency() argument
4293 command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL); in xhci_change_max_exit_latency()
4297 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4299 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4304 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4308 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4309 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4316 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4317 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4318 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_change_max_exit_latency()
4323 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4324 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4327 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4332 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_change_max_exit_latency()
4336 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_change_max_exit_latency()
4340 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4342 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4345 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4357 static int xhci_calculate_hird_besl(struct xhci_hcd *xhci, in xhci_calculate_hird_besl() argument
4364 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4401 /* xHCI l1 is set in steps of 256us, xHCI 1.0 section 5.4.11.2 */ in xhci_calculate_usb2_hw_lpm_params()
4416 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_set_usb2_hardware_lpm() local
4425 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4428 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4439 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4441 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4447 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", in xhci_set_usb2_hardware_lpm()
4455 * systems. See XHCI_DEFAULT_BESL definition in xhci.h in xhci_set_usb2_hardware_lpm()
4465 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4467 ret = xhci_change_max_exit_latency(xhci, udev, in xhci_set_usb2_hardware_lpm()
4471 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4478 hird = xhci_calculate_hird_besl(xhci, udev); in xhci_set_usb2_hardware_lpm()
4495 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4496 xhci_change_max_exit_latency(xhci, udev, 0); in xhci_set_usb2_hardware_lpm()
4504 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4512 static int xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int port, in xhci_check_usb2_port_capability() argument
4518 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4519 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4521 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4522 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4533 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_device() local
4544 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4546 xhci, portnum, XHCI_HLC)) { in xhci_update_device()
4550 if (xhci_check_usb2_port_capability(xhci, portnum, in xhci_update_device()
4655 static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci, in xhci_calculate_u1_timeout() argument
4669 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4719 static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci, in xhci_calculate_u2_timeout() argument
4733 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4750 static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_call_host_update_timeout_for_endpoint() argument
4757 return xhci_calculate_u1_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4759 return xhci_calculate_u2_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4764 static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_update_timeout_for_endpoint() argument
4772 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_endpoint()
4789 static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci, in xhci_update_timeout_for_interface() argument
4798 if (xhci_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_interface()
4805 static int xhci_check_tier_policy(struct xhci_hcd *xhci, in xhci_check_tier_policy() argument
4817 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
4819 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
4837 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_calculate_lpm_timeout() local
4856 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4890 if (xhci_update_timeout_for_interface(xhci, udev, in xhci_calculate_lpm_timeout()
4932 /* xHCI host controller max exit latency field is only 16 bits wide. */ in calculate_max_exit_latency()
4945 struct xhci_hcd *xhci; in xhci_enable_usb3_lpm_timeout() local
4951 xhci = hcd_to_xhci(hcd); in xhci_enable_usb3_lpm_timeout()
4956 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
4957 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
4960 if (xhci_check_tier_policy(xhci, udev, state) < 0) in xhci_enable_usb3_lpm_timeout()
4965 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
4978 ret = xhci_change_max_exit_latency(xhci, udev, mel); in xhci_enable_usb3_lpm_timeout()
4987 struct xhci_hcd *xhci; in xhci_disable_usb3_lpm_timeout() local
4990 xhci = hcd_to_xhci(hcd); in xhci_disable_usb3_lpm_timeout()
4991 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
4992 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
4996 return xhci_change_max_exit_latency(xhci, udev, mel); in xhci_disable_usb3_lpm_timeout()
5032 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_hub_device() local
5045 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
5047 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n"); in xhci_update_hub_device()
5051 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_update_hub_device()
5057 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_update_hub_device()
5059 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5063 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5065 xhci_alloc_tt_info(xhci, vdev, hdev, tt, GFP_ATOMIC)) { in xhci_update_hub_device()
5066 xhci_dbg(xhci, "Could not allocate xHCI TT structure.\n"); in xhci_update_hub_device()
5067 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5068 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5072 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5074 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5078 * but it may be already set to 1 when setup an xHCI virtual in xhci_update_hub_device()
5086 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5087 xhci_dbg(xhci, "xHCI version %x needs hub " in xhci_update_hub_device()
5089 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5095 * xHCI 1.0: this field shall be 0 if the device is not a in xhci_update_hub_device()
5101 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5105 xhci_dbg(xhci, "xHCI version %x doesn't need hub " in xhci_update_hub_device()
5107 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5110 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5112 xhci_dbg(xhci, "Set up %s for hub device.\n", in xhci_update_hub_device()
5113 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5119 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5120 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5123 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5126 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5133 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_get_frame() local
5135 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5138 static void xhci_hcd_init_usb2_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb2_data() argument
5140 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5144 * USB 2.0 roothub under xHCI has an integrated TT, in xhci_hcd_init_usb2_data()
5151 static void xhci_hcd_init_usb3_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb3_data() argument
5156 * Early xHCI 1.1 spec did not mention USB 3.1 capable hosts in xhci_hcd_init_usb3_data()
5159 * This was later clarified in xHCI 1.2. in xhci_hcd_init_usb3_data()
5164 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5167 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5183 xhci_info(xhci, "Host supports USB 3.%x %sSuperSpeed\n", in xhci_hcd_init_usb3_data()
5186 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5191 struct xhci_hcd *xhci; in xhci_gen_setup() local
5205 /* XHCI controllers don't stop the ep queue on short packets :| */ in xhci_gen_setup()
5208 xhci = hcd_to_xhci(hcd); in xhci_gen_setup()
5211 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5215 mutex_init(&xhci->mutex); in xhci_gen_setup()
5216 xhci->main_hcd = hcd; in xhci_gen_setup()
5217 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5218 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5219 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5220 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5221 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5223 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5224 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5225 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5226 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5227 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5228 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5229 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5231 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5232 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5233 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5234 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5236 xhci->quirks |= quirks; in xhci_gen_setup()
5239 get_quirks(dev, xhci); in xhci_gen_setup()
5241 /* In xhci controllers which follow xhci 1.0 spec gives a spurious in xhci_gen_setup()
5245 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5246 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5249 retval = xhci_halt(xhci); in xhci_gen_setup()
5253 xhci_zero_64b_regs(xhci); in xhci_gen_setup()
5255 xhci_dbg(xhci, "Resetting HCD\n"); in xhci_gen_setup()
5257 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_gen_setup()
5260 xhci_dbg(xhci, "Reset complete\n"); in xhci_gen_setup()
5263 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5266 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5269 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5270 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5274 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5276 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5286 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5290 xhci_dbg(xhci, "Calling HCD init\n"); in xhci_gen_setup()
5295 xhci_dbg(xhci, "Called HCD init\n"); in xhci_gen_setup()
5298 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5300 xhci_hcd_init_usb2_data(xhci, hcd); in xhci_gen_setup()
5302 xhci_info(xhci, "hcc params 0x%08x hci version 0x%x quirks 0x%016llx\n", in xhci_gen_setup()
5303 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5312 struct xhci_hcd *xhci; in xhci_clear_tt_buffer_complete() local
5318 xhci = hcd_to_xhci(hcd); in xhci_clear_tt_buffer_complete()
5320 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5325 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5326 xhci_ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_clear_tt_buffer_complete()
5327 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5331 .description = "xhci-hcd",
5332 .product_desc = "xHCI Host Controller",