Lines Matching +full:generic +full:- +full:xhci
1 // SPDX-License-Identifier: GPL-2.0
3 * xHCI host controller driver
22 #include <linux/dma-mapping.h>
24 #include "xhci.h"
25 #include "xhci-trace.h"
26 #include "xhci-debugfs.h"
27 #include "xhci-dbgcap.h"
47 if (!td || !td->start_seg) in td_on_ring()
50 xhci_for_each_ring_seg(ring->first_seg, seg) { in td_on_ring()
51 if (seg == td->start_seg) in td_on_ring()
59 * xhci_handshake - spin reading hc until handshake completes or fails
69 * hardware flakeout), or the register reads as all-ones (hardware removed).
81 return -ENODEV; in xhci_handshake()
87 * xhci_handshake_check_state - same as xhci_handshake but takes an additional
91 int xhci_handshake_check_state(struct xhci_hcd *xhci, void __iomem *ptr, in xhci_handshake_check_state() argument
100 xhci->xhc_state & exit_state, in xhci_handshake_check_state()
103 if (result == U32_MAX || xhci->xhc_state & exit_state) in xhci_handshake_check_state()
104 return -ENODEV; in xhci_handshake_check_state()
110 * Disable interrupts and begin the xHCI halting process.
112 void xhci_quiesce(struct xhci_hcd *xhci) in xhci_quiesce() argument
119 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
123 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
125 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
136 int xhci_halt(struct xhci_hcd *xhci) in xhci_halt() argument
140 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Halt the HC"); in xhci_halt()
141 xhci_quiesce(xhci); in xhci_halt()
143 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
146 xhci_warn(xhci, "Host halt failed, %d\n", ret); in xhci_halt()
150 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
151 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
159 int xhci_start(struct xhci_hcd *xhci) in xhci_start() argument
164 temp = readl(&xhci->op_regs->command); in xhci_start()
166 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Turn on HC, cmd = 0x%x.", in xhci_start()
168 writel(temp, &xhci->op_regs->command); in xhci_start()
174 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
176 if (ret == -ETIMEDOUT) in xhci_start()
177 xhci_err(xhci, "Host took too long to start, " in xhci_start()
182 xhci->xhc_state = 0; in xhci_start()
183 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
196 int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us) in xhci_reset() argument
202 state = readl(&xhci->op_regs->status); in xhci_reset()
205 xhci_warn(xhci, "Host not accessible, reset failed.\n"); in xhci_reset()
206 return -ENODEV; in xhci_reset()
210 xhci_warn(xhci, "Host controller not halted, aborting reset.\n"); in xhci_reset()
214 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "// Reset the HC"); in xhci_reset()
215 command = readl(&xhci->op_regs->command); in xhci_reset()
217 writel(command, &xhci->op_regs->command); in xhci_reset()
219 /* Existing Intel xHCI controllers require a delay of 1 mS, in xhci_reset()
226 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
229 ret = xhci_handshake_check_state(xhci, &xhci->op_regs->command, in xhci_reset()
234 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
235 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
237 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_reset()
240 * xHCI cannot write to any doorbells or operational registers other in xhci_reset()
243 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
245 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
246 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
247 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
248 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
249 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
250 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
255 static void xhci_zero_64b_regs(struct xhci_hcd *xhci) in xhci_zero_64b_regs() argument
257 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
278 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
279 domain->type == IOMMU_DOMAIN_IDENTITY) in xhci_zero_64b_regs()
282 xhci_info(xhci, "Zeroing 64bit base registers, expecting fault\n"); in xhci_zero_64b_regs()
285 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
287 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
290 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
292 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
295 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
297 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
298 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
300 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
302 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
303 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
308 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
309 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
311 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
312 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
314 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
318 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
322 xhci_info(xhci, "Fault detected\n"); in xhci_zero_64b_regs()
329 if (!ir || !ir->ir_set) in xhci_enable_interrupter()
330 return -EINVAL; in xhci_enable_interrupter()
332 iman = readl(&ir->ir_set->irq_pending); in xhci_enable_interrupter()
333 writel(ER_IRQ_ENABLE(iman), &ir->ir_set->irq_pending); in xhci_enable_interrupter()
342 if (!ir || !ir->ir_set) in xhci_disable_interrupter()
343 return -EINVAL; in xhci_disable_interrupter()
345 iman = readl(&ir->ir_set->irq_pending); in xhci_disable_interrupter()
346 writel(ER_IRQ_DISABLE(iman), &ir->ir_set->irq_pending); in xhci_disable_interrupter()
357 if (!ir || !ir->ir_set || imod_interval > U16_MAX * 250) in xhci_set_interrupter_moderation()
358 return -EINVAL; in xhci_set_interrupter_moderation()
360 imod = readl(&ir->ir_set->irq_control); in xhci_set_interrupter_moderation()
363 writel(imod, &ir->ir_set->irq_control); in xhci_set_interrupter_moderation()
370 struct xhci_hcd *xhci; in compliance_mode_recovery() local
376 xhci = from_timer(xhci, t, comp_mode_recovery_timer); in compliance_mode_recovery()
377 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
378 hcd = rhub->hcd; in compliance_mode_recovery()
383 for (i = 0; i < rhub->num_ports; i++) { in compliance_mode_recovery()
384 temp = readl(rhub->ports[i]->addr); in compliance_mode_recovery()
390 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
391 "Compliance mode detected->port %d", in compliance_mode_recovery()
393 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery()
396 if (hcd->state == HC_STATE_SUSPENDED) in compliance_mode_recovery()
403 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
404 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
409 * Quirk to work around issue generated by the SN65LVPE502CP USB3.0 re-driver
415 * status event is generated when entering compliance mode (per xhci spec),
418 static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci) in compliance_mode_recovery_timer_init() argument
420 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
421 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
423 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
426 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
427 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in compliance_mode_recovery_timer_init()
433 * USB3.0 re-driver and that need the Compliance Mode Quirk.
435 * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820
446 if (!(strstr(dmi_sys_vendor, "Hewlett-Packard"))) in xhci_compliance_mode_recovery_timer_quirk_check()
458 static int xhci_all_ports_seen_u0(struct xhci_hcd *xhci) in xhci_all_ports_seen_u0() argument
460 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
465 * Initialize memory for HCD and xHC (one-time init).
473 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_init() local
476 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_init"); in xhci_init()
477 spin_lock_init(&xhci->lock); in xhci_init()
479 retval = xhci_mem_init(xhci, GFP_KERNEL); in xhci_init()
480 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_init"); in xhci_init()
484 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
485 compliance_mode_recovery_timer_init(xhci); in xhci_init()
491 /*-------------------------------------------------------------------------*/
493 static int xhci_run_finished(struct xhci_hcd *xhci) in xhci_run_finished() argument
495 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run_finished()
500 * Enable interrupts before starting the host (xhci 4.2 and 5.5.2). in xhci_run_finished()
503 spin_lock_irqsave(&xhci->lock, flags); in xhci_run_finished()
505 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable interrupts"); in xhci_run_finished()
506 temp = readl(&xhci->op_regs->command); in xhci_run_finished()
508 writel(temp, &xhci->op_regs->command); in xhci_run_finished()
510 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable primary interrupter"); in xhci_run_finished()
513 if (xhci_start(xhci)) { in xhci_run_finished()
514 xhci_halt(xhci); in xhci_run_finished()
515 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
516 return -ENODEV; in xhci_run_finished()
519 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
521 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
522 xhci_ring_cmd_db(xhci); in xhci_run_finished()
524 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
539 * Setup MSI-X vectors and enable interrupts.
545 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_run() local
546 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_run()
547 /* Start the xHCI host controller running only after the USB 2.0 roothub in xhci_run()
551 hcd->uses_new_polling = 1; in xhci_run()
552 if (hcd->msi_enabled) in xhci_run()
553 ir->ip_autoclear = true; in xhci_run()
556 return xhci_run_finished(xhci); in xhci_run()
558 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "xhci_run"); in xhci_run()
560 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_run()
562 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
565 xhci_set_interrupter_moderation(ir, xhci->imod_interval); in xhci_run()
567 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
570 command = xhci_alloc_command(xhci, false, GFP_KERNEL); in xhci_run()
572 return -ENOMEM; in xhci_run()
574 ret = xhci_queue_vendor_command(xhci, command, 0, 0, 0, in xhci_run()
577 xhci_free_command(xhci, command); in xhci_run()
579 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_run()
582 xhci_create_dbc_dev(xhci); in xhci_run()
584 xhci_debugfs_init(xhci); in xhci_run()
586 if (xhci_has_one_roothub(xhci)) in xhci_run()
587 return xhci_run_finished(xhci); in xhci_run()
589 set_bit(HCD_FLAG_DEFER_RH_REGISTER, &hcd->flags); in xhci_run()
596 * Stop xHCI driver.
607 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_stop() local
608 struct xhci_interrupter *ir = xhci->interrupters[0]; in xhci_stop()
610 mutex_lock(&xhci->mutex); in xhci_stop()
614 mutex_unlock(&xhci->mutex); in xhci_stop()
618 xhci_remove_dbc_dev(xhci); in xhci_stop()
620 spin_lock_irq(&xhci->lock); in xhci_stop()
621 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
622 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
623 xhci_halt(xhci); in xhci_stop()
624 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_stop()
625 spin_unlock_irq(&xhci->lock); in xhci_stop()
628 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
629 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_stop()
630 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
631 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_stop()
636 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
639 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
641 temp = readl(&xhci->op_regs->status); in xhci_stop()
642 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
645 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "cleaning up memory"); in xhci_stop()
646 xhci_mem_cleanup(xhci); in xhci_stop()
647 xhci_debugfs_exit(xhci); in xhci_stop()
648 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_stop()
649 "xhci_stop completed - status = %x", in xhci_stop()
650 readl(&xhci->op_regs->status)); in xhci_stop()
651 mutex_unlock(&xhci->mutex); in xhci_stop()
656 * Shutdown HC (not bus-specific)
666 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_shutdown() local
668 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
669 usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev)); in xhci_shutdown()
672 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_shutdown()
673 __func__, hcd->self.busnum); in xhci_shutdown()
674 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_shutdown()
675 del_timer_sync(&hcd->rh_timer); in xhci_shutdown()
677 if (xhci->shared_hcd) { in xhci_shutdown()
678 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
679 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
682 spin_lock_irq(&xhci->lock); in xhci_shutdown()
683 xhci_halt(xhci); in xhci_shutdown()
687 * firmware delay in ADL-P PCH if port are left in U3 at shutdown in xhci_shutdown()
689 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
690 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
691 xhci_reset(xhci, XHCI_RESET_SHORT_USEC); in xhci_shutdown()
693 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
695 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_shutdown()
696 "xhci_shutdown completed - status = %x", in xhci_shutdown()
697 readl(&xhci->op_regs->status)); in xhci_shutdown()
702 static void xhci_save_registers(struct xhci_hcd *xhci) in xhci_save_registers() argument
707 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
708 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
709 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
710 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
714 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_save_registers()
715 ir = xhci->interrupters[i]; in xhci_save_registers()
719 ir->s3_erst_size = readl(&ir->ir_set->erst_size); in xhci_save_registers()
720 ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_save_registers()
721 ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_save_registers()
722 ir->s3_irq_pending = readl(&ir->ir_set->irq_pending); in xhci_save_registers()
723 ir->s3_irq_control = readl(&ir->ir_set->irq_control); in xhci_save_registers()
727 static void xhci_restore_registers(struct xhci_hcd *xhci) in xhci_restore_registers() argument
732 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
733 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
734 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
735 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
738 for (i = 0; i < xhci->max_interrupters; i++) { in xhci_restore_registers()
739 ir = xhci->interrupters[i]; in xhci_restore_registers()
743 writel(ir->s3_erst_size, &ir->ir_set->erst_size); in xhci_restore_registers()
744 xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); in xhci_restore_registers()
745 xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); in xhci_restore_registers()
746 writel(ir->s3_irq_pending, &ir->ir_set->irq_pending); in xhci_restore_registers()
747 writel(ir->s3_irq_control, &ir->ir_set->irq_control); in xhci_restore_registers()
751 static void xhci_set_cmd_ring_deq(struct xhci_hcd *xhci) in xhci_set_cmd_ring_deq() argument
756 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
758 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
759 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
761 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
762 xhci_dbg_trace(xhci, trace_xhci_dbg_init, in xhci_set_cmd_ring_deq()
765 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
772 * need to re-program it on resume. Unfortunately, the pointer must be 64-byte
775 * middle of the ring (TRBs are 16-byte aligned).
777 static void xhci_clear_command_ring(struct xhci_hcd *xhci) in xhci_clear_command_ring() argument
782 ring = xhci->cmd_ring; in xhci_clear_command_ring()
783 xhci_for_each_ring_seg(ring->first_seg, seg) { in xhci_clear_command_ring()
785 memset(seg->trbs, 0, sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); in xhci_clear_command_ring()
787 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= cpu_to_le32(~TRB_CYCLE); in xhci_clear_command_ring()
793 * Yes, this will need to be re-written after resume, but we're paranoid in xhci_clear_command_ring()
798 xhci_set_cmd_ring_deq(xhci); in xhci_clear_command_ring()
806 * Internal wake causes immediate xHCI wake after suspend. PORT_CSC write done
810 static void xhci_disable_hub_port_wake(struct xhci_hcd *xhci, in xhci_disable_hub_port_wake() argument
818 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
820 for (i = 0; i < rhub->num_ports; i++) { in xhci_disable_hub_port_wake()
821 portsc = readl(rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
834 writel(t2, rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
835 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
836 rhub->hcd->self.busnum, i + 1, portsc, t2); in xhci_disable_hub_port_wake()
839 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
842 static bool xhci_pending_portevent(struct xhci_hcd *xhci) in xhci_pending_portevent() argument
849 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
855 * being written to the Event Ring. See note in xhci 1.1 section 4.19.2. in xhci_pending_portevent()
858 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
859 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
860 while (port_index--) { in xhci_pending_portevent()
861 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
866 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
867 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
868 while (port_index--) { in xhci_pending_portevent()
869 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
878 * Stop HC (not bus-specific)
883 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) in xhci_suspend() argument
887 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_suspend()
891 if (!hcd->state) in xhci_suspend()
894 if (hcd->state != HC_STATE_SUSPENDED || in xhci_suspend()
895 (xhci->shared_hcd && xhci->shared_hcd->state != HC_STATE_SUSPENDED)) in xhci_suspend()
896 return -EINVAL; in xhci_suspend()
899 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
900 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
905 xhci_dbc_suspend(xhci); in xhci_suspend()
908 xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", in xhci_suspend()
909 __func__, hcd->self.busnum); in xhci_suspend()
910 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_suspend()
911 del_timer_sync(&hcd->rh_timer); in xhci_suspend()
912 if (xhci->shared_hcd) { in xhci_suspend()
913 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
914 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
917 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
920 spin_lock_irq(&xhci->lock); in xhci_suspend()
921 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_suspend()
922 if (xhci->shared_hcd) in xhci_suspend()
923 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
928 command = readl(&xhci->op_regs->command); in xhci_suspend()
930 writel(command, &xhci->op_regs->command); in xhci_suspend()
933 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
935 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
937 xhci_warn(xhci, "WARN: xHC CMD_RUN timeout\n"); in xhci_suspend()
938 spin_unlock_irq(&xhci->lock); in xhci_suspend()
939 return -ETIMEDOUT; in xhci_suspend()
941 xhci_clear_command_ring(xhci); in xhci_suspend()
944 xhci_save_registers(xhci); in xhci_suspend()
947 command = readl(&xhci->op_regs->command); in xhci_suspend()
949 writel(command, &xhci->op_regs->command); in xhci_suspend()
950 xhci->broken_suspend = 0; in xhci_suspend()
951 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
959 * if SRE and HCE bits are not set (as per xhci in xhci_suspend()
962 res = readl(&xhci->op_regs->status); in xhci_suspend()
963 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
966 xhci->broken_suspend = 1; in xhci_suspend()
968 xhci_warn(xhci, "WARN: xHC save state timeout\n"); in xhci_suspend()
969 spin_unlock_irq(&xhci->lock); in xhci_suspend()
970 return -ETIMEDOUT; in xhci_suspend()
973 spin_unlock_irq(&xhci->lock); in xhci_suspend()
976 * Deleting Compliance Mode Recovery Timer because the xHCI Host in xhci_suspend()
979 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
980 (!(xhci_all_ports_seen_u0(xhci)))) { in xhci_suspend()
981 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
982 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_suspend()
992 * start xHC (not bus-specific)
997 int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg) in xhci_resume() argument
1001 struct usb_hcd *hcd = xhci_to_hcd(xhci); in xhci_resume()
1008 if (!hcd->state) in xhci_resume()
1015 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
1016 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
1019 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_resume()
1020 if (xhci->shared_hcd) in xhci_resume()
1021 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
1023 spin_lock_irq(&xhci->lock); in xhci_resume()
1025 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
1033 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1036 xhci_warn(xhci, "Controller not ready at resume %d\n", in xhci_resume()
1038 spin_unlock_irq(&xhci->lock); in xhci_resume()
1042 xhci_restore_registers(xhci); in xhci_resume()
1044 xhci_set_cmd_ring_deq(xhci); in xhci_resume()
1047 command = readl(&xhci->op_regs->command); in xhci_resume()
1049 writel(command, &xhci->op_regs->command); in xhci_resume()
1052 * restore so setting the timeout to 100ms. Xhci specification in xhci_resume()
1055 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1057 xhci_warn(xhci, "WARN: xHC restore state timeout\n"); in xhci_resume()
1058 spin_unlock_irq(&xhci->lock); in xhci_resume()
1059 return -ETIMEDOUT; in xhci_resume()
1063 temp = readl(&xhci->op_regs->status); in xhci_resume()
1065 /* re-initialize the HC on Restore Error, or Host Controller Error */ in xhci_resume()
1067 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1069 if (!xhci->broken_suspend) in xhci_resume()
1070 xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); in xhci_resume()
1074 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1075 !(xhci_all_ports_seen_u0(xhci))) { in xhci_resume()
1076 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1077 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_resume()
1082 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1083 if (xhci->shared_hcd) in xhci_resume()
1084 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1086 xhci_dbg(xhci, "Stop HCD\n"); in xhci_resume()
1087 xhci_halt(xhci); in xhci_resume()
1088 xhci_zero_64b_regs(xhci); in xhci_resume()
1089 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_resume()
1090 spin_unlock_irq(&xhci->lock); in xhci_resume()
1094 xhci_dbg(xhci, "// Disabling event ring interrupts\n"); in xhci_resume()
1095 temp = readl(&xhci->op_regs->status); in xhci_resume()
1096 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1097 xhci_disable_interrupter(xhci->interrupters[0]); in xhci_resume()
1099 xhci_dbg(xhci, "cleaning up memory\n"); in xhci_resume()
1100 xhci_mem_cleanup(xhci); in xhci_resume()
1101 xhci_debugfs_exit(xhci); in xhci_resume()
1102 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1103 readl(&xhci->op_regs->status)); in xhci_resume()
1109 xhci_dbg(xhci, "Initialize the xhci_hcd\n"); in xhci_resume()
1115 xhci_dbg(xhci, "Start the primary HCD\n"); in xhci_resume()
1117 if (!retval && xhci->shared_hcd) { in xhci_resume()
1118 xhci_dbg(xhci, "Start the secondary HCD\n"); in xhci_resume()
1119 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1127 hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1129 if (xhci->shared_hcd) { in xhci_resume()
1130 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1131 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1139 command = readl(&xhci->op_regs->command); in xhci_resume()
1141 writel(command, &xhci->op_regs->command); in xhci_resume()
1142 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1154 spin_unlock_irq(&xhci->lock); in xhci_resume()
1156 xhci_dbc_resume(xhci); in xhci_resume()
1165 if (xhci->usb3_rhub.bus_state.suspended_ports || in xhci_resume()
1166 xhci->usb3_rhub.bus_state.bus_suspended) in xhci_resume()
1169 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1174 pending_portevent = xhci_pending_portevent(xhci); in xhci_resume()
1178 if (xhci->shared_hcd) in xhci_resume()
1179 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1186 * be re-initialized Always after a system resume. Ports are subject in xhci_resume()
1190 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1191 compliance_mode_recovery_timer_init(xhci); in xhci_resume()
1193 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1194 usb_asmedia_modifyflowcontrol(to_pci_dev(hcd->self.controller)); in xhci_resume()
1196 /* Re-enable port polling. */ in xhci_resume()
1197 xhci_dbg(xhci, "%s: starting usb%d port polling.\n", in xhci_resume()
1198 __func__, hcd->self.busnum); in xhci_resume()
1199 if (xhci->shared_hcd) { in xhci_resume()
1200 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1201 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1203 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_resume()
1211 /*-------------------------------------------------------------------------*/
1221 buf_len = urb->transfer_buffer_length; in xhci_map_temp_buffer()
1224 dev_to_node(hcd->self.sysdev)); in xhci_map_temp_buffer()
1226 return -ENOMEM; in xhci_map_temp_buffer()
1229 sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_map_temp_buffer()
1232 urb->transfer_buffer = temp; in xhci_map_temp_buffer()
1233 urb->transfer_dma = dma_map_single(hcd->self.sysdev, in xhci_map_temp_buffer()
1234 urb->transfer_buffer, in xhci_map_temp_buffer()
1235 urb->transfer_buffer_length, in xhci_map_temp_buffer()
1238 if (dma_mapping_error(hcd->self.sysdev, in xhci_map_temp_buffer()
1239 urb->transfer_dma)) { in xhci_map_temp_buffer()
1240 ret = -EAGAIN; in xhci_map_temp_buffer()
1243 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in xhci_map_temp_buffer()
1260 tail_sg = urb->sg; in xhci_urb_temp_buffer_required()
1261 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_urb_temp_buffer_required()
1263 if (!urb->num_sgs) in xhci_urb_temp_buffer_required()
1266 if (urb->dev->speed >= USB_SPEED_SUPER) in xhci_urb_temp_buffer_required()
1271 if (urb->transfer_buffer_length != 0 && in xhci_urb_temp_buffer_required()
1272 !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in xhci_urb_temp_buffer_required()
1273 for_each_sg(urb->sg, sg, urb->num_sgs, i) { in xhci_urb_temp_buffer_required()
1274 len = len + sg->length; in xhci_urb_temp_buffer_required()
1275 if (i > trb_size - 2) { in xhci_urb_temp_buffer_required()
1276 len = len - tail_sg->length; in xhci_urb_temp_buffer_required()
1297 buf_len = urb->transfer_buffer_length; in xhci_unmap_temp_buf()
1300 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_temp_buf()
1301 dma_unmap_single(hcd->self.sysdev, in xhci_unmap_temp_buf()
1302 urb->transfer_dma, in xhci_unmap_temp_buf()
1303 urb->transfer_buffer_length, in xhci_unmap_temp_buf()
1307 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, in xhci_unmap_temp_buf()
1308 urb->transfer_buffer, in xhci_unmap_temp_buf()
1314 urb->actual_length = len; in xhci_unmap_temp_buf()
1317 urb->transfer_flags &= ~URB_DMA_MAP_SINGLE; in xhci_unmap_temp_buf()
1318 kfree(urb->transfer_buffer); in xhci_unmap_temp_buf()
1319 urb->transfer_buffer = NULL; in xhci_unmap_temp_buf()
1331 struct xhci_hcd *xhci; in xhci_map_urb_for_dma() local
1333 xhci = hcd_to_xhci(hcd); in xhci_map_urb_for_dma()
1338 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1347 struct xhci_hcd *xhci; in xhci_unmap_urb_for_dma() local
1350 xhci = hcd_to_xhci(hcd); in xhci_unmap_urb_for_dma()
1352 if (urb->num_sgs && (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_urb_for_dma()
1355 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1362 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and
1366 * Index = (epnum * 2) + direction - 1,
1369 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
1378 (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; in xhci_get_endpoint_index()
1384 * address from the XHCI endpoint index.
1410 return fls(added_ctxs) - 1; in xhci_last_valid_endpoint()
1414 * returns 0 this is a root hub; returns -EINVAL for NULL pointers.
1419 struct xhci_hcd *xhci; in xhci_check_args() local
1423 pr_debug("xHCI %s called with invalid args\n", func); in xhci_check_args()
1424 return -EINVAL; in xhci_check_args()
1426 if (!udev->parent) { in xhci_check_args()
1427 pr_debug("xHCI %s called for root hub\n", func); in xhci_check_args()
1431 xhci = hcd_to_xhci(hcd); in xhci_check_args()
1433 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1434 xhci_dbg(xhci, "xHCI %s called with unaddressed device\n", in xhci_check_args()
1436 return -EINVAL; in xhci_check_args()
1439 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1440 if (virt_dev->udev != udev) { in xhci_check_args()
1441 xhci_dbg(xhci, "xHCI %s called with udev and " in xhci_check_args()
1443 return -EINVAL; in xhci_check_args()
1447 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1448 return -ENODEV; in xhci_check_args()
1453 static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1463 static int xhci_check_ep0_maxpacket(struct xhci_hcd *xhci, struct xhci_virt_device *vdev) in xhci_check_ep0_maxpacket() argument
1472 ep_ctx = xhci_get_ep_ctx(xhci, vdev->out_ctx, 0); in xhci_check_ep0_maxpacket()
1473 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); in xhci_check_ep0_maxpacket()
1474 max_packet_size = usb_endpoint_maxp(&vdev->udev->ep0.desc); in xhci_check_ep0_maxpacket()
1481 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1483 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1486 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1487 "Max packet size in xHCI HW = %d", in xhci_check_ep0_maxpacket()
1489 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_check_ep0_maxpacket()
1492 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_ep0_maxpacket()
1494 return -ENOMEM; in xhci_check_ep0_maxpacket()
1496 command->in_ctx = vdev->in_ctx; in xhci_check_ep0_maxpacket()
1497 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_ep0_maxpacket()
1499 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_ep0_maxpacket()
1501 ret = -ENOMEM; in xhci_check_ep0_maxpacket()
1505 xhci_endpoint_copy(xhci, vdev->in_ctx, vdev->out_ctx, 0); in xhci_check_ep0_maxpacket()
1507 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, 0); in xhci_check_ep0_maxpacket()
1508 ep_ctx->ep_info &= cpu_to_le32(~EP_STATE_MASK);/* must clear */ in xhci_check_ep0_maxpacket()
1509 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); in xhci_check_ep0_maxpacket()
1510 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); in xhci_check_ep0_maxpacket()
1512 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); in xhci_check_ep0_maxpacket()
1513 ctrl_ctx->drop_flags = 0; in xhci_check_ep0_maxpacket()
1515 ret = xhci_configure_endpoint(xhci, vdev->udev, command, in xhci_check_ep0_maxpacket()
1518 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_check_ep0_maxpacket()
1521 dev_dbg(&vdev->udev->dev, "incorrect max packet size %d for ep0\n", in xhci_check_ep0_maxpacket()
1523 return -EINVAL; in xhci_check_ep0_maxpacket()
1526 kfree(command->completion); in xhci_check_ep0_maxpacket()
1533 * non-error returns are a promise to giveback() the urb later
1538 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_urb_enqueue() local
1546 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_enqueue()
1548 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) in xhci_urb_enqueue()
1549 num_tds = urb->number_of_packets; in xhci_urb_enqueue()
1550 else if (usb_endpoint_is_bulk_out(&urb->ep->desc) && in xhci_urb_enqueue()
1551 urb->transfer_buffer_length > 0 && in xhci_urb_enqueue()
1552 urb->transfer_flags & URB_ZERO_PACKET && in xhci_urb_enqueue()
1553 !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc))) in xhci_urb_enqueue()
1560 return -ENOMEM; in xhci_urb_enqueue()
1562 urb_priv->num_tds = num_tds; in xhci_urb_enqueue()
1563 urb_priv->num_tds_done = 0; in xhci_urb_enqueue()
1564 urb->hcpriv = urb_priv; in xhci_urb_enqueue()
1568 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1570 ret = xhci_check_args(hcd, urb->dev, urb->ep, in xhci_urb_enqueue()
1573 ret = ret ? ret : -EINVAL; in xhci_urb_enqueue()
1577 slot_id = urb->dev->slot_id; in xhci_urb_enqueue()
1580 ret = -ESHUTDOWN; in xhci_urb_enqueue()
1584 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1585 xhci_dbg(xhci, "Can't queue urb, port error, link inactive\n"); in xhci_urb_enqueue()
1586 ret = -ENODEV; in xhci_urb_enqueue()
1590 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1591 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1592 urb->ep->desc.bEndpointAddress, urb); in xhci_urb_enqueue()
1593 ret = -ESHUTDOWN; in xhci_urb_enqueue()
1597 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1600 xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams transition state %x\n", in xhci_urb_enqueue()
1602 ret = -EINVAL; in xhci_urb_enqueue()
1606 xhci_warn(xhci, "Can't enqueue URB while manually clearing toggle\n"); in xhci_urb_enqueue()
1607 ret = -EINVAL; in xhci_urb_enqueue()
1611 switch (usb_endpoint_type(&urb->ep->desc)) { in xhci_urb_enqueue()
1614 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1618 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1622 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1626 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, in xhci_urb_enqueue()
1633 urb->hcpriv = NULL; in xhci_urb_enqueue()
1635 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1655 * series of 1-TRB transfer no-op TDs. (No-ops shouldn't be chained.) The
1657 * endpoint command, as noted in the xHCI 0.95 errata.
1675 struct xhci_hcd *xhci; in xhci_urb_dequeue() local
1684 xhci = hcd_to_xhci(hcd); in xhci_urb_dequeue()
1685 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1695 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1696 urb_priv = urb->hcpriv; in xhci_urb_dequeue()
1700 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_dequeue()
1701 ep = &vdev->eps[ep_index]; in xhci_urb_dequeue()
1702 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); in xhci_urb_dequeue()
1707 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1708 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1709 xhci_hc_died(xhci); in xhci_urb_dequeue()
1714 * check ring is not re-allocated since URB was enqueued. If it is, then in xhci_urb_dequeue()
1718 if (!td_on_ring(&urb_priv->td[0], ep_ring)) { in xhci_urb_dequeue()
1719 xhci_err(xhci, "Canceled URB td not found on endpoint ring"); in xhci_urb_dequeue()
1720 for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1721 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1722 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1723 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1728 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1729 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1731 for (i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1732 i < urb_priv->num_tds; in xhci_urb_dequeue()
1734 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1735 if (!list_empty(&td->td_list)) in xhci_urb_dequeue()
1736 list_del_init(&td->td_list); in xhci_urb_dequeue()
1737 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1738 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1743 i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1744 if (i < urb_priv->num_tds) in xhci_urb_dequeue()
1745 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, in xhci_urb_dequeue()
1748 urb, urb->dev->devpath, in xhci_urb_dequeue()
1749 urb->ep->desc.bEndpointAddress, in xhci_urb_dequeue()
1751 urb_priv->td[i].start_seg, in xhci_urb_dequeue()
1752 urb_priv->td[i].start_trb)); in xhci_urb_dequeue()
1754 for (; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1755 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1757 if (list_empty(&td->cancelled_td_list)) { in xhci_urb_dequeue()
1758 td->cancel_status = TD_DIRTY; in xhci_urb_dequeue()
1759 list_add_tail(&td->cancelled_td_list, in xhci_urb_dequeue()
1760 &ep->cancelled_td_list); in xhci_urb_dequeue()
1765 if (ep->ep_state & (EP_STOP_CMD_PENDING | EP_HALTED | SET_DEQ_PENDING)) { in xhci_urb_dequeue()
1766 xhci_dbg(xhci, "Not queuing Stop Endpoint on slot %d ep %d in state 0x%x\n", in xhci_urb_dequeue()
1767 urb->dev->slot_id, ep_index, ep->ep_state); in xhci_urb_dequeue()
1772 if (ep->ep_state & EP_CLEARING_TT) { in xhci_urb_dequeue()
1774 xhci_dbg(xhci, "Invalidating TDs instantly on slot %d ep %d in state 0x%x\n", in xhci_urb_dequeue()
1775 urb->dev->slot_id, ep_index, ep->ep_state); in xhci_urb_dequeue()
1779 command = xhci_alloc_command(xhci, false, GFP_ATOMIC); in xhci_urb_dequeue()
1781 ret = -ENOMEM; in xhci_urb_dequeue()
1784 ep->stop_time = jiffies; in xhci_urb_dequeue()
1785 ep->ep_state |= EP_STOP_CMD_PENDING; in xhci_urb_dequeue()
1786 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1788 xhci_ring_cmd_db(xhci); in xhci_urb_dequeue()
1791 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1798 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1799 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN); in xhci_urb_dequeue()
1814 * the xhci->devs[slot_id] structure.
1819 struct xhci_hcd *xhci; in xhci_drop_endpoint() local
1831 xhci = hcd_to_xhci(hcd); in xhci_drop_endpoint()
1832 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1833 return -ENODEV; in xhci_drop_endpoint()
1835 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_drop_endpoint()
1836 drop_flag = xhci_get_endpoint_flag(&ep->desc); in xhci_drop_endpoint()
1838 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1843 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1844 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1847 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_drop_endpoint()
1852 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_drop_endpoint()
1853 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); in xhci_drop_endpoint()
1858 le32_to_cpu(ctrl_ctx->drop_flags) & in xhci_drop_endpoint()
1859 xhci_get_endpoint_flag(&ep->desc)) { in xhci_drop_endpoint()
1861 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1862 xhci_warn(xhci, "xHCI %s called with disabled ep %p\n", in xhci_drop_endpoint()
1867 ctrl_ctx->drop_flags |= cpu_to_le32(drop_flag); in xhci_drop_endpoint()
1868 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_drop_endpoint()
1870 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); in xhci_drop_endpoint()
1871 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_drop_endpoint()
1873 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1875 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1877 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_drop_endpoint()
1878 (unsigned int) ep->desc.bEndpointAddress, in xhci_drop_endpoint()
1879 udev->slot_id, in xhci_drop_endpoint()
1897 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1902 struct xhci_hcd *xhci; in xhci_add_endpoint() local
1915 ep->hcpriv = NULL; in xhci_add_endpoint()
1918 xhci = hcd_to_xhci(hcd); in xhci_add_endpoint()
1919 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1920 return -ENODEV; in xhci_add_endpoint()
1922 added_ctxs = xhci_get_endpoint_flag(&ep->desc); in xhci_add_endpoint()
1928 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1933 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1934 in_ctx = virt_dev->in_ctx; in xhci_add_endpoint()
1937 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_add_endpoint()
1942 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_add_endpoint()
1946 if (virt_dev->eps[ep_index].ring && in xhci_add_endpoint()
1947 !(le32_to_cpu(ctrl_ctx->drop_flags) & added_ctxs)) { in xhci_add_endpoint()
1948 xhci_warn(xhci, "Trying to add endpoint 0x%x " in xhci_add_endpoint()
1950 (unsigned int) ep->desc.bEndpointAddress); in xhci_add_endpoint()
1951 return -EINVAL; in xhci_add_endpoint()
1957 if (le32_to_cpu(ctrl_ctx->add_flags) & added_ctxs) { in xhci_add_endpoint()
1958 xhci_warn(xhci, "xHCI %s called with enabled ep %p\n", in xhci_add_endpoint()
1968 if (xhci_endpoint_init(xhci, virt_dev, udev, ep, GFP_NOIO) < 0) { in xhci_add_endpoint()
1969 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", in xhci_add_endpoint()
1970 __func__, ep->desc.bEndpointAddress); in xhci_add_endpoint()
1971 return -ENOMEM; in xhci_add_endpoint()
1974 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs); in xhci_add_endpoint()
1975 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_add_endpoint()
1979 * this re-adds a new state for the endpoint from the new endpoint in xhci_add_endpoint()
1980 * descriptors. We must drop and re-add this endpoint, so we leave the in xhci_add_endpoint()
1983 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_add_endpoint()
1986 ep->hcpriv = udev; in xhci_add_endpoint()
1988 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1991 xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", in xhci_add_endpoint()
1992 (unsigned int) ep->desc.bEndpointAddress, in xhci_add_endpoint()
1993 udev->slot_id, in xhci_add_endpoint()
2000 static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev) in xhci_zero_in_ctx() argument
2007 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_zero_in_ctx()
2009 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_zero_in_ctx()
2019 ctrl_ctx->drop_flags = 0; in xhci_zero_in_ctx()
2020 ctrl_ctx->add_flags = 0; in xhci_zero_in_ctx()
2021 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
2022 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_zero_in_ctx()
2024 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in xhci_zero_in_ctx()
2026 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
2027 ep_ctx->ep_info = 0; in xhci_zero_in_ctx()
2028 ep_ctx->ep_info2 = 0; in xhci_zero_in_ctx()
2029 ep_ctx->deq = 0; in xhci_zero_in_ctx()
2030 ep_ctx->tx_info = 0; in xhci_zero_in_ctx()
2034 static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, in xhci_configure_endpoint_result() argument
2042 xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); in xhci_configure_endpoint_result()
2043 ret = -ETIME; in xhci_configure_endpoint_result()
2046 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2048 ret = -ENOMEM; in xhci_configure_endpoint_result()
2053 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2055 ret = -ENOSPC; in xhci_configure_endpoint_result()
2060 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " in xhci_configure_endpoint_result()
2063 ret = -EINVAL; in xhci_configure_endpoint_result()
2066 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2068 ret = -ENODEV; in xhci_configure_endpoint_result()
2071 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint_result()
2076 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_configure_endpoint_result()
2078 ret = -EINVAL; in xhci_configure_endpoint_result()
2084 static int xhci_evaluate_context_result(struct xhci_hcd *xhci, in xhci_evaluate_context_result() argument
2092 xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); in xhci_evaluate_context_result()
2093 ret = -ETIME; in xhci_evaluate_context_result()
2096 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2097 "WARN: xHCI driver setup invalid evaluate context command.\n"); in xhci_evaluate_context_result()
2098 ret = -EINVAL; in xhci_evaluate_context_result()
2101 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2103 ret = -EINVAL; in xhci_evaluate_context_result()
2106 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2108 ret = -EINVAL; in xhci_evaluate_context_result()
2111 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2113 ret = -ENODEV; in xhci_evaluate_context_result()
2117 dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); in xhci_evaluate_context_result()
2118 ret = -EINVAL; in xhci_evaluate_context_result()
2121 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_evaluate_context_result()
2126 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n", in xhci_evaluate_context_result()
2128 ret = -EINVAL; in xhci_evaluate_context_result()
2134 static u32 xhci_count_num_new_endpoints(struct xhci_hcd *xhci, in xhci_count_num_new_endpoints() argument
2144 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_new_endpoints()
2145 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_new_endpoints()
2151 return hweight32(valid_add_flags) - in xhci_count_num_new_endpoints()
2155 static unsigned int xhci_count_num_dropped_endpoints(struct xhci_hcd *xhci, in xhci_count_num_dropped_endpoints() argument
2161 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_dropped_endpoints()
2162 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_dropped_endpoints()
2164 return hweight32(valid_drop_flags) - in xhci_count_num_dropped_endpoints()
2174 * - the first configure endpoint command drops more endpoints than it adds
2175 * - a second configure endpoint command that adds more endpoints is queued
2176 * - the first configure endpoint command fails, so the config is unchanged
2177 * - the second command may succeed, even though there isn't enough resources
2179 * Must be called with xhci->lock held.
2181 static int xhci_reserve_host_resources(struct xhci_hcd *xhci, in xhci_reserve_host_resources() argument
2186 added_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_reserve_host_resources()
2187 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2188 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2191 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2192 xhci->limit_active_eps); in xhci_reserve_host_resources()
2193 return -ENOMEM; in xhci_reserve_host_resources()
2195 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2196 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_resources()
2198 xhci->num_active_eps); in xhci_reserve_host_resources()
2206 * Must be called with xhci->lock held.
2208 static void xhci_free_host_resources(struct xhci_hcd *xhci, in xhci_free_host_resources() argument
2213 num_failed_eps = xhci_count_num_new_endpoints(xhci, ctrl_ctx); in xhci_free_host_resources()
2214 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2215 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_host_resources()
2218 xhci->num_active_eps); in xhci_free_host_resources()
2225 * Must be called with xhci->lock held.
2227 static void xhci_finish_resource_reservation(struct xhci_hcd *xhci, in xhci_finish_resource_reservation() argument
2232 num_dropped_eps = xhci_count_num_dropped_endpoints(xhci, ctrl_ctx); in xhci_finish_resource_reservation()
2233 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2235 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_finish_resource_reservation()
2238 xhci->num_active_eps); in xhci_finish_resource_reservation()
2243 switch (udev->speed) { in xhci_get_block_size()
2262 if (interval_bw->overhead[LS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2264 if (interval_bw->overhead[FS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2273 static int xhci_check_tt_bw_table(struct xhci_hcd *xhci, in xhci_check_tt_bw_table() argument
2281 bw_table = &xhci->rh_bw[virt_dev->rhub_port->hw_portnum].bw_table; in xhci_check_tt_bw_table()
2282 tt_info = virt_dev->tt_info; in xhci_check_tt_bw_table()
2289 if (old_active_eps == 0 && tt_info->active_eps != 0) { in xhci_check_tt_bw_table()
2290 if (bw_table->bw_used + TT_HS_OVERHEAD > HS_BW_LIMIT) in xhci_check_tt_bw_table()
2291 return -ENOMEM; in xhci_check_tt_bw_table()
2303 static int xhci_check_ss_bw(struct xhci_hcd *xhci, in xhci_check_ss_bw() argument
2309 if (virt_dev->bw_table->ss_bw_in > (SS_BW_LIMIT_IN - bw_reserved)) in xhci_check_ss_bw()
2310 return -ENOMEM; in xhci_check_ss_bw()
2313 if (virt_dev->bw_table->ss_bw_out > (SS_BW_LIMIT_OUT - bw_reserved)) in xhci_check_ss_bw()
2314 return -ENOMEM; in xhci_check_ss_bw()
2320 * This algorithm is a very conservative estimate of the worst-case scheduling
2328 * over-estimate.
2360 static int xhci_check_bw_table(struct xhci_hcd *xhci, in xhci_check_bw_table() argument
2375 if (virt_dev->udev->speed >= USB_SPEED_SUPER) in xhci_check_bw_table()
2376 return xhci_check_ss_bw(xhci, virt_dev); in xhci_check_bw_table()
2378 if (virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2387 bw_table = virt_dev->bw_table; in xhci_check_bw_table()
2391 block_size = xhci_get_block_size(virt_dev->udev); in xhci_check_bw_table()
2396 if (virt_dev->tt_info) { in xhci_check_bw_table()
2397 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2399 virt_dev->rhub_port->hw_portnum + 1); in xhci_check_bw_table()
2400 if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_check_bw_table()
2401 xhci_warn(xhci, "Not enough bandwidth on HS bus for " in xhci_check_bw_table()
2403 return -ENOMEM; in xhci_check_bw_table()
2405 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2407 virt_dev->tt_info->slot_id, in xhci_check_bw_table()
2408 virt_dev->tt_info->ttport); in xhci_check_bw_table()
2410 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2412 virt_dev->rhub_port->hw_portnum + 1); in xhci_check_bw_table()
2418 bw_used = DIV_ROUND_UP(bw_table->interval0_esit_payload, block_size) + in xhci_check_bw_table()
2419 bw_table->interval_bw[0].num_packets * in xhci_check_bw_table()
2420 xhci_get_largest_overhead(&bw_table->interval_bw[0]); in xhci_check_bw_table()
2433 bw_table->interval_bw[i].num_packets; in xhci_check_bw_table()
2438 if (list_empty(&bw_table->interval_bw[i].endpoints)) in xhci_check_bw_table()
2444 ep_entry = bw_table->interval_bw[i].endpoints.next; in xhci_check_bw_table()
2449 virt_ep->bw_info.max_packet_size, in xhci_check_bw_table()
2457 &bw_table->interval_bw[i]); in xhci_check_bw_table()
2493 xhci_warn(xhci, "Not enough bandwidth. " in xhci_check_bw_table()
2496 return -ENOMEM; in xhci_check_bw_table()
2500 * Ok, we know we have some packets left over after even-handedly in xhci_check_bw_table()
2502 * fit into, so we over-schedule and say they will be scheduled every in xhci_check_bw_table()
2508 if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2514 xhci->rh_bw[virt_dev->rhub_port->hw_portnum].num_active_tts; in xhci_check_bw_table()
2517 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_check_bw_table()
2521 (max_bandwidth - bw_used - bw_reserved) * 100 / in xhci_check_bw_table()
2526 xhci_warn(xhci, "Not enough bandwidth. Proposed: %u, Max: %u\n", in xhci_check_bw_table()
2528 return -ENOMEM; in xhci_check_bw_table()
2531 bw_table->bw_used = bw_used; in xhci_check_bw_table()
2549 unsigned int mps = DIV_ROUND_UP(ep_bw->max_packet_size, SS_BLOCK); in xhci_get_ss_bw_consumed()
2551 if (ep_bw->ep_interval == 0) in xhci_get_ss_bw_consumed()
2553 (ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2555 return DIV_ROUND_UP(ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2557 1 << ep_bw->ep_interval); in xhci_get_ss_bw_consumed()
2561 static void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci, in xhci_drop_ep_from_interval_table() argument
2571 if (xhci_is_async_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2574 if (udev->speed >= USB_SPEED_SUPER) { in xhci_drop_ep_from_interval_table()
2575 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2576 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2579 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2587 if (list_empty(&virt_ep->bw_endpoint_list)) in xhci_drop_ep_from_interval_table()
2592 if (udev->speed == USB_SPEED_HIGH) in xhci_drop_ep_from_interval_table()
2593 normalized_interval = ep_bw->ep_interval; in xhci_drop_ep_from_interval_table()
2595 normalized_interval = ep_bw->ep_interval - 3; in xhci_drop_ep_from_interval_table()
2598 bw_table->interval0_esit_payload -= ep_bw->max_esit_payload; in xhci_drop_ep_from_interval_table()
2599 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_drop_ep_from_interval_table()
2600 interval_bw->num_packets -= ep_bw->num_packets; in xhci_drop_ep_from_interval_table()
2601 switch (udev->speed) { in xhci_drop_ep_from_interval_table()
2603 interval_bw->overhead[LS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2606 interval_bw->overhead[FS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2609 interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2618 tt_info->active_eps -= 1; in xhci_drop_ep_from_interval_table()
2619 list_del_init(&virt_ep->bw_endpoint_list); in xhci_drop_ep_from_interval_table()
2622 static void xhci_add_ep_to_interval_table(struct xhci_hcd *xhci, in xhci_add_ep_to_interval_table() argument
2633 if (xhci_is_async_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2636 if (udev->speed == USB_SPEED_SUPER) { in xhci_add_ep_to_interval_table()
2637 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2638 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2641 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2649 if (udev->speed == USB_SPEED_HIGH) in xhci_add_ep_to_interval_table()
2650 normalized_interval = ep_bw->ep_interval; in xhci_add_ep_to_interval_table()
2652 normalized_interval = ep_bw->ep_interval - 3; in xhci_add_ep_to_interval_table()
2655 bw_table->interval0_esit_payload += ep_bw->max_esit_payload; in xhci_add_ep_to_interval_table()
2656 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_add_ep_to_interval_table()
2657 interval_bw->num_packets += ep_bw->num_packets; in xhci_add_ep_to_interval_table()
2658 switch (udev->speed) { in xhci_add_ep_to_interval_table()
2660 interval_bw->overhead[LS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2663 interval_bw->overhead[FS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2666 interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2676 tt_info->active_eps += 1; in xhci_add_ep_to_interval_table()
2678 list_for_each_entry(smaller_ep, &interval_bw->endpoints, in xhci_add_ep_to_interval_table()
2680 if (ep_bw->max_packet_size >= in xhci_add_ep_to_interval_table()
2681 smaller_ep->bw_info.max_packet_size) { in xhci_add_ep_to_interval_table()
2683 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2684 &smaller_ep->bw_endpoint_list); in xhci_add_ep_to_interval_table()
2689 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2690 &interval_bw->endpoints); in xhci_add_ep_to_interval_table()
2693 void xhci_update_tt_active_eps(struct xhci_hcd *xhci, in xhci_update_tt_active_eps() argument
2698 if (!virt_dev->tt_info) in xhci_update_tt_active_eps()
2701 rh_bw_info = &xhci->rh_bw[virt_dev->rhub_port->hw_portnum]; in xhci_update_tt_active_eps()
2703 virt_dev->tt_info->active_eps != 0) { in xhci_update_tt_active_eps()
2704 rh_bw_info->num_active_tts += 1; in xhci_update_tt_active_eps()
2705 rh_bw_info->bw_table.bw_used += TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2707 virt_dev->tt_info->active_eps == 0) { in xhci_update_tt_active_eps()
2708 rh_bw_info->num_active_tts -= 1; in xhci_update_tt_active_eps()
2709 rh_bw_info->bw_table.bw_used -= TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2713 static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, in xhci_reserve_bandwidth() argument
2722 if (virt_dev->tt_info) in xhci_reserve_bandwidth()
2723 old_active_eps = virt_dev->tt_info->active_eps; in xhci_reserve_bandwidth()
2727 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_reserve_bandwidth()
2729 return -ENOMEM; in xhci_reserve_bandwidth()
2737 memcpy(&ep_bw_info[i], &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2743 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2744 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2745 virt_dev->bw_table, in xhci_reserve_bandwidth()
2746 virt_dev->udev, in xhci_reserve_bandwidth()
2747 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2748 virt_dev->tt_info); in xhci_reserve_bandwidth()
2751 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2755 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2756 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2757 virt_dev->bw_table, in xhci_reserve_bandwidth()
2758 virt_dev->udev, in xhci_reserve_bandwidth()
2759 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2760 virt_dev->tt_info); in xhci_reserve_bandwidth()
2763 if (!xhci_check_bw_table(xhci, virt_dev, old_active_eps)) { in xhci_reserve_bandwidth()
2767 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_reserve_bandwidth()
2780 xhci_drop_ep_from_interval_table(xhci, in xhci_reserve_bandwidth()
2781 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2782 virt_dev->bw_table, in xhci_reserve_bandwidth()
2783 virt_dev->udev, in xhci_reserve_bandwidth()
2784 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2785 virt_dev->tt_info); in xhci_reserve_bandwidth()
2788 memcpy(&virt_dev->eps[i].bw_info, &ep_bw_info[i], in xhci_reserve_bandwidth()
2792 xhci_add_ep_to_interval_table(xhci, in xhci_reserve_bandwidth()
2793 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2794 virt_dev->bw_table, in xhci_reserve_bandwidth()
2795 virt_dev->udev, in xhci_reserve_bandwidth()
2796 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2797 virt_dev->tt_info); in xhci_reserve_bandwidth()
2799 return -ENOMEM; in xhci_reserve_bandwidth()
2803 * Synchronous XHCI stop endpoint helper. Issues the stop endpoint command and
2811 int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, int suspend, in xhci_stop_endpoint_sync() argument
2818 command = xhci_alloc_command(xhci, true, gfp_flags); in xhci_stop_endpoint_sync()
2820 return -ENOMEM; in xhci_stop_endpoint_sync()
2822 spin_lock_irqsave(&xhci->lock, flags); in xhci_stop_endpoint_sync()
2823 ret = xhci_queue_stop_endpoint(xhci, command, ep->vdev->slot_id, in xhci_stop_endpoint_sync()
2824 ep->ep_index, suspend); in xhci_stop_endpoint_sync()
2826 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_sync()
2830 xhci_ring_cmd_db(xhci); in xhci_stop_endpoint_sync()
2831 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_stop_endpoint_sync()
2833 wait_for_completion(command->completion); in xhci_stop_endpoint_sync()
2836 if (command->status == COMP_COMMAND_ABORTED || in xhci_stop_endpoint_sync()
2837 command->status == COMP_COMMAND_RING_STOPPED) { in xhci_stop_endpoint_sync()
2838 xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); in xhci_stop_endpoint_sync()
2839 ret = -ETIME; in xhci_stop_endpoint_sync()
2842 xhci_free_command(xhci, command); in xhci_stop_endpoint_sync()
2851 static int xhci_configure_endpoint(struct xhci_hcd *xhci, in xhci_configure_endpoint() argument
2863 return -EINVAL; in xhci_configure_endpoint()
2865 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2867 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2868 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2869 return -ESHUTDOWN; in xhci_configure_endpoint()
2872 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2874 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_configure_endpoint()
2876 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2877 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_configure_endpoint()
2879 return -ENOMEM; in xhci_configure_endpoint()
2882 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2883 xhci_reserve_host_resources(xhci, ctrl_ctx)) { in xhci_configure_endpoint()
2884 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2885 xhci_warn(xhci, "Not enough host resources, " in xhci_configure_endpoint()
2887 xhci->num_active_eps); in xhci_configure_endpoint()
2888 return -ENOMEM; in xhci_configure_endpoint()
2890 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && !ctx_change && in xhci_configure_endpoint()
2891 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2892 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2893 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2894 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2895 xhci_warn(xhci, "Not enough bandwidth\n"); in xhci_configure_endpoint()
2896 return -ENOMEM; in xhci_configure_endpoint()
2899 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2905 ret = xhci_queue_configure_endpoint(xhci, command, in xhci_configure_endpoint()
2906 command->in_ctx->dma, in xhci_configure_endpoint()
2907 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2909 ret = xhci_queue_evaluate_context(xhci, command, in xhci_configure_endpoint()
2910 command->in_ctx->dma, in xhci_configure_endpoint()
2911 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2913 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2914 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2915 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2916 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_configure_endpoint()
2918 return -ENOMEM; in xhci_configure_endpoint()
2920 xhci_ring_cmd_db(xhci); in xhci_configure_endpoint()
2921 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2924 wait_for_completion(command->completion); in xhci_configure_endpoint()
2927 ret = xhci_configure_endpoint_result(xhci, udev, in xhci_configure_endpoint()
2928 &command->status); in xhci_configure_endpoint()
2930 ret = xhci_evaluate_context_result(xhci, udev, in xhci_configure_endpoint()
2931 &command->status); in xhci_configure_endpoint()
2933 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2934 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2939 xhci_free_host_resources(xhci, ctrl_ctx); in xhci_configure_endpoint()
2941 xhci_finish_resource_reservation(xhci, ctrl_ctx); in xhci_configure_endpoint()
2942 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2947 static void xhci_check_bw_drop_ep_streams(struct xhci_hcd *xhci, in xhci_check_bw_drop_ep_streams() argument
2950 struct xhci_virt_ep *ep = &vdev->eps[i]; in xhci_check_bw_drop_ep_streams()
2952 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_check_bw_drop_ep_streams()
2953 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on set_interface, freeing streams.\n", in xhci_check_bw_drop_ep_streams()
2955 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2956 ep->stream_info = NULL; in xhci_check_bw_drop_ep_streams()
2957 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_check_bw_drop_ep_streams()
2968 * else should be touching the xhci->devs[slot_id] structure, so we
2969 * don't need to take the xhci->lock for manipulating that.
2975 struct xhci_hcd *xhci; in xhci_check_bandwidth() local
2984 xhci = hcd_to_xhci(hcd); in xhci_check_bandwidth()
2985 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2986 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2987 return -ENODEV; in xhci_check_bandwidth()
2989 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_check_bandwidth()
2990 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2992 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_check_bandwidth()
2994 return -ENOMEM; in xhci_check_bandwidth()
2996 command->in_ctx = virt_dev->in_ctx; in xhci_check_bandwidth()
2998 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ in xhci_check_bandwidth()
2999 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_bandwidth()
3001 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_check_bandwidth()
3003 ret = -ENOMEM; in xhci_check_bandwidth()
3006 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_check_bandwidth()
3007 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); in xhci_check_bandwidth()
3008 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); in xhci_check_bandwidth()
3011 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && in xhci_check_bandwidth()
3012 ctrl_ctx->drop_flags == 0) { in xhci_check_bandwidth()
3017 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
3018 for (i = 31; i >= 1; i--) { in xhci_check_bandwidth()
3021 if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32)) in xhci_check_bandwidth()
3022 || (ctrl_ctx->add_flags & le32) || i == 1) { in xhci_check_bandwidth()
3023 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_check_bandwidth()
3024 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); in xhci_check_bandwidth()
3029 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_check_bandwidth()
3037 if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) && in xhci_check_bandwidth()
3038 !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))) { in xhci_check_bandwidth()
3039 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
3040 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
3043 xhci_zero_in_ctx(xhci, virt_dev); in xhci_check_bandwidth()
3049 if (!virt_dev->eps[i].new_ring) in xhci_check_bandwidth()
3054 if (virt_dev->eps[i].ring) { in xhci_check_bandwidth()
3055 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_check_bandwidth()
3057 xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); in xhci_check_bandwidth()
3058 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; in xhci_check_bandwidth()
3059 virt_dev->eps[i].new_ring = NULL; in xhci_check_bandwidth()
3060 xhci_debugfs_create_endpoint(xhci, virt_dev, i); in xhci_check_bandwidth()
3063 kfree(command->completion); in xhci_check_bandwidth()
3072 struct xhci_hcd *xhci; in xhci_reset_bandwidth() local
3079 xhci = hcd_to_xhci(hcd); in xhci_reset_bandwidth()
3081 xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); in xhci_reset_bandwidth()
3082 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
3085 if (virt_dev->eps[i].new_ring) { in xhci_reset_bandwidth()
3086 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_reset_bandwidth()
3087 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3088 virt_dev->eps[i].new_ring = NULL; in xhci_reset_bandwidth()
3091 xhci_zero_in_ctx(xhci, virt_dev); in xhci_reset_bandwidth()
3095 static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci, in xhci_setup_input_ctx_for_config_ep() argument
3101 ctrl_ctx->add_flags = cpu_to_le32(add_flags); in xhci_setup_input_ctx_for_config_ep()
3102 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags); in xhci_setup_input_ctx_for_config_ep()
3103 xhci_slot_copy(xhci, in_ctx, out_ctx); in xhci_setup_input_ctx_for_config_ep()
3104 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_setup_input_ctx_for_config_ep()
3110 struct xhci_hcd *xhci; in xhci_endpoint_disable() local
3117 xhci = hcd_to_xhci(hcd); in xhci_endpoint_disable()
3119 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3121 udev = (struct usb_device *)host_ep->hcpriv; in xhci_endpoint_disable()
3122 if (!udev || !udev->slot_id) in xhci_endpoint_disable()
3125 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3129 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_disable()
3130 ep = &vdev->eps[ep_index]; in xhci_endpoint_disable()
3133 if (ep->ep_state & EP_CLEARING_TT) { in xhci_endpoint_disable()
3134 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3139 if (ep->ep_state) in xhci_endpoint_disable()
3140 xhci_dbg(xhci, "endpoint disable with ep_state 0x%x\n", in xhci_endpoint_disable()
3141 ep->ep_state); in xhci_endpoint_disable()
3143 host_ep->hcpriv = NULL; in xhci_endpoint_disable()
3144 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3156 * endpoint. Refer to the additional note in xhci spcification section 4.6.8.
3158 * vdev may be lost due to xHC restore error and re-initialization during S3/S4
3165 struct xhci_hcd *xhci; in xhci_endpoint_reset() local
3176 xhci = hcd_to_xhci(hcd); in xhci_endpoint_reset()
3177 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_reset()
3182 * mismatch. Reconfigure the xhci ep0 endpoint context here in that case in xhci_endpoint_reset()
3184 if (usb_endpoint_xfer_control(&host_ep->desc) && ep_index == 0) { in xhci_endpoint_reset()
3187 if (udev->speed != USB_SPEED_FULL || !udev->slot_id) in xhci_endpoint_reset()
3190 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3191 if (!vdev || vdev->udev != udev) in xhci_endpoint_reset()
3194 xhci_check_ep0_maxpacket(xhci, vdev); in xhci_endpoint_reset()
3200 if (!host_ep->hcpriv) in xhci_endpoint_reset()
3202 udev = (struct usb_device *) host_ep->hcpriv; in xhci_endpoint_reset()
3203 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3205 if (!udev->slot_id || !vdev) in xhci_endpoint_reset()
3208 ep = &vdev->eps[ep_index]; in xhci_endpoint_reset()
3211 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3212 if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) { in xhci_endpoint_reset()
3213 ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE; in xhci_endpoint_reset()
3214 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3217 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3218 /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */ in xhci_endpoint_reset()
3219 if (usb_endpoint_xfer_control(&host_ep->desc) || in xhci_endpoint_reset()
3220 usb_endpoint_xfer_isoc(&host_ep->desc)) in xhci_endpoint_reset()
3223 ep_flag = xhci_get_endpoint_flag(&host_ep->desc); in xhci_endpoint_reset()
3228 stop_cmd = xhci_alloc_command(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3232 cfg_cmd = xhci_alloc_command_with_ctx(xhci, true, GFP_NOWAIT); in xhci_endpoint_reset()
3236 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3239 ep->ep_state |= EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3247 if (!list_empty(&ep->ring->td_list)) { in xhci_endpoint_reset()
3248 dev_err(&udev->dev, "EP not empty, refuse reset\n"); in xhci_endpoint_reset()
3249 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3250 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3254 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3257 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3258 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3259 xhci_dbg(xhci, "%s: Failed to queue stop ep command, %d ", in xhci_endpoint_reset()
3264 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3265 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3267 wait_for_completion(stop_cmd->completion); in xhci_endpoint_reset()
3269 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3272 ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); in xhci_endpoint_reset()
3274 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3275 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3276 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_endpoint_reset()
3281 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3283 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3285 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3286 udev->slot_id, false); in xhci_endpoint_reset()
3288 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3289 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3290 xhci_dbg(xhci, "%s: Failed to queue config ep command, %d ", in xhci_endpoint_reset()
3295 xhci_ring_cmd_db(xhci); in xhci_endpoint_reset()
3296 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3298 wait_for_completion(cfg_cmd->completion); in xhci_endpoint_reset()
3300 xhci_free_command(xhci, cfg_cmd); in xhci_endpoint_reset()
3302 xhci_free_command(xhci, stop_cmd); in xhci_endpoint_reset()
3303 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3304 if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) in xhci_endpoint_reset()
3305 ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3306 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3309 static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, in xhci_check_streams_endpoint() argument
3318 return -EINVAL; in xhci_check_streams_endpoint()
3319 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__); in xhci_check_streams_endpoint()
3321 return ret ? ret : -EINVAL; in xhci_check_streams_endpoint()
3322 if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { in xhci_check_streams_endpoint()
3323 xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion" in xhci_check_streams_endpoint()
3325 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3326 return -EINVAL; in xhci_check_streams_endpoint()
3329 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_check_streams_endpoint()
3330 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3333 xhci_warn(xhci, "WARN: SuperSpeed bulk endpoint 0x%x " in xhci_check_streams_endpoint()
3335 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3336 xhci_warn(xhci, "Send email to xHCI maintainer and ask for " in xhci_check_streams_endpoint()
3338 return -EINVAL; in xhci_check_streams_endpoint()
3340 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3341 xhci_warn(xhci, "Cannot setup streams for SuperSpeed bulk " in xhci_check_streams_endpoint()
3343 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3344 return -EINVAL; in xhci_check_streams_endpoint()
3349 static void xhci_calculate_streams_entries(struct xhci_hcd *xhci, in xhci_calculate_streams_entries() argument
3359 * level page entries), but that's an optional feature for xHCI host in xhci_calculate_streams_entries()
3362 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3364 xhci_dbg(xhci, "xHCI HW only supports %u stream ctx entries.\n", in xhci_calculate_streams_entries()
3375 static int xhci_calculate_streams_and_bitmask(struct xhci_hcd *xhci, in xhci_calculate_streams_and_bitmask() argument
3386 ret = xhci_check_streams_endpoint(xhci, udev, in xhci_calculate_streams_and_bitmask()
3387 eps[i], udev->slot_id); in xhci_calculate_streams_and_bitmask()
3391 max_streams = usb_ss_max_streams(&eps[i]->ss_ep_comp); in xhci_calculate_streams_and_bitmask()
3392 if (max_streams < (*num_streams - 1)) { in xhci_calculate_streams_and_bitmask()
3393 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n", in xhci_calculate_streams_and_bitmask()
3394 eps[i]->desc.bEndpointAddress, in xhci_calculate_streams_and_bitmask()
3399 endpoint_flag = xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_streams_and_bitmask()
3401 return -EINVAL; in xhci_calculate_streams_and_bitmask()
3407 static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci, in xhci_calculate_no_streams_bitmask() argument
3417 slot_id = udev->slot_id; in xhci_calculate_no_streams_bitmask()
3418 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3422 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3423 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3426 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3429 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3435 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3438 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3439 xhci_warn(xhci, "WARN xhci_free_streams() called " in xhci_calculate_no_streams_bitmask()
3440 "with non-streams endpoint\n"); in xhci_calculate_no_streams_bitmask()
3443 changed_ep_bitmask |= xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3469 struct xhci_hcd *xhci; in xhci_alloc_streams() local
3480 return -EINVAL; in xhci_alloc_streams()
3483 * stream 0 that is reserved for xHCI usage. in xhci_alloc_streams()
3486 xhci = hcd_to_xhci(hcd); in xhci_alloc_streams()
3487 xhci_dbg(xhci, "Driver wants %u stream IDs (including stream 0).\n", in xhci_alloc_streams()
3491 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3492 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3493 xhci_dbg(xhci, "xHCI controller does not support streams.\n"); in xhci_alloc_streams()
3494 return -ENOSYS; in xhci_alloc_streams()
3497 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_alloc_streams()
3499 return -ENOMEM; in xhci_alloc_streams()
3501 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_alloc_streams()
3503 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_alloc_streams()
3505 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3506 return -ENOMEM; in xhci_alloc_streams()
3513 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3514 ret = xhci_calculate_streams_and_bitmask(xhci, udev, eps, in xhci_alloc_streams()
3517 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3518 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3522 xhci_warn(xhci, "WARN: endpoints can't handle " in xhci_alloc_streams()
3524 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3525 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3526 return -EINVAL; in xhci_alloc_streams()
3528 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3533 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3534 vdev->eps[ep_index].ep_state |= EP_GETTING_STREAMS; in xhci_alloc_streams()
3536 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3542 xhci_calculate_streams_entries(xhci, &num_streams, &num_stream_ctxs); in xhci_alloc_streams()
3543 xhci_dbg(xhci, "Need %u stream ctx entries for %u stream IDs.\n", in xhci_alloc_streams()
3547 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3548 max_packet = usb_endpoint_maxp(&eps[i]->desc); in xhci_alloc_streams()
3549 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3553 if (!vdev->eps[ep_index].stream_info) in xhci_alloc_streams()
3564 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3565 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3567 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3568 vdev->out_ctx, ep_index); in xhci_alloc_streams()
3569 xhci_setup_streams_ep_input_ctx(xhci, ep_ctx, in xhci_alloc_streams()
3570 vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3575 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3576 vdev->out_ctx, ctrl_ctx, in xhci_alloc_streams()
3580 ret = xhci_configure_endpoint(xhci, udev, config_cmd, in xhci_alloc_streams()
3590 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3592 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3593 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3594 xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n", in xhci_alloc_streams()
3595 udev->slot_id, ep_index); in xhci_alloc_streams()
3596 vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; in xhci_alloc_streams()
3598 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3599 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3602 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3603 xhci_debugfs_create_stream_files(xhci, vdev, ep_index); in xhci_alloc_streams()
3606 return num_streams - 1; in xhci_alloc_streams()
3611 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3612 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3613 vdev->eps[ep_index].stream_info = NULL; in xhci_alloc_streams()
3617 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3618 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_alloc_streams()
3619 xhci_endpoint_zero(xhci, vdev, eps[i]); in xhci_alloc_streams()
3621 xhci_free_command(xhci, config_cmd); in xhci_alloc_streams()
3622 return -ENOMEM; in xhci_alloc_streams()
3636 struct xhci_hcd *xhci; in xhci_free_streams() local
3644 xhci = hcd_to_xhci(hcd); in xhci_free_streams()
3645 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3648 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3649 changed_ep_bitmask = xhci_calculate_no_streams_bitmask(xhci, in xhci_free_streams()
3652 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3653 return -EINVAL; in xhci_free_streams()
3660 ep_index = xhci_get_endpoint_index(&eps[0]->desc); in xhci_free_streams()
3661 command = vdev->eps[ep_index].stream_info->free_streams_command; in xhci_free_streams()
3662 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_free_streams()
3664 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3665 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_free_streams()
3667 return -EINVAL; in xhci_free_streams()
3673 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3674 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3675 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3678 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3679 vdev->out_ctx, ep_index); in xhci_free_streams()
3681 &vdev->eps[ep_index]); in xhci_free_streams()
3683 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3684 vdev->out_ctx, ctrl_ctx, in xhci_free_streams()
3686 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3691 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_free_streams()
3700 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3702 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3703 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3704 vdev->eps[ep_index].stream_info = NULL; in xhci_free_streams()
3708 vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS; in xhci_free_streams()
3709 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_free_streams()
3711 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3721 * Must be called with xhci->lock held.
3723 void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci, in xhci_free_device_endpoint_resources() argument
3731 if (virt_dev->eps[i].ring) { in xhci_free_device_endpoint_resources()
3736 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3738 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_free_device_endpoint_resources()
3742 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3751 * xhci_address_device(), and then re-set up the configuration. If this is
3753 * settings will be re-installed through the normal bandwidth allocation
3762 * re-initialization during S3/S4. In this case, call xhci_alloc_dev() to
3763 * re-allocate the device.
3770 struct xhci_hcd *xhci; in xhci_discover_or_reset_device() local
3780 xhci = hcd_to_xhci(hcd); in xhci_discover_or_reset_device()
3781 slot_id = udev->slot_id; in xhci_discover_or_reset_device()
3782 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3784 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3785 "not exist. Re-allocate the device\n", slot_id); in xhci_discover_or_reset_device()
3790 return -EINVAL; in xhci_discover_or_reset_device()
3793 if (virt_dev->tt_info) in xhci_discover_or_reset_device()
3794 old_active_eps = virt_dev->tt_info->active_eps; in xhci_discover_or_reset_device()
3796 if (virt_dev->udev != udev) { in xhci_discover_or_reset_device()
3799 * Re-allocate the device. in xhci_discover_or_reset_device()
3801 xhci_dbg(xhci, "The device to be reset with slot ID %u does " in xhci_discover_or_reset_device()
3802 "not match the udev. Re-allocate the device\n", in xhci_discover_or_reset_device()
3808 return -EINVAL; in xhci_discover_or_reset_device()
3812 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3813 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_discover_or_reset_device()
3817 if (xhci->quirks & XHCI_ETRON_HOST) { in xhci_discover_or_reset_device()
3819 * Obtaining a new device slot to inform the xHCI host that in xhci_discover_or_reset_device()
3822 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_discover_or_reset_device()
3823 xhci_free_virt_device(xhci, udev->slot_id); in xhci_discover_or_reset_device()
3829 ret = -EINVAL; in xhci_discover_or_reset_device()
3836 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id); in xhci_discover_or_reset_device()
3843 reset_device_cmd = xhci_alloc_command(xhci, true, GFP_NOIO); in xhci_discover_or_reset_device()
3845 xhci_dbg(xhci, "Couldn't allocate command structure.\n"); in xhci_discover_or_reset_device()
3846 return -ENOMEM; in xhci_discover_or_reset_device()
3850 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3852 ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id); in xhci_discover_or_reset_device()
3854 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_discover_or_reset_device()
3855 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3858 xhci_ring_cmd_db(xhci); in xhci_discover_or_reset_device()
3859 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3862 wait_for_completion(reset_device_cmd->completion); in xhci_discover_or_reset_device()
3868 ret = reset_device_cmd->status; in xhci_discover_or_reset_device()
3872 xhci_warn(xhci, "Timeout waiting for reset device command\n"); in xhci_discover_or_reset_device()
3873 ret = -ETIME; in xhci_discover_or_reset_device()
3877 xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n", in xhci_discover_or_reset_device()
3879 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3880 xhci_dbg(xhci, "Not freeing device rings.\n"); in xhci_discover_or_reset_device()
3885 xhci_dbg(xhci, "Successful reset device command.\n"); in xhci_discover_or_reset_device()
3888 if (xhci_is_vendor_info_code(xhci, ret)) in xhci_discover_or_reset_device()
3890 xhci_warn(xhci, "Unknown completion code %u for " in xhci_discover_or_reset_device()
3892 ret = -EINVAL; in xhci_discover_or_reset_device()
3897 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3898 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3900 xhci_free_device_endpoint_resources(xhci, virt_dev, false); in xhci_discover_or_reset_device()
3901 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3906 struct xhci_virt_ep *ep = &virt_dev->eps[i]; in xhci_discover_or_reset_device()
3908 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_discover_or_reset_device()
3909 xhci_warn(xhci, "WARN: endpoint 0x%02x has streams on device reset, freeing streams.\n", in xhci_discover_or_reset_device()
3911 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3912 ep->stream_info = NULL; in xhci_discover_or_reset_device()
3913 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_discover_or_reset_device()
3916 if (ep->ring) { in xhci_discover_or_reset_device()
3917 xhci_debugfs_remove_endpoint(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3918 xhci_free_endpoint_ring(xhci, virt_dev, i); in xhci_discover_or_reset_device()
3920 if (!list_empty(&virt_dev->eps[i].bw_endpoint_list)) in xhci_discover_or_reset_device()
3921 xhci_drop_ep_from_interval_table(xhci, in xhci_discover_or_reset_device()
3922 &virt_dev->eps[i].bw_info, in xhci_discover_or_reset_device()
3923 virt_dev->bw_table, in xhci_discover_or_reset_device()
3925 &virt_dev->eps[i], in xhci_discover_or_reset_device()
3926 virt_dev->tt_info); in xhci_discover_or_reset_device()
3927 xhci_clear_endpoint_bw_info(&virt_dev->eps[i].bw_info); in xhci_discover_or_reset_device()
3930 xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); in xhci_discover_or_reset_device()
3931 virt_dev->flags = 0; in xhci_discover_or_reset_device()
3935 xhci_free_command(xhci, reset_device_cmd); in xhci_discover_or_reset_device()
3946 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_free_dev() local
3957 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3958 pm_runtime_put_noidle(hcd->self.controller); in xhci_free_dev()
3964 if (ret <= 0 && ret != -ENODEV) in xhci_free_dev()
3967 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3968 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3973 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING; in xhci_free_dev()
3974 virt_dev->udev = NULL; in xhci_free_dev()
3975 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3977 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3978 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3979 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3983 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id) in xhci_disable_slot() argument
3990 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_disable_slot()
3992 return -ENOMEM; in xhci_disable_slot()
3994 xhci_debugfs_remove_slot(xhci, slot_id); in xhci_disable_slot()
3996 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3998 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3999 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
4000 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
4001 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4003 return -ENODEV; in xhci_disable_slot()
4006 ret = xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, in xhci_disable_slot()
4009 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4013 xhci_ring_cmd_db(xhci); in xhci_disable_slot()
4014 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4016 wait_for_completion(command->completion); in xhci_disable_slot()
4018 if (command->status != COMP_SUCCESS) in xhci_disable_slot()
4019 xhci_warn(xhci, "Unsuccessful disable slot %u command, status %d\n", in xhci_disable_slot()
4020 slot_id, command->status); in xhci_disable_slot()
4022 xhci_free_command(xhci, command); in xhci_disable_slot()
4031 * Must be called with xhci->lock held.
4033 static int xhci_reserve_host_control_ep_resources(struct xhci_hcd *xhci) in xhci_reserve_host_control_ep_resources() argument
4035 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
4036 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
4039 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
4040 return -ENOMEM; in xhci_reserve_host_control_ep_resources()
4042 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
4043 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, in xhci_reserve_host_control_ep_resources()
4045 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
4056 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_alloc_dev() local
4063 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_alloc_dev()
4067 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4068 ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0); in xhci_alloc_dev()
4070 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4071 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); in xhci_alloc_dev()
4072 xhci_free_command(xhci, command); in xhci_alloc_dev()
4075 xhci_ring_cmd_db(xhci); in xhci_alloc_dev()
4076 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4078 wait_for_completion(command->completion); in xhci_alloc_dev()
4079 slot_id = command->slot_id; in xhci_alloc_dev()
4081 if (!slot_id || command->status != COMP_SUCCESS) { in xhci_alloc_dev()
4082 xhci_err(xhci, "Error while assigning device slot ID: %s\n", in xhci_alloc_dev()
4083 xhci_trb_comp_code_string(command->status)); in xhci_alloc_dev()
4084 xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", in xhci_alloc_dev()
4086 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
4087 xhci_free_command(xhci, command); in xhci_alloc_dev()
4091 xhci_free_command(xhci, command); in xhci_alloc_dev()
4093 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
4094 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4095 ret = xhci_reserve_host_control_ep_resources(xhci); in xhci_alloc_dev()
4097 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4098 xhci_warn(xhci, "Not enough host resources, " in xhci_alloc_dev()
4100 xhci->num_active_eps); in xhci_alloc_dev()
4103 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4109 if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO)) { in xhci_alloc_dev()
4110 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); in xhci_alloc_dev()
4113 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
4114 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
4117 udev->slot_id = slot_id; in xhci_alloc_dev()
4119 xhci_debugfs_create_slot(xhci, slot_id); in xhci_alloc_dev()
4125 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4126 pm_runtime_get_noresume(hcd->self.controller); in xhci_alloc_dev()
4133 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4134 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4140 * xhci_setup_device - issues an Address Device command to assign a unique
4156 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_setup_device() local
4162 mutex_lock(&xhci->mutex); in xhci_setup_device()
4164 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4165 ret = -ESHUTDOWN; in xhci_setup_device()
4169 if (!udev->slot_id) { in xhci_setup_device()
4170 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4171 "Bad Slot ID %d", udev->slot_id); in xhci_setup_device()
4172 ret = -EINVAL; in xhci_setup_device()
4176 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4181 * a zero-dereference was observed once due to virt_dev = 0. in xhci_setup_device()
4184 xhci_warn(xhci, "Virt dev invalid for slot_id 0x%x!\n", in xhci_setup_device()
4185 udev->slot_id); in xhci_setup_device()
4186 ret = -EINVAL; in xhci_setup_device()
4189 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4193 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_setup_device()
4195 xhci_dbg(xhci, "Slot already in default state\n"); in xhci_setup_device()
4200 command = xhci_alloc_command(xhci, true, GFP_KERNEL); in xhci_setup_device()
4202 ret = -ENOMEM; in xhci_setup_device()
4206 command->in_ctx = virt_dev->in_ctx; in xhci_setup_device()
4207 command->timeout_ms = timeout_ms; in xhci_setup_device()
4209 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4210 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_setup_device()
4212 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_setup_device()
4214 ret = -EINVAL; in xhci_setup_device()
4218 * If this is the first Set Address since device plug-in or in xhci_setup_device()
4219 * virt_device realloaction after a resume with an xHCI power loss, in xhci_setup_device()
4222 if (!slot_ctx->dev_info) in xhci_setup_device()
4223 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4226 xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); in xhci_setup_device()
4227 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); in xhci_setup_device()
4228 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4230 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4231 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4234 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4236 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4237 udev->slot_id, setup); in xhci_setup_device()
4239 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4240 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4244 xhci_ring_cmd_db(xhci); in xhci_setup_device()
4245 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4248 wait_for_completion(command->completion); in xhci_setup_device()
4254 switch (command->status) { in xhci_setup_device()
4257 xhci_warn(xhci, "Timeout while waiting for setup device command\n"); in xhci_setup_device()
4258 ret = -ETIME; in xhci_setup_device()
4262 xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", in xhci_setup_device()
4263 act, udev->slot_id); in xhci_setup_device()
4264 ret = -EINVAL; in xhci_setup_device()
4267 dev_warn(&udev->dev, "Device not responding to setup %s.\n", act); in xhci_setup_device()
4269 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4270 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4271 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4274 xhci_setup_addressable_virt_dev(xhci, udev); in xhci_setup_device()
4276 kfree(command->completion); in xhci_setup_device()
4278 return -EPROTO; in xhci_setup_device()
4280 dev_warn(&udev->dev, in xhci_setup_device()
4282 ret = -ENODEV; in xhci_setup_device()
4285 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4289 xhci_err(xhci, in xhci_setup_device()
4291 act, command->status); in xhci_setup_device()
4292 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4293 ret = -EINVAL; in xhci_setup_device()
4298 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4299 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4301 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4303 udev->slot_id, in xhci_setup_device()
4304 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4306 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4307 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4309 (unsigned long long)virt_dev->out_ctx->dma); in xhci_setup_device()
4310 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4311 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4316 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4317 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4319 ctrl_ctx->add_flags = 0; in xhci_setup_device()
4320 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4321 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4322 udev->devaddr = (u8)(le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4324 xhci_dbg_trace(xhci, trace_xhci_dbg_address, in xhci_setup_device()
4326 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4328 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4330 kfree(command->completion); in xhci_setup_device()
4359 return rhub->ports[port1 - 1]->hw_portnum + 1; in xhci_find_raw_port_number()
4366 static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, in xhci_change_max_exit_latency() argument
4376 command = xhci_alloc_command_with_ctx(xhci, true, GFP_KERNEL); in xhci_change_max_exit_latency()
4378 return -ENOMEM; in xhci_change_max_exit_latency()
4380 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4382 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4386 * xHC was re-initialized. Exit latency will be set later after in xhci_change_max_exit_latency()
4387 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4390 if (!virt_dev || max_exit_latency == virt_dev->current_mel) { in xhci_change_max_exit_latency()
4391 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4392 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4397 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_change_max_exit_latency()
4399 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4400 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4401 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_change_max_exit_latency()
4403 return -ENOMEM; in xhci_change_max_exit_latency()
4406 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4407 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4409 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_change_max_exit_latency()
4410 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4411 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); in xhci_change_max_exit_latency()
4412 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency); in xhci_change_max_exit_latency()
4413 slot_ctx->dev_state = 0; in xhci_change_max_exit_latency()
4415 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, in xhci_change_max_exit_latency()
4419 ret = xhci_configure_endpoint(xhci, udev, command, in xhci_change_max_exit_latency()
4423 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4424 virt_dev->current_mel = max_exit_latency; in xhci_change_max_exit_latency()
4425 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4428 xhci_free_command(xhci, command); in xhci_change_max_exit_latency()
4440 static int xhci_calculate_hird_besl(struct xhci_hcd *xhci, in xhci_calculate_hird_besl() argument
4447 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4448 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_hird_besl()
4464 besl_host = (u2del - 51) / 75 + 1; in xhci_calculate_hird_besl()
4482 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_usb2_hw_lpm_params()
4484 /* xHCI l1 is set in steps of 256us, xHCI 1.0 section 5.4.11.2 */ in xhci_calculate_usb2_hw_lpm_params()
4485 l1 = udev->l1_params.timeout / 256; in xhci_calculate_usb2_hw_lpm_params()
4499 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_set_usb2_hardware_lpm() local
4508 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4509 return -EPERM; in xhci_set_usb2_hardware_lpm()
4511 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4512 !udev->lpm_capable) in xhci_set_usb2_hardware_lpm()
4513 return -EPERM; in xhci_set_usb2_hardware_lpm()
4515 if (!udev->parent || udev->parent->parent || in xhci_set_usb2_hardware_lpm()
4516 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_set_usb2_hardware_lpm()
4517 return -EPERM; in xhci_set_usb2_hardware_lpm()
4519 if (udev->usb2_hw_lpm_capable != 1) in xhci_set_usb2_hardware_lpm()
4520 return -EPERM; in xhci_set_usb2_hardware_lpm()
4522 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4524 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4525 port_num = udev->portnum - 1; in xhci_set_usb2_hardware_lpm()
4526 pm_addr = ports[port_num]->addr + PORTPMSC; in xhci_set_usb2_hardware_lpm()
4528 hlpm_addr = ports[port_num]->addr + PORTHLPMC; in xhci_set_usb2_hardware_lpm()
4530 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", in xhci_set_usb2_hardware_lpm()
4535 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4538 * systems. See XHCI_DEFAULT_BESL definition in xhci.h in xhci_set_usb2_hardware_lpm()
4540 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_set_usb2_hardware_lpm()
4545 hird = udev->l1_params.besl; in xhci_set_usb2_hardware_lpm()
4548 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4550 ret = xhci_change_max_exit_latency(xhci, udev, in xhci_set_usb2_hardware_lpm()
4554 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4561 hird = xhci_calculate_hird_besl(xhci, udev); in xhci_set_usb2_hardware_lpm()
4565 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); in xhci_set_usb2_hardware_lpm()
4577 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4578 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4579 xhci_change_max_exit_latency(xhci, udev, 0); in xhci_set_usb2_hardware_lpm()
4580 readl_poll_timeout(ports[port_num]->addr, pm_val, in xhci_set_usb2_hardware_lpm()
4587 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4593 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_device() local
4598 if (hcd->speed >= HCD_USB3 && !udev->parent->parent) { in xhci_update_device()
4599 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_update_device()
4601 udev->tunnel_mode = xhci_port_is_tunneled(xhci, port); in xhci_update_device()
4602 if (udev->tunnel_mode == USB_LINK_UNKNOWN) in xhci_update_device()
4603 dev_dbg(&udev->dev, "link tunnel state unknown\n"); in xhci_update_device()
4604 else if (udev->tunnel_mode == USB_LINK_TUNNELED) in xhci_update_device()
4605 dev_dbg(&udev->dev, "tunneled over USB4 link\n"); in xhci_update_device()
4606 else if (udev->tunnel_mode == USB_LINK_NATIVE) in xhci_update_device()
4607 dev_dbg(&udev->dev, "native USB 3.x link\n"); in xhci_update_device()
4611 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable || !xhci->hw_lpm_support) in xhci_update_device()
4614 /* we only support lpm for non-hub device connected to root hub yet */ in xhci_update_device()
4615 if (!udev->parent || udev->parent->parent || in xhci_update_device()
4616 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_update_device()
4619 port = xhci->usb2_rhub.ports[udev->portnum - 1]; in xhci_update_device()
4620 capability = port->port_cap->protocol_caps; in xhci_update_device()
4623 udev->usb2_hw_lpm_capable = 1; in xhci_update_device()
4624 udev->l1_params.timeout = XHCI_L1_TIMEOUT; in xhci_update_device()
4625 udev->l1_params.besl = XHCI_DEFAULT_BESL; in xhci_update_device()
4627 udev->usb2_hw_lpm_besl_capable = 1; in xhci_update_device()
4633 /*---------------------- USB 3.0 Link PM functions ------------------------*/
4635 /* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
4639 return (1ULL << (desc->bInterval - 1)) * 125 * 1000; in xhci_service_interval_to_ns()
4653 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4654 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4659 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4660 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4665 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n", in xhci_get_timeout_no_hub_lpm()
4674 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4678 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4685 * - For control endpoints, U1 system exit latency (SEL) * 3
4686 * - For bulk endpoints, U1 SEL * 5
4687 * - For interrupt endpoints:
4688 * - Notification EPs, U1 SEL * 3
4689 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
4690 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
4703 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4706 timeout_ns = udev->u1_params.sel * 5; in xhci_calculate_intel_u1_timeout()
4711 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4719 if (timeout_ns < udev->u1_params.sel * 2) in xhci_calculate_intel_u1_timeout()
4720 timeout_ns = udev->u1_params.sel * 2; in xhci_calculate_intel_u1_timeout()
4729 /* Returns the hub-encoded U1 timeout value. */
4730 static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci, in xhci_calculate_u1_timeout() argument
4738 if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { in xhci_calculate_u1_timeout()
4739 dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); in xhci_calculate_u1_timeout()
4744 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4747 timeout_ns = udev->u1_params.sel; in xhci_calculate_u1_timeout()
4758 * USB 3.0 hub, we have to disable hub-initiated U1. in xhci_calculate_u1_timeout()
4762 dev_dbg(&udev->dev, "Hub-initiated U1 disabled " in xhci_calculate_u1_timeout()
4768 * - 10 ms (to avoid the bandwidth impact on the scheduler)
4769 * - largest bInterval of any active periodic endpoint (to avoid going
4771 * - the U2 Exit Latency of the device
4786 u2_del_ns = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat) * 1000ULL; in xhci_calculate_intel_u2_timeout()
4793 /* Returns the hub-encoded U2 timeout value. */
4794 static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci, in xhci_calculate_u2_timeout() argument
4802 if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { in xhci_calculate_u2_timeout()
4803 dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); in xhci_calculate_u2_timeout()
4808 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4811 timeout_ns = udev->u2_params.sel; in xhci_calculate_u2_timeout()
4816 * USB 3.0 hub, we have to disable hub-initiated U2. in xhci_calculate_u2_timeout()
4820 dev_dbg(&udev->dev, "Hub-initiated U2 disabled " in xhci_calculate_u2_timeout()
4825 static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_call_host_update_timeout_for_endpoint() argument
4832 return xhci_calculate_u1_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4834 return xhci_calculate_u2_timeout(xhci, udev, desc); in xhci_call_host_update_timeout_for_endpoint()
4839 static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci, in xhci_update_timeout_for_endpoint() argument
4847 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_endpoint()
4850 /* If we found we can't enable hub-initiated LPM, and in xhci_update_timeout_for_endpoint()
4852 * device-initiated LPM as well, then we will disable LPM in xhci_update_timeout_for_endpoint()
4857 return -E2BIG; in xhci_update_timeout_for_endpoint()
4864 static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci, in xhci_update_timeout_for_interface() argument
4872 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in xhci_update_timeout_for_interface()
4873 if (xhci_update_timeout_for_endpoint(xhci, udev, in xhci_update_timeout_for_interface()
4874 &alt->endpoint[j].desc, state, timeout)) in xhci_update_timeout_for_interface()
4875 return -E2BIG; in xhci_update_timeout_for_interface()
4880 static int xhci_check_tier_policy(struct xhci_hcd *xhci, in xhci_check_tier_policy() argument
4884 struct usb_device *parent = udev->parent; in xhci_check_tier_policy()
4888 parent = parent->parent; in xhci_check_tier_policy()
4892 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
4894 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
4899 dev_dbg(&udev->dev, "Tier policy prevents U1/U2 LPM states for devices at tier %d\n", in xhci_check_tier_policy()
4901 return -E2BIG; in xhci_check_tier_policy()
4905 * If the tier check or timeout setting functions return with a non-zero exit
4912 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_calculate_lpm_timeout() local
4923 dev_warn(&udev->dev, "Can't enable unknown link state %i\n", in xhci_calculate_lpm_timeout()
4931 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4935 config = udev->actconfig; in xhci_calculate_lpm_timeout()
4939 for (i = 0; i < config->desc.bNumInterfaces; i++) { in xhci_calculate_lpm_timeout()
4941 struct usb_interface *intf = config->interface[i]; in xhci_calculate_lpm_timeout()
4946 /* Check if any currently bound drivers want hub-initiated LPM in xhci_calculate_lpm_timeout()
4949 if (intf->dev.driver) { in xhci_calculate_lpm_timeout()
4950 driver = to_usb_driver(intf->dev.driver); in xhci_calculate_lpm_timeout()
4951 if (driver && driver->disable_hub_initiated_lpm) { in xhci_calculate_lpm_timeout()
4952 dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n", in xhci_calculate_lpm_timeout()
4953 state_name, driver->name); in xhci_calculate_lpm_timeout()
4962 if (!intf->cur_altsetting) in xhci_calculate_lpm_timeout()
4965 if (xhci_update_timeout_for_interface(xhci, udev, in xhci_calculate_lpm_timeout()
4966 intf->cur_altsetting, in xhci_calculate_lpm_timeout()
4998 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) || in calculate_max_exit_latency()
5000 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000); in calculate_max_exit_latency()
5001 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) || in calculate_max_exit_latency()
5003 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000); in calculate_max_exit_latency()
5007 /* xHCI host controller max exit latency field is only 16 bits wide. */ in calculate_max_exit_latency()
5009 dev_warn(&udev->dev, "Link PM max exit latency of %lluus " in calculate_max_exit_latency()
5011 return -E2BIG; in calculate_max_exit_latency()
5016 /* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
5020 struct xhci_hcd *xhci; in xhci_enable_usb3_lpm_timeout() local
5026 xhci = hcd_to_xhci(hcd); in xhci_enable_usb3_lpm_timeout()
5027 /* The LPM timeout values are pretty host-controller specific, so don't in xhci_enable_usb3_lpm_timeout()
5028 * enable hub-initiated timeouts unless the vendor has provided in xhci_enable_usb3_lpm_timeout()
5031 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
5032 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
5035 if (xhci_check_tier_policy(xhci, udev, state) < 0) in xhci_enable_usb3_lpm_timeout()
5039 if (udev->parent && !udev->parent->parent) { in xhci_enable_usb3_lpm_timeout()
5040 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
5041 if (port->lpm_incapable) in xhci_enable_usb3_lpm_timeout()
5053 ret = xhci_change_max_exit_latency(xhci, udev, mel); in xhci_enable_usb3_lpm_timeout()
5062 struct xhci_hcd *xhci; in xhci_disable_usb3_lpm_timeout() local
5065 xhci = hcd_to_xhci(hcd); in xhci_disable_usb3_lpm_timeout()
5066 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
5067 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
5071 return xhci_change_max_exit_latency(xhci, udev, mel); in xhci_disable_usb3_lpm_timeout()
5099 /*-------------------------------------------------------------------------*/
5107 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_update_hub_device() local
5117 if (!hdev->parent) in xhci_update_hub_device()
5120 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
5122 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n"); in xhci_update_hub_device()
5123 return -EINVAL; in xhci_update_hub_device()
5126 config_cmd = xhci_alloc_command_with_ctx(xhci, true, mem_flags); in xhci_update_hub_device()
5128 return -ENOMEM; in xhci_update_hub_device()
5130 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_update_hub_device()
5132 xhci_warn(xhci, "%s: Could not get input context, bad type.\n", in xhci_update_hub_device()
5134 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5135 return -ENOMEM; in xhci_update_hub_device()
5138 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5139 if (hdev->speed == USB_SPEED_HIGH && in xhci_update_hub_device()
5140 xhci_alloc_tt_info(xhci, vdev, hdev, tt, GFP_ATOMIC)) { in xhci_update_hub_device()
5141 xhci_dbg(xhci, "Could not allocate xHCI TT structure.\n"); in xhci_update_hub_device()
5142 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5143 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5144 return -ENOMEM; in xhci_update_hub_device()
5147 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5148 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_update_hub_device()
5149 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5150 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); in xhci_update_hub_device()
5153 * but it may be already set to 1 when setup an xHCI virtual in xhci_update_hub_device()
5156 if (tt->multi) in xhci_update_hub_device()
5157 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_update_hub_device()
5158 else if (hdev->speed == USB_SPEED_FULL) in xhci_update_hub_device()
5159 slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); in xhci_update_hub_device()
5161 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5162 xhci_dbg(xhci, "xHCI version %x needs hub " in xhci_update_hub_device()
5164 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5165 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(hdev->maxchild)); in xhci_update_hub_device()
5166 /* Set TT think time - convert from ns to FS bit times. in xhci_update_hub_device()
5170 * xHCI 1.0: this field shall be 0 if the device is not a in xhci_update_hub_device()
5171 * High-spped hub. in xhci_update_hub_device()
5173 think_time = tt->think_time; in xhci_update_hub_device()
5175 think_time = (think_time / 666) - 1; in xhci_update_hub_device()
5176 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5177 slot_ctx->tt_info |= in xhci_update_hub_device()
5180 xhci_dbg(xhci, "xHCI version %x doesn't need hub " in xhci_update_hub_device()
5182 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5184 slot_ctx->dev_state = 0; in xhci_update_hub_device()
5185 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5187 xhci_dbg(xhci, "Set up %s for hub device.\n", in xhci_update_hub_device()
5188 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5194 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5195 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5198 ret = xhci_configure_endpoint(xhci, hdev, config_cmd, in xhci_update_hub_device()
5201 xhci_free_command(xhci, config_cmd); in xhci_update_hub_device()
5208 struct xhci_hcd *xhci = hcd_to_xhci(hcd); in xhci_get_frame() local
5210 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5213 static void xhci_hcd_init_usb2_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb2_data() argument
5215 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5216 hcd->speed = HCD_USB2; in xhci_hcd_init_usb2_data()
5217 hcd->self.root_hub->speed = USB_SPEED_HIGH; in xhci_hcd_init_usb2_data()
5219 * USB 2.0 roothub under xHCI has an integrated TT, in xhci_hcd_init_usb2_data()
5223 hcd->has_tt = 1; in xhci_hcd_init_usb2_data()
5226 static void xhci_hcd_init_usb3_data(struct xhci_hcd *xhci, struct usb_hcd *hcd) in xhci_hcd_init_usb3_data() argument
5231 * Early xHCI 1.1 spec did not mention USB 3.1 capable hosts in xhci_hcd_init_usb3_data()
5233 * is a two digit BCD containig minor and sub-minor numbers. in xhci_hcd_init_usb3_data()
5234 * This was later clarified in xHCI 1.2. in xhci_hcd_init_usb3_data()
5239 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5242 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5246 hcd->speed = HCD_USB32; in xhci_hcd_init_usb3_data()
5247 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5248 hcd->self.root_hub->rx_lanes = 2; in xhci_hcd_init_usb3_data()
5249 hcd->self.root_hub->tx_lanes = 2; in xhci_hcd_init_usb3_data()
5250 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x2; in xhci_hcd_init_usb3_data()
5253 hcd->speed = HCD_USB31; in xhci_hcd_init_usb3_data()
5254 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5255 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x1; in xhci_hcd_init_usb3_data()
5258 xhci_info(xhci, "Host supports USB 3.%x %sSuperSpeed\n", in xhci_hcd_init_usb3_data()
5261 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5266 struct xhci_hcd *xhci; in xhci_gen_setup() local
5271 struct device *dev = hcd->self.sysdev; in xhci_gen_setup()
5274 /* Accept arbitrarily long scatter-gather lists */ in xhci_gen_setup()
5275 hcd->self.sg_tablesize = ~0; in xhci_gen_setup()
5278 hcd->self.no_sg_constraint = 1; in xhci_gen_setup()
5280 /* XHCI controllers don't stop the ep queue on short packets :| */ in xhci_gen_setup()
5281 hcd->self.no_stop_on_short = 1; in xhci_gen_setup()
5283 xhci = hcd_to_xhci(hcd); in xhci_gen_setup()
5286 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5290 mutex_init(&xhci->mutex); in xhci_gen_setup()
5291 xhci->main_hcd = hcd; in xhci_gen_setup()
5292 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5293 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5294 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5295 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5296 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5297 /* Cache read-only capability registers */ in xhci_gen_setup()
5298 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5299 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5300 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5301 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5302 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5303 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5304 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5306 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5307 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5308 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5309 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5311 xhci->quirks |= quirks; in xhci_gen_setup()
5314 get_quirks(dev, xhci); in xhci_gen_setup()
5316 /* In xhci controllers which follow xhci 1.0 spec gives a spurious in xhci_gen_setup()
5320 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5321 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5323 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_gen_setup()
5324 xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits"); in xhci_gen_setup()
5325 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_gen_setup()
5329 retval = xhci_halt(xhci); in xhci_gen_setup()
5333 xhci_zero_64b_regs(xhci); in xhci_gen_setup()
5335 xhci_dbg(xhci, "Resetting HCD\n"); in xhci_gen_setup()
5337 retval = xhci_reset(xhci, XHCI_RESET_LONG_USEC); in xhci_gen_setup()
5340 xhci_dbg(xhci, "Reset complete\n"); in xhci_gen_setup()
5343 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5344 * of HCCPARAMS1 is set to 1. However, the xHCs don't support 64-bit in xhci_gen_setup()
5346 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5349 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5350 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5352 /* Set dma_mask and coherent_dma_mask to 64-bits, in xhci_gen_setup()
5353 * if xHC supports 64-bit addressing */ in xhci_gen_setup()
5354 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5356 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5360 * This is to avoid error in cases where a 32-bit USB in xhci_gen_setup()
5361 * controller is used on a 64-bit capable system. in xhci_gen_setup()
5366 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5370 xhci_dbg(xhci, "Calling HCD init\n"); in xhci_gen_setup()
5375 xhci_dbg(xhci, "Called HCD init\n"); in xhci_gen_setup()
5378 xhci_hcd_init_usb3_data(xhci, hcd); in xhci_gen_setup()
5380 xhci_hcd_init_usb2_data(xhci, hcd); in xhci_gen_setup()
5382 xhci_info(xhci, "hcc params 0x%08x hci version 0x%x quirks 0x%016llx\n", in xhci_gen_setup()
5383 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5392 struct xhci_hcd *xhci; in xhci_clear_tt_buffer_complete() local
5398 xhci = hcd_to_xhci(hcd); in xhci_clear_tt_buffer_complete()
5400 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5401 udev = (struct usb_device *)ep->hcpriv; in xhci_clear_tt_buffer_complete()
5402 slot_id = udev->slot_id; in xhci_clear_tt_buffer_complete()
5403 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_clear_tt_buffer_complete()
5405 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5406 xhci_ring_doorbell_for_active_rings(xhci, slot_id, ep_index); in xhci_clear_tt_buffer_complete()
5407 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5411 .description = "xhci-hcd",
5412 .product_desc = "xHCI Host Controller",
5416 * generic hardware linkage
5482 /* Copy the generic table to drv then apply the overrides */ in xhci_init_driver()
5486 drv->hcd_priv_size += over->extra_priv_size; in xhci_init_driver()
5487 if (over->reset) in xhci_init_driver()
5488 drv->reset = over->reset; in xhci_init_driver()
5489 if (over->start) in xhci_init_driver()
5490 drv->start = over->start; in xhci_init_driver()
5491 if (over->add_endpoint) in xhci_init_driver()
5492 drv->add_endpoint = over->add_endpoint; in xhci_init_driver()
5493 if (over->drop_endpoint) in xhci_init_driver()
5494 drv->drop_endpoint = over->drop_endpoint; in xhci_init_driver()
5495 if (over->check_bandwidth) in xhci_init_driver()
5496 drv->check_bandwidth = over->check_bandwidth; in xhci_init_driver()
5497 if (over->reset_bandwidth) in xhci_init_driver()
5498 drv->reset_bandwidth = over->reset_bandwidth; in xhci_init_driver()
5499 if (over->update_hub_device) in xhci_init_driver()
5500 drv->update_hub_device = over->update_hub_device; in xhci_init_driver()
5501 if (over->hub_control) in xhci_init_driver()
5502 drv->hub_control = over->hub_control; in xhci_init_driver()
5532 return -ENODEV; in xhci_hcd_init()