Lines Matching full:xhci
3 * xHCI host controller driver
23 #include <linux/usb/xhci-sideband.h>
25 #include "xhci.h"
26 #include "xhci-trace.h"
27 #include "xhci-debugfs.h"
28 #include "xhci-dbgcap.h"
88 * Disable interrupts and begin the xHCI halting process.
90 void xhci_quiesce(struct xhci_hcd *xhci) in xhci_quiesce() argument
97 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
101 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
103 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
114 int xhci_halt(struct xhci_hcd *xhci) in xhci_halt() argument
118 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC"); in xhci_halt()
119 xhci_quiesce(xhci); in xhci_halt()
121 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
124 if (!(xhci->xhc_state & XHCI_STATE_DYING)) in xhci_halt()
125 xhci_warn(xhci, "Host halt failed, %d\n", ret); in xhci_halt()
129 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
130 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
138 int xhci_start(struct xhci_hcd *xhci) in xhci_start() argument
143 temp = readl(&xhci->op_regs->command); in xhci_start()
145 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.", in xhci_start()
147 writel(temp, &xhci->op_regs->command); in xhci_start()
153 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
156 xhci_err(xhci, "Host took too long to start, " in xhci_start()
161 xhci->xhc_state = 0; in xhci_start()
162 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
175 int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us) in xhci_reset() argument
181 state = readl(&xhci->op_regs->status); in xhci_reset()
184 if (!(xhci->xhc_state & XHCI_STATE_DYING)) in xhci_reset()
185 xhci_warn(xhci, "Host not accessible, reset failed.\n"); in xhci_reset()
190 xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); in xhci_reset()
194 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); in xhci_reset()
195 command = readl(&xhci->op_regs->command); in xhci_reset()
197 writel(command, &xhci->op_regs->command); in xhci_reset()
199 /* Existing Intel xHCI controllers require a delay of 1 mS, in xhci_reset()
206 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
209 ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us); in xhci_reset()
213 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
214 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
216 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_reset()
219 * xHCI cannot write to any doorbells or operational registers other in xhci_reset()
222 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
224 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
225 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
226 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
227 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
228 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
229 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
234 static void xhci_zero_64b_regs(struct xhci_hcd *xhci) in xhci_zero_64b_regs() argument
236 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
257 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
261 xhci_info(xhci, "Zeroing 64bit base registers, expecting fault\n"); in xhci_zero_64b_regs()
264 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
266 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
269 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
271 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
274 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
276 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
277 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
279 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
281 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
282 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
287 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
288 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
290 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
291 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
293 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
297 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
301 xhci_info(xhci, "Fault detected\n"); in xhci_zero_64b_regs()
321 int xhci_disable_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir) in xhci_disable_interrupter() argument
335 xhci_dbg(xhci, "%s: Interrupt pending\n", __func__); in xhci_disable_interrupter()
362 struct xhci_hcd *xhci; in compliance_mode_recovery() local
368 xhci = timer_container_of(xhci, t, comp_mode_recovery_timer); in compliance_mode_recovery()
369 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
382 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
385 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
395 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
396 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
407 * status event is generated when entering compliance mode (per xhci spec),
410 static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci) in compliance_mode_recovery_timer_init() argument
412 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
413 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
415 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
418 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
419 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery_timer_init()
450 static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) in xhci_all_ports_seen_u0() argument
452 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
455 static void xhci_hcd_page_size(struct xhci_hcd *xhci) in xhci_hcd_page_size() argument
459 page_size = readl(&xhci->op_regs->page_size) & XHCI_PAGE_SIZE_MASK; in xhci_hcd_page_size()
461 xhci_warn(xhci, "Invalid page size register = 0x%x\n", page_size); in xhci_hcd_page_size()
466 xhci->page_size = page_size << 12; in xhci_hcd_page_size()
467 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "HCD page size set to %iK", in xhci_hcd_page_size()
468 xhci->page_size >> 10); in xhci_hcd_page_size()
471 static void xhci_enable_max_dev_slots(struct xhci_hcd *xhci) in xhci_enable_max_dev_slots() argument
476 max_slots = HCS_MAX_SLOTS(xhci->hcs_params1); in xhci_enable_max_dev_slots()
477 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xHC can handle at most %d device slots", in xhci_enable_max_dev_slots()
480 config_reg = readl(&xhci->op_regs->config_reg); in xhci_enable_max_dev_slots()
484 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Setting Max device slots reg = 0x%x", in xhci_enable_max_dev_slots()
486 writel(config_reg, &xhci->op_regs->config_reg); in xhci_enable_max_dev_slots()
489 static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) in xhci_set_cmd_ring_deq() argument
494 deq_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, xhci->cmd_ring->dequeue); in xhci_set_cmd_ring_deq()
497 crcr = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
502 crcr |= xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
504 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Setting command ring address to 0x%llx", crcr); in xhci_set_cmd_ring_deq()
505 xhci_write_64(xhci, crcr, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
508 static void xhci_set_doorbell_ptr(struct xhci_hcd *xhci) in xhci_set_doorbell_ptr() argument
512 offset = readl(&xhci->cap_regs->db_off) & DBOFF_MASK; in xhci_set_doorbell_ptr()
513 xhci->dba = (void __iomem *)xhci->cap_regs + offset; in xhci_set_doorbell_ptr()
514 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_set_doorbell_ptr()
522 static void xhci_set_dev_notifications(struct xhci_hcd *xhci) in xhci_set_dev_notifications() argument
526 dev_notf = readl(&xhci->op_regs->dev_notification); in xhci_set_dev_notifications()
529 writel(dev_notf, &xhci->op_regs->dev_notification); in xhci_set_dev_notifications()
541 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_init() local
544 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Starting %s", __func__); in xhci_init()
545 spin_lock_init(&xhci->lock); in xhci_init()
547 INIT_LIST_HEAD(&xhci->cmd_list); in xhci_init()
548 INIT_DELAYED_WORK(&xhci->cmd_timer, xhci_handle_command_timeout); in xhci_init()
549 init_completion(&xhci->cmd_ring_stop_completion); in xhci_init()
550 xhci_hcd_page_size(xhci); in xhci_init()
551 memset(xhci->devs, 0, MAX_HC_SLOTS * sizeof(*xhci->devs)); in xhci_init()
553 retval = xhci_mem_init(xhci, GFP_KERNEL); in xhci_init()
558 xhci_enable_max_dev_slots(xhci); in xhci_init()
561 xhci_set_cmd_ring_deq(xhci); in xhci_init()
564 xhci_write_64(xhci, xhci->dcbaa->dma, &xhci->op_regs->dcbaa_ptr); in xhci_init()
567 xhci_set_doorbell_ptr(xhci); in xhci_init()
570 xhci_set_dev_notifications(xhci); in xhci_init()
573 xhci_add_interrupter(xhci, 0); in xhci_init()
574 xhci->interrupters[0]->isoc_bei_interval = AVOID_BEI_INTERVAL_MAX; in xhci_init()
578 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
579 compliance_mode_recovery_timer_init(xhci); in xhci_init()
582 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished %s", __func__); in xhci_init()
588 static int xhci_run_finished(struct xhci_hcd *xhci) in xhci_run_finished() argument
590 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run_finished()
595 * Enable interrupts before starting the host (xhci 4.2 and 5.5.2). in xhci_run_finished()
598 spin_lock_irqsave(&xhci->lock, flags); in xhci_run_finished()
600 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable interrupts"); in xhci_run_finished()
601 temp = readl(&xhci->op_regs->command); in xhci_run_finished()
603 writel(temp, &xhci->op_regs->command); in xhci_run_finished()
605 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable primary interrupter"); in xhci_run_finished()
608 if (xhci_start(xhci)) { in xhci_run_finished()
609 xhci_halt(xhci); in xhci_run_finished()
610 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
614 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
616 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
617 xhci_ring_cmd_db(xhci); in xhci_run_finished()
619 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
640 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_run() local
641 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run()
642 /* Start the xHCI host controller running only after the USB 2.0 roothub in xhci_run()
651 return xhci_run_finished(xhci); in xhci_run()
653 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_run"); in xhci_run()
655 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_run()
657 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
660 xhci_set_interrupter_moderation(ir, xhci->imod_interval); in xhci_run()
662 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
665 command = xhci_alloc_command(xhci, false, GFP_KERNEL); in xhci_run()
669 ret = xhci_queue_vendor_command(xhci, command, 0, 0, 0, in xhci_run()
672 xhci_free_command(xhci, command); in xhci_run()
674 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
677 xhci_create_dbc_dev(xhci); in xhci_run()
679 xhci_debugfs_init(xhci); in xhci_run()
681 if (xhci_has_one_roothub(xhci)) in xhci_run()
682 return xhci_run_finished(xhci); in xhci_run()
691 * Stop xHCI driver.
702 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_stop() local
703 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_stop()
705 mutex_lock(&xhci->mutex); in xhci_stop()
709 mutex_unlock(&xhci->mutex); in xhci_stop()
713 xhci_remove_dbc_dev(xhci); in xhci_stop()
715 spin_lock_irq(&xhci->lock); in xhci_stop()
716 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
717 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
718 xhci_halt(xhci); in xhci_stop()
719 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_stop()
720 spin_unlock_irq(&xhci->lock); in xhci_stop()
723 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
724 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_stop()
725 timer_delete_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
726 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_stop()
731 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
734 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
736 temp = readl(&xhci->op_regs->status); in xhci_stop()
737 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
738 xhci_disable_interrupter(xhci, ir); in xhci_stop()
740 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); in xhci_stop()
741 xhci_mem_cleanup(xhci); in xhci_stop()
742 xhci_debugfs_exit(xhci); in xhci_stop()
743 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
745 readl(&xhci->op_regs->status)); in xhci_stop()
746 mutex_unlock(&xhci->mutex); in xhci_stop()
761 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_shutdown() local
763 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
767 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_shutdown()
772 if (xhci->shared_hcd) { in xhci_shutdown()
773 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
774 timer_delete_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
777 spin_lock_irq(&xhci->lock); in xhci_shutdown()
778 xhci_halt(xhci); in xhci_shutdown()
784 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
785 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
786 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_shutdown()
788 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
790 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_shutdown()
792 readl(&xhci->op_regs->status)); in xhci_shutdown()
797 static void xhci_save_registers(struct xhci_hcd *xhci) in xhci_save_registers() argument
802 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
803 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
804 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
805 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
809 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_save_registers()
810 ir = xhci->interrupters[i]; in xhci_save_registers()
815 ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_save_registers()
816 ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_save_registers()
822 static void xhci_restore_registers(struct xhci_hcd *xhci) in xhci_restore_registers() argument
827 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
828 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
829 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
830 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
833 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_restore_registers()
834 ir = xhci->interrupters[i]; in xhci_restore_registers()
839 xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); in xhci_restore_registers()
840 xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); in xhci_restore_registers()
855 static void xhci_clear_command_ring(struct xhci_hcd *xhci) in xhci_clear_command_ring() argument
860 ring = xhci->cmd_ring; in xhci_clear_command_ring()
876 xhci_set_cmd_ring_deq(xhci); in xhci_clear_command_ring()
884 * Internal wake causes immediate xHCI wake after suspend. PORT_CSC write done
888 static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci, in xhci_disable_hub_port_wake() argument
896 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
913 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
917 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
920 static bool xhci_pending_portevent(struct xhci_hcd *xhci) in xhci_pending_portevent() argument
927 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
933 * being written to the Event Ring. See note in xhci 1.1 section 4.19.2. in xhci_pending_portevent()
936 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
937 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
944 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
945 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
961 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) in xhci_suspend() argument
965 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_suspend()
973 (xhci->shared_hcd && xhci->shared_hcd->state != HC_STATE_SUSPENDED)) in xhci_suspend()
977 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
978 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
983 xhci_dbc_suspend(xhci); in xhci_suspend()
986 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_suspend()
990 if (xhci->shared_hcd) { in xhci_suspend()
991 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
992 timer_delete_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
995 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
998 spin_lock_irq(&xhci->lock); in xhci_suspend()
1000 if (xhci->shared_hcd) in xhci_suspend()
1001 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
1006 command = readl(&xhci->op_regs->command); in xhci_suspend()
1008 writel(command, &xhci->op_regs->command); in xhci_suspend()
1011 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
1013 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
1015 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); in xhci_suspend()
1016 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1019 xhci_clear_command_ring(xhci); in xhci_suspend()
1022 xhci_save_registers(xhci); in xhci_suspend()
1025 command = readl(&xhci->op_regs->command); in xhci_suspend()
1027 writel(command, &xhci->op_regs->command); in xhci_suspend()
1028 xhci->broken_suspend = 0; in xhci_suspend()
1029 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
1037 * if SRE and HCE bits are not set (as per xhci in xhci_suspend()
1040 res = readl(&xhci->op_regs->status); in xhci_suspend()
1041 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
1044 xhci->broken_suspend = 1; in xhci_suspend()
1046 xhci_warn(xhci, "WARN: xHC save state timeout\n"); in xhci_suspend()
1047 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1051 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1054 * Deleting Compliance Mode Recovery Timer because the xHCI Host in xhci_suspend()
1057 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
1058 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_suspend()
1059 timer_delete_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
1060 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_suspend()
1075 int xhci_resume(struct xhci_hcd *xhci, bool power_lost, bool is_auto_resume) in xhci_resume() argument
1078 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_resume()
1091 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
1092 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
1096 if (xhci->shared_hcd) in xhci_resume()
1097 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
1099 spin_lock_irq(&xhci->lock); in xhci_resume()
1101 if (xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
1109 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1112 xhci_warn(xhci, "Controller not ready at resume %d\n", in xhci_resume()
1114 spin_unlock_irq(&xhci->lock); in xhci_resume()
1118 xhci_restore_registers(xhci); in xhci_resume()
1120 xhci_set_cmd_ring_deq(xhci); in xhci_resume()
1123 command = readl(&xhci->op_regs->command); in xhci_resume()
1125 writel(command, &xhci->op_regs->command); in xhci_resume()
1128 * restore so setting the timeout to 100ms. Xhci specification in xhci_resume()
1131 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1133 xhci_warn(xhci, "WARN: xHC restore state timeout\n"); in xhci_resume()
1134 spin_unlock_irq(&xhci->lock); in xhci_resume()
1139 temp = readl(&xhci->op_regs->status); in xhci_resume()
1143 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1145 xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); in xhci_resume()
1150 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1151 !(xhci_all_ports_seen_u0(xhci))) { in xhci_resume()
1152 timer_delete_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1153 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_resume()
1158 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1159 if (xhci->shared_hcd) in xhci_resume()
1160 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1162 xhci_dbg(xhci, "Stop HCD\n"); in xhci_resume()
1163 xhci_halt(xhci); in xhci_resume()
1164 xhci_zero_64b_regs(xhci); in xhci_resume()
1165 if (xhci->xhc_state & XHCI_STATE_REMOVING) in xhci_resume()
1168 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_resume()
1169 spin_unlock_irq(&xhci->lock); in xhci_resume()
1173 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); in xhci_resume()
1174 temp = readl(&xhci->op_regs->status); in xhci_resume()
1175 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1176 xhci_disable_interrupter(xhci, xhci->interrupters[0]); in xhci_resume()
1178 xhci_dbg(xhci, "cleaning up memory\n"); in xhci_resume()
1179 xhci_mem_cleanup(xhci); in xhci_resume()
1180 xhci_debugfs_exit(xhci); in xhci_resume()
1181 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1182 readl(&xhci->op_regs->status)); in xhci_resume()
1188 xhci_dbg(xhci, "Initialize the xhci_hcd\n"); in xhci_resume()
1194 xhci_dbg(xhci, "Start the primary HCD\n"); in xhci_resume()
1196 if (!retval && xhci->shared_hcd) { in xhci_resume()
1197 xhci_dbg(xhci, "Start the secondary HCD\n"); in xhci_resume()
1198 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1208 if (xhci->shared_hcd) { in xhci_resume()
1209 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1210 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1218 command = readl(&xhci->op_regs->command); in xhci_resume()
1220 writel(command, &xhci->op_regs->command); in xhci_resume()
1221 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1233 spin_unlock_irq(&xhci->lock); in xhci_resume()
1235 xhci_dbc_resume(xhci); in xhci_resume()
1244 if (xhci->usb3_rhub.bus_state.suspended_ports || in xhci_resume()
1245 xhci->usb3_rhub.bus_state.bus_suspended) in xhci_resume()
1248 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1252 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1256 if (xhci->shared_hcd) in xhci_resume()
1257 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1268 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1269 compliance_mode_recovery_timer_init(xhci); in xhci_resume()
1271 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1275 xhci_dbg(xhci, "%s: starting usb%d port polling.\n", in xhci_resume()
1277 if (xhci->shared_hcd) { in xhci_resume()
1278 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1279 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1409 struct xhci_hcd *xhci; in xhci_map_urb_for_dma() local
1411 xhci = hcd_to_xhci(hcd); in xhci_map_urb_for_dma()
1416 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1425 struct xhci_hcd *xhci; in xhci_unmap_urb_for_dma() local
1428 xhci = hcd_to_xhci(hcd); in xhci_unmap_urb_for_dma()
1433 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1463 * address from the XHCI endpoint index.
1498 struct xhci_hcd *xhci; in xhci_check_args() local
1502 pr_debug("xHCI %s called with invalid args\n", func); in xhci_check_args()
1506 pr_debug("xHCI %s called for root hub\n", func); in xhci_check_args()
1510 xhci = hcd_to_xhci(hcd); in xhci_check_args()
1512 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1513 xhci_dbg(xhci, "xHCI %s called with unaddressed device\n", in xhci_check_args()
1518 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1520 xhci_dbg(xhci, "xHCI %s called with udev and " in xhci_check_args()
1526 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1532 static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1542 static int xhci_check_ep0_maxpacket(struct xhci_hcd *xhci, struct xhci_virt_device *vdev) in xhci_check_ep0_maxpacket() argument
1551 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, 0); in xhci_check_ep0_maxpacket()
1560 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1562 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1565 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1566 "Max packet size in xHCI HW = %d", in xhci_check_ep0_maxpacket()
1568 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1571 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_ep0_maxpacket()
1578 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_ep0_maxpacket()
1584 xhci_endpoint_copy(xhci, vdev->in_ctx, vdev->out_ctx, 0); in xhci_check_ep0_maxpacket()
1586 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, 0); in xhci_check_ep0_maxpacket()
1594 ret = xhci_configure_endpoint(xhci, vdev->udev, command, in xhci_check_ep0_maxpacket()
1617 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_urb_enqueue() local
1647 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1663 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1664 xhci_dbg(xhci, "Can't queue urb, port error, link inactive\n"); in xhci_urb_enqueue()
1669 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1670 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1676 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1679 xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams transition state %x\n", in xhci_urb_enqueue()
1685 xhci_warn(xhci, "Can't enqueue URB while manually clearing toggle\n"); in xhci_urb_enqueue()
1693 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1697 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1701 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1705 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1714 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1736 * endpoint command, as noted in the xHCI 0.95 errata.
1754 struct xhci_hcd *xhci; in xhci_urb_dequeue() local
1763 xhci = hcd_to_xhci(hcd); in xhci_urb_dequeue()
1764 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1774 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1781 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_urb_dequeue()
1786 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1787 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1788 xhci_hc_died(xhci); in xhci_urb_dequeue()
1798 xhci_err(xhci, "Canceled URB td not found on endpoint ring"); in xhci_urb_dequeue()
1807 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1808 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1824 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1845 xhci_dbg(xhci, "Not queuing Stop Endpoint on slot %d ep %d in state 0x%x\n", in xhci_urb_dequeue()
1853 xhci_dbg(xhci, "Invalidating TDs instantly on slot %d ep %d in state 0x%x\n", in xhci_urb_dequeue()
1858 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_urb_dequeue()
1865 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1867 xhci_ring_cmd_db(xhci); in xhci_urb_dequeue()
1870 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1877 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1893 * the xhci->devs[slot_id] structure.
1898 struct xhci_hcd *xhci; in xhci_drop_endpoint() local
1910 xhci = hcd_to_xhci(hcd); in xhci_drop_endpoint()
1911 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1914 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_drop_endpoint()
1917 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1922 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1923 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1926 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_drop_endpoint()
1932 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_drop_endpoint()
1940 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1941 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", in xhci_drop_endpoint()
1952 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1954 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1956 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_drop_endpoint()
1976 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1981 struct xhci_hcd *xhci; in xhci_add_endpoint() local
1997 xhci = hcd_to_xhci(hcd); in xhci_add_endpoint()
1998 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
2007 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
2012 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
2016 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_add_endpoint()
2027 xhci_warn(xhci, "Trying to add endpoint 0x%x " in xhci_add_endpoint()
2037 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", in xhci_add_endpoint()
2047 if (xhci_endpoint_init(xhci, virt_dev, udev, ep, GFP_NOIO) < 0) { in xhci_add_endpoint()
2067 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
2070 xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_add_endpoint()
2079 static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev) in xhci_zero_in_ctx() argument
2088 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_zero_in_ctx()
2100 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
2105 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
2113 static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, in xhci_configure_endpoint_result() argument
2121 xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); in xhci_configure_endpoint_result()
2150 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint_result()
2155 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_configure_endpoint_result()
2163 static int xhci_evaluate_context_result(struct xhci_hcd *xhci, in xhci_evaluate_context_result() argument
2171 xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); in xhci_evaluate_context_result()
2176 "WARN: xHCI driver setup invalid evaluate context command.\n"); in xhci_evaluate_context_result()
2200 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_evaluate_context_result()
2205 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_evaluate_context_result()
2213 static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, in xhci_count_num_new_endpoints() argument
2234 static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci, in xhci_count_num_dropped_endpoints() argument
2258 * Must be called with xhci->lock held.
2260 static int xhci_reserve_host_resources(struct xhci_hcd *xhci, in xhci_reserve_host_resources() argument
2265 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_reserve_host_resources()
2266 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2267 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2270 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2271 xhci->limit_active_eps); in xhci_reserve_host_resources()
2274 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2275 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2277 xhci->num_active_eps); in xhci_reserve_host_resources()
2285 * Must be called with xhci->lock held.
2287 static void xhci_free_host_resources(struct xhci_hcd *xhci, in xhci_free_host_resources() argument
2292 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_free_host_resources()
2293 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2294 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_host_resources()
2297 xhci->num_active_eps); in xhci_free_host_resources()
2304 * Must be called with xhci->lock held.
2306 static void xhci_finish_resource_reservation(struct xhci_hcd *xhci, in xhci_finish_resource_reservation() argument
2311 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx); in xhci_finish_resource_reservation()
2312 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2314 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_finish_resource_reservation()
2317 xhci->num_active_eps); in xhci_finish_resource_reservation()
2352 static int xhci_check_tt_bw_table(struct xhci_hcd *xhci, in xhci_check_tt_bw_table() argument
2360 bw_table = &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].bw_table; in xhci_check_tt_bw_table()
2382 static int xhci_check_ss_bw(struct xhci_hcd *xhci, in xhci_check_ss_bw() argument
2439 static int xhci_check_bw_table(struct xhci_hcd *xhci, in xhci_check_bw_table() argument
2455 return xhci_check_ss_bw(xhci, virt_dev); in xhci_check_bw_table()
2476 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2479 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_check_bw_table()
2480 xhci_warn(xhci, "Not enough bandwidth on HS bus for " in xhci_check_bw_table()
2484 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2489 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2572 xhci_warn(xhci, "Not enough bandwidth. " in xhci_check_bw_table()
2593 xhci->rh_bw[virt_dev->rhub_port->hw_portnum].num_active_tts; in xhci_check_bw_table()
2596 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2605 xhci_warn(xhci, "Not enough bandwidth. Proposed: %u, Max: %u\n", in xhci_check_bw_table()
2640 static void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci, in xhci_drop_ep_from_interval_table() argument
2655 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2658 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2701 static void xhci_add_ep_to_interval_table(struct xhci_hcd *xhci, in xhci_add_ep_to_interval_table() argument
2717 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2720 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2772 void xhci_update_tt_active_eps(struct xhci_hcd *xhci, in xhci_update_tt_active_eps() argument
2780 rh_bw_info = &xhci->rh_bw[virt_dev->rhub_port->hw_portnum]; in xhci_update_tt_active_eps()
2792 static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, in xhci_reserve_bandwidth() argument
2806 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_reserve_bandwidth()
2822 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2830 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2834 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2842 if (!xhci_check_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_reserve_bandwidth()
2846 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_reserve_bandwidth()
2859 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2871 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2882 * Synchronous XHCI stop endpoint helper. Issues the stop endpoint command and
2890 int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int suspend, in xhci_stop_endpoint_sync() argument
2897 command = xhci_alloc_command(xhci, true, gfp_flags); in xhci_stop_endpoint_sync()
2901 spin_lock_irqsave(&xhci->lock, flags); in xhci_stop_endpoint_sync()
2902 ret = xhci_queue_stop_endpoint(xhci, command, ep->vdev->slot_id, in xhci_stop_endpoint_sync()
2905 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_sync()
2909 xhci_ring_cmd_db(xhci); in xhci_stop_endpoint_sync()
2910 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_sync()
2917 xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); in xhci_stop_endpoint_sync()
2921 xhci_free_command(xhci, command); in xhci_stop_endpoint_sync()
2944 static int xhci_configure_endpoint(struct xhci_hcd *xhci, in xhci_configure_endpoint() argument
2958 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2960 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2961 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2965 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2969 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2970 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_configure_endpoint()
2975 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2976 xhci_reserve_host_resources(xhci, ctrl_ctx)) { in xhci_configure_endpoint()
2977 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2978 xhci_warn(xhci, "Not enough host resources, " in xhci_configure_endpoint()
2980 xhci->num_active_eps); in xhci_configure_endpoint()
2983 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && !ctx_change && in xhci_configure_endpoint()
2984 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2985 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2986 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2987 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2988 xhci_warn(xhci, "Not enough bandwidth\n"); in xhci_configure_endpoint()
2992 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2998 ret = xhci_queue_configure_endpoint(xhci, command, in xhci_configure_endpoint()
3002 ret = xhci_queue_evaluate_context(xhci, command, in xhci_configure_endpoint()
3006 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
3007 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
3008 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
3009 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint()
3013 xhci_ring_cmd_db(xhci); in xhci_configure_endpoint()
3014 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
3020 ret = xhci_configure_endpoint_result(xhci, udev, in xhci_configure_endpoint()
3023 ret = xhci_evaluate_context_result(xhci, udev, in xhci_configure_endpoint()
3026 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
3027 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
3032 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
3034 xhci_finish_resource_reservation(xhci, ctrl_ctx); in xhci_configure_endpoint()
3035 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
3040 static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci, in xhci_check_bw_drop_ep_streams() argument
3046 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on set_interface, freeing streams.\n", in xhci_check_bw_drop_ep_streams()
3048 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
3061 * else should be touching the xhci->devs[slot_id] structure, so we
3062 * don't need to take the xhci->lock for manipulating that.
3068 struct xhci_hcd *xhci; in xhci_check_bandwidth() local
3077 xhci = hcd_to_xhci(hcd); in xhci_check_bandwidth()
3078 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
3079 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
3082 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_check_bandwidth()
3083 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
3085 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_bandwidth()
3094 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_bandwidth()
3110 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
3122 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_check_bandwidth()
3132 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
3133 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
3136 xhci_zero_in_ctx(xhci, virt_dev); in xhci_check_bandwidth()
3148 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
3150 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
3153 xhci_debugfs_create_endpoint(xhci, virt_dev, i); in xhci_check_bandwidth()
3165 struct xhci_hcd *xhci; in xhci_reset_bandwidth() local
3172 xhci = hcd_to_xhci(hcd); in xhci_reset_bandwidth()
3174 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_reset_bandwidth()
3175 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
3179 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_reset_bandwidth()
3180 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3184 xhci_zero_in_ctx(xhci, virt_dev); in xhci_reset_bandwidth()
3188 /* Get the available bandwidth of the ports under the xhci roothub */
3189 int xhci_get_port_bandwidth(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, in xhci_get_port_bandwidth() argument
3196 if (!ctx || !xhci) in xhci_get_port_bandwidth()
3199 cmd = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_get_port_bandwidth()
3205 /* get xhci port bandwidth, refer to xhci rev1_2 protocol 4.6.15 */ in xhci_get_port_bandwidth()
3206 spin_lock_irqsave(&xhci->lock, flags); in xhci_get_port_bandwidth()
3208 ret = xhci_queue_get_port_bw(xhci, cmd, ctx->dma, dev_speed, 0); in xhci_get_port_bandwidth()
3210 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_get_port_bandwidth()
3213 xhci_ring_cmd_db(xhci); in xhci_get_port_bandwidth()
3214 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_get_port_bandwidth()
3224 static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, in xhci_setup_input_ctx_for_config_ep() argument
3232 xhci_slot_copy(xhci, in_ctx, out_ctx); in xhci_setup_input_ctx_for_config_ep()
3239 struct xhci_hcd *xhci; in xhci_endpoint_disable() local
3246 xhci = hcd_to_xhci(hcd); in xhci_endpoint_disable()
3248 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3254 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3263 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3269 xhci_dbg(xhci, "endpoint disable with ep_state 0x%x\n", in xhci_endpoint_disable()
3273 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3285 * endpoint. Refer to the additional note in xhci spcification section 4.6.8.
3294 struct xhci_hcd *xhci; in xhci_endpoint_reset() local
3305 xhci = hcd_to_xhci(hcd); in xhci_endpoint_reset()
3311 * mismatch. Reconfigure the xhci ep0 endpoint context here in that case in xhci_endpoint_reset()
3319 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3323 xhci_check_ep0_maxpacket(xhci, vdev); in xhci_endpoint_reset()
3332 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3340 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3343 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3346 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3357 stop_cmd = xhci_alloc_command(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3361 cfg_cmd = xhci_alloc_command_with_ctx(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3365 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3378 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3379 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3383 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3386 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3387 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3388 xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ", in xhci_endpoint_reset()
3393 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3394 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3398 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3403 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3404 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3405 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_endpoint_reset()
3410 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3412 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3414 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3417 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3418 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3419 xhci_dbg(xhci, "%s: Failed to queue config ep command, %d ", in xhci_endpoint_reset()
3424 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3425 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3429 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3431 xhci_free_command(xhci, stop_cmd); in xhci_endpoint_reset()
3432 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3435 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3438 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, in xhci_check_streams_endpoint() argument
3448 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__); in xhci_check_streams_endpoint()
3452 xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion" in xhci_check_streams_endpoint()
3459 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3462 xhci_warn(xhci, "WARN: SuperSpeed bulk endpoint 0x%x " in xhci_check_streams_endpoint()
3465 xhci_warn(xhci, "Send email to xHCI maintainer and ask for " in xhci_check_streams_endpoint()
3469 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3470 xhci_warn(xhci, "Cannot setup streams for SuperSpeed bulk " in xhci_check_streams_endpoint()
3478 static void xhci_calculate_streams_entries(struct xhci_hcd *xhci, in xhci_calculate_streams_entries() argument
3488 * level page entries), but that's an optional feature for xHCI host in xhci_calculate_streams_entries()
3491 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3493 xhci_dbg(xhci, "xHCI HW only supports %u stream ctx entries.\n", in xhci_calculate_streams_entries()
3504 static int xhci_calculate_streams_and_bitmask(struct xhci_hcd *xhci, in xhci_calculate_streams_and_bitmask() argument
3515 ret = xhci_check_streams_endpoint(xhci, udev, in xhci_calculate_streams_and_bitmask()
3522 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n", in xhci_calculate_streams_and_bitmask()
3536 static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci, in xhci_calculate_no_streams_bitmask() argument
3547 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3552 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3555 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3564 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3568 xhci_warn(xhci, "WARN xhci_free_streams() called " in xhci_calculate_no_streams_bitmask()
3598 struct xhci_hcd *xhci; in xhci_alloc_streams() local
3612 * stream 0 that is reserved for xHCI usage. in xhci_alloc_streams()
3615 xhci = hcd_to_xhci(hcd); in xhci_alloc_streams()
3616 xhci_dbg(xhci, "Driver wants %u stream IDs (including stream 0).\n", in xhci_alloc_streams()
3620 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3621 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3622 xhci_dbg(xhci, "xHCI controller does not support streams.\n"); in xhci_alloc_streams()
3626 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_alloc_streams()
3632 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_alloc_streams()
3634 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3642 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3643 ret = xhci_calculate_streams_and_bitmask(xhci, udev, eps, in xhci_alloc_streams()
3646 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3647 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3651 xhci_warn(xhci, "WARN: endpoints can't handle " in xhci_alloc_streams()
3653 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3654 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3657 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3665 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3671 xhci_calculate_streams_entries(xhci, &num_streams, &num_stream_ctxs); in xhci_alloc_streams()
3672 xhci_dbg(xhci, "Need %u stream ctx entries for %u stream IDs.\n", in xhci_alloc_streams()
3678 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3694 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3696 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3698 xhci_setup_streams_ep_input_ctx(xhci, ep_ctx, in xhci_alloc_streams()
3704 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3709 ret = xhci_configure_endpoint(xhci, udev, config_cmd, in xhci_alloc_streams()
3719 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3723 xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n", in xhci_alloc_streams()
3727 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3728 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3732 xhci_debugfs_create_stream_files(xhci, vdev, ep_index); in xhci_alloc_streams()
3741 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3748 xhci_endpoint_zero(xhci, vdev, eps[i]); in xhci_alloc_streams()
3750 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3765 struct xhci_hcd *xhci; in xhci_free_streams() local
3773 xhci = hcd_to_xhci(hcd); in xhci_free_streams()
3774 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3777 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3778 changed_ep_bitmask = xhci_calculate_no_streams_bitmask(xhci, in xhci_free_streams()
3781 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3793 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3794 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_free_streams()
3803 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3804 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3807 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3812 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3815 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3820 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_free_streams()
3829 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3832 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3840 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3850 * Must be called with xhci->lock held.
3852 void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, in xhci_free_device_endpoint_resources() argument
3865 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3867 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_device_endpoint_resources()
3871 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3899 struct xhci_hcd *xhci; in xhci_discover_or_reset_device() local
3909 xhci = hcd_to_xhci(hcd); in xhci_discover_or_reset_device()
3911 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3913 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3930 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3941 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3946 if (xhci->quirks & XHCI_ETRON_HOST) { in xhci_discover_or_reset_device()
3948 * Obtaining a new device slot to inform the xHCI host that in xhci_discover_or_reset_device()
3951 ret = xhci_disable_and_free_slot(xhci, udev->slot_id); in xhci_discover_or_reset_device()
3964 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); in xhci_discover_or_reset_device()
3971 reset_device_cmd = xhci_alloc_command(xhci, true, GFP_NOIO); in xhci_discover_or_reset_device()
3973 xhci_dbg(xhci, "Couldn't allocate command structure.\n"); in xhci_discover_or_reset_device()
3978 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3980 ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id); in xhci_discover_or_reset_device()
3982 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_discover_or_reset_device()
3983 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3986 xhci_ring_cmd_db(xhci); in xhci_discover_or_reset_device()
3987 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
4000 xhci_warn(xhci, "Timeout waiting for reset device command\n"); in xhci_discover_or_reset_device()
4005 xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n", in xhci_discover_or_reset_device()
4007 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
4008 xhci_dbg(xhci, "Not freeing device rings.\n"); in xhci_discover_or_reset_device()
4014 xhci_dbg(xhci, "Successful reset device command.\n"); in xhci_discover_or_reset_device()
4017 if (xhci_is_vendor_info_code(xhci, ret)) in xhci_discover_or_reset_device()
4019 xhci_warn(xhci, "Unknown completion code %u for " in xhci_discover_or_reset_device()
4026 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
4027 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
4029 xhci_free_device_endpoint_resources(xhci, virt_dev, false); in xhci_discover_or_reset_device()
4030 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
4038 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on device reset, freeing streams.\n", in xhci_discover_or_reset_device()
4040 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
4048 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_discover_or_reset_device()
4049 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_discover_or_reset_device()
4052 xhci_drop_ep_from_interval_table(xhci, in xhci_discover_or_reset_device()
4061 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_discover_or_reset_device()
4066 xhci_free_command(xhci, reset_device_cmd); in xhci_discover_or_reset_device()
4077 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_free_dev() local
4088 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
4098 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
4099 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
4106 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
4108 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
4109 xhci_free_virt_device(xhci, virt_dev, udev->slot_id); in xhci_free_dev()
4110 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
4114 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id) in xhci_disable_slot() argument
4121 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_disable_slot()
4125 xhci_debugfs_remove_slot(xhci, slot_id); in xhci_disable_slot()
4127 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
4129 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
4130 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
4131 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
4132 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4137 ret = xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, in xhci_disable_slot()
4140 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4144 xhci_ring_cmd_db(xhci); in xhci_disable_slot()
4145 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4150 xhci_warn(xhci, "Unsuccessful disable slot %u command, status %d\n", in xhci_disable_slot()
4153 xhci_free_command(xhci, command); in xhci_disable_slot()
4158 int xhci_disable_and_free_slot(struct xhci_hcd *xhci, u32 slot_id) in xhci_disable_and_free_slot() argument
4160 struct xhci_virt_device *vdev = xhci->devs[slot_id]; in xhci_disable_and_free_slot()
4163 ret = xhci_disable_slot(xhci, slot_id); in xhci_disable_and_free_slot()
4164 xhci_free_virt_device(xhci, vdev, slot_id); in xhci_disable_and_free_slot()
4172 * Must be called with xhci->lock held.
4174 static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci) in xhci_reserve_host_control_ep_resources() argument
4176 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
4177 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
4180 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
4183 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
4184 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
4186 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
4197 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_alloc_dev() local
4204 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_alloc_dev()
4208 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4209 ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0); in xhci_alloc_dev()
4211 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4212 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_alloc_dev()
4213 xhci_free_command(xhci, command); in xhci_alloc_dev()
4216 xhci_ring_cmd_db(xhci); in xhci_alloc_dev()
4217 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4223 xhci_err(xhci, "Error while assigning device slot ID: %s\n", in xhci_alloc_dev()
4225 xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", in xhci_alloc_dev()
4227 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
4228 xhci_free_command(xhci, command); in xhci_alloc_dev()
4232 xhci_free_command(xhci, command); in xhci_alloc_dev()
4234 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
4235 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4236 ret = xhci_reserve_host_control_ep_resources(xhci); in xhci_alloc_dev()
4238 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4239 xhci_warn(xhci, "Not enough host resources, " in xhci_alloc_dev()
4241 xhci->num_active_eps); in xhci_alloc_dev()
4244 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4250 if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO)) { in xhci_alloc_dev()
4251 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); in xhci_alloc_dev()
4254 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
4255 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
4260 xhci_debugfs_create_slot(xhci, slot_id); in xhci_alloc_dev()
4266 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4274 xhci_disable_and_free_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4296 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_setup_device() local
4302 mutex_lock(&xhci->mutex); in xhci_setup_device()
4304 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4310 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4316 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4324 xhci_warn(xhci, "Virt dev invalid for slot_id 0x%x!\n", in xhci_setup_device()
4329 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4335 xhci_dbg(xhci, "Slot already in default state\n"); in xhci_setup_device()
4340 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_setup_device()
4349 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4352 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_setup_device()
4359 * virt_device realloaction after a resume with an xHCI power loss, in xhci_setup_device()
4363 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4366 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); in xhci_setup_device()
4370 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4374 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4376 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4379 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4380 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4384 xhci_ring_cmd_db(xhci); in xhci_setup_device()
4385 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4397 xhci_warn(xhci, "Timeout while waiting for setup device command\n"); in xhci_setup_device()
4402 xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", in xhci_setup_device()
4409 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4410 ret = xhci_disable_and_free_slot(xhci, udev->slot_id); in xhci_setup_device()
4413 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4424 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4428 xhci_err(xhci, in xhci_setup_device()
4431 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4437 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4438 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4440 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4443 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4445 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4446 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4449 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4455 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4460 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4463 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4467 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4505 static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, in xhci_change_max_exit_latency() argument
4515 command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL); in xhci_change_max_exit_latency()
4519 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4521 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4526 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4530 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4531 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4538 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4539 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4540 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_change_max_exit_latency()
4545 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4546 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4549 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4554 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_change_max_exit_latency()
4558 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_change_max_exit_latency()
4562 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4564 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4567 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4579 static int xhci_calculate_hird_besl(struct xhci_hcd *xhci, in xhci_calculate_hird_besl() argument
4586 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4623 /* xHCI l1 is set in steps of 256us, xHCI 1.0 section 5.4.11.2 */ in xhci_calculate_usb2_hw_lpm_params()
4638 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_set_usb2_hardware_lpm() local
4647 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4650 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4661 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4663 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4669 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", in xhci_set_usb2_hardware_lpm()
4677 * systems. See XHCI_DEFAULT_BESL definition in xhci.h in xhci_set_usb2_hardware_lpm()
4687 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4689 ret = xhci_change_max_exit_latency(xhci, udev, in xhci_set_usb2_hardware_lpm()
4693 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4700 hird = xhci_calculate_hird_besl(xhci, udev); in xhci_set_usb2_hardware_lpm()
4717 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4718 xhci_change_max_exit_latency(xhci, udev, 0); in xhci_set_usb2_hardware_lpm()
4726 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4732 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_device() local
4738 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_update_device()
4740 udev->tunnel_mode = xhci_port_is_tunneled(xhci, port); in xhci_update_device()
4750 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable || !xhci->hw_lpm_support) in xhci_update_device()
4758 port = xhci->usb2_rhub.ports[udev->portnum - 1]; in xhci_update_device()
4869 static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci, in xhci_calculate_u1_timeout() argument
4883 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4933 static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci, in xhci_calculate_u2_timeout() argument
4947 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4964 static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_call_host_update_timeout_for_endpoint() argument
4971 return xhci_calculate_u1_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4973 return xhci_calculate_u2_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4978 static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_update_timeout_for_endpoint() argument
4986 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_endpoint()
5003 static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci, in xhci_update_timeout_for_interface() argument
5012 if (xhci_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_interface()
5019 static int xhci_check_tier_policy(struct xhci_hcd *xhci, in xhci_check_tier_policy() argument
5031 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
5033 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
5051 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_calculate_lpm_timeout() local
5070 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
5104 if (xhci_update_timeout_for_interface(xhci, udev, in xhci_calculate_lpm_timeout()
5146 /* xHCI host controller max exit latency field is only 16 bits wide. */ in calculate_max_exit_latency()
5159 struct xhci_hcd *xhci; in xhci_enable_usb3_lpm_timeout() local
5165 xhci = hcd_to_xhci(hcd); in xhci_enable_usb3_lpm_timeout()
5170 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
5171 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
5174 if (xhci_check_tier_policy(xhci, udev, state) < 0) in xhci_enable_usb3_lpm_timeout()
5179 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
5192 ret = xhci_change_max_exit_latency(xhci, udev, mel); in xhci_enable_usb3_lpm_timeout()
5201 struct xhci_hcd *xhci; in xhci_disable_usb3_lpm_timeout() local
5204 xhci = hcd_to_xhci(hcd); in xhci_disable_usb3_lpm_timeout()
5205 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
5206 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
5210 return xhci_change_max_exit_latency(xhci, udev, mel); in xhci_disable_usb3_lpm_timeout()
5246 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_hub_device() local
5259 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
5261 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n"); in xhci_update_hub_device()
5265 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_update_hub_device()
5271 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_update_hub_device()
5273 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5277 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5279 xhci_alloc_tt_info(xhci, vdev, hdev, tt, GFP_ATOMIC)) { in xhci_update_hub_device()
5280 xhci_dbg(xhci, "Could not allocate xHCI TT structure.\n"); in xhci_update_hub_device()
5281 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5282 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5286 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5288 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5292 * but it may be already set to 1 when setup an xHCI virtual in xhci_update_hub_device()
5300 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5301 xhci_dbg(xhci, "xHCI version %x needs hub " in xhci_update_hub_device()
5303 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5309 * xHCI 1.0: this field shall be 0 if the device is not a in xhci_update_hub_device()
5315 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5319 xhci_dbg(xhci, "xHCI version %x doesn't need hub " in xhci_update_hub_device()
5321 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5324 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5326 xhci_dbg(xhci, "Set up %s for hub device.\n", in xhci_update_hub_device()
5327 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5333 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5334 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5337 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5340 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5347 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_get_frame() local
5349 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5352 static void xhci_hcd_init_usb2_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb2_data() argument
5354 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5358 * USB 2.0 roothub under xHCI has an integrated TT, in xhci_hcd_init_usb2_data()
5365 static void xhci_hcd_init_usb3_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb3_data() argument
5370 * Early xHCI 1.1 spec did not mention USB 3.1 capable hosts in xhci_hcd_init_usb3_data()
5373 * This was later clarified in xHCI 1.2. in xhci_hcd_init_usb3_data()
5378 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5381 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5397 xhci_info(xhci, "Host supports USB 3.%x %sSuperSpeed\n", in xhci_hcd_init_usb3_data()
5400 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5405 struct xhci_hcd *xhci; in xhci_gen_setup() local
5419 /* XHCI controllers don't stop the ep queue on short packets :| */ in xhci_gen_setup()
5422 xhci = hcd_to_xhci(hcd); in xhci_gen_setup()
5425 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5429 mutex_init(&xhci->mutex); in xhci_gen_setup()
5430 xhci->main_hcd = hcd; in xhci_gen_setup()
5431 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5432 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5433 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5434 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5435 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5437 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5438 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5439 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5440 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5441 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5442 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5443 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5445 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5446 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5447 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5448 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5450 xhci->quirks |= quirks; in xhci_gen_setup()
5453 get_quirks(dev, xhci); in xhci_gen_setup()
5455 /* In xhci controllers which follow xhci 1.0 spec gives a spurious in xhci_gen_setup()
5459 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5460 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5462 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_gen_setup()
5463 xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits"); in xhci_gen_setup()
5464 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_gen_setup()
5468 retval = xhci_halt(xhci); in xhci_gen_setup()
5472 xhci_zero_64b_regs(xhci); in xhci_gen_setup()
5474 xhci_dbg(xhci, "Resetting HCD\n"); in xhci_gen_setup()
5476 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_gen_setup()
5479 xhci_dbg(xhci, "Reset complete\n"); in xhci_gen_setup()
5482 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5485 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5488 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5489 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5493 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5495 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5505 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5509 xhci_dbg(xhci, "Calling HCD init\n"); in xhci_gen_setup()
5514 xhci_dbg(xhci, "Called HCD init\n"); in xhci_gen_setup()
5517 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5519 xhci_hcd_init_usb2_data(xhci, hcd); in xhci_gen_setup()
5521 xhci_info(xhci, "hcc params 0x%08x hci version 0x%x quirks 0x%016llx\n", in xhci_gen_setup()
5522 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5531 struct xhci_hcd *xhci; in xhci_clear_tt_buffer_complete() local
5537 xhci = hcd_to_xhci(hcd); in xhci_clear_tt_buffer_complete()
5539 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5544 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5545 xhci_ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_clear_tt_buffer_complete()
5546 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5550 .description = "xhci-hcd",
5551 .product_desc = "xHCI Host Controller",