• Home
  • Raw
  • Download

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"
85 * Disable interrupts and begin the xHCI halting process.
87 void xhci_quiesce(struct xhci_hcd *xhci) in xhci_quiesce() argument
94 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
98 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
100 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
111 int xhci_halt(struct xhci_hcd *xhci) in xhci_halt() argument
115 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC"); in xhci_halt()
116 xhci_quiesce(xhci); in xhci_halt()
118 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
121 xhci_warn(xhci, "Host halt failed, %d\n", ret); in xhci_halt()
125 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
126 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
134 int xhci_start(struct xhci_hcd *xhci) in xhci_start() argument
139 temp = readl(&xhci->op_regs->command); in xhci_start()
141 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.", in xhci_start()
143 writel(temp, &xhci->op_regs->command); in xhci_start()
149 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
152 xhci_err(xhci, "Host took too long to start, " in xhci_start()
157 xhci->xhc_state = 0; in xhci_start()
158 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
171 int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us) in xhci_reset() argument
177 state = readl(&xhci->op_regs->status); in xhci_reset()
180 xhci_warn(xhci, "Host not accessible, reset failed.\n"); in xhci_reset()
185 xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); in xhci_reset()
189 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); in xhci_reset()
190 command = readl(&xhci->op_regs->command); in xhci_reset()
192 writel(command, &xhci->op_regs->command); in xhci_reset()
194 /* Existing Intel xHCI controllers require a delay of 1 mS, in xhci_reset()
201 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
204 ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us); in xhci_reset()
208 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
209 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
211 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_reset()
214 * xHCI cannot write to any doorbells or operational registers other in xhci_reset()
217 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
219 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
220 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
221 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
222 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
223 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
224 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
229 static void xhci_zero_64b_regs(struct xhci_hcd *xhci) in xhci_zero_64b_regs() argument
231 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
252 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
256 xhci_info(xhci, "Zeroing 64bit base registers, expecting fault\n"); in xhci_zero_64b_regs()
259 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
261 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
264 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
266 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
269 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
271 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
272 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
274 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
276 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
277 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
282 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
283 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
285 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
286 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
288 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
292 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
296 xhci_info(xhci, "Fault detected\n"); in xhci_zero_64b_regs()
327 struct xhci_hcd *xhci; in compliance_mode_recovery() local
333 xhci = from_timer(xhci, t, comp_mode_recovery_timer); in compliance_mode_recovery()
334 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
347 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
350 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
360 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
361 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
372 * status event is generated when entering compliance mode (per xhci spec),
375 static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci) in compliance_mode_recovery_timer_init() argument
377 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
378 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
380 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
383 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
384 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery_timer_init()
415 static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) in xhci_all_ports_seen_u0() argument
417 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
430 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_init() local
433 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); in xhci_init()
434 spin_lock_init(&xhci->lock); in xhci_init()
435 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_init()
436 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_init()
438 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_init()
440 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_init()
441 "xHCI doesn't need link TRB QUIRK"); in xhci_init()
443 retval = xhci_mem_init(xhci, GFP_KERNEL); in xhci_init()
444 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init"); in xhci_init()
448 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
449 compliance_mode_recovery_timer_init(xhci); in xhci_init()
457 static int xhci_run_finished(struct xhci_hcd *xhci) in xhci_run_finished() argument
459 struct xhci_interrupter *ir = xhci->interrupter; in xhci_run_finished()
464 * Enable interrupts before starting the host (xhci 4.2 and 5.5.2). in xhci_run_finished()
467 spin_lock_irqsave(&xhci->lock, flags); in xhci_run_finished()
469 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable interrupts"); in xhci_run_finished()
470 temp = readl(&xhci->op_regs->command); in xhci_run_finished()
472 writel(temp, &xhci->op_regs->command); in xhci_run_finished()
474 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable primary interrupter"); in xhci_run_finished()
477 if (xhci_start(xhci)) { in xhci_run_finished()
478 xhci_halt(xhci); in xhci_run_finished()
479 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
483 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
485 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
486 xhci_ring_cmd_db(xhci); in xhci_run_finished()
488 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
510 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_run() local
511 struct xhci_interrupter *ir = xhci->interrupter; in xhci_run()
512 /* Start the xHCI host controller running only after the USB 2.0 roothub in xhci_run()
518 return xhci_run_finished(xhci); in xhci_run()
520 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_run"); in xhci_run()
522 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_run()
524 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
527 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
531 temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; in xhci_run()
534 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
537 command = xhci_alloc_command(xhci, false, GFP_KERNEL); in xhci_run()
541 ret = xhci_queue_vendor_command(xhci, command, 0, 0, 0, in xhci_run()
544 xhci_free_command(xhci, command); in xhci_run()
546 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
549 xhci_create_dbc_dev(xhci); in xhci_run()
551 xhci_debugfs_init(xhci); in xhci_run()
553 if (xhci_has_one_roothub(xhci)) in xhci_run()
554 return xhci_run_finished(xhci); in xhci_run()
563 * Stop xHCI driver.
574 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_stop() local
575 struct xhci_interrupter *ir = xhci->interrupter; in xhci_stop()
577 mutex_lock(&xhci->mutex); in xhci_stop()
581 mutex_unlock(&xhci->mutex); in xhci_stop()
585 xhci_remove_dbc_dev(xhci); in xhci_stop()
587 spin_lock_irq(&xhci->lock); in xhci_stop()
588 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
589 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
590 xhci_halt(xhci); in xhci_stop()
591 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_stop()
592 spin_unlock_irq(&xhci->lock); in xhci_stop()
595 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
596 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_stop()
597 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
598 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_stop()
603 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
606 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
608 temp = readl(&xhci->op_regs->status); in xhci_stop()
609 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
612 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); in xhci_stop()
613 xhci_mem_cleanup(xhci); in xhci_stop()
614 xhci_debugfs_exit(xhci); in xhci_stop()
615 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
617 readl(&xhci->op_regs->status)); in xhci_stop()
618 mutex_unlock(&xhci->mutex); in xhci_stop()
633 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_shutdown() local
635 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
639 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_shutdown()
644 if (xhci->shared_hcd) { in xhci_shutdown()
645 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
646 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
649 spin_lock_irq(&xhci->lock); in xhci_shutdown()
650 xhci_halt(xhci); in xhci_shutdown()
656 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
657 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
658 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_shutdown()
660 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
662 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_shutdown()
664 readl(&xhci->op_regs->status)); in xhci_shutdown()
669 static void xhci_save_registers(struct xhci_hcd *xhci) in xhci_save_registers() argument
671 struct xhci_interrupter *ir = xhci->interrupter; in xhci_save_registers()
673 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
674 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
675 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
676 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
682 ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_save_registers()
683 ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_save_registers()
688 static void xhci_restore_registers(struct xhci_hcd *xhci) in xhci_restore_registers() argument
690 struct xhci_interrupter *ir = xhci->interrupter; in xhci_restore_registers()
692 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
693 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
694 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
695 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
697 xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); in xhci_restore_registers()
698 xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); in xhci_restore_registers()
703 static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) in xhci_set_cmd_ring_deq() argument
708 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
710 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
711 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
713 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
714 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_set_cmd_ring_deq()
717 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
729 static void xhci_clear_command_ring(struct xhci_hcd *xhci) in xhci_clear_command_ring() argument
734 ring = xhci->cmd_ring; in xhci_clear_command_ring()
764 xhci_set_cmd_ring_deq(xhci); in xhci_clear_command_ring()
772 * Internal wake causes immediate xHCI wake after suspend. PORT_CSC write done
776 static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci, in xhci_disable_hub_port_wake() argument
784 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
801 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
805 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
808 static bool xhci_pending_portevent(struct xhci_hcd *xhci) in xhci_pending_portevent() argument
815 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
821 * being written to the Event Ring. See note in xhci 1.1 section 4.19.2. in xhci_pending_portevent()
824 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
825 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
832 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
833 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
849 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) in xhci_suspend() argument
853 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_suspend()
861 (xhci->shared_hcd && xhci->shared_hcd->state != HC_STATE_SUSPENDED)) in xhci_suspend()
865 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
866 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
871 xhci_dbc_suspend(xhci); in xhci_suspend()
874 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_suspend()
878 if (xhci->shared_hcd) { in xhci_suspend()
879 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
880 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
883 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
886 spin_lock_irq(&xhci->lock); in xhci_suspend()
888 if (xhci->shared_hcd) in xhci_suspend()
889 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
894 command = readl(&xhci->op_regs->command); in xhci_suspend()
896 writel(command, &xhci->op_regs->command); in xhci_suspend()
899 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
901 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
903 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); in xhci_suspend()
904 spin_unlock_irq(&xhci->lock); in xhci_suspend()
907 xhci_clear_command_ring(xhci); in xhci_suspend()
910 xhci_save_registers(xhci); in xhci_suspend()
913 command = readl(&xhci->op_regs->command); in xhci_suspend()
915 writel(command, &xhci->op_regs->command); in xhci_suspend()
916 xhci->broken_suspend = 0; in xhci_suspend()
917 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
925 * if SRE and HCE bits are not set (as per xhci in xhci_suspend()
928 res = readl(&xhci->op_regs->status); in xhci_suspend()
929 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
932 xhci->broken_suspend = 1; in xhci_suspend()
934 xhci_warn(xhci, "WARN: xHC save state timeout\n"); in xhci_suspend()
935 spin_unlock_irq(&xhci->lock); in xhci_suspend()
939 spin_unlock_irq(&xhci->lock); in xhci_suspend()
942 * Deleting Compliance Mode Recovery Timer because the xHCI Host in xhci_suspend()
945 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
946 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_suspend()
947 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
948 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_suspend()
963 int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg) in xhci_resume() argument
967 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_resume()
981 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
982 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
986 if (xhci->shared_hcd) in xhci_resume()
987 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
989 spin_lock_irq(&xhci->lock); in xhci_resume()
991 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
999 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1002 xhci_warn(xhci, "Controller not ready at resume %d\n", in xhci_resume()
1004 spin_unlock_irq(&xhci->lock); in xhci_resume()
1008 xhci_restore_registers(xhci); in xhci_resume()
1010 xhci_set_cmd_ring_deq(xhci); in xhci_resume()
1013 command = readl(&xhci->op_regs->command); in xhci_resume()
1015 writel(command, &xhci->op_regs->command); in xhci_resume()
1018 * restore so setting the timeout to 100ms. Xhci specification in xhci_resume()
1021 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1023 xhci_warn(xhci, "WARN: xHC restore state timeout\n"); in xhci_resume()
1024 spin_unlock_irq(&xhci->lock); in xhci_resume()
1029 temp = readl(&xhci->op_regs->status); in xhci_resume()
1033 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1035 if (!xhci->broken_suspend) in xhci_resume()
1036 xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); in xhci_resume()
1040 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1041 !(xhci_all_ports_seen_u0(xhci))) { in xhci_resume()
1042 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1043 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_resume()
1048 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1049 if (xhci->shared_hcd) in xhci_resume()
1050 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1052 xhci_dbg(xhci, "Stop HCD\n"); in xhci_resume()
1053 xhci_halt(xhci); in xhci_resume()
1054 xhci_zero_64b_regs(xhci); in xhci_resume()
1055 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_resume()
1056 spin_unlock_irq(&xhci->lock); in xhci_resume()
1060 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); in xhci_resume()
1061 temp = readl(&xhci->op_regs->status); in xhci_resume()
1062 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1063 xhci_disable_interrupter(xhci->interrupter); in xhci_resume()
1065 xhci_dbg(xhci, "cleaning up memory\n"); in xhci_resume()
1066 xhci_mem_cleanup(xhci); in xhci_resume()
1067 xhci_debugfs_exit(xhci); in xhci_resume()
1068 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1069 readl(&xhci->op_regs->status)); in xhci_resume()
1075 xhci_dbg(xhci, "Initialize the xhci_hcd\n"); in xhci_resume()
1081 xhci_dbg(xhci, "Start the primary HCD\n"); in xhci_resume()
1083 if (!retval && xhci->shared_hcd) { in xhci_resume()
1084 xhci_dbg(xhci, "Start the secondary HCD\n"); in xhci_resume()
1085 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1089 if (xhci->shared_hcd) in xhci_resume()
1090 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1095 command = readl(&xhci->op_regs->command); in xhci_resume()
1097 writel(command, &xhci->op_regs->command); in xhci_resume()
1098 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1110 spin_unlock_irq(&xhci->lock); in xhci_resume()
1112 xhci_dbc_resume(xhci); in xhci_resume()
1122 if (xhci->usb3_rhub.bus_state.suspended_ports || in xhci_resume()
1123 xhci->usb3_rhub.bus_state.bus_suspended) in xhci_resume()
1126 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1131 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1135 if (xhci->shared_hcd) in xhci_resume()
1136 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1146 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1147 compliance_mode_recovery_timer_init(xhci); in xhci_resume()
1149 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1153 xhci_dbg(xhci, "%s: starting usb%d port polling.\n", in xhci_resume()
1155 if (xhci->shared_hcd) { in xhci_resume()
1156 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1157 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1285 struct xhci_hcd *xhci; in xhci_map_urb_for_dma() local
1287 xhci = hcd_to_xhci(hcd); in xhci_map_urb_for_dma()
1292 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1301 struct xhci_hcd *xhci; in xhci_unmap_urb_for_dma() local
1304 xhci = hcd_to_xhci(hcd); in xhci_unmap_urb_for_dma()
1309 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1338 * address from the XHCI endpoint index.
1373 struct xhci_hcd *xhci; in xhci_check_args() local
1377 pr_debug("xHCI %s called with invalid args\n", func); in xhci_check_args()
1381 pr_debug("xHCI %s called for root hub\n", func); in xhci_check_args()
1385 xhci = hcd_to_xhci(hcd); in xhci_check_args()
1387 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1388 xhci_dbg(xhci, "xHCI %s called with unaddressed device\n", in xhci_check_args()
1393 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1395 xhci_dbg(xhci, "xHCI %s called with udev and " in xhci_check_args()
1401 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1407 static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1417 static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, in xhci_check_maxpacket() argument
1428 out_ctx = xhci->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
1429 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_check_maxpacket()
1433 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1435 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1438 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1439 "Max packet size in xHCI HW = %d", in xhci_check_maxpacket()
1441 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_maxpacket()
1449 command = xhci_alloc_command(xhci, true, mem_flags); in xhci_check_maxpacket()
1453 command->in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
1456 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_maxpacket()
1462 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
1463 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
1465 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_check_maxpacket()
1473 ret = xhci_configure_endpoint(xhci, urb->dev, command, in xhci_check_maxpacket()
1493 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_urb_enqueue() local
1510 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1515 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1516 xhci_dbg(xhci, "Can't queue urb, port error, link inactive\n"); in xhci_urb_enqueue()
1545 ret = xhci_check_maxpacket(xhci, slot_id, in xhci_urb_enqueue()
1555 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1557 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1558 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1564 xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams transition state %x\n", in xhci_urb_enqueue()
1570 xhci_warn(xhci, "Can't enqueue URB while manually clearing toggle\n"); in xhci_urb_enqueue()
1578 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1582 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1586 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1590 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1599 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1621 * endpoint command, as noted in the xHCI 0.95 errata.
1639 struct xhci_hcd *xhci; in xhci_urb_dequeue() local
1648 xhci = hcd_to_xhci(hcd); in xhci_urb_dequeue()
1649 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1659 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1666 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_urb_dequeue()
1671 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1672 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1673 xhci_hc_died(xhci); in xhci_urb_dequeue()
1683 xhci_err(xhci, "Canceled URB td not found on endpoint ring"); in xhci_urb_dequeue()
1692 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1693 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1709 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1732 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_urb_dequeue()
1738 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1740 xhci_ring_cmd_db(xhci); in xhci_urb_dequeue()
1743 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1750 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1766 * the xhci->devs[slot_id] structure.
1771 struct xhci_hcd *xhci; in xhci_drop_endpoint() local
1783 xhci = hcd_to_xhci(hcd); in xhci_drop_endpoint()
1784 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1787 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_drop_endpoint()
1790 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1795 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1796 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1799 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_drop_endpoint()
1805 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_drop_endpoint()
1813 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1814 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", in xhci_drop_endpoint()
1825 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1827 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1829 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_drop_endpoint()
1849 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1854 struct xhci_hcd *xhci; in xhci_add_endpoint() local
1870 xhci = hcd_to_xhci(hcd); in xhci_add_endpoint()
1871 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1880 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1885 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1889 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_add_endpoint()
1900 xhci_warn(xhci, "Trying to add endpoint 0x%x " in xhci_add_endpoint()
1910 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", in xhci_add_endpoint()
1920 if (xhci_endpoint_init(xhci, virt_dev, udev, ep, GFP_NOIO) < 0) { in xhci_add_endpoint()
1940 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1943 xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_add_endpoint()
1952 static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev) in xhci_zero_in_ctx() argument
1961 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_zero_in_ctx()
1973 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
1978 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
1986 static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, in xhci_configure_endpoint_result() argument
1994 xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); in xhci_configure_endpoint_result()
2023 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint_result()
2028 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_configure_endpoint_result()
2036 static int xhci_evaluate_context_result(struct xhci_hcd *xhci, in xhci_evaluate_context_result() argument
2044 xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); in xhci_evaluate_context_result()
2049 "WARN: xHCI driver setup invalid evaluate context command.\n"); in xhci_evaluate_context_result()
2073 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_evaluate_context_result()
2078 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_evaluate_context_result()
2086 static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, in xhci_count_num_new_endpoints() argument
2107 static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci, in xhci_count_num_dropped_endpoints() argument
2131 * Must be called with xhci->lock held.
2133 static int xhci_reserve_host_resources(struct xhci_hcd *xhci, in xhci_reserve_host_resources() argument
2138 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_reserve_host_resources()
2139 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2140 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2143 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2144 xhci->limit_active_eps); in xhci_reserve_host_resources()
2147 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2148 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2150 xhci->num_active_eps); in xhci_reserve_host_resources()
2158 * Must be called with xhci->lock held.
2160 static void xhci_free_host_resources(struct xhci_hcd *xhci, in xhci_free_host_resources() argument
2165 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_free_host_resources()
2166 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2167 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_host_resources()
2170 xhci->num_active_eps); in xhci_free_host_resources()
2177 * Must be called with xhci->lock held.
2179 static void xhci_finish_resource_reservation(struct xhci_hcd *xhci, in xhci_finish_resource_reservation() argument
2184 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx); in xhci_finish_resource_reservation()
2185 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2187 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_finish_resource_reservation()
2190 xhci->num_active_eps); in xhci_finish_resource_reservation()
2225 static int xhci_check_tt_bw_table(struct xhci_hcd *xhci, in xhci_check_tt_bw_table() argument
2233 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2255 static int xhci_check_ss_bw(struct xhci_hcd *xhci, in xhci_check_ss_bw() argument
2312 static int xhci_check_bw_table(struct xhci_hcd *xhci, in xhci_check_bw_table() argument
2328 return xhci_check_ss_bw(xhci, virt_dev); in xhci_check_bw_table()
2349 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2352 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_check_bw_table()
2353 xhci_warn(xhci, "Not enough bandwidth on HS bus for " in xhci_check_bw_table()
2357 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2362 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2445 xhci_warn(xhci, "Not enough bandwidth. " in xhci_check_bw_table()
2468 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2471 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2480 xhci_warn(xhci, "Not enough bandwidth. Proposed: %u, Max: %u\n", in xhci_check_bw_table()
2515 static void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci, in xhci_drop_ep_from_interval_table() argument
2530 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2533 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2576 static void xhci_add_ep_to_interval_table(struct xhci_hcd *xhci, in xhci_add_ep_to_interval_table() argument
2592 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2595 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2647 void xhci_update_tt_active_eps(struct xhci_hcd *xhci, in xhci_update_tt_active_eps() argument
2655 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2667 static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, in xhci_reserve_bandwidth() argument
2681 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_reserve_bandwidth()
2697 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2705 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2709 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2717 if (!xhci_check_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_reserve_bandwidth()
2721 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_reserve_bandwidth()
2734 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2746 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2760 static int xhci_configure_endpoint(struct xhci_hcd *xhci, in xhci_configure_endpoint() argument
2774 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2776 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2777 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2781 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2785 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2786 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_configure_endpoint()
2791 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2792 xhci_reserve_host_resources(xhci, ctrl_ctx)) { in xhci_configure_endpoint()
2793 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2794 xhci_warn(xhci, "Not enough host resources, " in xhci_configure_endpoint()
2796 xhci->num_active_eps); in xhci_configure_endpoint()
2799 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && in xhci_configure_endpoint()
2800 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2801 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2802 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2803 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2804 xhci_warn(xhci, "Not enough bandwidth\n"); in xhci_configure_endpoint()
2808 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2814 ret = xhci_queue_configure_endpoint(xhci, command, in xhci_configure_endpoint()
2818 ret = xhci_queue_evaluate_context(xhci, command, in xhci_configure_endpoint()
2822 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2823 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2824 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2825 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint()
2829 xhci_ring_cmd_db(xhci); in xhci_configure_endpoint()
2830 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2836 ret = xhci_configure_endpoint_result(xhci, udev, in xhci_configure_endpoint()
2839 ret = xhci_evaluate_context_result(xhci, udev, in xhci_configure_endpoint()
2842 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2843 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2848 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2850 xhci_finish_resource_reservation(xhci, ctrl_ctx); in xhci_configure_endpoint()
2851 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2856 static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci, in xhci_check_bw_drop_ep_streams() argument
2862 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on set_interface, freeing streams.\n", in xhci_check_bw_drop_ep_streams()
2864 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2877 * else should be touching the xhci->devs[slot_id] structure, so we
2878 * don't need to take the xhci->lock for manipulating that.
2884 struct xhci_hcd *xhci; in xhci_check_bandwidth() local
2893 xhci = hcd_to_xhci(hcd); in xhci_check_bandwidth()
2894 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2895 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2898 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_check_bandwidth()
2899 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2901 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_bandwidth()
2910 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_bandwidth()
2926 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
2938 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_check_bandwidth()
2948 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
2949 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
2952 xhci_zero_in_ctx(xhci, virt_dev); in xhci_check_bandwidth()
2964 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
2966 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
2969 xhci_debugfs_create_endpoint(xhci, virt_dev, i); in xhci_check_bandwidth()
2981 struct xhci_hcd *xhci; in xhci_reset_bandwidth() local
2988 xhci = hcd_to_xhci(hcd); in xhci_reset_bandwidth()
2990 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_reset_bandwidth()
2991 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
2995 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_reset_bandwidth()
2996 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3000 xhci_zero_in_ctx(xhci, virt_dev); in xhci_reset_bandwidth()
3004 static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, in xhci_setup_input_ctx_for_config_ep() argument
3012 xhci_slot_copy(xhci, in_ctx, out_ctx); in xhci_setup_input_ctx_for_config_ep()
3019 struct xhci_hcd *xhci; in xhci_endpoint_disable() local
3026 xhci = hcd_to_xhci(hcd); in xhci_endpoint_disable()
3028 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3034 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3043 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3049 xhci_dbg(xhci, "endpoint disable with ep_state 0x%x\n", in xhci_endpoint_disable()
3053 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3065 * endpoint. Refer to the additional note in xhci spcification section 4.6.8.
3071 struct xhci_hcd *xhci; in xhci_endpoint_reset() local
3082 xhci = hcd_to_xhci(hcd); in xhci_endpoint_reset()
3086 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3099 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3102 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3105 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3116 stop_cmd = xhci_alloc_command(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3120 cfg_cmd = xhci_alloc_command_with_ctx(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3124 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3137 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3138 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3142 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3145 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3146 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3147 xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ", in xhci_endpoint_reset()
3152 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3153 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3157 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3162 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3163 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3164 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_endpoint_reset()
3169 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3171 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3173 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3176 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3177 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3178 xhci_dbg(xhci, "%s: Failed to queue config ep command, %d ", in xhci_endpoint_reset()
3183 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3184 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3188 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3190 xhci_free_command(xhci, stop_cmd); in xhci_endpoint_reset()
3191 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3194 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3197 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, in xhci_check_streams_endpoint() argument
3207 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__); in xhci_check_streams_endpoint()
3211 xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion" in xhci_check_streams_endpoint()
3218 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3221 xhci_warn(xhci, "WARN: SuperSpeed bulk endpoint 0x%x " in xhci_check_streams_endpoint()
3224 xhci_warn(xhci, "Send email to xHCI maintainer and ask for " in xhci_check_streams_endpoint()
3228 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3229 xhci_warn(xhci, "Cannot setup streams for SuperSpeed bulk " in xhci_check_streams_endpoint()
3237 static void xhci_calculate_streams_entries(struct xhci_hcd *xhci, in xhci_calculate_streams_entries() argument
3247 * level page entries), but that's an optional feature for xHCI host in xhci_calculate_streams_entries()
3250 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3252 xhci_dbg(xhci, "xHCI HW only supports %u stream ctx entries.\n", in xhci_calculate_streams_entries()
3263 static int xhci_calculate_streams_and_bitmask(struct xhci_hcd *xhci, in xhci_calculate_streams_and_bitmask() argument
3274 ret = xhci_check_streams_endpoint(xhci, udev, in xhci_calculate_streams_and_bitmask()
3281 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n", in xhci_calculate_streams_and_bitmask()
3295 static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci, in xhci_calculate_no_streams_bitmask() argument
3306 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3311 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3314 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3323 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3327 xhci_warn(xhci, "WARN xhci_free_streams() called " in xhci_calculate_no_streams_bitmask()
3357 struct xhci_hcd *xhci; in xhci_alloc_streams() local
3371 * stream 0 that is reserved for xHCI usage. in xhci_alloc_streams()
3374 xhci = hcd_to_xhci(hcd); in xhci_alloc_streams()
3375 xhci_dbg(xhci, "Driver wants %u stream IDs (including stream 0).\n", in xhci_alloc_streams()
3379 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3380 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3381 xhci_dbg(xhci, "xHCI controller does not support streams.\n"); in xhci_alloc_streams()
3385 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_alloc_streams()
3391 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_alloc_streams()
3393 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3401 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3402 ret = xhci_calculate_streams_and_bitmask(xhci, udev, eps, in xhci_alloc_streams()
3405 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3406 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3410 xhci_warn(xhci, "WARN: endpoints can't handle " in xhci_alloc_streams()
3412 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3413 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3416 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3424 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3430 xhci_calculate_streams_entries(xhci, &num_streams, &num_stream_ctxs); in xhci_alloc_streams()
3431 xhci_dbg(xhci, "Need %u stream ctx entries for %u stream IDs.\n", in xhci_alloc_streams()
3437 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3453 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3455 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3457 xhci_setup_streams_ep_input_ctx(xhci, ep_ctx, in xhci_alloc_streams()
3463 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3468 ret = xhci_configure_endpoint(xhci, udev, config_cmd, in xhci_alloc_streams()
3478 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3482 xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n", in xhci_alloc_streams()
3486 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3487 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3491 xhci_debugfs_create_stream_files(xhci, vdev, ep_index); in xhci_alloc_streams()
3500 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3507 xhci_endpoint_zero(xhci, vdev, eps[i]); in xhci_alloc_streams()
3509 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3524 struct xhci_hcd *xhci; in xhci_free_streams() local
3532 xhci = hcd_to_xhci(hcd); in xhci_free_streams()
3533 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3536 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3537 changed_ep_bitmask = xhci_calculate_no_streams_bitmask(xhci, in xhci_free_streams()
3540 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3552 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3553 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_free_streams()
3562 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3563 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3566 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3571 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3574 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3579 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_free_streams()
3588 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3591 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3599 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3609 * Must be called with xhci->lock held.
3611 void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, in xhci_free_device_endpoint_resources() argument
3624 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3626 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_device_endpoint_resources()
3630 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3656 struct xhci_hcd *xhci; in xhci_discover_or_reset_device() local
3666 xhci = hcd_to_xhci(hcd); in xhci_discover_or_reset_device()
3668 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3670 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3687 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3698 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3705 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); in xhci_discover_or_reset_device()
3712 reset_device_cmd = xhci_alloc_command(xhci, true, GFP_NOIO); in xhci_discover_or_reset_device()
3714 xhci_dbg(xhci, "Couldn't allocate command structure.\n"); in xhci_discover_or_reset_device()
3719 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3721 ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id); in xhci_discover_or_reset_device()
3723 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_discover_or_reset_device()
3724 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3727 xhci_ring_cmd_db(xhci); in xhci_discover_or_reset_device()
3728 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3741 xhci_warn(xhci, "Timeout waiting for reset device command\n"); in xhci_discover_or_reset_device()
3746 xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n", in xhci_discover_or_reset_device()
3748 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3749 xhci_dbg(xhci, "Not freeing device rings.\n"); in xhci_discover_or_reset_device()
3754 xhci_dbg(xhci, "Successful reset device command.\n"); in xhci_discover_or_reset_device()
3757 if (xhci_is_vendor_info_code(xhci, ret)) in xhci_discover_or_reset_device()
3759 xhci_warn(xhci, "Unknown completion code %u for " in xhci_discover_or_reset_device()
3766 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3767 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3769 xhci_free_device_endpoint_resources(xhci, virt_dev, false); in xhci_discover_or_reset_device()
3770 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3778 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on device reset, freeing streams.\n", in xhci_discover_or_reset_device()
3780 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3786 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3787 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3790 xhci_drop_ep_from_interval_table(xhci, in xhci_discover_or_reset_device()
3799 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_discover_or_reset_device()
3804 xhci_free_command(xhci, reset_device_cmd); in xhci_discover_or_reset_device()
3815 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_free_dev() local
3826 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3836 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3837 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3844 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3846 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3847 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3848 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3852 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id) in xhci_disable_slot() argument
3859 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_disable_slot()
3863 xhci_debugfs_remove_slot(xhci, slot_id); in xhci_disable_slot()
3865 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3867 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3868 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3869 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3870 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3875 ret = xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, in xhci_disable_slot()
3878 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3882 xhci_ring_cmd_db(xhci); in xhci_disable_slot()
3883 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3888 xhci_warn(xhci, "Unsuccessful disable slot %u command, status %d\n", in xhci_disable_slot()
3891 xhci_free_command(xhci, command); in xhci_disable_slot()
3900 * Must be called with xhci->lock held.
3902 static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci) in xhci_reserve_host_control_ep_resources() argument
3904 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
3905 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
3908 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
3911 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
3912 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
3914 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
3925 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_alloc_dev() local
3932 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_alloc_dev()
3936 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3937 ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0); in xhci_alloc_dev()
3939 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3940 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_alloc_dev()
3941 xhci_free_command(xhci, command); in xhci_alloc_dev()
3944 xhci_ring_cmd_db(xhci); in xhci_alloc_dev()
3945 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3951 xhci_err(xhci, "Error while assigning device slot ID: %s\n", in xhci_alloc_dev()
3953 xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", in xhci_alloc_dev()
3955 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
3956 xhci_free_command(xhci, command); in xhci_alloc_dev()
3960 xhci_free_command(xhci, command); in xhci_alloc_dev()
3962 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
3963 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3964 ret = xhci_reserve_host_control_ep_resources(xhci); in xhci_alloc_dev()
3966 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3967 xhci_warn(xhci, "Not enough host resources, " in xhci_alloc_dev()
3969 xhci->num_active_eps); in xhci_alloc_dev()
3972 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3978 if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO)) { in xhci_alloc_dev()
3979 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); in xhci_alloc_dev()
3982 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
3983 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
3988 xhci_debugfs_create_slot(xhci, slot_id); in xhci_alloc_dev()
3994 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4002 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4003 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4019 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_setup_device() local
4025 mutex_lock(&xhci->mutex); in xhci_setup_device()
4027 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4033 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4039 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4047 xhci_warn(xhci, "Virt dev invalid for slot_id 0x%x!\n", in xhci_setup_device()
4052 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4058 xhci_dbg(xhci, "Slot already in default state\n"); in xhci_setup_device()
4063 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_setup_device()
4071 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4074 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_setup_device()
4081 * virt_device realloaction after a resume with an xHCI power loss, in xhci_setup_device()
4085 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4088 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); in xhci_setup_device()
4092 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4096 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4098 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4101 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4102 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4106 xhci_ring_cmd_db(xhci); in xhci_setup_device()
4107 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4119 xhci_warn(xhci, "Timeout while waiting for setup device command\n"); in xhci_setup_device()
4124 xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", in xhci_setup_device()
4131 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4132 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4133 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4145 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4149 xhci_err(xhci, in xhci_setup_device()
4152 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4158 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4159 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4161 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4164 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4166 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4167 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4170 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4176 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4181 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4184 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4188 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4224 static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, in xhci_change_max_exit_latency() argument
4234 command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL); in xhci_change_max_exit_latency()
4238 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4240 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4245 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4249 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4250 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4257 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4258 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4259 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_change_max_exit_latency()
4264 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4265 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4268 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4273 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_change_max_exit_latency()
4277 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_change_max_exit_latency()
4281 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4283 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4286 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4298 static int xhci_calculate_hird_besl(struct xhci_hcd *xhci, in xhci_calculate_hird_besl() argument
4305 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4342 /* xHCI l1 is set in steps of 256us, xHCI 1.0 section 5.4.11.2 */ in xhci_calculate_usb2_hw_lpm_params()
4357 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_set_usb2_hardware_lpm() local
4366 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4369 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4380 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4382 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4388 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", in xhci_set_usb2_hardware_lpm()
4396 * systems. See XHCI_DEFAULT_BESL definition in xhci.h in xhci_set_usb2_hardware_lpm()
4406 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4408 ret = xhci_change_max_exit_latency(xhci, udev, in xhci_set_usb2_hardware_lpm()
4412 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4419 hird = xhci_calculate_hird_besl(xhci, udev); in xhci_set_usb2_hardware_lpm()
4436 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4437 xhci_change_max_exit_latency(xhci, udev, 0); in xhci_set_usb2_hardware_lpm()
4445 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4453 static int xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int port, in xhci_check_usb2_port_capability() argument
4459 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4460 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4462 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4463 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4474 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_device() local
4485 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4487 xhci, portnum, XHCI_HLC)) { in xhci_update_device()
4491 if (xhci_check_usb2_port_capability(xhci, portnum, in xhci_update_device()
4596 static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci, in xhci_calculate_u1_timeout() argument
4610 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4660 static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci, in xhci_calculate_u2_timeout() argument
4674 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4691 static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_call_host_update_timeout_for_endpoint() argument
4698 return xhci_calculate_u1_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4700 return xhci_calculate_u2_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4705 static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_update_timeout_for_endpoint() argument
4713 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_endpoint()
4730 static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci, in xhci_update_timeout_for_interface() argument
4739 if (xhci_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_interface()
4746 static int xhci_check_tier_policy(struct xhci_hcd *xhci, in xhci_check_tier_policy() argument
4758 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
4760 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
4778 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_calculate_lpm_timeout() local
4797 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4831 if (xhci_update_timeout_for_interface(xhci, udev, in xhci_calculate_lpm_timeout()
4873 /* xHCI host controller max exit latency field is only 16 bits wide. */ in calculate_max_exit_latency()
4886 struct xhci_hcd *xhci; in xhci_enable_usb3_lpm_timeout() local
4892 xhci = hcd_to_xhci(hcd); in xhci_enable_usb3_lpm_timeout()
4897 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
4898 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
4901 if (xhci_check_tier_policy(xhci, udev, state) < 0) in xhci_enable_usb3_lpm_timeout()
4906 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
4919 ret = xhci_change_max_exit_latency(xhci, udev, mel); in xhci_enable_usb3_lpm_timeout()
4928 struct xhci_hcd *xhci; in xhci_disable_usb3_lpm_timeout() local
4931 xhci = hcd_to_xhci(hcd); in xhci_disable_usb3_lpm_timeout()
4932 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
4933 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
4937 return xhci_change_max_exit_latency(xhci, udev, mel); in xhci_disable_usb3_lpm_timeout()
4973 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_hub_device() local
4986 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
4988 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n"); in xhci_update_hub_device()
4992 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_update_hub_device()
4998 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_update_hub_device()
5000 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5004 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5006 xhci_alloc_tt_info(xhci, vdev, hdev, tt, GFP_ATOMIC)) { in xhci_update_hub_device()
5007 xhci_dbg(xhci, "Could not allocate xHCI TT structure.\n"); in xhci_update_hub_device()
5008 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5009 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5013 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5015 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5019 * but it may be already set to 1 when setup an xHCI virtual in xhci_update_hub_device()
5027 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5028 xhci_dbg(xhci, "xHCI version %x needs hub " in xhci_update_hub_device()
5030 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5036 * xHCI 1.0: this field shall be 0 if the device is not a in xhci_update_hub_device()
5042 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5046 xhci_dbg(xhci, "xHCI version %x doesn't need hub " in xhci_update_hub_device()
5048 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5051 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5053 xhci_dbg(xhci, "Set up %s for hub device.\n", in xhci_update_hub_device()
5054 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5060 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5061 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5064 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5067 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5074 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_get_frame() local
5076 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5079 static void xhci_hcd_init_usb2_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb2_data() argument
5081 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5085 * USB 2.0 roothub under xHCI has an integrated TT, in xhci_hcd_init_usb2_data()
5092 static void xhci_hcd_init_usb3_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb3_data() argument
5097 * Early xHCI 1.1 spec did not mention USB 3.1 capable hosts in xhci_hcd_init_usb3_data()
5100 * This was later clarified in xHCI 1.2. in xhci_hcd_init_usb3_data()
5105 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5108 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5124 xhci_info(xhci, "Host supports USB 3.%x %sSuperSpeed\n", in xhci_hcd_init_usb3_data()
5127 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5132 struct xhci_hcd *xhci; in xhci_gen_setup() local
5146 /* XHCI controllers don't stop the ep queue on short packets :| */ in xhci_gen_setup()
5149 xhci = hcd_to_xhci(hcd); in xhci_gen_setup()
5152 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5156 mutex_init(&xhci->mutex); in xhci_gen_setup()
5157 xhci->main_hcd = hcd; in xhci_gen_setup()
5158 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5159 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5160 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5161 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5162 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5164 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5165 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5166 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5167 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5168 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5169 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5170 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5172 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5173 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5174 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5175 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5177 xhci->quirks |= quirks; in xhci_gen_setup()
5180 get_quirks(dev, xhci); in xhci_gen_setup()
5182 /* In xhci controllers which follow xhci 1.0 spec gives a spurious in xhci_gen_setup()
5186 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5187 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5190 retval = xhci_halt(xhci); in xhci_gen_setup()
5194 xhci_zero_64b_regs(xhci); in xhci_gen_setup()
5196 xhci_dbg(xhci, "Resetting HCD\n"); in xhci_gen_setup()
5198 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_gen_setup()
5201 xhci_dbg(xhci, "Reset complete\n"); in xhci_gen_setup()
5204 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5207 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5210 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5211 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5215 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5217 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5227 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5231 xhci_dbg(xhci, "Calling HCD init\n"); in xhci_gen_setup()
5236 xhci_dbg(xhci, "Called HCD init\n"); in xhci_gen_setup()
5239 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5241 xhci_hcd_init_usb2_data(xhci, hcd); in xhci_gen_setup()
5243 xhci_info(xhci, "hcc params 0x%08x hci version 0x%x quirks 0x%016llx\n", in xhci_gen_setup()
5244 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5253 struct xhci_hcd *xhci; in xhci_clear_tt_buffer_complete() local
5259 xhci = hcd_to_xhci(hcd); in xhci_clear_tt_buffer_complete()
5261 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5266 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5267 xhci_ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_clear_tt_buffer_complete()
5268 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5272 .description = "xhci-hcd",
5273 .product_desc = "xHCI Host Controller",