Lines Matching +full:usb2 +full:- +full:lpm +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0
19 #include <linux/dma-mapping.h>
22 #include "xhci-trace.h"
23 #include "xhci-debugfs.h"
24 #include "xhci-dbgcap.h"
42 struct xhci_segment *seg = ring->first_seg; in td_on_ring()
44 if (!td || !td->start_seg) in td_on_ring()
47 if (seg == td->start_seg) in td_on_ring()
49 seg = seg->next; in td_on_ring()
50 } while (seg && seg != ring->first_seg); in td_on_ring()
56 * xhci_handshake - spin reading hc until handshake completes or fails
66 * hardware flakeout), or the register reads as all-ones (hardware removed).
78 return -ENODEV; in xhci_handshake()
84 * Disable interrupts and begin the xHCI halting process.
93 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
97 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
99 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
105 * Disable any IRQs and clear the run/stop bit.
116 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
122 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
123 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
135 temp = readl(&xhci->op_regs->command); in xhci_start()
139 writel(temp, &xhci->op_regs->command); in xhci_start()
145 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
147 if (ret == -ETIMEDOUT) in xhci_start()
153 xhci->xhc_state = 0; in xhci_start()
171 state = readl(&xhci->op_regs->status); in xhci_reset()
175 return -ENODEV; in xhci_reset()
184 command = readl(&xhci->op_regs->command); in xhci_reset()
186 writel(command, &xhci->op_regs->command); in xhci_reset()
195 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
198 ret = xhci_handshake(&xhci->op_regs->command, in xhci_reset()
203 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
204 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
212 ret = xhci_handshake(&xhci->op_regs->status, in xhci_reset()
215 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
216 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
217 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
218 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
219 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
220 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
227 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
246 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !device_iommu_mapped(dev)) in xhci_zero_64b_regs()
252 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
254 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
257 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
259 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
262 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
264 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
265 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
267 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
269 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
270 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
275 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
276 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
278 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
279 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
281 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
285 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
302 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); in xhci_setup_msi()
311 ret = request_irq(pdev->irq, xhci_msi_irq, in xhci_setup_msi()
315 "disable MSI interrupt"); in xhci_setup_msi()
323 * Set up MSI-X
329 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); in xhci_setup_msix()
332 * calculate number of msi-x vectors supported. in xhci_setup_msix()
333 * - HCS_MAX_INTRS: the max number of interrupts the host can handle, in xhci_setup_msix()
335 * - num_online_cpus: maximum msi-x vectors per CPUs core. in xhci_setup_msix()
338 xhci->msix_count = min(num_online_cpus() + 1, in xhci_setup_msix()
339 HCS_MAX_INTRS(xhci->hcs_params1)); in xhci_setup_msix()
341 ret = pci_alloc_irq_vectors(pdev, xhci->msix_count, xhci->msix_count, in xhci_setup_msix()
345 "Failed to enable MSI-X"); in xhci_setup_msix()
349 for (i = 0; i < xhci->msix_count; i++) { in xhci_setup_msix()
356 hcd->msix_enabled = 1; in xhci_setup_msix()
360 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); in xhci_setup_msix()
361 while (--i >= 0) in xhci_setup_msix()
367 /* Free any IRQs and disable MSI-X */
371 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); in xhci_cleanup_msix()
373 if (xhci->quirks & XHCI_PLAT) in xhci_cleanup_msix()
377 if (hcd->irq > 0) in xhci_cleanup_msix()
380 if (hcd->msix_enabled) { in xhci_cleanup_msix()
383 for (i = 0; i < xhci->msix_count; i++) in xhci_cleanup_msix()
390 hcd->msix_enabled = 0; in xhci_cleanup_msix()
397 if (hcd->msix_enabled) { in xhci_msix_sync_irqs()
398 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); in xhci_msix_sync_irqs()
401 for (i = 0; i < xhci->msix_count; i++) in xhci_msix_sync_irqs()
413 if (xhci->quirks & XHCI_PLAT) in xhci_try_enable_msi()
416 pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); in xhci_try_enable_msi()
421 if (xhci->quirks & XHCI_BROKEN_MSI) in xhci_try_enable_msi()
425 if (hcd->irq) in xhci_try_enable_msi()
426 free_irq(hcd->irq, hcd); in xhci_try_enable_msi()
427 hcd->irq = 0; in xhci_try_enable_msi()
435 hcd->msi_enabled = 1; in xhci_try_enable_msi()
439 if (!pdev->irq) { in xhci_try_enable_msi()
440 xhci_err(xhci, "No msi-x/msi found and no IRQ in BIOS\n"); in xhci_try_enable_msi()
441 return -EINVAL; in xhci_try_enable_msi()
445 if (!strlen(hcd->irq_descr)) in xhci_try_enable_msi()
446 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", in xhci_try_enable_msi()
447 hcd->driver->description, hcd->self.busnum); in xhci_try_enable_msi()
450 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, in xhci_try_enable_msi()
451 hcd->irq_descr, hcd); in xhci_try_enable_msi()
454 pdev->irq); in xhci_try_enable_msi()
457 hcd->irq = pdev->irq; in xhci_try_enable_msi()
487 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
489 for (i = 0; i < rhub->num_ports; i++) { in compliance_mode_recovery()
490 temp = readl(rhub->ports[i]->addr); in compliance_mode_recovery()
497 "Compliance mode detected->port %d", in compliance_mode_recovery()
501 hcd = xhci->shared_hcd; in compliance_mode_recovery()
503 if (hcd->state == HC_STATE_SUSPENDED) in compliance_mode_recovery()
510 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
511 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
516 * Quirk to work around issue generated by the SN65LVPE502CP USB3.0 re-driver
527 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
528 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
530 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
533 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
540 * USB3.0 re-driver and that need the Compliance Mode Quirk.
542 * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820
553 if (!(strstr(dmi_sys_vendor, "Hewlett-Packard"))) in xhci_compliance_mode_recovery_timer_quirk_check()
567 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
572 * Initialize memory for HCD and xHC (one-time init).
584 spin_lock_init(&xhci->lock); in xhci_init()
585 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_init()
588 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_init()
598 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
605 /*-------------------------------------------------------------------------*/
612 return -ENODEV; in xhci_run_finished()
614 xhci->shared_hcd->state = HC_STATE_RUNNING; in xhci_run_finished()
615 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
617 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
635 * Setup MSI-X vectors and enable interrupts.
648 hcd->uses_new_polling = 1; in xhci_run()
658 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_run()
665 temp = readl(&xhci->ir_set->irq_control); in xhci_run()
667 temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; in xhci_run()
668 writel(temp, &xhci->ir_set->irq_control); in xhci_run()
671 temp = readl(&xhci->op_regs->command); in xhci_run()
675 writel(temp, &xhci->op_regs->command); in xhci_run()
677 temp = readl(&xhci->ir_set->irq_pending); in xhci_run()
680 xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); in xhci_run()
681 writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); in xhci_run()
683 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
688 return -ENOMEM; in xhci_run()
695 set_bit(HCD_FLAG_DEFER_RH_REGISTER, &hcd->flags); in xhci_run()
697 "Finished xhci_run for USB2 roothub"); in xhci_run()
713 * Disable device contexts, disable IRQs, and quiesce the HC.
721 mutex_lock(&xhci->mutex); in xhci_stop()
725 mutex_unlock(&xhci->mutex); in xhci_stop()
731 spin_lock_irq(&xhci->lock); in xhci_stop()
732 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
733 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
736 spin_unlock_irq(&xhci->lock); in xhci_stop()
741 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
743 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
749 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
754 temp = readl(&xhci->op_regs->status); in xhci_stop()
755 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
756 temp = readl(&xhci->ir_set->irq_pending); in xhci_stop()
757 writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending); in xhci_stop()
763 "xhci_stop completed - status = %x", in xhci_stop()
764 readl(&xhci->op_regs->status)); in xhci_stop()
765 mutex_unlock(&xhci->mutex); in xhci_stop()
769 * Shutdown HC (not bus-specific)
781 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
782 usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev)); in xhci_shutdown()
784 spin_lock_irq(&xhci->lock); in xhci_shutdown()
787 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) in xhci_shutdown()
789 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
794 "xhci_shutdown completed - status = %x", in xhci_shutdown()
795 readl(&xhci->op_regs->status)); in xhci_shutdown()
802 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
803 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
804 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
805 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
806 xhci->s3.erst_size = readl(&xhci->ir_set->erst_size); in xhci_save_registers()
807 xhci->s3.erst_base = xhci_read_64(xhci, &xhci->ir_set->erst_base); in xhci_save_registers()
808 xhci->s3.erst_dequeue = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); in xhci_save_registers()
809 xhci->s3.irq_pending = readl(&xhci->ir_set->irq_pending); in xhci_save_registers()
810 xhci->s3.irq_control = readl(&xhci->ir_set->irq_control); in xhci_save_registers()
815 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
816 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
817 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
818 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
819 writel(xhci->s3.erst_size, &xhci->ir_set->erst_size); in xhci_restore_registers()
820 xhci_write_64(xhci, xhci->s3.erst_base, &xhci->ir_set->erst_base); in xhci_restore_registers()
821 xhci_write_64(xhci, xhci->s3.erst_dequeue, &xhci->ir_set->erst_dequeue); in xhci_restore_registers()
822 writel(xhci->s3.irq_pending, &xhci->ir_set->irq_pending); in xhci_restore_registers()
823 writel(xhci->s3.irq_control, &xhci->ir_set->irq_control); in xhci_restore_registers()
831 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
833 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
834 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
836 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
840 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
847 * need to re-program it on resume. Unfortunately, the pointer must be 64-byte
850 * middle of the ring (TRBs are 16-byte aligned).
857 ring = xhci->cmd_ring; in xhci_clear_command_ring()
858 seg = ring->deq_seg; in xhci_clear_command_ring()
860 memset(seg->trbs, 0, in xhci_clear_command_ring()
861 sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); in xhci_clear_command_ring()
862 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= in xhci_clear_command_ring()
864 seg = seg->next; in xhci_clear_command_ring()
865 } while (seg != ring->deq_seg); in xhci_clear_command_ring()
868 ring->deq_seg = ring->first_seg; in xhci_clear_command_ring()
869 ring->dequeue = ring->first_seg->trbs; in xhci_clear_command_ring()
870 ring->enq_seg = ring->deq_seg; in xhci_clear_command_ring()
871 ring->enqueue = ring->dequeue; in xhci_clear_command_ring()
873 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in xhci_clear_command_ring()
878 ring->cycle_state = 1; in xhci_clear_command_ring()
882 * Yes, this will need to be re-written after resume, but we're paranoid in xhci_clear_command_ring()
891 * Disable port wake bits if do_wakeup is not set.
907 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
909 for (i = 0; i < rhub->num_ports; i++) { in xhci_disable_hub_port_wake()
910 portsc = readl(rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
923 writel(t2, rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
924 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
925 rhub->hcd->self.busnum, i + 1, portsc, t2); in xhci_disable_hub_port_wake()
928 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
938 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
947 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
948 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
949 while (port_index--) { in xhci_pending_portevent()
950 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
955 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
956 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
957 while (port_index--) { in xhci_pending_portevent()
958 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
967 * Stop HC (not bus-specific)
980 if (!hcd->state) in xhci_suspend()
983 if (hcd->state != HC_STATE_SUSPENDED || in xhci_suspend()
984 xhci->shared_hcd->state != HC_STATE_SUSPENDED) in xhci_suspend()
985 return -EINVAL; in xhci_suspend()
988 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
989 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
998 __func__, hcd->self.busnum); in xhci_suspend()
999 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_suspend()
1000 del_timer_sync(&hcd->rh_timer); in xhci_suspend()
1001 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
1002 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
1004 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
1007 spin_lock_irq(&xhci->lock); in xhci_suspend()
1008 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_suspend()
1009 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
1014 command = readl(&xhci->op_regs->command); in xhci_suspend()
1016 writel(command, &xhci->op_regs->command); in xhci_suspend()
1019 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
1021 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
1024 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1025 return -ETIMEDOUT; in xhci_suspend()
1033 command = readl(&xhci->op_regs->command); in xhci_suspend()
1035 writel(command, &xhci->op_regs->command); in xhci_suspend()
1036 xhci->broken_suspend = 0; in xhci_suspend()
1037 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
1048 res = readl(&xhci->op_regs->status); in xhci_suspend()
1049 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
1052 xhci->broken_suspend = 1; in xhci_suspend()
1055 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1056 return -ETIMEDOUT; in xhci_suspend()
1059 spin_unlock_irq(&xhci->lock); in xhci_suspend()
1065 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
1067 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
1074 /* synchronize irq when using MSI-X */ in xhci_suspend()
1082 * start xHC (not bus-specific)
1096 if (!hcd->state) in xhci_resume()
1103 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
1104 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
1107 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_resume()
1108 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
1110 spin_lock_irq(&xhci->lock); in xhci_resume()
1111 if ((xhci->quirks & XHCI_RESET_ON_RESUME) || xhci->broken_suspend) in xhci_resume()
1119 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1124 spin_unlock_irq(&xhci->lock); in xhci_resume()
1133 command = readl(&xhci->op_regs->command); in xhci_resume()
1135 writel(command, &xhci->op_regs->command); in xhci_resume()
1141 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1144 spin_unlock_irq(&xhci->lock); in xhci_resume()
1145 return -ETIMEDOUT; in xhci_resume()
1147 temp = readl(&xhci->op_regs->status); in xhci_resume()
1150 /* If restore operation fails, re-initialize the HC during resume */ in xhci_resume()
1153 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1155 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1161 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1162 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1168 spin_unlock_irq(&xhci->lock); in xhci_resume()
1174 temp = readl(&xhci->op_regs->status); in xhci_resume()
1175 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1176 temp = readl(&xhci->ir_set->irq_pending); in xhci_resume()
1177 writel(ER_IRQ_DISABLE(temp), &xhci->ir_set->irq_pending); in xhci_resume()
1182 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1183 readl(&xhci->op_regs->status)); in xhci_resume()
1192 secondary_hcd = xhci->shared_hcd; in xhci_resume()
1195 retval = xhci_init(hcd->primary_hcd); in xhci_resume()
1201 retval = xhci_run(hcd->primary_hcd); in xhci_resume()
1206 hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1207 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1212 command = readl(&xhci->op_regs->command); in xhci_resume()
1214 writel(command, &xhci->op_regs->command); in xhci_resume()
1215 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1227 spin_unlock_irq(&xhci->lock); in xhci_resume()
1245 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1251 * be re-initialized Always after a system resume. Ports are subject in xhci_resume()
1255 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1258 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1259 usb_asmedia_modifyflowcontrol(to_pci_dev(hcd->self.controller)); in xhci_resume()
1261 /* Re-enable port polling. */ in xhci_resume()
1263 __func__, hcd->self.busnum); in xhci_resume()
1264 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1265 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1266 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_resume()
1274 /*-------------------------------------------------------------------------*/
1284 buf_len = urb->transfer_buffer_length; in xhci_map_temp_buffer()
1287 dev_to_node(hcd->self.sysdev)); in xhci_map_temp_buffer()
1290 sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_map_temp_buffer()
1293 urb->transfer_buffer = temp; in xhci_map_temp_buffer()
1294 urb->transfer_dma = dma_map_single(hcd->self.sysdev, in xhci_map_temp_buffer()
1295 urb->transfer_buffer, in xhci_map_temp_buffer()
1296 urb->transfer_buffer_length, in xhci_map_temp_buffer()
1299 if (dma_mapping_error(hcd->self.sysdev, in xhci_map_temp_buffer()
1300 urb->transfer_dma)) { in xhci_map_temp_buffer()
1301 ret = -EAGAIN; in xhci_map_temp_buffer()
1304 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in xhci_map_temp_buffer()
1321 tail_sg = urb->sg; in xhci_urb_temp_buffer_required()
1322 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_urb_temp_buffer_required()
1324 if (!urb->num_sgs) in xhci_urb_temp_buffer_required()
1327 if (urb->dev->speed >= USB_SPEED_SUPER) in xhci_urb_temp_buffer_required()
1332 if (urb->transfer_buffer_length != 0 && in xhci_urb_temp_buffer_required()
1333 !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in xhci_urb_temp_buffer_required()
1334 for_each_sg(urb->sg, sg, urb->num_sgs, i) { in xhci_urb_temp_buffer_required()
1335 len = len + sg->length; in xhci_urb_temp_buffer_required()
1336 if (i > trb_size - 2) { in xhci_urb_temp_buffer_required()
1337 len = len - tail_sg->length; in xhci_urb_temp_buffer_required()
1358 buf_len = urb->transfer_buffer_length; in xhci_unmap_temp_buf()
1361 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_temp_buf()
1362 dma_unmap_single(hcd->self.sysdev, in xhci_unmap_temp_buf()
1363 urb->transfer_dma, in xhci_unmap_temp_buf()
1364 urb->transfer_buffer_length, in xhci_unmap_temp_buf()
1368 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, in xhci_unmap_temp_buf()
1369 urb->transfer_buffer, in xhci_unmap_temp_buf()
1375 urb->actual_length = len; in xhci_unmap_temp_buf()
1378 urb->transfer_flags &= ~URB_DMA_MAP_SINGLE; in xhci_unmap_temp_buf()
1379 kfree(urb->transfer_buffer); in xhci_unmap_temp_buf()
1380 urb->transfer_buffer = NULL; in xhci_unmap_temp_buf()
1399 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1413 if (urb->num_sgs && (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_urb_for_dma()
1416 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1423 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and
1427 * Index = (epnum * 2) + direction - 1,
1430 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
1439 (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; in xhci_get_endpoint_index()
1471 return fls(added_ctxs) - 1; in xhci_last_valid_endpoint()
1475 * returns 0 this is a root hub; returns -EINVAL for NULL pointers.
1485 return -EINVAL; in xhci_check_args()
1487 if (!udev->parent) { in xhci_check_args()
1494 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1497 return -EINVAL; in xhci_check_args()
1500 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1501 if (virt_dev->udev != udev) { in xhci_check_args()
1504 return -EINVAL; in xhci_check_args()
1508 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1509 return -ENODEV; in xhci_check_args()
1535 out_ctx = xhci->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
1537 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); in xhci_check_maxpacket()
1538 max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); in xhci_check_maxpacket()
1552 /* FIXME: This won't work if a non-default control endpoint in xhci_check_maxpacket()
1558 return -ENOMEM; in xhci_check_maxpacket()
1560 command->in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
1561 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_maxpacket()
1565 ret = -ENOMEM; in xhci_check_maxpacket()
1569 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
1570 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
1572 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_check_maxpacket()
1573 ep_ctx->ep_info &= cpu_to_le32(~EP_STATE_MASK);/* must clear */ in xhci_check_maxpacket()
1574 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); in xhci_check_maxpacket()
1575 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); in xhci_check_maxpacket()
1577 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); in xhci_check_maxpacket()
1578 ctrl_ctx->drop_flags = 0; in xhci_check_maxpacket()
1580 ret = xhci_configure_endpoint(xhci, urb->dev, command, in xhci_check_maxpacket()
1586 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_check_maxpacket()
1588 kfree(command->completion); in xhci_check_maxpacket()
1595 * non-error returns are a promise to giveback() the urb later
1608 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, in xhci_urb_enqueue()
1610 return -EINVAL; in xhci_urb_enqueue()
1612 slot_id = urb->dev->slot_id; in xhci_urb_enqueue()
1613 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_enqueue()
1614 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1617 return -ESHUTDOWN; in xhci_urb_enqueue()
1619 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1621 return -ENODEV; in xhci_urb_enqueue()
1624 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) in xhci_urb_enqueue()
1625 num_tds = urb->number_of_packets; in xhci_urb_enqueue()
1626 else if (usb_endpoint_is_bulk_out(&urb->ep->desc) && in xhci_urb_enqueue()
1627 urb->transfer_buffer_length > 0 && in xhci_urb_enqueue()
1628 urb->transfer_flags & URB_ZERO_PACKET && in xhci_urb_enqueue()
1629 !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc))) in xhci_urb_enqueue()
1636 return -ENOMEM; in xhci_urb_enqueue()
1638 urb_priv->num_tds = num_tds; in xhci_urb_enqueue()
1639 urb_priv->num_tds_done = 0; in xhci_urb_enqueue()
1640 urb->hcpriv = urb_priv; in xhci_urb_enqueue()
1644 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in xhci_urb_enqueue()
1648 if (urb->dev->speed == USB_SPEED_FULL) { in xhci_urb_enqueue()
1653 urb->hcpriv = NULL; in xhci_urb_enqueue()
1659 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1661 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1662 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1663 urb->ep->desc.bEndpointAddress, urb); in xhci_urb_enqueue()
1664 ret = -ESHUTDOWN; in xhci_urb_enqueue()
1670 ret = -EINVAL; in xhci_urb_enqueue()
1675 ret = -EINVAL; in xhci_urb_enqueue()
1679 switch (usb_endpoint_type(&urb->ep->desc)) { in xhci_urb_enqueue()
1701 urb->hcpriv = NULL; in xhci_urb_enqueue()
1703 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1723 * series of 1-TRB transfer no-op TDs. (No-ops shouldn't be chained.) The
1753 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1763 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1764 urb_priv = urb->hcpriv; in xhci_urb_dequeue()
1768 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_dequeue()
1769 ep = &vdev->eps[ep_index]; in xhci_urb_dequeue()
1775 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1776 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1782 * check ring is not re-allocated since URB was enqueued. If it is, then in xhci_urb_dequeue()
1786 if (!td_on_ring(&urb_priv->td[0], ep_ring)) { in xhci_urb_dequeue()
1788 for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1789 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1790 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1791 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1796 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1799 for (i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1800 i < urb_priv->num_tds; in xhci_urb_dequeue()
1802 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1803 if (!list_empty(&td->td_list)) in xhci_urb_dequeue()
1804 list_del_init(&td->td_list); in xhci_urb_dequeue()
1805 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1806 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1811 i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1812 if (i < urb_priv->num_tds) in xhci_urb_dequeue()
1816 urb, urb->dev->devpath, in xhci_urb_dequeue()
1817 urb->ep->desc.bEndpointAddress, in xhci_urb_dequeue()
1819 urb_priv->td[i].start_seg, in xhci_urb_dequeue()
1820 urb_priv->td[i].first_trb)); in xhci_urb_dequeue()
1822 for (; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1823 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1825 if (list_empty(&td->cancelled_td_list)) { in xhci_urb_dequeue()
1826 td->cancel_status = TD_DIRTY; in xhci_urb_dequeue()
1827 list_add_tail(&td->cancelled_td_list, in xhci_urb_dequeue()
1828 &ep->cancelled_td_list); in xhci_urb_dequeue()
1835 if (!(ep->ep_state & EP_STOP_CMD_PENDING)) { in xhci_urb_dequeue()
1838 ret = -ENOMEM; in xhci_urb_dequeue()
1841 ep->ep_state |= EP_STOP_CMD_PENDING; in xhci_urb_dequeue()
1842 ep->stop_cmd_timer.expires = jiffies + in xhci_urb_dequeue()
1844 add_timer(&ep->stop_cmd_timer); in xhci_urb_dequeue()
1845 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1850 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1857 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1858 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN); in xhci_urb_dequeue()
1873 * the xhci->devs[slot_id] structure.
1891 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1892 return -ENODEV; in xhci_drop_endpoint()
1895 drop_flag = xhci_get_endpoint_flag(&ep->desc); in xhci_drop_endpoint()
1897 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1902 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1903 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1911 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_drop_endpoint()
1917 le32_to_cpu(ctrl_ctx->drop_flags) & in xhci_drop_endpoint()
1918 xhci_get_endpoint_flag(&ep->desc)) { in xhci_drop_endpoint()
1920 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1926 ctrl_ctx->drop_flags |= cpu_to_le32(drop_flag); in xhci_drop_endpoint()
1927 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_drop_endpoint()
1929 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); in xhci_drop_endpoint()
1930 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_drop_endpoint()
1932 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1934 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1937 (unsigned int) ep->desc.bEndpointAddress, in xhci_drop_endpoint()
1938 udev->slot_id, in xhci_drop_endpoint()
1956 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1974 ep->hcpriv = NULL; in xhci_add_endpoint()
1978 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1979 return -ENODEV; in xhci_add_endpoint()
1981 added_ctxs = xhci_get_endpoint_flag(&ep->desc); in xhci_add_endpoint()
1987 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1992 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1993 in_ctx = virt_dev->in_ctx; in xhci_add_endpoint()
2001 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_add_endpoint()
2005 if (virt_dev->eps[ep_index].ring && in xhci_add_endpoint()
2006 !(le32_to_cpu(ctrl_ctx->drop_flags) & added_ctxs)) { in xhci_add_endpoint()
2009 (unsigned int) ep->desc.bEndpointAddress); in xhci_add_endpoint()
2010 return -EINVAL; in xhci_add_endpoint()
2016 if (le32_to_cpu(ctrl_ctx->add_flags) & added_ctxs) { in xhci_add_endpoint()
2028 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", in xhci_add_endpoint()
2029 __func__, ep->desc.bEndpointAddress); in xhci_add_endpoint()
2030 return -ENOMEM; in xhci_add_endpoint()
2033 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs); in xhci_add_endpoint()
2034 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_add_endpoint()
2038 * this re-adds a new state for the endpoint from the new endpoint in xhci_add_endpoint()
2039 * descriptors. We must drop and re-add this endpoint, so we leave the in xhci_add_endpoint()
2042 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_add_endpoint()
2045 ep->hcpriv = udev; in xhci_add_endpoint()
2047 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
2051 (unsigned int) ep->desc.bEndpointAddress, in xhci_add_endpoint()
2052 udev->slot_id, in xhci_add_endpoint()
2066 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_zero_in_ctx()
2078 ctrl_ctx->drop_flags = 0; in xhci_zero_in_ctx()
2079 ctrl_ctx->add_flags = 0; in xhci_zero_in_ctx()
2080 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
2081 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_zero_in_ctx()
2083 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in xhci_zero_in_ctx()
2085 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
2086 ep_ctx->ep_info = 0; in xhci_zero_in_ctx()
2087 ep_ctx->ep_info2 = 0; in xhci_zero_in_ctx()
2088 ep_ctx->deq = 0; in xhci_zero_in_ctx()
2089 ep_ctx->tx_info = 0; in xhci_zero_in_ctx()
2102 ret = -ETIME; in xhci_configure_endpoint_result()
2105 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2107 ret = -ENOMEM; in xhci_configure_endpoint_result()
2112 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2114 ret = -ENOSPC; in xhci_configure_endpoint_result()
2119 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " in xhci_configure_endpoint_result()
2122 ret = -EINVAL; in xhci_configure_endpoint_result()
2125 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2127 ret = -ENODEV; in xhci_configure_endpoint_result()
2137 ret = -EINVAL; in xhci_configure_endpoint_result()
2152 ret = -ETIME; in xhci_evaluate_context_result()
2155 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2157 ret = -EINVAL; in xhci_evaluate_context_result()
2160 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2162 ret = -EINVAL; in xhci_evaluate_context_result()
2165 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2167 ret = -EINVAL; in xhci_evaluate_context_result()
2170 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2172 ret = -ENODEV; in xhci_evaluate_context_result()
2176 dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); in xhci_evaluate_context_result()
2177 ret = -EINVAL; in xhci_evaluate_context_result()
2187 ret = -EINVAL; in xhci_evaluate_context_result()
2203 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_new_endpoints()
2204 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_new_endpoints()
2210 return hweight32(valid_add_flags) - in xhci_count_num_new_endpoints()
2220 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_dropped_endpoints()
2221 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_dropped_endpoints()
2223 return hweight32(valid_drop_flags) - in xhci_count_num_dropped_endpoints()
2233 * - the first configure endpoint command drops more endpoints than it adds
2234 * - a second configure endpoint command that adds more endpoints is queued
2235 * - the first configure endpoint command fails, so the config is unchanged
2236 * - the second command may succeed, even though there isn't enough resources
2238 * Must be called with xhci->lock held.
2246 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2250 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2251 xhci->limit_active_eps); in xhci_reserve_host_resources()
2252 return -ENOMEM; in xhci_reserve_host_resources()
2254 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2257 xhci->num_active_eps); in xhci_reserve_host_resources()
2265 * Must be called with xhci->lock held.
2273 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2277 xhci->num_active_eps); in xhci_free_host_resources()
2284 * Must be called with xhci->lock held.
2292 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2297 xhci->num_active_eps); in xhci_finish_resource_reservation()
2302 switch (udev->speed) { in xhci_get_block_size()
2322 if (interval_bw->overhead[LS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2324 if (interval_bw->overhead[FS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2341 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2342 tt_info = virt_dev->tt_info; in xhci_check_tt_bw_table()
2349 if (old_active_eps == 0 && tt_info->active_eps != 0) { in xhci_check_tt_bw_table()
2350 if (bw_table->bw_used + TT_HS_OVERHEAD > HS_BW_LIMIT) in xhci_check_tt_bw_table()
2351 return -ENOMEM; in xhci_check_tt_bw_table()
2369 if (virt_dev->bw_table->ss_bw_in > (SS_BW_LIMIT_IN - bw_reserved)) in xhci_check_ss_bw()
2370 return -ENOMEM; in xhci_check_ss_bw()
2373 if (virt_dev->bw_table->ss_bw_out > (SS_BW_LIMIT_OUT - bw_reserved)) in xhci_check_ss_bw()
2374 return -ENOMEM; in xhci_check_ss_bw()
2380 * This algorithm is a very conservative estimate of the worst-case scheduling
2388 * over-estimate.
2435 if (virt_dev->udev->speed >= USB_SPEED_SUPER) in xhci_check_bw_table()
2438 if (virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2447 bw_table = virt_dev->bw_table; in xhci_check_bw_table()
2451 block_size = xhci_get_block_size(virt_dev->udev); in xhci_check_bw_table()
2456 if (virt_dev->tt_info) { in xhci_check_bw_table()
2459 virt_dev->real_port); in xhci_check_bw_table()
2463 return -ENOMEM; in xhci_check_bw_table()
2467 virt_dev->tt_info->slot_id, in xhci_check_bw_table()
2468 virt_dev->tt_info->ttport); in xhci_check_bw_table()
2472 virt_dev->real_port); in xhci_check_bw_table()
2478 bw_used = DIV_ROUND_UP(bw_table->interval0_esit_payload, block_size) + in xhci_check_bw_table()
2479 bw_table->interval_bw[0].num_packets * in xhci_check_bw_table()
2480 xhci_get_largest_overhead(&bw_table->interval_bw[0]); in xhci_check_bw_table()
2493 bw_table->interval_bw[i].num_packets; in xhci_check_bw_table()
2498 if (list_empty(&bw_table->interval_bw[i].endpoints)) in xhci_check_bw_table()
2504 ep_entry = bw_table->interval_bw[i].endpoints.next; in xhci_check_bw_table()
2509 virt_ep->bw_info.max_packet_size, in xhci_check_bw_table()
2517 &bw_table->interval_bw[i]); in xhci_check_bw_table()
2556 return -ENOMEM; in xhci_check_bw_table()
2560 * Ok, we know we have some packets left over after even-handedly in xhci_check_bw_table()
2562 * fit into, so we over-schedule and say they will be scheduled every in xhci_check_bw_table()
2568 if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2569 unsigned int port_index = virt_dev->real_port - 1; in xhci_check_bw_table()
2576 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2583 (max_bandwidth - bw_used - bw_reserved) * 100 / in xhci_check_bw_table()
2590 return -ENOMEM; in xhci_check_bw_table()
2593 bw_table->bw_used = bw_used; in xhci_check_bw_table()
2611 unsigned int mps = DIV_ROUND_UP(ep_bw->max_packet_size, SS_BLOCK); in xhci_get_ss_bw_consumed()
2613 if (ep_bw->ep_interval == 0) in xhci_get_ss_bw_consumed()
2615 (ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2617 return DIV_ROUND_UP(ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2619 1 << ep_bw->ep_interval); in xhci_get_ss_bw_consumed()
2633 if (xhci_is_async_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2636 if (udev->speed >= USB_SPEED_SUPER) { in xhci_drop_ep_from_interval_table()
2637 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2638 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2641 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2649 if (list_empty(&virt_ep->bw_endpoint_list)) in xhci_drop_ep_from_interval_table()
2654 if (udev->speed == USB_SPEED_HIGH) in xhci_drop_ep_from_interval_table()
2655 normalized_interval = ep_bw->ep_interval; in xhci_drop_ep_from_interval_table()
2657 normalized_interval = ep_bw->ep_interval - 3; in xhci_drop_ep_from_interval_table()
2660 bw_table->interval0_esit_payload -= ep_bw->max_esit_payload; in xhci_drop_ep_from_interval_table()
2661 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_drop_ep_from_interval_table()
2662 interval_bw->num_packets -= ep_bw->num_packets; in xhci_drop_ep_from_interval_table()
2663 switch (udev->speed) { in xhci_drop_ep_from_interval_table()
2665 interval_bw->overhead[LS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2668 interval_bw->overhead[FS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2671 interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2683 tt_info->active_eps -= 1; in xhci_drop_ep_from_interval_table()
2684 list_del_init(&virt_ep->bw_endpoint_list); in xhci_drop_ep_from_interval_table()
2698 if (xhci_is_async_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2701 if (udev->speed == USB_SPEED_SUPER) { in xhci_add_ep_to_interval_table()
2702 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2703 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2706 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2714 if (udev->speed == USB_SPEED_HIGH) in xhci_add_ep_to_interval_table()
2715 normalized_interval = ep_bw->ep_interval; in xhci_add_ep_to_interval_table()
2717 normalized_interval = ep_bw->ep_interval - 3; in xhci_add_ep_to_interval_table()
2720 bw_table->interval0_esit_payload += ep_bw->max_esit_payload; in xhci_add_ep_to_interval_table()
2721 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_add_ep_to_interval_table()
2722 interval_bw->num_packets += ep_bw->num_packets; in xhci_add_ep_to_interval_table()
2723 switch (udev->speed) { in xhci_add_ep_to_interval_table()
2725 interval_bw->overhead[LS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2728 interval_bw->overhead[FS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2731 interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2744 tt_info->active_eps += 1; in xhci_add_ep_to_interval_table()
2746 list_for_each_entry(smaller_ep, &interval_bw->endpoints, in xhci_add_ep_to_interval_table()
2748 if (ep_bw->max_packet_size >= in xhci_add_ep_to_interval_table()
2749 smaller_ep->bw_info.max_packet_size) { in xhci_add_ep_to_interval_table()
2751 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2752 &smaller_ep->bw_endpoint_list); in xhci_add_ep_to_interval_table()
2757 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2758 &interval_bw->endpoints); in xhci_add_ep_to_interval_table()
2766 if (!virt_dev->tt_info) in xhci_update_tt_active_eps()
2769 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2771 virt_dev->tt_info->active_eps != 0) { in xhci_update_tt_active_eps()
2772 rh_bw_info->num_active_tts += 1; in xhci_update_tt_active_eps()
2773 rh_bw_info->bw_table.bw_used += TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2775 virt_dev->tt_info->active_eps == 0) { in xhci_update_tt_active_eps()
2776 rh_bw_info->num_active_tts -= 1; in xhci_update_tt_active_eps()
2777 rh_bw_info->bw_table.bw_used -= TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2790 if (virt_dev->tt_info) in xhci_reserve_bandwidth()
2791 old_active_eps = virt_dev->tt_info->active_eps; in xhci_reserve_bandwidth()
2797 return -ENOMEM; in xhci_reserve_bandwidth()
2805 memcpy(&ep_bw_info[i], &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2812 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2813 virt_dev->bw_table, in xhci_reserve_bandwidth()
2814 virt_dev->udev, in xhci_reserve_bandwidth()
2815 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2816 virt_dev->tt_info); in xhci_reserve_bandwidth()
2819 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2824 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2825 virt_dev->bw_table, in xhci_reserve_bandwidth()
2826 virt_dev->udev, in xhci_reserve_bandwidth()
2827 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2828 virt_dev->tt_info); in xhci_reserve_bandwidth()
2849 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2850 virt_dev->bw_table, in xhci_reserve_bandwidth()
2851 virt_dev->udev, in xhci_reserve_bandwidth()
2852 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2853 virt_dev->tt_info); in xhci_reserve_bandwidth()
2856 memcpy(&virt_dev->eps[i].bw_info, &ep_bw_info[i], in xhci_reserve_bandwidth()
2861 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2862 virt_dev->bw_table, in xhci_reserve_bandwidth()
2863 virt_dev->udev, in xhci_reserve_bandwidth()
2864 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2865 virt_dev->tt_info); in xhci_reserve_bandwidth()
2867 return -ENOMEM; in xhci_reserve_bandwidth()
2886 return -EINVAL; in xhci_configure_endpoint()
2888 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2890 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2891 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2892 return -ESHUTDOWN; in xhci_configure_endpoint()
2895 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2897 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_configure_endpoint()
2899 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2902 return -ENOMEM; in xhci_configure_endpoint()
2905 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2907 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2910 xhci->num_active_eps); in xhci_configure_endpoint()
2911 return -ENOMEM; in xhci_configure_endpoint()
2913 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && in xhci_configure_endpoint()
2914 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2915 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2917 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2919 return -ENOMEM; in xhci_configure_endpoint()
2922 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2929 command->in_ctx->dma, in xhci_configure_endpoint()
2930 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2933 command->in_ctx->dma, in xhci_configure_endpoint()
2934 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2936 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2938 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2941 return -ENOMEM; in xhci_configure_endpoint()
2944 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2947 wait_for_completion(command->completion); in xhci_configure_endpoint()
2951 &command->status); in xhci_configure_endpoint()
2954 &command->status); in xhci_configure_endpoint()
2956 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2957 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2965 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2973 struct xhci_virt_ep *ep = &vdev->eps[i]; in xhci_check_bw_drop_ep_streams()
2975 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_check_bw_drop_ep_streams()
2978 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2979 ep->stream_info = NULL; in xhci_check_bw_drop_ep_streams()
2980 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_check_bw_drop_ep_streams()
2991 * else should be touching the xhci->devs[slot_id] structure, so we
2992 * don't need to take the xhci->lock for manipulating that.
3008 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
3009 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
3010 return -ENODEV; in xhci_check_bandwidth()
3013 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
3017 return -ENOMEM; in xhci_check_bandwidth()
3019 command->in_ctx = virt_dev->in_ctx; in xhci_check_bandwidth()
3021 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ in xhci_check_bandwidth()
3022 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_bandwidth()
3026 ret = -ENOMEM; in xhci_check_bandwidth()
3029 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_check_bandwidth()
3030 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); in xhci_check_bandwidth()
3031 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); in xhci_check_bandwidth()
3034 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && in xhci_check_bandwidth()
3035 ctrl_ctx->drop_flags == 0) { in xhci_check_bandwidth()
3040 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
3041 for (i = 31; i >= 1; i--) { in xhci_check_bandwidth()
3044 if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32)) in xhci_check_bandwidth()
3045 || (ctrl_ctx->add_flags & le32) || i == 1) { in xhci_check_bandwidth()
3046 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_check_bandwidth()
3047 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); in xhci_check_bandwidth()
3060 if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) && in xhci_check_bandwidth()
3061 !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))) { in xhci_check_bandwidth()
3072 if (!virt_dev->eps[i].new_ring) in xhci_check_bandwidth()
3077 if (virt_dev->eps[i].ring) { in xhci_check_bandwidth()
3081 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; in xhci_check_bandwidth()
3082 virt_dev->eps[i].new_ring = NULL; in xhci_check_bandwidth()
3086 kfree(command->completion); in xhci_check_bandwidth()
3105 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
3108 if (virt_dev->eps[i].new_ring) { in xhci_reset_bandwidth()
3110 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3111 virt_dev->eps[i].new_ring = NULL; in xhci_reset_bandwidth()
3124 ctrl_ctx->add_flags = cpu_to_le32(add_flags); in xhci_setup_input_ctx_for_config_ep()
3125 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags); in xhci_setup_input_ctx_for_config_ep()
3127 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_setup_input_ctx_for_config_ep()
3142 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3144 udev = (struct usb_device *)host_ep->hcpriv; in xhci_endpoint_disable()
3145 if (!udev || !udev->slot_id) in xhci_endpoint_disable()
3148 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3152 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_disable()
3153 ep = &vdev->eps[ep_index]; in xhci_endpoint_disable()
3158 if (ep->ep_state & EP_CLEARING_TT) { in xhci_endpoint_disable()
3159 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3164 if (ep->ep_state) in xhci_endpoint_disable()
3165 xhci_dbg(xhci, "endpoint disable with ep_state 0x%x\n", in xhci_endpoint_disable()
3166 ep->ep_state); in xhci_endpoint_disable()
3168 host_ep->hcpriv = NULL; in xhci_endpoint_disable()
3169 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3199 if (!host_ep->hcpriv) in xhci_endpoint_reset()
3201 udev = (struct usb_device *) host_ep->hcpriv; in xhci_endpoint_reset()
3202 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3205 * vdev may be lost due to xHC restore error and re-initialization in xhci_endpoint_reset()
3209 if (!udev->slot_id || !vdev) in xhci_endpoint_reset()
3211 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_reset()
3212 ep = &vdev->eps[ep_index]; in xhci_endpoint_reset()
3217 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3218 if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) { in xhci_endpoint_reset()
3219 ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE; in xhci_endpoint_reset()
3220 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3223 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3224 /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */ in xhci_endpoint_reset()
3225 if (usb_endpoint_xfer_control(&host_ep->desc) || in xhci_endpoint_reset()
3226 usb_endpoint_xfer_isoc(&host_ep->desc)) in xhci_endpoint_reset()
3229 ep_flag = xhci_get_endpoint_flag(&host_ep->desc); in xhci_endpoint_reset()
3242 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3245 ep->ep_state |= EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3253 if (!list_empty(&ep->ring->td_list)) { in xhci_endpoint_reset()
3254 dev_err(&udev->dev, "EP not empty, refuse reset\n"); in xhci_endpoint_reset()
3255 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3260 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3263 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3271 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3273 wait_for_completion(stop_cmd->completion); in xhci_endpoint_reset()
3275 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3278 ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); in xhci_endpoint_reset()
3280 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3287 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3289 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3291 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3292 udev->slot_id, false); in xhci_endpoint_reset()
3294 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3302 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3304 wait_for_completion(cfg_cmd->completion); in xhci_endpoint_reset()
3309 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3310 if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) in xhci_endpoint_reset()
3311 ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3312 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3324 return -EINVAL; in xhci_check_streams_endpoint()
3327 return -EINVAL; in xhci_check_streams_endpoint()
3328 if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { in xhci_check_streams_endpoint()
3331 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3332 return -EINVAL; in xhci_check_streams_endpoint()
3335 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_check_streams_endpoint()
3336 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3341 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3344 return -EINVAL; in xhci_check_streams_endpoint()
3346 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3349 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3350 return -EINVAL; in xhci_check_streams_endpoint()
3368 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3393 eps[i], udev->slot_id); in xhci_calculate_streams_and_bitmask()
3397 max_streams = usb_ss_max_streams(&eps[i]->ss_ep_comp); in xhci_calculate_streams_and_bitmask()
3398 if (max_streams < (*num_streams - 1)) { in xhci_calculate_streams_and_bitmask()
3400 eps[i]->desc.bEndpointAddress, in xhci_calculate_streams_and_bitmask()
3405 endpoint_flag = xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_streams_and_bitmask()
3407 return -EINVAL; in xhci_calculate_streams_and_bitmask()
3423 slot_id = udev->slot_id; in xhci_calculate_no_streams_bitmask()
3424 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3428 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3429 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3432 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3435 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3441 xhci_warn(xhci, "WARN Can't disable streams for " in xhci_calculate_no_streams_bitmask()
3444 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3446 "with non-streams endpoint\n"); in xhci_calculate_no_streams_bitmask()
3449 changed_ep_bitmask |= xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3486 return -EINVAL; in xhci_alloc_streams()
3497 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3498 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3500 return -ENOSYS; in xhci_alloc_streams()
3505 return -ENOMEM; in xhci_alloc_streams()
3507 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_alloc_streams()
3512 return -ENOMEM; in xhci_alloc_streams()
3519 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3524 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3531 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3532 return -EINVAL; in xhci_alloc_streams()
3534 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3539 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3540 vdev->eps[ep_index].ep_state |= EP_GETTING_STREAMS; in xhci_alloc_streams()
3542 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3553 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3554 max_packet = usb_endpoint_maxp(&eps[i]->desc); in xhci_alloc_streams()
3555 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3559 if (!vdev->eps[ep_index].stream_info) in xhci_alloc_streams()
3570 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3571 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3573 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3574 vdev->out_ctx, ep_index); in xhci_alloc_streams()
3576 vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3581 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3582 vdev->out_ctx, ctrl_ctx, in xhci_alloc_streams()
3596 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3598 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3599 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3601 udev->slot_id, ep_index); in xhci_alloc_streams()
3602 vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; in xhci_alloc_streams()
3605 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3608 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3612 return num_streams - 1; in xhci_alloc_streams()
3617 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3618 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3619 vdev->eps[ep_index].stream_info = NULL; in xhci_alloc_streams()
3623 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3624 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_alloc_streams()
3628 return -ENOMEM; in xhci_alloc_streams()
3651 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3654 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3658 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3659 return -EINVAL; in xhci_free_streams()
3666 ep_index = xhci_get_endpoint_index(&eps[0]->desc); in xhci_free_streams()
3667 command = vdev->eps[ep_index].stream_info->free_streams_command; in xhci_free_streams()
3668 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_free_streams()
3670 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3673 return -EINVAL; in xhci_free_streams()
3679 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3680 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3681 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3684 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3685 vdev->out_ctx, ep_index); in xhci_free_streams()
3687 &vdev->eps[ep_index]); in xhci_free_streams()
3689 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3690 vdev->out_ctx, ctrl_ctx, in xhci_free_streams()
3692 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3706 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3708 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3709 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3710 vdev->eps[ep_index].stream_info = NULL; in xhci_free_streams()
3714 vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS; in xhci_free_streams()
3715 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_free_streams()
3717 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3724 * Device command, or a Disable Slot command. The Reset Device command leaves
3725 * the control endpoint intact, whereas the Disable Slot command deletes it.
3727 * Must be called with xhci->lock held.
3737 if (virt_dev->eps[i].ring) { in xhci_free_device_endpoint_resources()
3742 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3748 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3753 * set the device address to 0, and disable all the endpoints except the default
3755 * xhci_address_device(), and then re-set up the configuration. If this is
3757 * settings will be re-installed through the normal bandwidth allocation
3766 * re-initialization during S3/S4. In this case, call xhci_alloc_dev() to
3767 * re-allocate the device.
3785 slot_id = udev->slot_id; in xhci_discover_or_reset_device()
3786 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3789 "not exist. Re-allocate the device\n", slot_id); in xhci_discover_or_reset_device()
3794 return -EINVAL; in xhci_discover_or_reset_device()
3797 if (virt_dev->tt_info) in xhci_discover_or_reset_device()
3798 old_active_eps = virt_dev->tt_info->active_eps; in xhci_discover_or_reset_device()
3800 if (virt_dev->udev != udev) { in xhci_discover_or_reset_device()
3803 * Re-allocate the device. in xhci_discover_or_reset_device()
3806 "not match the udev. Re-allocate the device\n", in xhci_discover_or_reset_device()
3812 return -EINVAL; in xhci_discover_or_reset_device()
3816 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3817 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_discover_or_reset_device()
3833 return -ENOMEM; in xhci_discover_or_reset_device()
3837 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3842 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3846 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3849 wait_for_completion(reset_device_cmd->completion); in xhci_discover_or_reset_device()
3855 ret = reset_device_cmd->status; in xhci_discover_or_reset_device()
3860 ret = -ETIME; in xhci_discover_or_reset_device()
3866 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3879 ret = -EINVAL; in xhci_discover_or_reset_device()
3884 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3885 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3888 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3893 struct xhci_virt_ep *ep = &virt_dev->eps[i]; in xhci_discover_or_reset_device()
3895 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_discover_or_reset_device()
3898 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3899 ep->stream_info = NULL; in xhci_discover_or_reset_device()
3900 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_discover_or_reset_device()
3903 if (ep->ring) { in xhci_discover_or_reset_device()
3907 if (!list_empty(&virt_dev->eps[i].bw_endpoint_list)) in xhci_discover_or_reset_device()
3909 &virt_dev->eps[i].bw_info, in xhci_discover_or_reset_device()
3910 virt_dev->bw_table, in xhci_discover_or_reset_device()
3912 &virt_dev->eps[i], in xhci_discover_or_reset_device()
3913 virt_dev->tt_info); in xhci_discover_or_reset_device()
3914 xhci_clear_endpoint_bw_info(&virt_dev->eps[i].bw_info); in xhci_discover_or_reset_device()
3918 virt_dev->flags = 0; in xhci_discover_or_reset_device()
3944 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3945 pm_runtime_put_noidle(hcd->self.controller); in xhci_free_dev()
3952 if (ret <= 0 && ret != -ENODEV) in xhci_free_dev()
3955 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3956 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3961 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING; in xhci_free_dev()
3962 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); in xhci_free_dev()
3964 virt_dev->udev = NULL; in xhci_free_dev()
3965 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3967 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3979 return -ENOMEM; in xhci_disable_slot()
3983 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3984 /* Don't disable the slot if the host controller is dead. */ in xhci_disable_slot()
3985 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3986 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3987 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3988 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3990 return -ENODEV; in xhci_disable_slot()
3996 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4001 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
4009 * Must be called with xhci->lock held.
4013 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
4017 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
4018 return -ENOMEM; in xhci_reserve_host_control_ep_resources()
4020 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
4023 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
4045 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4048 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4054 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4056 wait_for_completion(command->completion); in xhci_alloc_dev()
4057 slot_id = command->slot_id; in xhci_alloc_dev()
4059 if (!slot_id || command->status != COMP_SUCCESS) { in xhci_alloc_dev()
4063 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
4070 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
4071 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
4074 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4077 xhci->num_active_eps); in xhci_alloc_dev()
4080 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4090 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
4091 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
4094 udev->slot_id = slot_id; in xhci_alloc_dev()
4103 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4104 pm_runtime_get_noresume(hcd->self.controller); in xhci_alloc_dev()
4112 ret = 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()
4246 kfree(command->completion); in xhci_setup_device()
4248 return -EPROTO; in xhci_setup_device()
4250 dev_warn(&udev->dev, in xhci_setup_device()
4252 ret = -ENODEV; in xhci_setup_device()
4261 act, command->status); in xhci_setup_device()
4262 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4263 ret = -EINVAL; in xhci_setup_device()
4268 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4273 udev->slot_id, in xhci_setup_device()
4274 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4276 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4279 (unsigned long long)virt_dev->out_ctx->dma); in xhci_setup_device()
4280 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4281 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4286 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4287 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4289 ctrl_ctx->add_flags = 0; in xhci_setup_device()
4290 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4291 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4292 udev->devaddr = (u8)(le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4296 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4298 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4300 kfree(command->completion); in xhci_setup_device()
4327 return rhub->ports[port1 - 1]->hw_portnum + 1; in xhci_find_raw_port_number()
4344 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4346 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4350 * xHC was re-initialized. Exit latency will be set later after in xhci_change_max_exit_latency()
4351 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4354 if (!virt_dev || max_exit_latency == virt_dev->current_mel) { in xhci_change_max_exit_latency()
4355 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4360 command = xhci->lpm_command; in xhci_change_max_exit_latency()
4361 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_change_max_exit_latency()
4363 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4366 return -ENOMEM; in xhci_change_max_exit_latency()
4369 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4370 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4372 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_change_max_exit_latency()
4373 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4374 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); in xhci_change_max_exit_latency()
4375 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency); in xhci_change_max_exit_latency()
4376 slot_ctx->dev_state = 0; in xhci_change_max_exit_latency()
4379 "Set up evaluate context for LPM MEL change."); in xhci_change_max_exit_latency()
4386 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4387 virt_dev->current_mel = max_exit_latency; in xhci_change_max_exit_latency()
4388 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4395 /* BESL to HIRD Encoding array for USB2 LPM */
4399 /* Calculate HIRD/BESL for USB2 PORTPMSC*/
4407 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4408 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_hird_besl()
4424 besl_host = (u2del - 51) / 75 + 1; in xhci_calculate_hird_besl()
4434 /* Calculate BESLD, L1 timeout and HIRDM for USB2 PORTHLPMC */
4442 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_usb2_hw_lpm_params()
4445 l1 = udev->l1_params.timeout / 256; in xhci_calculate_usb2_hw_lpm_params()
4468 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4469 return -EPERM; in xhci_set_usb2_hardware_lpm()
4471 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4472 !udev->lpm_capable) in xhci_set_usb2_hardware_lpm()
4473 return -EPERM; in xhci_set_usb2_hardware_lpm()
4475 if (!udev->parent || udev->parent->parent || in xhci_set_usb2_hardware_lpm()
4476 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_set_usb2_hardware_lpm()
4477 return -EPERM; in xhci_set_usb2_hardware_lpm()
4479 if (udev->usb2_hw_lpm_capable != 1) in xhci_set_usb2_hardware_lpm()
4480 return -EPERM; in xhci_set_usb2_hardware_lpm()
4482 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4484 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4485 port_num = udev->portnum - 1; in xhci_set_usb2_hardware_lpm()
4486 pm_addr = ports[port_num]->addr + PORTPMSC; in xhci_set_usb2_hardware_lpm()
4488 hlpm_addr = ports[port_num]->addr + PORTHLPMC; in xhci_set_usb2_hardware_lpm()
4490 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", in xhci_set_usb2_hardware_lpm()
4491 enable ? "enable" : "disable", port_num + 1); in xhci_set_usb2_hardware_lpm()
4495 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4500 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_set_usb2_hardware_lpm()
4505 hird = udev->l1_params.besl; in xhci_set_usb2_hardware_lpm()
4508 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4510 /* USB 3.0 code dedicate one xhci->lpm_command->in_ctx in xhci_set_usb2_hardware_lpm()
4512 * context commands. It is protected by hcd->bandwidth in xhci_set_usb2_hardware_lpm()
4514 * the max ext latency in USB 2 BESL LPM as well, so in xhci_set_usb2_hardware_lpm()
4517 mutex_lock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4520 mutex_unlock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4524 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4535 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); in xhci_set_usb2_hardware_lpm()
4547 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4548 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4549 mutex_lock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4551 mutex_unlock(hcd->bandwidth_mutex); in xhci_set_usb2_hardware_lpm()
4552 readl_poll_timeout(ports[port_num]->addr, pm_val, in xhci_set_usb2_hardware_lpm()
4559 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4563 /* check if a usb2 port supports a given extened capability protocol
4564 * only USB2 ports extended protocol capability values are cached.
4573 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4574 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4576 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4577 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4589 int portnum = udev->portnum - 1; in xhci_update_device()
4591 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable) in xhci_update_device()
4594 /* we only support lpm for non-hub device connected to root hub yet */ in xhci_update_device()
4595 if (!udev->parent || udev->parent->parent || in xhci_update_device()
4596 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_update_device()
4599 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4602 udev->usb2_hw_lpm_capable = 1; in xhci_update_device()
4603 udev->l1_params.timeout = XHCI_L1_TIMEOUT; in xhci_update_device()
4604 udev->l1_params.besl = XHCI_DEFAULT_BESL; in xhci_update_device()
4607 udev->usb2_hw_lpm_besl_capable = 1; in xhci_update_device()
4613 /*---------------------- USB 3.0 Link PM functions ------------------------*/
4615 /* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
4619 return (1ULL << (desc->bInterval - 1)) * 125 * 1000; in xhci_service_interval_to_ns()
4633 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4634 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4639 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4640 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4645 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n", in xhci_get_timeout_no_hub_lpm()
4654 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4658 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4665 * - For control endpoints, U1 system exit latency (SEL) * 3
4666 * - For bulk endpoints, U1 SEL * 5
4667 * - For interrupt endpoints:
4668 * - Notification EPs, U1 SEL * 3
4669 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
4670 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
4683 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4686 timeout_ns = udev->u1_params.sel * 5; in xhci_calculate_intel_u1_timeout()
4691 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4699 if (timeout_ns < udev->u1_params.sel * 2) in xhci_calculate_intel_u1_timeout()
4700 timeout_ns = udev->u1_params.sel * 2; in xhci_calculate_intel_u1_timeout()
4709 /* Returns the hub-encoded U1 timeout value. */
4718 if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { in xhci_calculate_u1_timeout()
4719 dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); in xhci_calculate_u1_timeout()
4724 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_calculate_u1_timeout()
4727 timeout_ns = udev->u1_params.sel; in xhci_calculate_u1_timeout()
4738 * USB 3.0 hub, we have to disable hub-initiated U1. in xhci_calculate_u1_timeout()
4742 dev_dbg(&udev->dev, "Hub-initiated U1 disabled " in xhci_calculate_u1_timeout()
4748 * - 10 ms (to avoid the bandwidth impact on the scheduler)
4749 * - largest bInterval of any active periodic endpoint (to avoid going
4751 * - the U2 Exit Latency of the device
4766 u2_del_ns = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat) * 1000ULL; in xhci_calculate_intel_u2_timeout()
4773 /* Returns the hub-encoded U2 timeout value. */
4782 if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { in xhci_calculate_u2_timeout()
4783 dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); in xhci_calculate_u2_timeout()
4788 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_calculate_u2_timeout()
4791 timeout_ns = udev->u2_params.sel; in xhci_calculate_u2_timeout()
4796 * USB 3.0 hub, we have to disable hub-initiated U2. in xhci_calculate_u2_timeout()
4800 dev_dbg(&udev->dev, "Hub-initiated U2 disabled " in xhci_calculate_u2_timeout()
4830 /* If we found we can't enable hub-initiated LPM, and in xhci_update_timeout_for_endpoint()
4832 * device-initiated LPM as well, then we will disable LPM in xhci_update_timeout_for_endpoint()
4837 return -E2BIG; in xhci_update_timeout_for_endpoint()
4852 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in xhci_update_timeout_for_interface()
4854 &alt->endpoint[j].desc, state, timeout)) in xhci_update_timeout_for_interface()
4855 return -E2BIG; in xhci_update_timeout_for_interface()
4870 for (parent = udev->parent, num_hubs = 0; parent->parent; in xhci_check_intel_tier_policy()
4871 parent = parent->parent) in xhci_check_intel_tier_policy()
4877 dev_dbg(&udev->dev, "Disabling U1 link state for device" in xhci_check_intel_tier_policy()
4878 " below second-tier hub.\n"); in xhci_check_intel_tier_policy()
4879 dev_dbg(&udev->dev, "Plug device into first-tier hub " in xhci_check_intel_tier_policy()
4881 return -E2BIG; in xhci_check_intel_tier_policy()
4888 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_check_tier_policy()
4895 * If the tier check or timeout setting functions return with a non-zero exit
4913 dev_warn(&udev->dev, "Can't enable unknown link state %i\n", in xhci_calculate_lpm_timeout()
4924 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4928 config = udev->actconfig; in xhci_calculate_lpm_timeout()
4932 for (i = 0; i < config->desc.bNumInterfaces; i++) { in xhci_calculate_lpm_timeout()
4934 struct usb_interface *intf = config->interface[i]; in xhci_calculate_lpm_timeout()
4939 /* Check if any currently bound drivers want hub-initiated LPM in xhci_calculate_lpm_timeout()
4942 if (intf->dev.driver) { in xhci_calculate_lpm_timeout()
4943 driver = to_usb_driver(intf->dev.driver); in xhci_calculate_lpm_timeout()
4944 if (driver && driver->disable_hub_initiated_lpm) { in xhci_calculate_lpm_timeout()
4945 dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n", in xhci_calculate_lpm_timeout()
4946 state_name, driver->name); in xhci_calculate_lpm_timeout()
4955 if (!intf->cur_altsetting) in xhci_calculate_lpm_timeout()
4959 intf->cur_altsetting, in xhci_calculate_lpm_timeout()
4991 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) || in calculate_max_exit_latency()
4993 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000); in calculate_max_exit_latency()
4994 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) || in calculate_max_exit_latency()
4996 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000); in calculate_max_exit_latency()
5004 dev_warn(&udev->dev, "Link PM max exit latency of %lluus " in calculate_max_exit_latency()
5006 return -E2BIG; in calculate_max_exit_latency()
5011 /* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
5021 /* The LPM timeout values are pretty host-controller specific, so don't in xhci_enable_usb3_lpm_timeout()
5022 * enable hub-initiated timeouts unless the vendor has provided in xhci_enable_usb3_lpm_timeout()
5025 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
5026 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
5032 /* Max Exit Latency is too big, disable LPM. */ in xhci_enable_usb3_lpm_timeout()
5050 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
5051 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
5083 /*-------------------------------------------------------------------------*/
5101 if (!hdev->parent) in xhci_update_hub_device()
5104 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
5107 return -EINVAL; in xhci_update_hub_device()
5112 return -ENOMEM; in xhci_update_hub_device()
5114 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_update_hub_device()
5119 return -ENOMEM; in xhci_update_hub_device()
5122 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5123 if (hdev->speed == USB_SPEED_HIGH && in xhci_update_hub_device()
5127 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5128 return -ENOMEM; in xhci_update_hub_device()
5131 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5132 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_update_hub_device()
5133 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5134 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); in xhci_update_hub_device()
5140 if (tt->multi) in xhci_update_hub_device()
5141 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_update_hub_device()
5142 else if (hdev->speed == USB_SPEED_FULL) in xhci_update_hub_device()
5143 slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); in xhci_update_hub_device()
5145 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5148 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5149 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(hdev->maxchild)); in xhci_update_hub_device()
5150 /* Set TT think time - convert from ns to FS bit times. in xhci_update_hub_device()
5155 * High-spped hub. in xhci_update_hub_device()
5157 think_time = tt->think_time; in xhci_update_hub_device()
5159 think_time = (think_time / 666) - 1; in xhci_update_hub_device()
5160 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5161 slot_ctx->tt_info |= in xhci_update_hub_device()
5166 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5168 slot_ctx->dev_state = 0; in xhci_update_hub_device()
5169 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5172 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5178 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5193 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5203 struct device *dev = hcd->self.sysdev; in xhci_gen_setup()
5207 /* Accept arbitrarily long scatter-gather lists */ in xhci_gen_setup()
5208 hcd->self.sg_tablesize = ~0; in xhci_gen_setup()
5211 hcd->self.no_sg_constraint = 1; in xhci_gen_setup()
5214 hcd->self.no_stop_on_short = 1; in xhci_gen_setup()
5219 xhci->main_hcd = hcd; in xhci_gen_setup()
5220 xhci->usb2_rhub.hcd = hcd; in xhci_gen_setup()
5224 hcd->speed = HCD_USB2; in xhci_gen_setup()
5225 hcd->self.root_hub->speed = USB_SPEED_HIGH; in xhci_gen_setup()
5231 hcd->has_tt = 1; in xhci_gen_setup()
5236 * is a two digit BCD containig minor and sub-minor numbers. in xhci_gen_setup()
5242 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_gen_setup()
5245 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_gen_setup()
5249 hcd->speed = HCD_USB32; in xhci_gen_setup()
5250 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_gen_setup()
5251 hcd->self.root_hub->rx_lanes = 2; in xhci_gen_setup()
5252 hcd->self.root_hub->tx_lanes = 2; in xhci_gen_setup()
5253 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x2; in xhci_gen_setup()
5256 hcd->speed = HCD_USB31; in xhci_gen_setup()
5257 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_gen_setup()
5258 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x1; in xhci_gen_setup()
5265 xhci->usb3_rhub.hcd = hcd; in xhci_gen_setup()
5272 mutex_init(&xhci->mutex); in xhci_gen_setup()
5273 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5274 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5275 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5276 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5277 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5278 /* Cache read-only capability registers */ in xhci_gen_setup()
5279 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5280 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5281 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5282 xhci->hcc_params = readl(&xhci->cap_regs->hc_capbase); in xhci_gen_setup()
5283 xhci->hci_version = HC_VERSION(xhci->hcc_params); in xhci_gen_setup()
5284 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5285 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5286 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5288 xhci->quirks |= quirks; in xhci_gen_setup()
5296 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5297 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5314 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5315 * of HCCPARAMS1 is set to 1. However, the xHCs don't support 64-bit in xhci_gen_setup()
5317 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5320 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5321 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5323 /* Set dma_mask and coherent_dma_mask to 64-bits, in xhci_gen_setup()
5324 * if xHC supports 64-bit addressing */ in xhci_gen_setup()
5325 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5327 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5331 * This is to avoid error in cases where a 32-bit USB in xhci_gen_setup()
5332 * controller is used on a 64-bit capable system. in xhci_gen_setup()
5337 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5349 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5366 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5367 udev = (struct usb_device *)ep->hcpriv; in xhci_clear_tt_buffer_complete()
5368 slot_id = udev->slot_id; in xhci_clear_tt_buffer_complete()
5369 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_clear_tt_buffer_complete()
5371 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5373 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5377 .description = "xhci-hcd",
5452 drv->hcd_priv_size += over->extra_priv_size; in xhci_init_driver()
5453 if (over->reset) in xhci_init_driver()
5454 drv->reset = over->reset; in xhci_init_driver()
5455 if (over->start) in xhci_init_driver()
5456 drv->start = over->start; in xhci_init_driver()
5457 if (over->add_endpoint) in xhci_init_driver()
5458 drv->add_endpoint = over->add_endpoint; in xhci_init_driver()
5459 if (over->drop_endpoint) in xhci_init_driver()
5460 drv->drop_endpoint = over->drop_endpoint; in xhci_init_driver()
5461 if (over->check_bandwidth) in xhci_init_driver()
5462 drv->check_bandwidth = over->check_bandwidth; in xhci_init_driver()
5463 if (over->reset_bandwidth) in xhci_init_driver()
5464 drv->reset_bandwidth = over->reset_bandwidth; in xhci_init_driver()
5494 return -ENODEV; in xhci_hcd_init()