• Home
  • Raw
  • Download

Lines Matching +full:additional +full:- +full:devs

1 // SPDX-License-Identifier: GPL-2.0
20 #include <linux/dma-mapping.h>
23 #include "xhci-trace.h"
24 #include "xhci-mtk.h"
25 #include "xhci-debugfs.h"
26 #include "xhci-dbgcap.h"
44 struct xhci_segment *seg = ring->first_seg; in td_on_ring()
46 if (!td || !td->start_seg) in td_on_ring()
49 if (seg == td->start_seg) in td_on_ring()
51 seg = seg->next; in td_on_ring()
52 } while (seg && seg != ring->first_seg); in td_on_ring()
58 * xhci_handshake - spin reading hc until handshake completes or fails
68 * hardware flakeout), or the register reads as all-ones (hardware removed).
80 return -ENODEV; in xhci_handshake()
95 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
99 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
101 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
118 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
124 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
125 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
137 temp = readl(&xhci->op_regs->command); in xhci_start()
141 writel(temp, &xhci->op_regs->command); in xhci_start()
147 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
149 if (ret == -ETIMEDOUT) in xhci_start()
155 xhci->xhc_state = 0; in xhci_start()
156 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
175 state = readl(&xhci->op_regs->status); in xhci_reset()
179 return -ENODEV; in xhci_reset()
188 command = readl(&xhci->op_regs->command); in xhci_reset()
190 writel(command, &xhci->op_regs->command); in xhci_reset()
199 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
202 ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us); in xhci_reset()
206 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
207 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
215 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
217 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
218 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
219 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
220 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
221 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
222 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
229 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
250 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
251 domain->type == IOMMU_DOMAIN_IDENTITY) in xhci_zero_64b_regs()
257 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
259 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
262 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
264 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
267 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
269 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
270 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
272 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
274 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
275 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
280 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
281 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
283 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
284 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
286 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
290 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
307 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); in xhci_setup_msi()
316 ret = request_irq(pdev->irq, xhci_msi_irq, in xhci_setup_msi()
328 * Set up MSI-X
334 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); in xhci_setup_msix()
337 * calculate number of msi-x vectors supported. in xhci_setup_msix()
338 * - HCS_MAX_INTRS: the max number of interrupts the host can handle, in xhci_setup_msix()
340 * - num_online_cpus: maximum msi-x vectors per CPUs core. in xhci_setup_msix()
341 * Add additional 1 vector to ensure always available interrupt. in xhci_setup_msix()
343 xhci->msix_count = min(num_online_cpus() + 1, in xhci_setup_msix()
344 HCS_MAX_INTRS(xhci->hcs_params1)); in xhci_setup_msix()
346 ret = pci_alloc_irq_vectors(pdev, xhci->msix_count, xhci->msix_count, in xhci_setup_msix()
350 "Failed to enable MSI-X"); in xhci_setup_msix()
354 for (i = 0; i < xhci->msix_count; i++) { in xhci_setup_msix()
361 hcd->msix_enabled = 1; in xhci_setup_msix()
365 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); in xhci_setup_msix()
366 while (--i >= 0) in xhci_setup_msix()
372 /* Free any IRQs and disable MSI-X */
376 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); in xhci_cleanup_msix()
378 if (xhci->quirks & XHCI_PLAT) in xhci_cleanup_msix()
382 if (hcd->irq > 0) in xhci_cleanup_msix()
385 if (hcd->msix_enabled) { in xhci_cleanup_msix()
388 for (i = 0; i < xhci->msix_count; i++) in xhci_cleanup_msix()
395 hcd->msix_enabled = 0; in xhci_cleanup_msix()
402 if (hcd->msix_enabled) { in xhci_msix_sync_irqs()
403 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); in xhci_msix_sync_irqs()
406 for (i = 0; i < xhci->msix_count; i++) in xhci_msix_sync_irqs()
418 if (xhci->quirks & XHCI_PLAT) in xhci_try_enable_msi()
421 pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); in xhci_try_enable_msi()
426 if (xhci->quirks & XHCI_BROKEN_MSI) in xhci_try_enable_msi()
430 if (hcd->irq) in xhci_try_enable_msi()
431 free_irq(hcd->irq, hcd); in xhci_try_enable_msi()
432 hcd->irq = 0; in xhci_try_enable_msi()
440 hcd->msi_enabled = 1; in xhci_try_enable_msi()
444 if (!pdev->irq) { in xhci_try_enable_msi()
445 xhci_err(xhci, "No msi-x/msi found and no IRQ in BIOS\n"); in xhci_try_enable_msi()
446 return -EINVAL; in xhci_try_enable_msi()
450 if (!strlen(hcd->irq_descr)) in xhci_try_enable_msi()
451 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in xhci_try_enable_msi()
452 hcd->driver->description, hcd->self.busnum); in xhci_try_enable_msi()
455 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, in xhci_try_enable_msi()
456 hcd->irq_descr, hcd); in xhci_try_enable_msi()
459 pdev->irq); in xhci_try_enable_msi()
462 hcd->irq = pdev->irq; in xhci_try_enable_msi()
492 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
494 for (i = 0; i < rhub->num_ports; i++) { in compliance_mode_recovery()
495 temp = readl(rhub->ports[i]->addr); in compliance_mode_recovery()
502 "Compliance mode detected->port %d", in compliance_mode_recovery()
506 hcd = xhci->shared_hcd; in compliance_mode_recovery()
508 if (hcd->state == HC_STATE_SUSPENDED) in compliance_mode_recovery()
515 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
516 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
521 * Quirk to work around issue generated by the SN65LVPE502CP USB3.0 re-driver
532 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
533 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
535 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
538 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
545 * USB3.0 re-driver and that need the Compliance Mode Quirk.
547 * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820
558 if (!(strstr(dmi_sys_vendor, "Hewlett-Packard"))) in xhci_compliance_mode_recovery_timer_quirk_check()
572 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
577 * Initialize memory for HCD and xHC (one-time init).
589 spin_lock_init(&xhci->lock); in xhci_init()
590 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_init()
593 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_init()
603 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
610 /*-------------------------------------------------------------------------*/
617 return -ENODEV; in xhci_run_finished()
619 xhci->shared_hcd->state = HC_STATE_RUNNING; in xhci_run_finished()
620 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
622 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
640 * Setup MSI-X vectors and enable interrupts.
653 hcd->uses_new_polling = 1; in xhci_run()
663 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_run()
670 temp = readl(&xhci->ir_set->irq_control); in xhci_run()
672 temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; in xhci_run()
673 writel(temp, &xhci->ir_set->irq_control); in xhci_run()
676 temp = readl(&xhci->op_regs->command); in xhci_run()
680 writel(temp, &xhci->op_regs->command); in xhci_run()
682 temp = readl(&xhci->ir_set->irq_pending); in xhci_run()
685 xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); in xhci_run()
686 writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); in xhci_run()
688 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
693 return -ENOMEM; in xhci_run()
703 set_bit(HCD_FLAG_DEFER_RH_REGISTER, &hcd->flags); in xhci_run()
727 mutex_lock(&xhci->mutex); in xhci_stop()
731 mutex_unlock(&xhci->mutex); in xhci_stop()
737 spin_lock_irq(&xhci->lock); in xhci_stop()
738 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
739 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
742 spin_unlock_irq(&xhci->lock); in xhci_stop()
747 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
749 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
755 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
760 temp = readl(&xhci->op_regs->status); in xhci_stop()
761 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
762 temp = readl(&xhci->ir_set->irq_pending); in xhci_stop()
763 writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending); in xhci_stop()
769 "xhci_stop completed - status = %x", in xhci_stop()
770 readl(&xhci->op_regs->status)); in xhci_stop()
771 mutex_unlock(&xhci->mutex); in xhci_stop()
775 * Shutdown HC (not bus-specific)
787 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
788 usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev)); in xhci_shutdown()
792 __func__, hcd->self.busnum); in xhci_shutdown()
793 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_shutdown()
794 del_timer_sync(&hcd->rh_timer); in xhci_shutdown()
796 if (xhci->shared_hcd) { in xhci_shutdown()
797 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
798 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
801 spin_lock_irq(&xhci->lock); in xhci_shutdown()
806 * firmware delay in ADL-P PCH if port are left in U3 at shutdown in xhci_shutdown()
808 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
809 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
812 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
817 "xhci_shutdown completed - status = %x", in xhci_shutdown()
818 readl(&xhci->op_regs->status)); in xhci_shutdown()
825 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
826 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
827 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
828 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
829 xhci->s3.erst_size = readl(&xhci->ir_set->erst_size); in xhci_save_registers()
830 xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base); in xhci_save_registers()
831 xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_save_registers()
832 xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending); in xhci_save_registers()
833 xhci->s3.irq_control = readl(&xhci->ir_set->irq_control); in xhci_save_registers()
838 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
839 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
840 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
841 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
842 writel(xhci->s3.erst_size, &xhci->ir_set->erst_size); in xhci_restore_registers()
843 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base); in xhci_restore_registers()
844 xhci_write_64(xhci, xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue); in xhci_restore_registers()
845 writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending); in xhci_restore_registers()
846 writel(xhci->s3.irq_control, &xhci->ir_set->irq_control); in xhci_restore_registers()
854 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
856 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
857 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
859 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
863 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
870 * need to re-program it on resume. Unfortunately, the pointer must be 64-byte
873 * middle of the ring (TRBs are 16-byte aligned).
880 ring = xhci->cmd_ring; in xhci_clear_command_ring()
881 seg = ring->deq_seg; in xhci_clear_command_ring()
883 memset(seg->trbs, 0, in xhci_clear_command_ring()
884 sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); in xhci_clear_command_ring()
885 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= in xhci_clear_command_ring()
887 seg = seg->next; in xhci_clear_command_ring()
888 } while (seg != ring->deq_seg); in xhci_clear_command_ring()
891 ring->deq_seg = ring->first_seg; in xhci_clear_command_ring()
892 ring->dequeue = ring->first_seg->trbs; in xhci_clear_command_ring()
893 ring->enq_seg = ring->deq_seg; in xhci_clear_command_ring()
894 ring->enqueue = ring->dequeue; in xhci_clear_command_ring()
896 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in xhci_clear_command_ring()
901 ring->cycle_state = 1; in xhci_clear_command_ring()
905 * Yes, this will need to be re-written after resume, but we're paranoid in xhci_clear_command_ring()
930 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
932 for (i = 0; i < rhub->num_ports; i++) { in xhci_disable_hub_port_wake()
933 portsc = readl(rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
946 writel(t2, rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
947 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
948 rhub->hcd->self.busnum, i + 1, portsc, t2); in xhci_disable_hub_port_wake()
951 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
961 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
970 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
971 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
972 while (port_index--) { in xhci_pending_portevent()
973 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
978 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
979 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
980 while (port_index--) { in xhci_pending_portevent()
981 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
990 * Stop HC (not bus-specific)
1003 if (!hcd->state) in xhci_suspend()
1006 if (hcd->state != HC_STATE_SUSPENDED || in xhci_suspend()
1007 xhci->shared_hcd->state != HC_STATE_SUSPENDED) in xhci_suspend()
1008 return -EINVAL; in xhci_suspend()
1011 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
1012 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
1021 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_suspend()
1022 del_timer_sync(&hcd->rh_timer); in xhci_suspend()
1023 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
1024 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
1026 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
1029 spin_lock_irq(&xhci->lock); in xhci_suspend()
1030 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_suspend()
1031 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
1036 command = readl(&xhci->op_regs->command); in xhci_suspend()
1038 writel(command, &xhci->op_regs->command); in xhci_suspend()
1041 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
1043 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
1046 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1047 return -ETIMEDOUT; in xhci_suspend()
1055 command = readl(&xhci->op_regs->command); in xhci_suspend()
1057 writel(command, &xhci->op_regs->command); in xhci_suspend()
1058 xhci->broken_suspend = 0; in xhci_suspend()
1059 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
1070 res = readl(&xhci->op_regs->status); in xhci_suspend()
1071 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
1074 xhci->broken_suspend = 1; in xhci_suspend()
1077 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1078 return -ETIMEDOUT; in xhci_suspend()
1081 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1087 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
1089 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
1096 /* synchronize irq when using MSI-X */ in xhci_suspend()
1104 * start xHC (not bus-specific)
1119 if (!hcd->state) in xhci_resume()
1126 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
1127 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
1130 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_resume()
1131 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
1133 spin_lock_irq(&xhci->lock); in xhci_resume()
1135 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
1143 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1148 spin_unlock_irq(&xhci->lock); in xhci_resume()
1157 command = readl(&xhci->op_regs->command); in xhci_resume()
1159 writel(command, &xhci->op_regs->command); in xhci_resume()
1165 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1168 spin_unlock_irq(&xhci->lock); in xhci_resume()
1169 return -ETIMEDOUT; in xhci_resume()
1173 temp = readl(&xhci->op_regs->status); in xhci_resume()
1175 /* re-initialize the HC on Restore Error, or Host Controller Error */ in xhci_resume()
1178 if (!xhci->broken_suspend) in xhci_resume()
1183 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1185 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1191 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1192 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1198 spin_unlock_irq(&xhci->lock); in xhci_resume()
1204 temp = readl(&xhci->op_regs->status); in xhci_resume()
1205 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1206 temp = readl(&xhci->ir_set->irq_pending); in xhci_resume()
1207 writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending); in xhci_resume()
1212 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1213 readl(&xhci->op_regs->status)); in xhci_resume()
1222 secondary_hcd = xhci->shared_hcd; in xhci_resume()
1225 retval = xhci_init(hcd->primary_hcd); in xhci_resume()
1231 retval = xhci_run(hcd->primary_hcd); in xhci_resume()
1236 hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1237 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1242 command = readl(&xhci->op_regs->command); in xhci_resume()
1244 writel(command, &xhci->op_regs->command); in xhci_resume()
1245 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1257 spin_unlock_irq(&xhci->lock); in xhci_resume()
1275 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1281 * be re-initialized Always after a system resume. Ports are subject in xhci_resume()
1285 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1288 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1289 usb_asmedia_modifyflowcontrol(to_pci_dev(hcd->self.controller)); in xhci_resume()
1291 /* Re-enable port polling. */ in xhci_resume()
1293 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1294 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1295 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_resume()
1303 /*-------------------------------------------------------------------------*/
1321 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and
1325 * Index = (epnum * 2) + direction - 1,
1328 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
1337 (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; in xhci_get_endpoint_index()
1377 return fls(added_ctxs) - 1; in xhci_last_valid_endpoint()
1381 * returns 0 this is a root hub; returns -EINVAL for NULL pointers.
1391 return -EINVAL; in xhci_check_args()
1393 if (!udev->parent) { in xhci_check_args()
1400 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1403 return -EINVAL; in xhci_check_args()
1406 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1407 if (virt_dev->udev != udev) { in xhci_check_args()
1410 return -EINVAL; in xhci_check_args()
1414 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1415 return -ENODEV; in xhci_check_args()
1441 out_ctx = xhci->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
1443 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); in xhci_check_maxpacket()
1444 max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); in xhci_check_maxpacket()
1458 /* FIXME: This won't work if a non-default control endpoint in xhci_check_maxpacket()
1464 return -ENOMEM; in xhci_check_maxpacket()
1466 command->in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
1467 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_maxpacket()
1471 ret = -ENOMEM; in xhci_check_maxpacket()
1475 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
1476 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
1478 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_check_maxpacket()
1479 ep_ctx->ep_info &= cpu_to_le32(~EP_STATE_MASK);/* must clear */ in xhci_check_maxpacket()
1480 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); in xhci_check_maxpacket()
1481 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); in xhci_check_maxpacket()
1483 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); in xhci_check_maxpacket()
1484 ctrl_ctx->drop_flags = 0; in xhci_check_maxpacket()
1486 ret = xhci_configure_endpoint(xhci, urb->dev, command, in xhci_check_maxpacket()
1492 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_check_maxpacket()
1494 kfree(command->completion); in xhci_check_maxpacket()
1501 * non-error returns are a promise to giveback() the urb later
1515 return -EINVAL; in xhci_urb_enqueue()
1516 ret = xhci_check_args(hcd, urb->dev, urb->ep, in xhci_urb_enqueue()
1519 return ret ? ret : -EINVAL; in xhci_urb_enqueue()
1521 slot_id = urb->dev->slot_id; in xhci_urb_enqueue()
1522 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_enqueue()
1523 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1528 return -ESHUTDOWN; in xhci_urb_enqueue()
1530 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1532 return -ENODEV; in xhci_urb_enqueue()
1535 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) in xhci_urb_enqueue()
1536 num_tds = urb->number_of_packets; in xhci_urb_enqueue()
1537 else if (usb_endpoint_is_bulk_out(&urb->ep->desc) && in xhci_urb_enqueue()
1538 urb->transfer_buffer_length > 0 && in xhci_urb_enqueue()
1539 urb->transfer_flags & URB_ZERO_PACKET && in xhci_urb_enqueue()
1540 !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc))) in xhci_urb_enqueue()
1547 return -ENOMEM; in xhci_urb_enqueue()
1549 urb_priv->num_tds = num_tds; in xhci_urb_enqueue()
1550 urb_priv->num_tds_done = 0; in xhci_urb_enqueue()
1551 urb->hcpriv = urb_priv; in xhci_urb_enqueue()
1555 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in xhci_urb_enqueue()
1559 if (urb->dev->speed == USB_SPEED_FULL) { in xhci_urb_enqueue()
1564 urb->hcpriv = NULL; in xhci_urb_enqueue()
1570 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1572 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1573 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1574 urb->ep->desc.bEndpointAddress, urb); in xhci_urb_enqueue()
1575 ret = -ESHUTDOWN; in xhci_urb_enqueue()
1581 ret = -EINVAL; in xhci_urb_enqueue()
1586 ret = -EINVAL; in xhci_urb_enqueue()
1590 switch (usb_endpoint_type(&urb->ep->desc)) { in xhci_urb_enqueue()
1612 urb->hcpriv = NULL; in xhci_urb_enqueue()
1614 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1634 * series of 1-TRB transfer no-op TDs. (No-ops shouldn't be chained.) The
1664 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1674 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1675 urb_priv = urb->hcpriv; in xhci_urb_dequeue()
1679 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_dequeue()
1680 ep = &vdev->eps[ep_index]; in xhci_urb_dequeue()
1686 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1687 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1693 * check ring is not re-allocated since URB was enqueued. If it is, then in xhci_urb_dequeue()
1697 if (!td_on_ring(&urb_priv->td[0], ep_ring)) { in xhci_urb_dequeue()
1699 for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1700 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1701 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1702 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1707 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1710 for (i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1711 i < urb_priv->num_tds; in xhci_urb_dequeue()
1713 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1714 if (!list_empty(&td->td_list)) in xhci_urb_dequeue()
1715 list_del_init(&td->td_list); in xhci_urb_dequeue()
1716 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1717 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1722 i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1723 if (i < urb_priv->num_tds) in xhci_urb_dequeue()
1727 urb, urb->dev->devpath, in xhci_urb_dequeue()
1728 urb->ep->desc.bEndpointAddress, in xhci_urb_dequeue()
1730 urb_priv->td[i].start_seg, in xhci_urb_dequeue()
1731 urb_priv->td[i].first_trb)); in xhci_urb_dequeue()
1733 for (; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1734 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1735 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); in xhci_urb_dequeue()
1741 if (!(ep->ep_state & EP_STOP_CMD_PENDING)) { in xhci_urb_dequeue()
1744 ret = -ENOMEM; in xhci_urb_dequeue()
1747 ep->ep_state |= EP_STOP_CMD_PENDING; in xhci_urb_dequeue()
1748 ep->stop_cmd_timer.expires = jiffies + in xhci_urb_dequeue()
1750 add_timer(&ep->stop_cmd_timer); in xhci_urb_dequeue()
1751 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1756 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1763 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1764 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN); in xhci_urb_dequeue()
1779 * the xhci->devs[slot_id] structure.
1797 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1798 return -ENODEV; in xhci_drop_endpoint()
1801 drop_flag = xhci_get_endpoint_flag(&ep->desc); in xhci_drop_endpoint()
1803 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1808 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1809 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1817 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_drop_endpoint()
1823 le32_to_cpu(ctrl_ctx->drop_flags) & in xhci_drop_endpoint()
1824 xhci_get_endpoint_flag(&ep->desc)) { in xhci_drop_endpoint()
1826 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1832 ctrl_ctx->drop_flags |= cpu_to_le32(drop_flag); in xhci_drop_endpoint()
1833 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_drop_endpoint()
1835 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); in xhci_drop_endpoint()
1836 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_drop_endpoint()
1838 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1840 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1842 if (xhci->quirks & XHCI_MTK_HOST) in xhci_drop_endpoint()
1846 (unsigned int) ep->desc.bEndpointAddress, in xhci_drop_endpoint()
1847 udev->slot_id, in xhci_drop_endpoint()
1864 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1882 ep->hcpriv = NULL; in xhci_add_endpoint()
1886 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1887 return -ENODEV; in xhci_add_endpoint()
1889 added_ctxs = xhci_get_endpoint_flag(&ep->desc); in xhci_add_endpoint()
1895 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1900 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1901 in_ctx = virt_dev->in_ctx; in xhci_add_endpoint()
1909 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_add_endpoint()
1913 if (virt_dev->eps[ep_index].ring && in xhci_add_endpoint()
1914 !(le32_to_cpu(ctrl_ctx->drop_flags) & added_ctxs)) { in xhci_add_endpoint()
1917 (unsigned int) ep->desc.bEndpointAddress); in xhci_add_endpoint()
1918 return -EINVAL; in xhci_add_endpoint()
1924 if (le32_to_cpu(ctrl_ctx->add_flags) & added_ctxs) { in xhci_add_endpoint()
1936 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", in xhci_add_endpoint()
1937 __func__, ep->desc.bEndpointAddress); in xhci_add_endpoint()
1938 return -ENOMEM; in xhci_add_endpoint()
1941 if (xhci->quirks & XHCI_MTK_HOST) { in xhci_add_endpoint()
1944 xhci_ring_free(xhci, virt_dev->eps[ep_index].new_ring); in xhci_add_endpoint()
1945 virt_dev->eps[ep_index].new_ring = NULL; in xhci_add_endpoint()
1950 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs); in xhci_add_endpoint()
1951 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_add_endpoint()
1955 * this re-adds a new state for the endpoint from the new endpoint in xhci_add_endpoint()
1956 * descriptors. We must drop and re-add this endpoint, so we leave the in xhci_add_endpoint()
1959 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_add_endpoint()
1962 ep->hcpriv = udev; in xhci_add_endpoint()
1964 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1968 (unsigned int) ep->desc.bEndpointAddress, in xhci_add_endpoint()
1969 udev->slot_id, in xhci_add_endpoint()
1982 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_zero_in_ctx()
1994 ctrl_ctx->drop_flags = 0; in xhci_zero_in_ctx()
1995 ctrl_ctx->add_flags = 0; in xhci_zero_in_ctx()
1996 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
1997 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_zero_in_ctx()
1999 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in xhci_zero_in_ctx()
2001 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
2002 ep_ctx->ep_info = 0; in xhci_zero_in_ctx()
2003 ep_ctx->ep_info2 = 0; in xhci_zero_in_ctx()
2004 ep_ctx->deq = 0; in xhci_zero_in_ctx()
2005 ep_ctx->tx_info = 0; in xhci_zero_in_ctx()
2018 ret = -ETIME; in xhci_configure_endpoint_result()
2021 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2023 ret = -ENOMEM; in xhci_configure_endpoint_result()
2028 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2030 ret = -ENOSPC; in xhci_configure_endpoint_result()
2035 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " in xhci_configure_endpoint_result()
2038 ret = -EINVAL; in xhci_configure_endpoint_result()
2041 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2043 ret = -ENODEV; in xhci_configure_endpoint_result()
2053 ret = -EINVAL; in xhci_configure_endpoint_result()
2068 ret = -ETIME; in xhci_evaluate_context_result()
2071 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2073 ret = -EINVAL; in xhci_evaluate_context_result()
2076 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2078 ret = -EINVAL; in xhci_evaluate_context_result()
2081 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2083 ret = -EINVAL; in xhci_evaluate_context_result()
2086 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2088 ret = -ENODEV; in xhci_evaluate_context_result()
2092 dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); in xhci_evaluate_context_result()
2093 ret = -EINVAL; in xhci_evaluate_context_result()
2103 ret = -EINVAL; in xhci_evaluate_context_result()
2119 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_new_endpoints()
2120 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_new_endpoints()
2126 return hweight32(valid_add_flags) - in xhci_count_num_new_endpoints()
2136 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_dropped_endpoints()
2137 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_dropped_endpoints()
2139 return hweight32(valid_drop_flags) - in xhci_count_num_dropped_endpoints()
2149 * - the first configure endpoint command drops more endpoints than it adds
2150 * - a second configure endpoint command that adds more endpoints is queued
2151 * - the first configure endpoint command fails, so the config is unchanged
2152 * - the second command may succeed, even though there isn't enough resources
2154 * Must be called with xhci->lock held.
2162 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2166 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2167 xhci->limit_active_eps); in xhci_reserve_host_resources()
2168 return -ENOMEM; in xhci_reserve_host_resources()
2170 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2173 xhci->num_active_eps); in xhci_reserve_host_resources()
2181 * Must be called with xhci->lock held.
2189 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2193 xhci->num_active_eps); in xhci_free_host_resources()
2200 * Must be called with xhci->lock held.
2208 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2213 xhci->num_active_eps); in xhci_finish_resource_reservation()
2218 switch (udev->speed) { in xhci_get_block_size()
2238 if (interval_bw->overhead[LS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2240 if (interval_bw->overhead[FS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2257 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2258 tt_info = virt_dev->tt_info; in xhci_check_tt_bw_table()
2265 if (old_active_eps == 0 && tt_info->active_eps != 0) { in xhci_check_tt_bw_table()
2266 if (bw_table->bw_used + TT_HS_OVERHEAD > HS_BW_LIMIT) in xhci_check_tt_bw_table()
2267 return -ENOMEM; in xhci_check_tt_bw_table()
2285 if (virt_dev->bw_table->ss_bw_in > (SS_BW_LIMIT_IN - bw_reserved)) in xhci_check_ss_bw()
2286 return -ENOMEM; in xhci_check_ss_bw()
2289 if (virt_dev->bw_table->ss_bw_out > (SS_BW_LIMIT_OUT - bw_reserved)) in xhci_check_ss_bw()
2290 return -ENOMEM; in xhci_check_ss_bw()
2296 * This algorithm is a very conservative estimate of the worst-case scheduling
2304 * over-estimate.
2351 if (virt_dev->udev->speed >= USB_SPEED_SUPER) in xhci_check_bw_table()
2354 if (virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2363 bw_table = virt_dev->bw_table; in xhci_check_bw_table()
2367 block_size = xhci_get_block_size(virt_dev->udev); in xhci_check_bw_table()
2372 if (virt_dev->tt_info) { in xhci_check_bw_table()
2375 virt_dev->real_port); in xhci_check_bw_table()
2379 return -ENOMEM; in xhci_check_bw_table()
2383 virt_dev->tt_info->slot_id, in xhci_check_bw_table()
2384 virt_dev->tt_info->ttport); in xhci_check_bw_table()
2388 virt_dev->real_port); in xhci_check_bw_table()
2394 bw_used = DIV_ROUND_UP(bw_table->interval0_esit_payload, block_size) + in xhci_check_bw_table()
2395 bw_table->interval_bw[0].num_packets * in xhci_check_bw_table()
2396 xhci_get_largest_overhead(&bw_table->interval_bw[0]); in xhci_check_bw_table()
2409 bw_table->interval_bw[i].num_packets; in xhci_check_bw_table()
2414 if (list_empty(&bw_table->interval_bw[i].endpoints)) in xhci_check_bw_table()
2420 ep_entry = bw_table->interval_bw[i].endpoints.next; in xhci_check_bw_table()
2425 virt_ep->bw_info.max_packet_size, in xhci_check_bw_table()
2433 &bw_table->interval_bw[i]); in xhci_check_bw_table()
2472 return -ENOMEM; in xhci_check_bw_table()
2476 * Ok, we know we have some packets left over after even-handedly in xhci_check_bw_table()
2478 * fit into, so we over-schedule and say they will be scheduled every in xhci_check_bw_table()
2484 if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2485 unsigned int port_index = virt_dev->real_port - 1; in xhci_check_bw_table()
2492 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2499 (max_bandwidth - bw_used - bw_reserved) * 100 / in xhci_check_bw_table()
2506 return -ENOMEM; in xhci_check_bw_table()
2509 bw_table->bw_used = bw_used; in xhci_check_bw_table()
2527 unsigned int mps = DIV_ROUND_UP(ep_bw->max_packet_size, SS_BLOCK); in xhci_get_ss_bw_consumed()
2529 if (ep_bw->ep_interval == 0) in xhci_get_ss_bw_consumed()
2531 (ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2533 return DIV_ROUND_UP(ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2535 1 << ep_bw->ep_interval); in xhci_get_ss_bw_consumed()
2549 if (xhci_is_async_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2552 if (udev->speed >= USB_SPEED_SUPER) { in xhci_drop_ep_from_interval_table()
2553 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2554 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2557 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2565 if (list_empty(&virt_ep->bw_endpoint_list)) in xhci_drop_ep_from_interval_table()
2570 if (udev->speed == USB_SPEED_HIGH) in xhci_drop_ep_from_interval_table()
2571 normalized_interval = ep_bw->ep_interval; in xhci_drop_ep_from_interval_table()
2573 normalized_interval = ep_bw->ep_interval - 3; in xhci_drop_ep_from_interval_table()
2576 bw_table->interval0_esit_payload -= ep_bw->max_esit_payload; in xhci_drop_ep_from_interval_table()
2577 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_drop_ep_from_interval_table()
2578 interval_bw->num_packets -= ep_bw->num_packets; in xhci_drop_ep_from_interval_table()
2579 switch (udev->speed) { in xhci_drop_ep_from_interval_table()
2581 interval_bw->overhead[LS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2584 interval_bw->overhead[FS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2587 interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2599 tt_info->active_eps -= 1; in xhci_drop_ep_from_interval_table()
2600 list_del_init(&virt_ep->bw_endpoint_list); in xhci_drop_ep_from_interval_table()
2614 if (xhci_is_async_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2617 if (udev->speed == USB_SPEED_SUPER) { in xhci_add_ep_to_interval_table()
2618 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2619 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2622 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2630 if (udev->speed == USB_SPEED_HIGH) in xhci_add_ep_to_interval_table()
2631 normalized_interval = ep_bw->ep_interval; in xhci_add_ep_to_interval_table()
2633 normalized_interval = ep_bw->ep_interval - 3; in xhci_add_ep_to_interval_table()
2636 bw_table->interval0_esit_payload += ep_bw->max_esit_payload; in xhci_add_ep_to_interval_table()
2637 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_add_ep_to_interval_table()
2638 interval_bw->num_packets += ep_bw->num_packets; in xhci_add_ep_to_interval_table()
2639 switch (udev->speed) { in xhci_add_ep_to_interval_table()
2641 interval_bw->overhead[LS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2644 interval_bw->overhead[FS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2647 interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2660 tt_info->active_eps += 1; in xhci_add_ep_to_interval_table()
2662 list_for_each_entry(smaller_ep, &interval_bw->endpoints, in xhci_add_ep_to_interval_table()
2664 if (ep_bw->max_packet_size >= in xhci_add_ep_to_interval_table()
2665 smaller_ep->bw_info.max_packet_size) { in xhci_add_ep_to_interval_table()
2667 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2668 &smaller_ep->bw_endpoint_list); in xhci_add_ep_to_interval_table()
2673 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2674 &interval_bw->endpoints); in xhci_add_ep_to_interval_table()
2682 if (!virt_dev->tt_info) in xhci_update_tt_active_eps()
2685 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2687 virt_dev->tt_info->active_eps != 0) { in xhci_update_tt_active_eps()
2688 rh_bw_info->num_active_tts += 1; in xhci_update_tt_active_eps()
2689 rh_bw_info->bw_table.bw_used += TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2691 virt_dev->tt_info->active_eps == 0) { in xhci_update_tt_active_eps()
2692 rh_bw_info->num_active_tts -= 1; in xhci_update_tt_active_eps()
2693 rh_bw_info->bw_table.bw_used -= TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2706 if (virt_dev->tt_info) in xhci_reserve_bandwidth()
2707 old_active_eps = virt_dev->tt_info->active_eps; in xhci_reserve_bandwidth()
2713 return -ENOMEM; in xhci_reserve_bandwidth()
2721 memcpy(&ep_bw_info[i], &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2728 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2729 virt_dev->bw_table, in xhci_reserve_bandwidth()
2730 virt_dev->udev, in xhci_reserve_bandwidth()
2731 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2732 virt_dev->tt_info); in xhci_reserve_bandwidth()
2735 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2740 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2741 virt_dev->bw_table, in xhci_reserve_bandwidth()
2742 virt_dev->udev, in xhci_reserve_bandwidth()
2743 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2744 virt_dev->tt_info); in xhci_reserve_bandwidth()
2765 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2766 virt_dev->bw_table, in xhci_reserve_bandwidth()
2767 virt_dev->udev, in xhci_reserve_bandwidth()
2768 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2769 virt_dev->tt_info); in xhci_reserve_bandwidth()
2772 memcpy(&virt_dev->eps[i].bw_info, &ep_bw_info[i], in xhci_reserve_bandwidth()
2777 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2778 virt_dev->bw_table, in xhci_reserve_bandwidth()
2779 virt_dev->udev, in xhci_reserve_bandwidth()
2780 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2781 virt_dev->tt_info); in xhci_reserve_bandwidth()
2783 return -ENOMEM; in xhci_reserve_bandwidth()
2802 return -EINVAL; in xhci_configure_endpoint()
2804 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2806 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2807 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2808 return -ESHUTDOWN; in xhci_configure_endpoint()
2811 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2813 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_configure_endpoint()
2815 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2818 return -ENOMEM; in xhci_configure_endpoint()
2821 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2823 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2826 xhci->num_active_eps); in xhci_configure_endpoint()
2827 return -ENOMEM; in xhci_configure_endpoint()
2829 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && !ctx_change && in xhci_configure_endpoint()
2830 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2831 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2833 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2835 return -ENOMEM; in xhci_configure_endpoint()
2838 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2845 command->in_ctx->dma, in xhci_configure_endpoint()
2846 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2849 command->in_ctx->dma, in xhci_configure_endpoint()
2850 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2852 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2854 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2857 return -ENOMEM; in xhci_configure_endpoint()
2860 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2863 wait_for_completion(command->completion); in xhci_configure_endpoint()
2867 &command->status); in xhci_configure_endpoint()
2870 &command->status); in xhci_configure_endpoint()
2872 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2873 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2881 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2889 struct xhci_virt_ep *ep = &vdev->eps[i]; in xhci_check_bw_drop_ep_streams()
2891 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_check_bw_drop_ep_streams()
2894 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2895 ep->stream_info = NULL; in xhci_check_bw_drop_ep_streams()
2896 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_check_bw_drop_ep_streams()
2907 * else should be touching the xhci->devs[slot_id] structure, so we
2908 * don't need to take the xhci->lock for manipulating that.
2924 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2925 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2926 return -ENODEV; in xhci_check_bandwidth()
2929 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2933 return -ENOMEM; in xhci_check_bandwidth()
2935 command->in_ctx = virt_dev->in_ctx; in xhci_check_bandwidth()
2937 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ in xhci_check_bandwidth()
2938 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_bandwidth()
2942 ret = -ENOMEM; in xhci_check_bandwidth()
2945 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_check_bandwidth()
2946 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); in xhci_check_bandwidth()
2947 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); in xhci_check_bandwidth()
2950 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && in xhci_check_bandwidth()
2951 ctrl_ctx->drop_flags == 0) { in xhci_check_bandwidth()
2956 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
2957 for (i = 31; i >= 1; i--) { in xhci_check_bandwidth()
2960 if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32)) in xhci_check_bandwidth()
2961 || (ctrl_ctx->add_flags & le32) || i == 1) { in xhci_check_bandwidth()
2962 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_check_bandwidth()
2963 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); in xhci_check_bandwidth()
2976 if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) && in xhci_check_bandwidth()
2977 !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))) { in xhci_check_bandwidth()
2988 if (!virt_dev->eps[i].new_ring) in xhci_check_bandwidth()
2993 if (virt_dev->eps[i].ring) { in xhci_check_bandwidth()
2997 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; in xhci_check_bandwidth()
2998 virt_dev->eps[i].new_ring = NULL; in xhci_check_bandwidth()
3002 kfree(command->completion); in xhci_check_bandwidth()
3020 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
3023 if (virt_dev->eps[i].new_ring) { in xhci_reset_bandwidth()
3025 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3026 virt_dev->eps[i].new_ring = NULL; in xhci_reset_bandwidth()
3038 ctrl_ctx->add_flags = cpu_to_le32(add_flags); in xhci_setup_input_ctx_for_config_ep()
3039 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags); in xhci_setup_input_ctx_for_config_ep()
3041 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_setup_input_ctx_for_config_ep()
3054 in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_setup_input_ctx_for_quirk()
3062 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_setup_input_ctx_for_quirk()
3063 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_setup_input_ctx_for_quirk()
3065 addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg, in xhci_setup_input_ctx_for_quirk()
3066 deq_state->new_deq_ptr); in xhci_setup_input_ctx_for_quirk()
3071 deq_state->new_deq_seg, in xhci_setup_input_ctx_for_quirk()
3072 deq_state->new_deq_ptr); in xhci_setup_input_ctx_for_quirk()
3075 ep_ctx->deq = cpu_to_le64(addr | deq_state->new_cycle_state); in xhci_setup_input_ctx_for_quirk()
3078 xhci_setup_input_ctx_for_config_ep(xhci, xhci->devs[slot_id]->in_ctx, in xhci_setup_input_ctx_for_quirk()
3079 xhci->devs[slot_id]->out_ctx, ctrl_ctx, in xhci_setup_input_ctx_for_quirk()
3103 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { in xhci_cleanup_stalled_ring()
3134 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3136 udev = (struct usb_device *)host_ep->hcpriv; in xhci_endpoint_disable()
3137 if (!udev || !udev->slot_id) in xhci_endpoint_disable()
3140 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3144 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_disable()
3145 ep = &vdev->eps[ep_index]; in xhci_endpoint_disable()
3150 if (ep->ep_state & EP_CLEARING_TT) { in xhci_endpoint_disable()
3151 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3156 if (ep->ep_state) in xhci_endpoint_disable()
3158 ep->ep_state); in xhci_endpoint_disable()
3160 host_ep->hcpriv = NULL; in xhci_endpoint_disable()
3161 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3173 * endpoint. Refer to the additional note in xhci spcification section 4.6.8.
3191 if (!host_ep->hcpriv) in xhci_endpoint_reset()
3193 udev = (struct usb_device *) host_ep->hcpriv; in xhci_endpoint_reset()
3194 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3197 * vdev may be lost due to xHC restore error and re-initialization in xhci_endpoint_reset()
3201 if (!udev->slot_id || !vdev) in xhci_endpoint_reset()
3203 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_reset()
3204 ep = &vdev->eps[ep_index]; in xhci_endpoint_reset()
3209 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3210 if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) { in xhci_endpoint_reset()
3211 ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE; in xhci_endpoint_reset()
3212 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3215 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3216 /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */ in xhci_endpoint_reset()
3217 if (usb_endpoint_xfer_control(&host_ep->desc) || in xhci_endpoint_reset()
3218 usb_endpoint_xfer_isoc(&host_ep->desc)) in xhci_endpoint_reset()
3221 ep_flag = xhci_get_endpoint_flag(&host_ep->desc); in xhci_endpoint_reset()
3234 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3237 ep->ep_state |= EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3245 if (!list_empty(&ep->ring->td_list)) { in xhci_endpoint_reset()
3246 dev_err(&udev->dev, "EP not empty, refuse reset\n"); in xhci_endpoint_reset()
3247 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3252 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3255 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3263 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3265 wait_for_completion(stop_cmd->completion); in xhci_endpoint_reset()
3267 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3270 ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); in xhci_endpoint_reset()
3272 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3279 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3281 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3283 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3284 udev->slot_id, false); in xhci_endpoint_reset()
3286 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3294 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3296 wait_for_completion(cfg_cmd->completion); in xhci_endpoint_reset()
3301 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3302 if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) in xhci_endpoint_reset()
3303 ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3304 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3316 return -EINVAL; in xhci_check_streams_endpoint()
3319 return ret ? ret : -EINVAL; in xhci_check_streams_endpoint()
3320 if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { in xhci_check_streams_endpoint()
3323 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3324 return -EINVAL; in xhci_check_streams_endpoint()
3327 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_check_streams_endpoint()
3328 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3333 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3336 return -EINVAL; in xhci_check_streams_endpoint()
3338 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3341 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3342 return -EINVAL; in xhci_check_streams_endpoint()
3360 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3385 eps[i], udev->slot_id); in xhci_calculate_streams_and_bitmask()
3389 max_streams = usb_ss_max_streams(&eps[i]->ss_ep_comp); in xhci_calculate_streams_and_bitmask()
3390 if (max_streams < (*num_streams - 1)) { in xhci_calculate_streams_and_bitmask()
3392 eps[i]->desc.bEndpointAddress, in xhci_calculate_streams_and_bitmask()
3397 endpoint_flag = xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_streams_and_bitmask()
3399 return -EINVAL; in xhci_calculate_streams_and_bitmask()
3415 slot_id = udev->slot_id; in xhci_calculate_no_streams_bitmask()
3416 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3420 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3421 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3427 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3436 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3438 "with non-streams endpoint\n"); in xhci_calculate_no_streams_bitmask()
3441 changed_ep_bitmask |= xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3478 return -EINVAL; in xhci_alloc_streams()
3489 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3490 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3492 return -ENOSYS; in xhci_alloc_streams()
3497 return -ENOMEM; in xhci_alloc_streams()
3499 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_alloc_streams()
3504 return -ENOMEM; in xhci_alloc_streams()
3511 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3516 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3523 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3524 return -EINVAL; in xhci_alloc_streams()
3526 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3531 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3532 vdev->eps[ep_index].ep_state |= EP_GETTING_STREAMS; in xhci_alloc_streams()
3534 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3545 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3546 max_packet = usb_endpoint_maxp(&eps[i]->desc); in xhci_alloc_streams()
3547 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3551 if (!vdev->eps[ep_index].stream_info) in xhci_alloc_streams()
3562 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3563 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3565 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3566 vdev->out_ctx, ep_index); in xhci_alloc_streams()
3568 vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3573 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3574 vdev->out_ctx, ctrl_ctx, in xhci_alloc_streams()
3588 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3590 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3591 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3593 udev->slot_id, ep_index); in xhci_alloc_streams()
3594 vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; in xhci_alloc_streams()
3597 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3600 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3604 return num_streams - 1; in xhci_alloc_streams()
3609 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3610 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3611 vdev->eps[ep_index].stream_info = NULL; in xhci_alloc_streams()
3615 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3616 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_alloc_streams()
3620 return -ENOMEM; in xhci_alloc_streams()
3643 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3646 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3650 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3651 return -EINVAL; in xhci_free_streams()
3658 ep_index = xhci_get_endpoint_index(&eps[0]->desc); in xhci_free_streams()
3659 command = vdev->eps[ep_index].stream_info->free_streams_command; in xhci_free_streams()
3660 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_free_streams()
3662 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3665 return -EINVAL; in xhci_free_streams()
3671 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3672 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3673 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3676 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3677 vdev->out_ctx, ep_index); in xhci_free_streams()
3679 &vdev->eps[ep_index]); in xhci_free_streams()
3681 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3682 vdev->out_ctx, ctrl_ctx, in xhci_free_streams()
3684 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3698 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3700 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3701 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3702 vdev->eps[ep_index].stream_info = NULL; in xhci_free_streams()
3706 vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS; in xhci_free_streams()
3707 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_free_streams()
3709 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3719 * Must be called with xhci->lock held.
3729 if (virt_dev->eps[i].ring) { in xhci_free_device_endpoint_resources()
3734 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3740 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3747 * xhci_address_device(), and then re-set up the configuration. If this is
3749 * settings will be re-installed through the normal bandwidth allocation
3758 * re-initialization during S3/S4. In this case, call xhci_alloc_dev() to
3759 * re-allocate the device.
3777 slot_id = udev->slot_id; in xhci_discover_or_reset_device()
3778 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3781 "not exist. Re-allocate the device\n", slot_id); in xhci_discover_or_reset_device()
3786 return -EINVAL; in xhci_discover_or_reset_device()
3789 if (virt_dev->tt_info) in xhci_discover_or_reset_device()
3790 old_active_eps = virt_dev->tt_info->active_eps; in xhci_discover_or_reset_device()
3792 if (virt_dev->udev != udev) { in xhci_discover_or_reset_device()
3795 * Re-allocate the device. in xhci_discover_or_reset_device()
3798 "not match the udev. Re-allocate the device\n", in xhci_discover_or_reset_device()
3804 return -EINVAL; in xhci_discover_or_reset_device()
3808 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3809 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_discover_or_reset_device()
3825 return -ENOMEM; in xhci_discover_or_reset_device()
3829 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3834 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3838 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3841 wait_for_completion(reset_device_cmd->completion); in xhci_discover_or_reset_device()
3847 ret = reset_device_cmd->status; in xhci_discover_or_reset_device()
3852 ret = -ETIME; in xhci_discover_or_reset_device()
3858 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3871 ret = -EINVAL; in xhci_discover_or_reset_device()
3876 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3877 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3880 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3885 struct xhci_virt_ep *ep = &virt_dev->eps[i]; in xhci_discover_or_reset_device()
3887 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_discover_or_reset_device()
3890 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3891 ep->stream_info = NULL; in xhci_discover_or_reset_device()
3892 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_discover_or_reset_device()
3895 if (ep->ring) { in xhci_discover_or_reset_device()
3899 if (!list_empty(&virt_dev->eps[i].bw_endpoint_list)) in xhci_discover_or_reset_device()
3901 &virt_dev->eps[i].bw_info, in xhci_discover_or_reset_device()
3902 virt_dev->bw_table, in xhci_discover_or_reset_device()
3904 &virt_dev->eps[i], in xhci_discover_or_reset_device()
3905 virt_dev->tt_info); in xhci_discover_or_reset_device()
3906 xhci_clear_endpoint_bw_info(&virt_dev->eps[i].bw_info); in xhci_discover_or_reset_device()
3910 virt_dev->flags = 0; in xhci_discover_or_reset_device()
3936 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3937 pm_runtime_put_noidle(hcd->self.controller); in xhci_free_dev()
3943 if (ret <= 0 && ret != -ENODEV) in xhci_free_dev()
3946 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3947 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3952 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING; in xhci_free_dev()
3953 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); in xhci_free_dev()
3955 virt_dev->udev = NULL; in xhci_free_dev()
3956 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3958 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3959 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3960 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3973 return -ENOMEM; in xhci_disable_slot()
3977 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3979 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3980 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3981 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3982 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3984 return -ENODEV; in xhci_disable_slot()
3990 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3995 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3997 wait_for_completion(command->completion); in xhci_disable_slot()
3999 if (command->status != COMP_SUCCESS) in xhci_disable_slot()
4001 slot_id, command->status); in xhci_disable_slot()
4012 * Must be called with xhci->lock held.
4016 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
4020 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
4021 return -ENOMEM; in xhci_reserve_host_control_ep_resources()
4023 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
4026 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
4048 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4051 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4057 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4059 wait_for_completion(command->completion); in xhci_alloc_dev()
4060 slot_id = command->slot_id; in xhci_alloc_dev()
4062 if (!slot_id || command->status != COMP_SUCCESS) { in xhci_alloc_dev()
4066 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
4073 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
4074 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4077 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4080 xhci->num_active_eps); in xhci_alloc_dev()
4083 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4093 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
4094 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
4097 udev->slot_id = slot_id; in xhci_alloc_dev()
4105 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4106 pm_runtime_get_noresume(hcd->self.controller); in xhci_alloc_dev()
4113 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4114 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4136 mutex_lock(&xhci->mutex); in xhci_setup_device()
4138 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4139 ret = -ESHUTDOWN; in xhci_setup_device()
4143 if (!udev->slot_id) { in xhci_setup_device()
4145 "Bad Slot ID %d", udev->slot_id); in xhci_setup_device()
4146 ret = -EINVAL; in xhci_setup_device()
4150 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4155 * a zero-dereference was observed once due to virt_dev = 0. in xhci_setup_device()
4159 udev->slot_id); in xhci_setup_device()
4160 ret = -EINVAL; in xhci_setup_device()
4163 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4167 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_setup_device()
4176 ret = -ENOMEM; in xhci_setup_device()
4180 command->in_ctx = virt_dev->in_ctx; in xhci_setup_device()
4182 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4183 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_setup_device()
4187 ret = -EINVAL; in xhci_setup_device()
4191 * If this is the first Set Address since device plug-in or in xhci_setup_device()
4195 if (!slot_ctx->dev_info) in xhci_setup_device()
4200 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); in xhci_setup_device()
4201 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4203 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4204 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4207 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4209 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4210 udev->slot_id, setup); in xhci_setup_device()
4212 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4218 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4221 wait_for_completion(command->completion); in xhci_setup_device()
4227 switch (command->status) { in xhci_setup_device()
4231 ret = -ETIME; in xhci_setup_device()
4236 act, udev->slot_id); in xhci_setup_device()
4237 ret = -EINVAL; in xhci_setup_device()
4240 dev_warn(&udev->dev, "Device not responding to setup %s.\n", act); in xhci_setup_device()
4242 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4243 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4244 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4249 kfree(command->completion); in xhci_setup_device()
4251 return -EPROTO; in xhci_setup_device()
4253 dev_warn(&udev->dev, in xhci_setup_device()
4255 ret = -ENODEV; in xhci_setup_device()
4264 act, command->status); in xhci_setup_device()
4265 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4266 ret = -EINVAL; in xhci_setup_device()
4271 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4276 udev->slot_id, in xhci_setup_device()
4277 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4279 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4282 (unsigned long long)virt_dev->out_ctx->dma); in xhci_setup_device()
4283 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4284 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4289 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4290 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4292 ctrl_ctx->add_flags = 0; in xhci_setup_device()
4293 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4294 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4295 udev->devaddr = (u8)(le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4299 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4301 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4303 kfree(command->completion); in xhci_setup_device()
4330 return rhub->ports[port1 - 1]->hw_portnum + 1; in xhci_find_raw_port_number()
4347 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4349 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4353 * xHC was re-initialized. Exit latency will be set later after in xhci_change_max_exit_latency()
4354 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4357 if (!virt_dev || max_exit_latency == virt_dev->current_mel) { in xhci_change_max_exit_latency()
4358 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4363 command = xhci->lpm_command; in xhci_change_max_exit_latency()
4364 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_change_max_exit_latency()
4366 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4369 return -ENOMEM; in xhci_change_max_exit_latency()
4372 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4373 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4375 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_change_max_exit_latency()
4376 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4377 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); in xhci_change_max_exit_latency()
4378 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency); in xhci_change_max_exit_latency()
4379 slot_ctx->dev_state = 0; in xhci_change_max_exit_latency()
4389 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4390 virt_dev->current_mel = max_exit_latency; in xhci_change_max_exit_latency()
4391 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4410 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4411 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_hird_besl()
4427 besl_host = (u2del - 51) / 75 + 1; in xhci_calculate_hird_besl()
4445 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_usb2_hw_lpm_params()
4448 l1 = udev->l1_params.timeout / 256; in xhci_calculate_usb2_hw_lpm_params()
4471 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4472 return -EPERM; in xhci_set_usb2_hardware_lpm()
4474 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4475 !udev->lpm_capable) in xhci_set_usb2_hardware_lpm()
4476 return -EPERM; in xhci_set_usb2_hardware_lpm()
4478 if (!udev->parent || udev->parent->parent || in xhci_set_usb2_hardware_lpm()
4479 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_set_usb2_hardware_lpm()
4480 return -EPERM; in xhci_set_usb2_hardware_lpm()
4482 if (udev->usb2_hw_lpm_capable != 1) in xhci_set_usb2_hardware_lpm()
4483 return -EPERM; in xhci_set_usb2_hardware_lpm()
4485 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4487 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4488 port_num = udev->portnum - 1; in xhci_set_usb2_hardware_lpm()
4489 pm_addr = ports[port_num]->addr + PORTPMSC; in xhci_set_usb2_hardware_lpm()
4491 hlpm_addr = ports[port_num]->addr + PORTHLPMC; in xhci_set_usb2_hardware_lpm()
4498 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4503 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_set_usb2_hardware_lpm()
4508 hird = udev->l1_params.besl; in xhci_set_usb2_hardware_lpm()
4511 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4513 /* USB 3.0 code dedicate one xhci->lpm_command->in_ctx in xhci_set_usb2_hardware_lpm()
4515 * context commands. It is protected by hcd->bandwidth in xhci_set_usb2_hardware_lpm()
4520 mutex_lock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4523 mutex_unlock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4527 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4538 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); in xhci_set_usb2_hardware_lpm()
4550 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4551 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4552 mutex_lock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4554 mutex_unlock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4555 readl_poll_timeout(ports[port_num]->addr, pm_val, in xhci_set_usb2_hardware_lpm()
4562 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4576 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4577 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4579 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4580 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4592 int portnum = udev->portnum - 1; in xhci_update_device()
4594 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable) in xhci_update_device()
4597 /* we only support lpm for non-hub device connected to root hub yet */ in xhci_update_device()
4598 if (!udev->parent || udev->parent->parent || in xhci_update_device()
4599 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_update_device()
4602 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4605 udev->usb2_hw_lpm_capable = 1; in xhci_update_device()
4606 udev->l1_params.timeout = XHCI_L1_TIMEOUT; in xhci_update_device()
4607 udev->l1_params.besl = XHCI_DEFAULT_BESL; in xhci_update_device()
4610 udev->usb2_hw_lpm_besl_capable = 1; in xhci_update_device()
4616 /*---------------------- USB 3.0 Link PM functions ------------------------*/
4618 /* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
4622 return (1ULL << (desc->bInterval - 1)) * 125 * 1000; in xhci_service_interval_to_ns()
4636 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4637 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4642 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4643 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4648 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n", in xhci_get_timeout_no_hub_lpm()
4657 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4661 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4668 * - For control endpoints, U1 system exit latency (SEL) * 3
4669 * - For bulk endpoints, U1 SEL * 5
4670 * - For interrupt endpoints:
4671 * - Notification EPs, U1 SEL * 3
4672 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
4673 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
4686 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4689 timeout_ns = udev->u1_params.sel * 5; in xhci_calculate_intel_u1_timeout()
4694 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4702 if (timeout_ns < udev->u1_params.sel * 2) in xhci_calculate_intel_u1_timeout()
4703 timeout_ns = udev->u1_params.sel * 2; in xhci_calculate_intel_u1_timeout()
4712 /* Returns the hub-encoded U1 timeout value. */
4721 if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { in xhci_calculate_u1_timeout()
4722 dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); in xhci_calculate_u1_timeout()
4727 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_calculate_u1_timeout()
4730 timeout_ns = udev->u1_params.sel; in xhci_calculate_u1_timeout()
4741 * USB 3.0 hub, we have to disable hub-initiated U1. in xhci_calculate_u1_timeout()
4745 dev_dbg(&udev->dev, "Hub-initiated U1 disabled " in xhci_calculate_u1_timeout()
4751 * - 10 ms (to avoid the bandwidth impact on the scheduler)
4752 * - largest bInterval of any active periodic endpoint (to avoid going
4754 * - the U2 Exit Latency of the device
4769 u2_del_ns = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat) * 1000ULL; in xhci_calculate_intel_u2_timeout()
4776 /* Returns the hub-encoded U2 timeout value. */
4785 if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { in xhci_calculate_u2_timeout()
4786 dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); in xhci_calculate_u2_timeout()
4791 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_calculate_u2_timeout()
4794 timeout_ns = udev->u2_params.sel; in xhci_calculate_u2_timeout()
4799 * USB 3.0 hub, we have to disable hub-initiated U2. in xhci_calculate_u2_timeout()
4803 dev_dbg(&udev->dev, "Hub-initiated U2 disabled " in xhci_calculate_u2_timeout()
4833 /* If we found we can't enable hub-initiated LPM, and in xhci_update_timeout_for_endpoint()
4835 * device-initiated LPM as well, then we will disable LPM in xhci_update_timeout_for_endpoint()
4840 return -E2BIG; in xhci_update_timeout_for_endpoint()
4855 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in xhci_update_timeout_for_interface()
4857 &alt->endpoint[j].desc, state, timeout)) in xhci_update_timeout_for_interface()
4858 return -E2BIG; in xhci_update_timeout_for_interface()
4874 for (parent = udev->parent, num_hubs = 0; parent->parent; in xhci_check_intel_tier_policy()
4875 parent = parent->parent) in xhci_check_intel_tier_policy()
4881 dev_dbg(&udev->dev, "Disabling U1 link state for device" in xhci_check_intel_tier_policy()
4882 " below second-tier hub.\n"); in xhci_check_intel_tier_policy()
4883 dev_dbg(&udev->dev, "Plug device into first-tier hub " in xhci_check_intel_tier_policy()
4885 return -E2BIG; in xhci_check_intel_tier_policy()
4892 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_check_tier_policy()
4899 * If the tier check or timeout setting functions return with a non-zero exit
4917 dev_warn(&udev->dev, "Can't enable unknown link state %i\n", in xhci_calculate_lpm_timeout()
4928 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4932 config = udev->actconfig; in xhci_calculate_lpm_timeout()
4936 for (i = 0; i < config->desc.bNumInterfaces; i++) { in xhci_calculate_lpm_timeout()
4938 struct usb_interface *intf = config->interface[i]; in xhci_calculate_lpm_timeout()
4943 /* Check if any currently bound drivers want hub-initiated LPM in xhci_calculate_lpm_timeout()
4946 if (intf->dev.driver) { in xhci_calculate_lpm_timeout()
4947 driver = to_usb_driver(intf->dev.driver); in xhci_calculate_lpm_timeout()
4948 if (driver && driver->disable_hub_initiated_lpm) { in xhci_calculate_lpm_timeout()
4949 dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n", in xhci_calculate_lpm_timeout()
4950 state_name, driver->name); in xhci_calculate_lpm_timeout()
4959 if (!intf->cur_altsetting) in xhci_calculate_lpm_timeout()
4963 intf->cur_altsetting, in xhci_calculate_lpm_timeout()
4995 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) || in calculate_max_exit_latency()
4997 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000); in calculate_max_exit_latency()
4998 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) || in calculate_max_exit_latency()
5000 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000); in calculate_max_exit_latency()
5008 dev_warn(&udev->dev, "Link PM max exit latency of %lluus " in calculate_max_exit_latency()
5010 return -E2BIG; in calculate_max_exit_latency()
5015 /* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
5026 /* The LPM timeout values are pretty host-controller specific, so don't in xhci_enable_usb3_lpm_timeout()
5027 * enable hub-initiated timeouts unless the vendor has provided in xhci_enable_usb3_lpm_timeout()
5030 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
5031 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
5035 if (udev->parent && !udev->parent->parent) { in xhci_enable_usb3_lpm_timeout()
5036 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
5037 if (port->lpm_incapable) in xhci_enable_usb3_lpm_timeout()
5062 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
5063 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
5095 /*-------------------------------------------------------------------------*/
5113 if (!hdev->parent) in xhci_update_hub_device()
5116 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
5119 return -EINVAL; in xhci_update_hub_device()
5124 return -ENOMEM; in xhci_update_hub_device()
5126 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_update_hub_device()
5131 return -ENOMEM; in xhci_update_hub_device()
5134 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5135 if (hdev->speed == USB_SPEED_HIGH && in xhci_update_hub_device()
5139 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5140 return -ENOMEM; in xhci_update_hub_device()
5143 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5144 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_update_hub_device()
5145 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5146 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); in xhci_update_hub_device()
5152 if (tt->multi) in xhci_update_hub_device()
5153 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_update_hub_device()
5154 else if (hdev->speed == USB_SPEED_FULL) in xhci_update_hub_device()
5155 slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); in xhci_update_hub_device()
5157 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5160 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5161 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(hdev->maxchild)); in xhci_update_hub_device()
5162 /* Set TT think time - convert from ns to FS bit times. in xhci_update_hub_device()
5167 * High-spped hub. in xhci_update_hub_device()
5169 think_time = tt->think_time; in xhci_update_hub_device()
5171 think_time = (think_time / 666) - 1; in xhci_update_hub_device()
5172 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5173 slot_ctx->tt_info |= in xhci_update_hub_device()
5178 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5180 slot_ctx->dev_state = 0; in xhci_update_hub_device()
5181 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5184 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5190 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5206 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5216 struct device *dev = hcd->self.sysdev; in xhci_gen_setup()
5220 /* Accept arbitrarily long scatter-gather lists */ in xhci_gen_setup()
5221 hcd->self.sg_tablesize = ~0; in xhci_gen_setup()
5224 hcd->self.no_sg_constraint = 1; in xhci_gen_setup()
5227 hcd->self.no_stop_on_short = 1; in xhci_gen_setup()
5232 xhci->main_hcd = hcd; in xhci_gen_setup()
5233 xhci->usb2_rhub.hcd = hcd; in xhci_gen_setup()
5237 hcd->speed = HCD_USB2; in xhci_gen_setup()
5238 hcd->self.root_hub->speed = USB_SPEED_HIGH; in xhci_gen_setup()
5244 hcd->has_tt = 1; in xhci_gen_setup()
5249 * is a two digit BCD containig minor and sub-minor numbers. in xhci_gen_setup()
5255 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_gen_setup()
5258 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_gen_setup()
5262 hcd->speed = HCD_USB32; in xhci_gen_setup()
5263 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_gen_setup()
5264 hcd->self.root_hub->rx_lanes = 2; in xhci_gen_setup()
5265 hcd->self.root_hub->tx_lanes = 2; in xhci_gen_setup()
5268 hcd->speed = HCD_USB31; in xhci_gen_setup()
5269 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_gen_setup()
5276 xhci->usb3_rhub.hcd = hcd; in xhci_gen_setup()
5283 mutex_init(&xhci->mutex); in xhci_gen_setup()
5284 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5285 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5286 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5287 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5288 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5289 /* Cache read-only capability registers */ in xhci_gen_setup()
5290 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5291 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5292 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5293 xhci->hcc_params = readl(&xhci->cap_regs->hc_capbase); in xhci_gen_setup()
5294 xhci->hci_version = HC_VERSION(xhci->hcc_params); in xhci_gen_setup()
5295 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5296 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5297 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5299 xhci->quirks |= quirks; in xhci_gen_setup()
5307 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5308 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5325 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5326 * of HCCPARAMS1 is set to 1. However, the xHCs don't support 64-bit in xhci_gen_setup()
5328 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5331 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5332 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5334 /* Set dma_mask and coherent_dma_mask to 64-bits, in xhci_gen_setup()
5335 * if xHC supports 64-bit addressing */ in xhci_gen_setup()
5336 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5338 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5342 * This is to avoid error in cases where a 32-bit USB in xhci_gen_setup()
5343 * controller is used on a 64-bit capable system. in xhci_gen_setup()
5348 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5360 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5377 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5378 udev = (struct usb_device *)ep->hcpriv; in xhci_clear_tt_buffer_complete()
5379 slot_id = udev->slot_id; in xhci_clear_tt_buffer_complete()
5380 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_clear_tt_buffer_complete()
5382 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5384 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5388 .description = "xhci-hcd",
5462 drv->hcd_priv_size += over->extra_priv_size; in xhci_init_driver()
5463 if (over->reset) in xhci_init_driver()
5464 drv->reset = over->reset; in xhci_init_driver()
5465 if (over->start) in xhci_init_driver()
5466 drv->start = over->start; in xhci_init_driver()
5467 if (over->check_bandwidth) in xhci_init_driver()
5468 drv->check_bandwidth = over->check_bandwidth; in xhci_init_driver()
5469 if (over->reset_bandwidth) in xhci_init_driver()
5470 drv->reset_bandwidth = over->reset_bandwidth; in xhci_init_driver()
5471 if (over->update_hub_device) in xhci_init_driver()
5472 drv->update_hub_device = over->update_hub_device; in xhci_init_driver()
5502 return -ENODEV; in xhci_hcd_init()