Lines Matching +full:usb3 +full:- +full:lpm +full:- +full:capable

1 // SPDX-License-Identifier: GPL-2.0
20 #include <linux/dma-mapping.h>
23 #include "xhci-trace.h"
24 #include "xhci-debugfs.h"
25 #include "xhci-dbgcap.h"
43 struct xhci_segment *seg = ring->first_seg; in td_on_ring()
45 if (!td || !td->start_seg) in td_on_ring()
48 if (seg == td->start_seg) in td_on_ring()
50 seg = seg->next; in td_on_ring()
51 } while (seg && seg != ring->first_seg); in td_on_ring()
57 * xhci_handshake - spin reading hc until handshake completes or fails
67 * hardware flakeout), or the register reads as all-ones (hardware removed).
79 return -ENODEV; in xhci_handshake()
94 halted = readl(&xhci->op_regs->status) & STS_HALT; in xhci_quiesce()
98 cmd = readl(&xhci->op_regs->command); in xhci_quiesce()
100 writel(cmd, &xhci->op_regs->command); in xhci_quiesce()
118 ret = xhci_handshake(&xhci->op_regs->status, in xhci_halt()
125 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_halt()
126 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_halt()
139 temp = readl(&xhci->op_regs->command); in xhci_start()
143 writel(temp, &xhci->op_regs->command); in xhci_start()
149 ret = xhci_handshake(&xhci->op_regs->status, in xhci_start()
151 if (ret == -ETIMEDOUT) in xhci_start()
157 xhci->xhc_state = 0; in xhci_start()
158 xhci->run_graceperiod = jiffies + msecs_to_jiffies(500); in xhci_start()
177 state = readl(&xhci->op_regs->status); in xhci_reset()
181 return -ENODEV; in xhci_reset()
190 command = readl(&xhci->op_regs->command); in xhci_reset()
192 writel(command, &xhci->op_regs->command); in xhci_reset()
201 if (xhci->quirks & XHCI_INTEL_HOST) in xhci_reset()
204 ret = xhci_handshake(&xhci->op_regs->command, CMD_RESET, 0, timeout_us); in xhci_reset()
208 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_reset()
209 usb_asmedia_modifyflowcontrol(to_pci_dev(xhci_to_hcd(xhci)->self.controller)); in xhci_reset()
217 ret = xhci_handshake(&xhci->op_regs->status, STS_CNR, 0, timeout_us); in xhci_reset()
219 xhci->usb2_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
220 xhci->usb2_rhub.bus_state.suspended_ports = 0; in xhci_reset()
221 xhci->usb2_rhub.bus_state.resuming_ports = 0; in xhci_reset()
222 xhci->usb3_rhub.bus_state.port_c_suspend = 0; in xhci_reset()
223 xhci->usb3_rhub.bus_state.suspended_ports = 0; in xhci_reset()
224 xhci->usb3_rhub.bus_state.resuming_ports = 0; in xhci_reset()
231 struct device *dev = xhci_to_hcd(xhci)->self.sysdev; in xhci_zero_64b_regs()
252 if (!(xhci->quirks & XHCI_ZERO_64B_REGS) || !domain || in xhci_zero_64b_regs()
253 domain->type == IOMMU_DOMAIN_IDENTITY) in xhci_zero_64b_regs()
259 val = readl(&xhci->op_regs->command); in xhci_zero_64b_regs()
261 writel(val, &xhci->op_regs->command); in xhci_zero_64b_regs()
264 val = readl(&xhci->op_regs->status); in xhci_zero_64b_regs()
266 writel(val, &xhci->op_regs->status); in xhci_zero_64b_regs()
269 val = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
271 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); in xhci_zero_64b_regs()
272 val = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
274 xhci_write_64(xhci, 0, &xhci->op_regs->cmd_ring); in xhci_zero_64b_regs()
276 intrs = min_t(u32, HCS_MAX_INTRS(xhci->hcs_params1), in xhci_zero_64b_regs()
277 ARRAY_SIZE(xhci->run_regs->ir_set)); in xhci_zero_64b_regs()
282 ir = &xhci->run_regs->ir_set[i]; in xhci_zero_64b_regs()
283 val = xhci_read_64(xhci, &ir->erst_base); in xhci_zero_64b_regs()
285 xhci_write_64(xhci, 0, &ir->erst_base); in xhci_zero_64b_regs()
286 val= xhci_read_64(xhci, &ir->erst_dequeue); in xhci_zero_64b_regs()
288 xhci_write_64(xhci, 0, &ir->erst_dequeue); in xhci_zero_64b_regs()
292 err = xhci_handshake(&xhci->op_regs->status, in xhci_zero_64b_regs()
303 if (!ir || !ir->ir_set) in xhci_enable_interrupter()
304 return -EINVAL; in xhci_enable_interrupter()
306 iman = readl(&ir->ir_set->irq_pending); in xhci_enable_interrupter()
307 writel(ER_IRQ_ENABLE(iman), &ir->ir_set->irq_pending); in xhci_enable_interrupter()
316 if (!ir || !ir->ir_set) in xhci_disable_interrupter()
317 return -EINVAL; in xhci_disable_interrupter()
319 iman = readl(&ir->ir_set->irq_pending); in xhci_disable_interrupter()
320 writel(ER_IRQ_DISABLE(iman), &ir->ir_set->irq_pending); in xhci_disable_interrupter()
334 rhub = &xhci->usb3_rhub; in compliance_mode_recovery()
335 hcd = rhub->hcd; in compliance_mode_recovery()
340 for (i = 0; i < rhub->num_ports; i++) { in compliance_mode_recovery()
341 temp = readl(rhub->ports[i]->addr); in compliance_mode_recovery()
348 "Compliance mode detected->port %d", in compliance_mode_recovery()
353 if (hcd->state == HC_STATE_SUSPENDED) in compliance_mode_recovery()
360 if (xhci->port_status_u0 != ((1 << rhub->num_ports) - 1)) in compliance_mode_recovery()
361 mod_timer(&xhci->comp_mode_recovery_timer, in compliance_mode_recovery()
366 * Quirk to work around issue generated by the SN65LVPE502CP USB3.0 re-driver
377 xhci->port_status_u0 = 0; in compliance_mode_recovery_timer_init()
378 timer_setup(&xhci->comp_mode_recovery_timer, compliance_mode_recovery, in compliance_mode_recovery_timer_init()
380 xhci->comp_mode_recovery_timer.expires = jiffies + in compliance_mode_recovery_timer_init()
383 add_timer(&xhci->comp_mode_recovery_timer); in compliance_mode_recovery_timer_init()
390 * USB3.0 re-driver and that need the Compliance Mode Quirk.
392 * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820
403 if (!(strstr(dmi_sys_vendor, "Hewlett-Packard"))) in xhci_compliance_mode_recovery_timer_quirk_check()
417 return (xhci->port_status_u0 == ((1 << xhci->usb3_rhub.num_ports) - 1)); in xhci_all_ports_seen_u0()
422 * Initialize memory for HCD and xHC (one-time init).
434 spin_lock_init(&xhci->lock); in xhci_init()
435 if (xhci->hci_version == 0x95 && link_quirk) { in xhci_init()
438 xhci->quirks |= XHCI_LINK_TRB_QUIRK; in xhci_init()
448 xhci->quirks |= XHCI_COMP_MODE_QUIRK; in xhci_init()
455 /*-------------------------------------------------------------------------*/
459 struct xhci_interrupter *ir = xhci->interrupter; in xhci_run_finished()
467 spin_lock_irqsave(&xhci->lock, flags); in xhci_run_finished()
470 temp = readl(&xhci->op_regs->command); in xhci_run_finished()
472 writel(temp, &xhci->op_regs->command); in xhci_run_finished()
479 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
480 return -ENODEV; in xhci_run_finished()
483 xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; in xhci_run_finished()
485 if (xhci->quirks & XHCI_NEC_HOST) in xhci_run_finished()
488 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_run_finished()
503 * Setup MSI-X vectors and enable interrupts.
511 struct xhci_interrupter *ir = xhci->interrupter; in xhci_run()
516 hcd->uses_new_polling = 1; in xhci_run()
522 temp_64 = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_run()
529 temp = readl(&ir->ir_set->irq_control); in xhci_run()
531 temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; in xhci_run()
532 writel(temp, &ir->ir_set->irq_control); in xhci_run()
534 if (xhci->quirks & XHCI_NEC_HOST) { in xhci_run()
539 return -ENOMEM; in xhci_run()
556 set_bit(HCD_FLAG_DEFER_RH_REGISTER, &hcd->flags); in xhci_run()
575 struct xhci_interrupter *ir = xhci->interrupter; in xhci_stop()
577 mutex_lock(&xhci->mutex); in xhci_stop()
581 mutex_unlock(&xhci->mutex); in xhci_stop()
587 spin_lock_irq(&xhci->lock); in xhci_stop()
588 xhci->xhc_state |= XHCI_STATE_HALTED; in xhci_stop()
589 xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; in xhci_stop()
592 spin_unlock_irq(&xhci->lock); in xhci_stop()
595 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_stop()
597 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_stop()
603 if (xhci->quirks & XHCI_AMD_PLL_FIX) in xhci_stop()
608 temp = readl(&xhci->op_regs->status); in xhci_stop()
609 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_stop()
616 "xhci_stop completed - status = %x", in xhci_stop()
617 readl(&xhci->op_regs->status)); in xhci_stop()
618 mutex_unlock(&xhci->mutex); in xhci_stop()
623 * Shutdown HC (not bus-specific)
629 * This will only ever be called with the main usb_hcd (the USB3 roothub).
635 if (xhci->quirks & XHCI_SPURIOUS_REBOOT) in xhci_shutdown()
636 usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev)); in xhci_shutdown()
640 __func__, hcd->self.busnum); in xhci_shutdown()
641 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_shutdown()
642 del_timer_sync(&hcd->rh_timer); in xhci_shutdown()
644 if (xhci->shared_hcd) { in xhci_shutdown()
645 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_shutdown()
646 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_shutdown()
649 spin_lock_irq(&xhci->lock); in xhci_shutdown()
654 * firmware delay in ADL-P PCH if port are left in U3 at shutdown in xhci_shutdown()
656 if (xhci->quirks & XHCI_SPURIOUS_WAKEUP || in xhci_shutdown()
657 xhci->quirks & XHCI_RESET_TO_DEFAULT) in xhci_shutdown()
660 spin_unlock_irq(&xhci->lock); in xhci_shutdown()
663 "xhci_shutdown completed - status = %x", in xhci_shutdown()
664 readl(&xhci->op_regs->status)); in xhci_shutdown()
671 struct xhci_interrupter *ir = xhci->interrupter; in xhci_save_registers()
673 xhci->s3.command = readl(&xhci->op_regs->command); in xhci_save_registers()
674 xhci->s3.dev_nt = readl(&xhci->op_regs->dev_notification); in xhci_save_registers()
675 xhci->s3.dcbaa_ptr = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_save_registers()
676 xhci->s3.config_reg = readl(&xhci->op_regs->config_reg); in xhci_save_registers()
681 ir->s3_erst_size = readl(&ir->ir_set->erst_size); in xhci_save_registers()
682 ir->s3_erst_base = xhci_read_64(xhci, &ir->ir_set->erst_base); in xhci_save_registers()
683 ir->s3_erst_dequeue = xhci_read_64(xhci, &ir->ir_set->erst_dequeue); in xhci_save_registers()
684 ir->s3_irq_pending = readl(&ir->ir_set->irq_pending); in xhci_save_registers()
685 ir->s3_irq_control = readl(&ir->ir_set->irq_control); in xhci_save_registers()
690 struct xhci_interrupter *ir = xhci->interrupter; in xhci_restore_registers()
692 writel(xhci->s3.command, &xhci->op_regs->command); in xhci_restore_registers()
693 writel(xhci->s3.dev_nt, &xhci->op_regs->dev_notification); in xhci_restore_registers()
694 xhci_write_64(xhci, xhci->s3.dcbaa_ptr, &xhci->op_regs->dcbaa_ptr); in xhci_restore_registers()
695 writel(xhci->s3.config_reg, &xhci->op_regs->config_reg); in xhci_restore_registers()
696 writel(ir->s3_erst_size, &ir->ir_set->erst_size); in xhci_restore_registers()
697 xhci_write_64(xhci, ir->s3_erst_base, &ir->ir_set->erst_base); in xhci_restore_registers()
698 xhci_write_64(xhci, ir->s3_erst_dequeue, &ir->ir_set->erst_dequeue); in xhci_restore_registers()
699 writel(ir->s3_irq_pending, &ir->ir_set->irq_pending); in xhci_restore_registers()
700 writel(ir->s3_irq_control, &ir->ir_set->irq_control); in xhci_restore_registers()
708 val_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
710 (xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, in xhci_set_cmd_ring_deq()
711 xhci->cmd_ring->dequeue) & in xhci_set_cmd_ring_deq()
713 xhci->cmd_ring->cycle_state; in xhci_set_cmd_ring_deq()
717 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); in xhci_set_cmd_ring_deq()
724 * need to re-program it on resume. Unfortunately, the pointer must be 64-byte
727 * middle of the ring (TRBs are 16-byte aligned).
734 ring = xhci->cmd_ring; in xhci_clear_command_ring()
735 seg = ring->deq_seg; in xhci_clear_command_ring()
737 memset(seg->trbs, 0, in xhci_clear_command_ring()
738 sizeof(union xhci_trb) * (TRBS_PER_SEGMENT - 1)); in xhci_clear_command_ring()
739 seg->trbs[TRBS_PER_SEGMENT - 1].link.control &= in xhci_clear_command_ring()
741 seg = seg->next; in xhci_clear_command_ring()
742 } while (seg != ring->deq_seg); in xhci_clear_command_ring()
745 ring->deq_seg = ring->first_seg; in xhci_clear_command_ring()
746 ring->dequeue = ring->first_seg->trbs; in xhci_clear_command_ring()
747 ring->enq_seg = ring->deq_seg; in xhci_clear_command_ring()
748 ring->enqueue = ring->dequeue; in xhci_clear_command_ring()
750 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1; in xhci_clear_command_ring()
755 ring->cycle_state = 1; in xhci_clear_command_ring()
759 * Yes, this will need to be re-written after resume, but we're paranoid in xhci_clear_command_ring()
784 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_hub_port_wake()
786 for (i = 0; i < rhub->num_ports; i++) { in xhci_disable_hub_port_wake()
787 portsc = readl(rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
800 writel(t2, rhub->ports[i]->addr); in xhci_disable_hub_port_wake()
801 xhci_dbg(xhci, "config port %d-%d wake bits, portsc: 0x%x, write: 0x%x\n", in xhci_disable_hub_port_wake()
802 rhub->hcd->self.busnum, i + 1, portsc, t2); in xhci_disable_hub_port_wake()
805 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_hub_port_wake()
815 status = readl(&xhci->op_regs->status); in xhci_pending_portevent()
824 port_index = xhci->usb2_rhub.num_ports; in xhci_pending_portevent()
825 ports = xhci->usb2_rhub.ports; in xhci_pending_portevent()
826 while (port_index--) { in xhci_pending_portevent()
827 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
832 port_index = xhci->usb3_rhub.num_ports; in xhci_pending_portevent()
833 ports = xhci->usb3_rhub.ports; in xhci_pending_portevent()
834 while (port_index--) { in xhci_pending_portevent()
835 portsc = readl(ports[port_index]->addr); in xhci_pending_portevent()
844 * Stop HC (not bus-specific)
857 if (!hcd->state) in xhci_suspend()
860 if (hcd->state != HC_STATE_SUSPENDED || in xhci_suspend()
861 (xhci->shared_hcd && xhci->shared_hcd->state != HC_STATE_SUSPENDED)) in xhci_suspend()
862 return -EINVAL; in xhci_suspend()
865 xhci_disable_hub_port_wake(xhci, &xhci->usb3_rhub, do_wakeup); in xhci_suspend()
866 xhci_disable_hub_port_wake(xhci, &xhci->usb2_rhub, do_wakeup); in xhci_suspend()
875 __func__, hcd->self.busnum); in xhci_suspend()
876 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_suspend()
877 del_timer_sync(&hcd->rh_timer); in xhci_suspend()
878 if (xhci->shared_hcd) { in xhci_suspend()
879 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_suspend()
880 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_suspend()
883 if (xhci->quirks & XHCI_SUSPEND_DELAY) in xhci_suspend()
886 spin_lock_irq(&xhci->lock); in xhci_suspend()
887 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_suspend()
888 if (xhci->shared_hcd) in xhci_suspend()
889 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_suspend()
894 command = readl(&xhci->op_regs->command); in xhci_suspend()
896 writel(command, &xhci->op_regs->command); in xhci_suspend()
899 delay *= (xhci->quirks & XHCI_SLOW_SUSPEND) ? 10 : 1; in xhci_suspend()
901 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
904 spin_unlock_irq(&xhci->lock); in xhci_suspend()
905 return -ETIMEDOUT; in xhci_suspend()
913 command = readl(&xhci->op_regs->command); in xhci_suspend()
915 writel(command, &xhci->op_regs->command); in xhci_suspend()
916 xhci->broken_suspend = 0; in xhci_suspend()
917 if (xhci_handshake(&xhci->op_regs->status, in xhci_suspend()
928 res = readl(&xhci->op_regs->status); in xhci_suspend()
929 if ((xhci->quirks & XHCI_SNPS_BROKEN_SUSPEND) && in xhci_suspend()
932 xhci->broken_suspend = 1; in xhci_suspend()
935 spin_unlock_irq(&xhci->lock); in xhci_suspend()
936 return -ETIMEDOUT; in xhci_suspend()
939 spin_unlock_irq(&xhci->lock); in xhci_suspend()
945 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_suspend()
947 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_suspend()
958 * start xHC (not bus-specific)
974 if (!hcd->state) in xhci_resume()
981 if (time_before(jiffies, xhci->usb2_rhub.bus_state.next_statechange) || in xhci_resume()
982 time_before(jiffies, xhci->usb3_rhub.bus_state.next_statechange)) in xhci_resume()
985 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in xhci_resume()
986 if (xhci->shared_hcd) in xhci_resume()
987 set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); in xhci_resume()
989 spin_lock_irq(&xhci->lock); in xhci_resume()
991 if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) in xhci_resume()
999 retval = xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1004 spin_unlock_irq(&xhci->lock); in xhci_resume()
1013 command = readl(&xhci->op_regs->command); in xhci_resume()
1015 writel(command, &xhci->op_regs->command); in xhci_resume()
1021 if (xhci_handshake(&xhci->op_regs->status, in xhci_resume()
1024 spin_unlock_irq(&xhci->lock); in xhci_resume()
1025 return -ETIMEDOUT; in xhci_resume()
1029 temp = readl(&xhci->op_regs->status); in xhci_resume()
1031 /* re-initialize the HC on Restore Error, or Host Controller Error */ in xhci_resume()
1033 !(xhci->xhc_state & XHCI_STATE_REMOVING)) { in xhci_resume()
1035 if (!xhci->broken_suspend) in xhci_resume()
1040 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && in xhci_resume()
1042 del_timer_sync(&xhci->comp_mode_recovery_timer); in xhci_resume()
1048 usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); in xhci_resume()
1049 if (xhci->shared_hcd) in xhci_resume()
1050 usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); in xhci_resume()
1056 spin_unlock_irq(&xhci->lock); in xhci_resume()
1061 temp = readl(&xhci->op_regs->status); in xhci_resume()
1062 writel((temp & ~0x1fff) | STS_EINT, &xhci->op_regs->status); in xhci_resume()
1063 xhci_disable_interrupter(xhci->interrupter); in xhci_resume()
1068 xhci_dbg(xhci, "xhci_stop completed - status = %x\n", in xhci_resume()
1069 readl(&xhci->op_regs->status)); in xhci_resume()
1083 if (!retval && xhci->shared_hcd) { in xhci_resume()
1085 retval = xhci_run(xhci->shared_hcd); in xhci_resume()
1093 hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1095 if (xhci->shared_hcd) { in xhci_resume()
1096 xhci->shared_hcd->state = HC_STATE_SUSPENDED; in xhci_resume()
1097 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1105 command = readl(&xhci->op_regs->command); in xhci_resume()
1107 writel(command, &xhci->op_regs->command); in xhci_resume()
1108 xhci_handshake(&xhci->op_regs->status, STS_HALT, in xhci_resume()
1120 spin_unlock_irq(&xhci->lock); in xhci_resume()
1131 if (xhci->usb3_rhub.bus_state.suspended_ports || in xhci_resume()
1132 xhci->usb3_rhub.bus_state.bus_suspended) in xhci_resume()
1144 if (xhci->shared_hcd) in xhci_resume()
1145 usb_hcd_resume_root_hub(xhci->shared_hcd); in xhci_resume()
1152 * be re-initialized Always after a system resume. Ports are subject in xhci_resume()
1156 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running) in xhci_resume()
1159 if (xhci->quirks & XHCI_ASMEDIA_MODIFY_FLOWCONTROL) in xhci_resume()
1160 usb_asmedia_modifyflowcontrol(to_pci_dev(hcd->self.controller)); in xhci_resume()
1162 /* Re-enable port polling. */ in xhci_resume()
1164 __func__, hcd->self.busnum); in xhci_resume()
1165 if (xhci->shared_hcd) { in xhci_resume()
1166 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_resume()
1167 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_resume()
1169 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_resume()
1177 /*-------------------------------------------------------------------------*/
1187 buf_len = urb->transfer_buffer_length; in xhci_map_temp_buffer()
1190 dev_to_node(hcd->self.sysdev)); in xhci_map_temp_buffer()
1192 return -ENOMEM; in xhci_map_temp_buffer()
1195 sg_pcopy_to_buffer(urb->sg, urb->num_sgs, in xhci_map_temp_buffer()
1198 urb->transfer_buffer = temp; in xhci_map_temp_buffer()
1199 urb->transfer_dma = dma_map_single(hcd->self.sysdev, in xhci_map_temp_buffer()
1200 urb->transfer_buffer, in xhci_map_temp_buffer()
1201 urb->transfer_buffer_length, in xhci_map_temp_buffer()
1204 if (dma_mapping_error(hcd->self.sysdev, in xhci_map_temp_buffer()
1205 urb->transfer_dma)) { in xhci_map_temp_buffer()
1206 ret = -EAGAIN; in xhci_map_temp_buffer()
1209 urb->transfer_flags |= URB_DMA_MAP_SINGLE; in xhci_map_temp_buffer()
1226 tail_sg = urb->sg; in xhci_urb_temp_buffer_required()
1227 max_pkt = usb_endpoint_maxp(&urb->ep->desc); in xhci_urb_temp_buffer_required()
1229 if (!urb->num_sgs) in xhci_urb_temp_buffer_required()
1232 if (urb->dev->speed >= USB_SPEED_SUPER) in xhci_urb_temp_buffer_required()
1237 if (urb->transfer_buffer_length != 0 && in xhci_urb_temp_buffer_required()
1238 !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { in xhci_urb_temp_buffer_required()
1239 for_each_sg(urb->sg, sg, urb->num_sgs, i) { in xhci_urb_temp_buffer_required()
1240 len = len + sg->length; in xhci_urb_temp_buffer_required()
1241 if (i > trb_size - 2) { in xhci_urb_temp_buffer_required()
1242 len = len - tail_sg->length; in xhci_urb_temp_buffer_required()
1263 buf_len = urb->transfer_buffer_length; in xhci_unmap_temp_buf()
1266 (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_temp_buf()
1267 dma_unmap_single(hcd->self.sysdev, in xhci_unmap_temp_buf()
1268 urb->transfer_dma, in xhci_unmap_temp_buf()
1269 urb->transfer_buffer_length, in xhci_unmap_temp_buf()
1273 len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, in xhci_unmap_temp_buf()
1274 urb->transfer_buffer, in xhci_unmap_temp_buf()
1280 urb->actual_length = len; in xhci_unmap_temp_buf()
1283 urb->transfer_flags &= ~URB_DMA_MAP_SINGLE; in xhci_unmap_temp_buf()
1284 kfree(urb->transfer_buffer); in xhci_unmap_temp_buf()
1285 urb->transfer_buffer = NULL; in xhci_unmap_temp_buf()
1304 if (xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) { in xhci_map_urb_for_dma()
1318 if (urb->num_sgs && (urb->transfer_flags & URB_DMA_MAP_SINGLE)) in xhci_unmap_urb_for_dma()
1321 if ((xhci->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK) && unmap_temp_buf) in xhci_unmap_urb_for_dma()
1328 * xhci_get_endpoint_index - Used for passing endpoint bitmasks between the core and
1332 * Index = (epnum * 2) + direction - 1,
1335 * index = (epnum * 2) + direction - 1 = (epnum * 2) + 1 - 1 = (epnum * 2)
1344 (usb_endpoint_dir_in(desc) ? 1 : 0) - 1; in xhci_get_endpoint_index()
1376 return fls(added_ctxs) - 1; in xhci_last_valid_endpoint()
1380 * returns 0 this is a root hub; returns -EINVAL for NULL pointers.
1390 return -EINVAL; in xhci_check_args()
1392 if (!udev->parent) { in xhci_check_args()
1399 if (!udev->slot_id || !xhci->devs[udev->slot_id]) { in xhci_check_args()
1402 return -EINVAL; in xhci_check_args()
1405 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_args()
1406 if (virt_dev->udev != udev) { in xhci_check_args()
1409 return -EINVAL; in xhci_check_args()
1413 if (xhci->xhc_state & XHCI_STATE_HALTED) in xhci_check_args()
1414 return -ENODEV; in xhci_check_args()
1440 out_ctx = xhci->devs[slot_id]->out_ctx; in xhci_check_maxpacket()
1442 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); in xhci_check_maxpacket()
1443 max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); in xhci_check_maxpacket()
1457 /* FIXME: This won't work if a non-default control endpoint in xhci_check_maxpacket()
1463 return -ENOMEM; in xhci_check_maxpacket()
1465 command->in_ctx = xhci->devs[slot_id]->in_ctx; in xhci_check_maxpacket()
1466 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_maxpacket()
1470 ret = -ENOMEM; in xhci_check_maxpacket()
1474 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, in xhci_check_maxpacket()
1475 xhci->devs[slot_id]->out_ctx, ep_index); in xhci_check_maxpacket()
1477 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_check_maxpacket()
1478 ep_ctx->ep_info &= cpu_to_le32(~EP_STATE_MASK);/* must clear */ in xhci_check_maxpacket()
1479 ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); in xhci_check_maxpacket()
1480 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); in xhci_check_maxpacket()
1482 ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG); in xhci_check_maxpacket()
1483 ctrl_ctx->drop_flags = 0; in xhci_check_maxpacket()
1485 ret = xhci_configure_endpoint(xhci, urb->dev, command, in xhci_check_maxpacket()
1491 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); in xhci_check_maxpacket()
1493 kfree(command->completion); in xhci_check_maxpacket()
1500 * non-error returns are a promise to giveback() the urb later
1514 return -EINVAL; in xhci_urb_enqueue()
1515 ret = xhci_check_args(hcd, urb->dev, urb->ep, in xhci_urb_enqueue()
1518 return ret ? ret : -EINVAL; in xhci_urb_enqueue()
1520 slot_id = urb->dev->slot_id; in xhci_urb_enqueue()
1521 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_enqueue()
1522 ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_urb_enqueue()
1525 return -ESHUTDOWN; in xhci_urb_enqueue()
1527 if (xhci->devs[slot_id]->flags & VDEV_PORT_ERROR) { in xhci_urb_enqueue()
1529 return -ENODEV; in xhci_urb_enqueue()
1532 if (usb_endpoint_xfer_isoc(&urb->ep->desc)) in xhci_urb_enqueue()
1533 num_tds = urb->number_of_packets; in xhci_urb_enqueue()
1534 else if (usb_endpoint_is_bulk_out(&urb->ep->desc) && in xhci_urb_enqueue()
1535 urb->transfer_buffer_length > 0 && in xhci_urb_enqueue()
1536 urb->transfer_flags & URB_ZERO_PACKET && in xhci_urb_enqueue()
1537 !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc))) in xhci_urb_enqueue()
1544 return -ENOMEM; in xhci_urb_enqueue()
1546 urb_priv->num_tds = num_tds; in xhci_urb_enqueue()
1547 urb_priv->num_tds_done = 0; in xhci_urb_enqueue()
1548 urb->hcpriv = urb_priv; in xhci_urb_enqueue()
1552 if (usb_endpoint_xfer_control(&urb->ep->desc)) { in xhci_urb_enqueue()
1556 if (urb->dev->speed == USB_SPEED_FULL) { in xhci_urb_enqueue()
1561 urb->hcpriv = NULL; in xhci_urb_enqueue()
1567 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_enqueue()
1569 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_enqueue()
1570 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", in xhci_urb_enqueue()
1571 urb->ep->desc.bEndpointAddress, urb); in xhci_urb_enqueue()
1572 ret = -ESHUTDOWN; in xhci_urb_enqueue()
1578 ret = -EINVAL; in xhci_urb_enqueue()
1583 ret = -EINVAL; in xhci_urb_enqueue()
1587 switch (usb_endpoint_type(&urb->ep->desc)) { in xhci_urb_enqueue()
1609 urb->hcpriv = NULL; in xhci_urb_enqueue()
1611 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_enqueue()
1631 * series of 1-TRB transfer no-op TDs. (No-ops shouldn't be chained.) The
1661 spin_lock_irqsave(&xhci->lock, flags); in xhci_urb_dequeue()
1671 vdev = xhci->devs[urb->dev->slot_id]; in xhci_urb_dequeue()
1672 urb_priv = urb->hcpriv; in xhci_urb_dequeue()
1676 ep_index = xhci_get_endpoint_index(&urb->ep->desc); in xhci_urb_dequeue()
1677 ep = &vdev->eps[ep_index]; in xhci_urb_dequeue()
1683 temp = readl(&xhci->op_regs->status); in xhci_urb_dequeue()
1684 if (temp == ~(u32)0 || xhci->xhc_state & XHCI_STATE_DYING) { in xhci_urb_dequeue()
1690 * check ring is not re-allocated since URB was enqueued. If it is, then in xhci_urb_dequeue()
1694 if (!td_on_ring(&urb_priv->td[0], ep_ring)) { in xhci_urb_dequeue()
1696 for (i = urb_priv->num_tds_done; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1697 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1698 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1699 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1704 if (xhci->xhc_state & XHCI_STATE_HALTED) { in xhci_urb_dequeue()
1707 for (i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1708 i < urb_priv->num_tds; in xhci_urb_dequeue()
1710 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1711 if (!list_empty(&td->td_list)) in xhci_urb_dequeue()
1712 list_del_init(&td->td_list); in xhci_urb_dequeue()
1713 if (!list_empty(&td->cancelled_td_list)) in xhci_urb_dequeue()
1714 list_del_init(&td->cancelled_td_list); in xhci_urb_dequeue()
1719 i = urb_priv->num_tds_done; in xhci_urb_dequeue()
1720 if (i < urb_priv->num_tds) in xhci_urb_dequeue()
1724 urb, urb->dev->devpath, in xhci_urb_dequeue()
1725 urb->ep->desc.bEndpointAddress, in xhci_urb_dequeue()
1727 urb_priv->td[i].start_seg, in xhci_urb_dequeue()
1728 urb_priv->td[i].first_trb)); in xhci_urb_dequeue()
1730 for (; i < urb_priv->num_tds; i++) { in xhci_urb_dequeue()
1731 td = &urb_priv->td[i]; in xhci_urb_dequeue()
1733 if (list_empty(&td->cancelled_td_list)) { in xhci_urb_dequeue()
1734 td->cancel_status = TD_DIRTY; in xhci_urb_dequeue()
1735 list_add_tail(&td->cancelled_td_list, in xhci_urb_dequeue()
1736 &ep->cancelled_td_list); in xhci_urb_dequeue()
1743 if (!(ep->ep_state & EP_STOP_CMD_PENDING)) { in xhci_urb_dequeue()
1746 ret = -ENOMEM; in xhci_urb_dequeue()
1749 ep->ep_state |= EP_STOP_CMD_PENDING; in xhci_urb_dequeue()
1750 xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, in xhci_urb_dequeue()
1755 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1762 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_urb_dequeue()
1763 usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN); in xhci_urb_dequeue()
1778 * the xhci->devs[slot_id] structure.
1796 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_drop_endpoint()
1797 return -ENODEV; in xhci_drop_endpoint()
1800 drop_flag = xhci_get_endpoint_flag(&ep->desc); in xhci_drop_endpoint()
1802 xhci_dbg(xhci, "xHCI %s - can't drop slot or ep 0 %#x\n", in xhci_drop_endpoint()
1807 in_ctx = xhci->devs[udev->slot_id]->in_ctx; in xhci_drop_endpoint()
1808 out_ctx = xhci->devs[udev->slot_id]->out_ctx; in xhci_drop_endpoint()
1816 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_drop_endpoint()
1822 le32_to_cpu(ctrl_ctx->drop_flags) & in xhci_drop_endpoint()
1823 xhci_get_endpoint_flag(&ep->desc)) { in xhci_drop_endpoint()
1825 if (xhci->devs[udev->slot_id]->eps[ep_index].ring != NULL) in xhci_drop_endpoint()
1831 ctrl_ctx->drop_flags |= cpu_to_le32(drop_flag); in xhci_drop_endpoint()
1832 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_drop_endpoint()
1834 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); in xhci_drop_endpoint()
1835 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_drop_endpoint()
1837 xhci_debugfs_remove_endpoint(xhci, xhci->devs[udev->slot_id], ep_index); in xhci_drop_endpoint()
1839 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); in xhci_drop_endpoint()
1842 (unsigned int) ep->desc.bEndpointAddress, in xhci_drop_endpoint()
1843 udev->slot_id, in xhci_drop_endpoint()
1861 * for mutual exclusion to protect the xhci->devs[slot_id] structure.
1879 ep->hcpriv = NULL; in xhci_add_endpoint()
1883 if (xhci->xhc_state & XHCI_STATE_DYING) in xhci_add_endpoint()
1884 return -ENODEV; in xhci_add_endpoint()
1886 added_ctxs = xhci_get_endpoint_flag(&ep->desc); in xhci_add_endpoint()
1892 xhci_dbg(xhci, "xHCI %s - can't add slot or ep 0 %#x\n", in xhci_add_endpoint()
1897 virt_dev = xhci->devs[udev->slot_id]; in xhci_add_endpoint()
1898 in_ctx = virt_dev->in_ctx; in xhci_add_endpoint()
1906 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_add_endpoint()
1910 if (virt_dev->eps[ep_index].ring && in xhci_add_endpoint()
1911 !(le32_to_cpu(ctrl_ctx->drop_flags) & added_ctxs)) { in xhci_add_endpoint()
1914 (unsigned int) ep->desc.bEndpointAddress); in xhci_add_endpoint()
1915 return -EINVAL; in xhci_add_endpoint()
1921 if (le32_to_cpu(ctrl_ctx->add_flags) & added_ctxs) { in xhci_add_endpoint()
1933 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", in xhci_add_endpoint()
1934 __func__, ep->desc.bEndpointAddress); in xhci_add_endpoint()
1935 return -ENOMEM; in xhci_add_endpoint()
1938 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs); in xhci_add_endpoint()
1939 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); in xhci_add_endpoint()
1943 * this re-adds a new state for the endpoint from the new endpoint in xhci_add_endpoint()
1944 * descriptors. We must drop and re-add this endpoint, so we leave the in xhci_add_endpoint()
1947 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); in xhci_add_endpoint()
1950 ep->hcpriv = udev; in xhci_add_endpoint()
1952 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); in xhci_add_endpoint()
1956 (unsigned int) ep->desc.bEndpointAddress, in xhci_add_endpoint()
1957 udev->slot_id, in xhci_add_endpoint()
1971 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_zero_in_ctx()
1983 ctrl_ctx->drop_flags = 0; in xhci_zero_in_ctx()
1984 ctrl_ctx->add_flags = 0; in xhci_zero_in_ctx()
1985 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_zero_in_ctx()
1986 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_zero_in_ctx()
1988 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1)); in xhci_zero_in_ctx()
1990 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, i); in xhci_zero_in_ctx()
1991 ep_ctx->ep_info = 0; in xhci_zero_in_ctx()
1992 ep_ctx->ep_info2 = 0; in xhci_zero_in_ctx()
1993 ep_ctx->deq = 0; in xhci_zero_in_ctx()
1994 ep_ctx->tx_info = 0; in xhci_zero_in_ctx()
2007 ret = -ETIME; in xhci_configure_endpoint_result()
2010 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2012 ret = -ENOMEM; in xhci_configure_endpoint_result()
2017 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2019 ret = -ENOSPC; in xhci_configure_endpoint_result()
2024 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, " in xhci_configure_endpoint_result()
2027 ret = -EINVAL; in xhci_configure_endpoint_result()
2030 dev_warn(&udev->dev, in xhci_configure_endpoint_result()
2032 ret = -ENODEV; in xhci_configure_endpoint_result()
2042 ret = -EINVAL; in xhci_configure_endpoint_result()
2057 ret = -ETIME; in xhci_evaluate_context_result()
2060 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2062 ret = -EINVAL; in xhci_evaluate_context_result()
2065 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2067 ret = -EINVAL; in xhci_evaluate_context_result()
2070 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2072 ret = -EINVAL; in xhci_evaluate_context_result()
2075 dev_warn(&udev->dev, in xhci_evaluate_context_result()
2077 ret = -ENODEV; in xhci_evaluate_context_result()
2081 dev_warn(&udev->dev, "WARN: Max Exit Latency too large\n"); in xhci_evaluate_context_result()
2082 ret = -EINVAL; in xhci_evaluate_context_result()
2092 ret = -EINVAL; in xhci_evaluate_context_result()
2108 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_new_endpoints()
2109 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_new_endpoints()
2115 return hweight32(valid_add_flags) - in xhci_count_num_new_endpoints()
2125 valid_add_flags = le32_to_cpu(ctrl_ctx->add_flags) >> 2; in xhci_count_num_dropped_endpoints()
2126 valid_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags) >> 2; in xhci_count_num_dropped_endpoints()
2128 return hweight32(valid_drop_flags) - in xhci_count_num_dropped_endpoints()
2138 * - the first configure endpoint command drops more endpoints than it adds
2139 * - a second configure endpoint command that adds more endpoints is queued
2140 * - the first configure endpoint command fails, so the config is unchanged
2141 * - the second command may succeed, even though there isn't enough resources
2143 * Must be called with xhci->lock held.
2151 if (xhci->num_active_eps + added_eps > xhci->limit_active_eps) { in xhci_reserve_host_resources()
2155 xhci->num_active_eps, added_eps, in xhci_reserve_host_resources()
2156 xhci->limit_active_eps); in xhci_reserve_host_resources()
2157 return -ENOMEM; in xhci_reserve_host_resources()
2159 xhci->num_active_eps += added_eps; in xhci_reserve_host_resources()
2162 xhci->num_active_eps); in xhci_reserve_host_resources()
2170 * Must be called with xhci->lock held.
2178 xhci->num_active_eps -= num_failed_eps; in xhci_free_host_resources()
2182 xhci->num_active_eps); in xhci_free_host_resources()
2189 * Must be called with xhci->lock held.
2197 xhci->num_active_eps -= num_dropped_eps; in xhci_finish_resource_reservation()
2202 xhci->num_active_eps); in xhci_finish_resource_reservation()
2207 switch (udev->speed) { in xhci_get_block_size()
2226 if (interval_bw->overhead[LS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2228 if (interval_bw->overhead[FS_OVERHEAD_TYPE]) in xhci_get_largest_overhead()
2245 bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; in xhci_check_tt_bw_table()
2246 tt_info = virt_dev->tt_info; in xhci_check_tt_bw_table()
2253 if (old_active_eps == 0 && tt_info->active_eps != 0) { in xhci_check_tt_bw_table()
2254 if (bw_table->bw_used + TT_HS_OVERHEAD > HS_BW_LIMIT) in xhci_check_tt_bw_table()
2255 return -ENOMEM; in xhci_check_tt_bw_table()
2273 if (virt_dev->bw_table->ss_bw_in > (SS_BW_LIMIT_IN - bw_reserved)) in xhci_check_ss_bw()
2274 return -ENOMEM; in xhci_check_ss_bw()
2277 if (virt_dev->bw_table->ss_bw_out > (SS_BW_LIMIT_OUT - bw_reserved)) in xhci_check_ss_bw()
2278 return -ENOMEM; in xhci_check_ss_bw()
2284 * This algorithm is a very conservative estimate of the worst-case scheduling
2292 * over-estimate.
2339 if (virt_dev->udev->speed >= USB_SPEED_SUPER) in xhci_check_bw_table()
2342 if (virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2351 bw_table = virt_dev->bw_table; in xhci_check_bw_table()
2355 block_size = xhci_get_block_size(virt_dev->udev); in xhci_check_bw_table()
2360 if (virt_dev->tt_info) { in xhci_check_bw_table()
2363 virt_dev->real_port); in xhci_check_bw_table()
2367 return -ENOMEM; in xhci_check_bw_table()
2371 virt_dev->tt_info->slot_id, in xhci_check_bw_table()
2372 virt_dev->tt_info->ttport); in xhci_check_bw_table()
2376 virt_dev->real_port); in xhci_check_bw_table()
2382 bw_used = DIV_ROUND_UP(bw_table->interval0_esit_payload, block_size) + in xhci_check_bw_table()
2383 bw_table->interval_bw[0].num_packets * in xhci_check_bw_table()
2384 xhci_get_largest_overhead(&bw_table->interval_bw[0]); in xhci_check_bw_table()
2397 bw_table->interval_bw[i].num_packets; in xhci_check_bw_table()
2402 if (list_empty(&bw_table->interval_bw[i].endpoints)) in xhci_check_bw_table()
2408 ep_entry = bw_table->interval_bw[i].endpoints.next; in xhci_check_bw_table()
2413 virt_ep->bw_info.max_packet_size, in xhci_check_bw_table()
2421 &bw_table->interval_bw[i]); in xhci_check_bw_table()
2460 return -ENOMEM; in xhci_check_bw_table()
2464 * Ok, we know we have some packets left over after even-handedly in xhci_check_bw_table()
2466 * fit into, so we over-schedule and say they will be scheduled every in xhci_check_bw_table()
2472 if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { in xhci_check_bw_table()
2473 unsigned int port_index = virt_dev->real_port - 1; in xhci_check_bw_table()
2480 xhci->rh_bw[port_index].num_active_tts; in xhci_check_bw_table()
2487 (max_bandwidth - bw_used - bw_reserved) * 100 / in xhci_check_bw_table()
2494 return -ENOMEM; in xhci_check_bw_table()
2497 bw_table->bw_used = bw_used; in xhci_check_bw_table()
2515 unsigned int mps = DIV_ROUND_UP(ep_bw->max_packet_size, SS_BLOCK); in xhci_get_ss_bw_consumed()
2517 if (ep_bw->ep_interval == 0) in xhci_get_ss_bw_consumed()
2519 (ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2521 return DIV_ROUND_UP(ep_bw->mult * ep_bw->num_packets * in xhci_get_ss_bw_consumed()
2523 1 << ep_bw->ep_interval); in xhci_get_ss_bw_consumed()
2537 if (xhci_is_async_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2540 if (udev->speed >= USB_SPEED_SUPER) { in xhci_drop_ep_from_interval_table()
2541 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_drop_ep_from_interval_table()
2542 xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= in xhci_drop_ep_from_interval_table()
2545 xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= in xhci_drop_ep_from_interval_table()
2553 if (list_empty(&virt_ep->bw_endpoint_list)) in xhci_drop_ep_from_interval_table()
2558 if (udev->speed == USB_SPEED_HIGH) in xhci_drop_ep_from_interval_table()
2559 normalized_interval = ep_bw->ep_interval; in xhci_drop_ep_from_interval_table()
2561 normalized_interval = ep_bw->ep_interval - 3; in xhci_drop_ep_from_interval_table()
2564 bw_table->interval0_esit_payload -= ep_bw->max_esit_payload; in xhci_drop_ep_from_interval_table()
2565 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_drop_ep_from_interval_table()
2566 interval_bw->num_packets -= ep_bw->num_packets; in xhci_drop_ep_from_interval_table()
2567 switch (udev->speed) { in xhci_drop_ep_from_interval_table()
2569 interval_bw->overhead[LS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2572 interval_bw->overhead[FS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2575 interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; in xhci_drop_ep_from_interval_table()
2584 tt_info->active_eps -= 1; in xhci_drop_ep_from_interval_table()
2585 list_del_init(&virt_ep->bw_endpoint_list); in xhci_drop_ep_from_interval_table()
2599 if (xhci_is_async_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2602 if (udev->speed == USB_SPEED_SUPER) { in xhci_add_ep_to_interval_table()
2603 if (xhci_is_sync_in_ep(ep_bw->type)) in xhci_add_ep_to_interval_table()
2604 xhci->devs[udev->slot_id]->bw_table->ss_bw_in += in xhci_add_ep_to_interval_table()
2607 xhci->devs[udev->slot_id]->bw_table->ss_bw_out += in xhci_add_ep_to_interval_table()
2615 if (udev->speed == USB_SPEED_HIGH) in xhci_add_ep_to_interval_table()
2616 normalized_interval = ep_bw->ep_interval; in xhci_add_ep_to_interval_table()
2618 normalized_interval = ep_bw->ep_interval - 3; in xhci_add_ep_to_interval_table()
2621 bw_table->interval0_esit_payload += ep_bw->max_esit_payload; in xhci_add_ep_to_interval_table()
2622 interval_bw = &bw_table->interval_bw[normalized_interval]; in xhci_add_ep_to_interval_table()
2623 interval_bw->num_packets += ep_bw->num_packets; in xhci_add_ep_to_interval_table()
2624 switch (udev->speed) { in xhci_add_ep_to_interval_table()
2626 interval_bw->overhead[LS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2629 interval_bw->overhead[FS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2632 interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; in xhci_add_ep_to_interval_table()
2642 tt_info->active_eps += 1; in xhci_add_ep_to_interval_table()
2644 list_for_each_entry(smaller_ep, &interval_bw->endpoints, in xhci_add_ep_to_interval_table()
2646 if (ep_bw->max_packet_size >= in xhci_add_ep_to_interval_table()
2647 smaller_ep->bw_info.max_packet_size) { in xhci_add_ep_to_interval_table()
2649 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2650 &smaller_ep->bw_endpoint_list); in xhci_add_ep_to_interval_table()
2655 list_add_tail(&virt_ep->bw_endpoint_list, in xhci_add_ep_to_interval_table()
2656 &interval_bw->endpoints); in xhci_add_ep_to_interval_table()
2664 if (!virt_dev->tt_info) in xhci_update_tt_active_eps()
2667 rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; in xhci_update_tt_active_eps()
2669 virt_dev->tt_info->active_eps != 0) { in xhci_update_tt_active_eps()
2670 rh_bw_info->num_active_tts += 1; in xhci_update_tt_active_eps()
2671 rh_bw_info->bw_table.bw_used += TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2673 virt_dev->tt_info->active_eps == 0) { in xhci_update_tt_active_eps()
2674 rh_bw_info->num_active_tts -= 1; in xhci_update_tt_active_eps()
2675 rh_bw_info->bw_table.bw_used -= TT_HS_OVERHEAD; in xhci_update_tt_active_eps()
2688 if (virt_dev->tt_info) in xhci_reserve_bandwidth()
2689 old_active_eps = virt_dev->tt_info->active_eps; in xhci_reserve_bandwidth()
2695 return -ENOMEM; in xhci_reserve_bandwidth()
2703 memcpy(&ep_bw_info[i], &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2710 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2711 virt_dev->bw_table, in xhci_reserve_bandwidth()
2712 virt_dev->udev, in xhci_reserve_bandwidth()
2713 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2714 virt_dev->tt_info); in xhci_reserve_bandwidth()
2717 xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); in xhci_reserve_bandwidth()
2722 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2723 virt_dev->bw_table, in xhci_reserve_bandwidth()
2724 virt_dev->udev, in xhci_reserve_bandwidth()
2725 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2726 virt_dev->tt_info); in xhci_reserve_bandwidth()
2747 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2748 virt_dev->bw_table, in xhci_reserve_bandwidth()
2749 virt_dev->udev, in xhci_reserve_bandwidth()
2750 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2751 virt_dev->tt_info); in xhci_reserve_bandwidth()
2754 memcpy(&virt_dev->eps[i].bw_info, &ep_bw_info[i], in xhci_reserve_bandwidth()
2759 &virt_dev->eps[i].bw_info, in xhci_reserve_bandwidth()
2760 virt_dev->bw_table, in xhci_reserve_bandwidth()
2761 virt_dev->udev, in xhci_reserve_bandwidth()
2762 &virt_dev->eps[i], in xhci_reserve_bandwidth()
2763 virt_dev->tt_info); in xhci_reserve_bandwidth()
2765 return -ENOMEM; in xhci_reserve_bandwidth()
2784 return -EINVAL; in xhci_configure_endpoint()
2786 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2788 if (xhci->xhc_state & XHCI_STATE_DYING) { in xhci_configure_endpoint()
2789 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2790 return -ESHUTDOWN; in xhci_configure_endpoint()
2793 virt_dev = xhci->devs[udev->slot_id]; in xhci_configure_endpoint()
2795 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_configure_endpoint()
2797 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2800 return -ENOMEM; in xhci_configure_endpoint()
2803 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && in xhci_configure_endpoint()
2805 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2808 xhci->num_active_eps); in xhci_configure_endpoint()
2809 return -ENOMEM; in xhci_configure_endpoint()
2811 if ((xhci->quirks & XHCI_SW_BW_CHECKING) && !ctx_change && in xhci_configure_endpoint()
2812 xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { in xhci_configure_endpoint()
2813 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2815 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2817 return -ENOMEM; in xhci_configure_endpoint()
2820 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_configure_endpoint()
2827 command->in_ctx->dma, in xhci_configure_endpoint()
2828 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2831 command->in_ctx->dma, in xhci_configure_endpoint()
2832 udev->slot_id, must_succeed); in xhci_configure_endpoint()
2834 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) in xhci_configure_endpoint()
2836 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2839 return -ENOMEM; in xhci_configure_endpoint()
2842 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2845 wait_for_completion(command->completion); in xhci_configure_endpoint()
2849 &command->status); in xhci_configure_endpoint()
2852 &command->status); in xhci_configure_endpoint()
2854 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_configure_endpoint()
2855 spin_lock_irqsave(&xhci->lock, flags); in xhci_configure_endpoint()
2863 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_configure_endpoint()
2871 struct xhci_virt_ep *ep = &vdev->eps[i]; in xhci_check_bw_drop_ep_streams()
2873 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_check_bw_drop_ep_streams()
2876 xhci_free_stream_info(xhci, ep->stream_info); in xhci_check_bw_drop_ep_streams()
2877 ep->stream_info = NULL; in xhci_check_bw_drop_ep_streams()
2878 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_check_bw_drop_ep_streams()
2889 * else should be touching the xhci->devs[slot_id] structure, so we
2890 * don't need to take the xhci->lock for manipulating that.
2906 if ((xhci->xhc_state & XHCI_STATE_DYING) || in xhci_check_bandwidth()
2907 (xhci->xhc_state & XHCI_STATE_REMOVING)) in xhci_check_bandwidth()
2908 return -ENODEV; in xhci_check_bandwidth()
2911 virt_dev = xhci->devs[udev->slot_id]; in xhci_check_bandwidth()
2915 return -ENOMEM; in xhci_check_bandwidth()
2917 command->in_ctx = virt_dev->in_ctx; in xhci_check_bandwidth()
2919 /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ in xhci_check_bandwidth()
2920 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_check_bandwidth()
2924 ret = -ENOMEM; in xhci_check_bandwidth()
2927 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_check_bandwidth()
2928 ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); in xhci_check_bandwidth()
2929 ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); in xhci_check_bandwidth()
2932 if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && in xhci_check_bandwidth()
2933 ctrl_ctx->drop_flags == 0) { in xhci_check_bandwidth()
2938 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_check_bandwidth()
2939 for (i = 31; i >= 1; i--) { in xhci_check_bandwidth()
2942 if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32)) in xhci_check_bandwidth()
2943 || (ctrl_ctx->add_flags & le32) || i == 1) { in xhci_check_bandwidth()
2944 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK); in xhci_check_bandwidth()
2945 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i)); in xhci_check_bandwidth()
2958 if ((le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) && in xhci_check_bandwidth()
2959 !(le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))) { in xhci_check_bandwidth()
2970 if (!virt_dev->eps[i].new_ring) in xhci_check_bandwidth()
2975 if (virt_dev->eps[i].ring) { in xhci_check_bandwidth()
2979 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; in xhci_check_bandwidth()
2980 virt_dev->eps[i].new_ring = NULL; in xhci_check_bandwidth()
2984 kfree(command->completion); in xhci_check_bandwidth()
3003 virt_dev = xhci->devs[udev->slot_id]; in xhci_reset_bandwidth()
3006 if (virt_dev->eps[i].new_ring) { in xhci_reset_bandwidth()
3008 xhci_ring_free(xhci, virt_dev->eps[i].new_ring); in xhci_reset_bandwidth()
3009 virt_dev->eps[i].new_ring = NULL; in xhci_reset_bandwidth()
3022 ctrl_ctx->add_flags = cpu_to_le32(add_flags); in xhci_setup_input_ctx_for_config_ep()
3023 ctrl_ctx->drop_flags = cpu_to_le32(drop_flags); in xhci_setup_input_ctx_for_config_ep()
3025 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_setup_input_ctx_for_config_ep()
3040 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_disable()
3042 udev = (struct usb_device *)host_ep->hcpriv; in xhci_endpoint_disable()
3043 if (!udev || !udev->slot_id) in xhci_endpoint_disable()
3046 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_disable()
3050 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_disable()
3051 ep = &vdev->eps[ep_index]; in xhci_endpoint_disable()
3054 if (ep->ep_state & EP_CLEARING_TT) { in xhci_endpoint_disable()
3055 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3060 if (ep->ep_state) in xhci_endpoint_disable()
3062 ep->ep_state); in xhci_endpoint_disable()
3064 host_ep->hcpriv = NULL; in xhci_endpoint_disable()
3065 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_disable()
3095 if (!host_ep->hcpriv) in xhci_endpoint_reset()
3097 udev = (struct usb_device *) host_ep->hcpriv; in xhci_endpoint_reset()
3098 vdev = xhci->devs[udev->slot_id]; in xhci_endpoint_reset()
3101 * vdev may be lost due to xHC restore error and re-initialization in xhci_endpoint_reset()
3105 if (!udev->slot_id || !vdev) in xhci_endpoint_reset()
3107 ep_index = xhci_get_endpoint_index(&host_ep->desc); in xhci_endpoint_reset()
3108 ep = &vdev->eps[ep_index]; in xhci_endpoint_reset()
3111 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3112 if (ep->ep_state & EP_HARD_CLEAR_TOGGLE) { in xhci_endpoint_reset()
3113 ep->ep_state &= ~EP_HARD_CLEAR_TOGGLE; in xhci_endpoint_reset()
3114 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3117 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3118 /* Only interrupt and bulk ep's use data toggle, USB2 spec 5.5.4-> */ in xhci_endpoint_reset()
3119 if (usb_endpoint_xfer_control(&host_ep->desc) || in xhci_endpoint_reset()
3120 usb_endpoint_xfer_isoc(&host_ep->desc)) in xhci_endpoint_reset()
3123 ep_flag = xhci_get_endpoint_flag(&host_ep->desc); in xhci_endpoint_reset()
3136 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3139 ep->ep_state |= EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3147 if (!list_empty(&ep->ring->td_list)) { in xhci_endpoint_reset()
3148 dev_err(&udev->dev, "EP not empty, refuse reset\n"); in xhci_endpoint_reset()
3149 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3154 err = xhci_queue_stop_endpoint(xhci, stop_cmd, udev->slot_id, in xhci_endpoint_reset()
3157 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3165 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3167 wait_for_completion(stop_cmd->completion); in xhci_endpoint_reset()
3169 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3172 ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); in xhci_endpoint_reset()
3174 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3181 xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, in xhci_endpoint_reset()
3183 xhci_endpoint_copy(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ep_index); in xhci_endpoint_reset()
3185 err = xhci_queue_configure_endpoint(xhci, cfg_cmd, cfg_cmd->in_ctx->dma, in xhci_endpoint_reset()
3186 udev->slot_id, false); in xhci_endpoint_reset()
3188 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3196 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3198 wait_for_completion(cfg_cmd->completion); in xhci_endpoint_reset()
3203 spin_lock_irqsave(&xhci->lock, flags); in xhci_endpoint_reset()
3204 if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) in xhci_endpoint_reset()
3205 ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; in xhci_endpoint_reset()
3206 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_endpoint_reset()
3218 return -EINVAL; in xhci_check_streams_endpoint()
3221 return ret ? ret : -EINVAL; in xhci_check_streams_endpoint()
3222 if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { in xhci_check_streams_endpoint()
3225 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3226 return -EINVAL; in xhci_check_streams_endpoint()
3229 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_check_streams_endpoint()
3230 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_check_streams_endpoint()
3235 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3238 return -EINVAL; in xhci_check_streams_endpoint()
3240 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) { in xhci_check_streams_endpoint()
3243 ep->desc.bEndpointAddress); in xhci_check_streams_endpoint()
3244 return -EINVAL; in xhci_check_streams_endpoint()
3262 max_streams = HCC_MAX_PSA(xhci->hcc_params); in xhci_calculate_streams_entries()
3287 eps[i], udev->slot_id); in xhci_calculate_streams_and_bitmask()
3291 max_streams = usb_ss_max_streams(&eps[i]->ss_ep_comp); in xhci_calculate_streams_and_bitmask()
3292 if (max_streams < (*num_streams - 1)) { in xhci_calculate_streams_and_bitmask()
3294 eps[i]->desc.bEndpointAddress, in xhci_calculate_streams_and_bitmask()
3299 endpoint_flag = xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_streams_and_bitmask()
3301 return -EINVAL; in xhci_calculate_streams_and_bitmask()
3317 slot_id = udev->slot_id; in xhci_calculate_no_streams_bitmask()
3318 if (!xhci->devs[slot_id]) in xhci_calculate_no_streams_bitmask()
3322 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3323 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state; in xhci_calculate_no_streams_bitmask()
3329 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3338 eps[i]->desc.bEndpointAddress); in xhci_calculate_no_streams_bitmask()
3340 "with non-streams endpoint\n"); in xhci_calculate_no_streams_bitmask()
3343 changed_ep_bitmask |= xhci_get_endpoint_flag(&eps[i]->desc); in xhci_calculate_no_streams_bitmask()
3380 return -EINVAL; in xhci_alloc_streams()
3391 if ((xhci->quirks & XHCI_BROKEN_STREAMS) || in xhci_alloc_streams()
3392 HCC_MAX_PSA(xhci->hcc_params) < 4) { in xhci_alloc_streams()
3394 return -ENOSYS; in xhci_alloc_streams()
3399 return -ENOMEM; in xhci_alloc_streams()
3401 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_alloc_streams()
3406 return -ENOMEM; in xhci_alloc_streams()
3413 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3418 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3425 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3426 return -EINVAL; in xhci_alloc_streams()
3428 vdev = xhci->devs[udev->slot_id]; in xhci_alloc_streams()
3433 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3434 vdev->eps[ep_index].ep_state |= EP_GETTING_STREAMS; in xhci_alloc_streams()
3436 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3447 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3448 max_packet = usb_endpoint_maxp(&eps[i]->desc); in xhci_alloc_streams()
3449 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci, in xhci_alloc_streams()
3453 if (!vdev->eps[ep_index].stream_info) in xhci_alloc_streams()
3464 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3465 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index); in xhci_alloc_streams()
3467 xhci_endpoint_copy(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3468 vdev->out_ctx, ep_index); in xhci_alloc_streams()
3470 vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3475 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx, in xhci_alloc_streams()
3476 vdev->out_ctx, ctrl_ctx, in xhci_alloc_streams()
3490 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_streams()
3492 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3493 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3495 udev->slot_id, ep_index); in xhci_alloc_streams()
3496 vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; in xhci_alloc_streams()
3499 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_streams()
3502 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3506 return num_streams - 1; in xhci_alloc_streams()
3511 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_alloc_streams()
3512 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_alloc_streams()
3513 vdev->eps[ep_index].stream_info = NULL; in xhci_alloc_streams()
3517 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS; in xhci_alloc_streams()
3518 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_alloc_streams()
3522 return -ENOMEM; in xhci_alloc_streams()
3545 vdev = xhci->devs[udev->slot_id]; in xhci_free_streams()
3548 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3552 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3553 return -EINVAL; in xhci_free_streams()
3560 ep_index = xhci_get_endpoint_index(&eps[0]->desc); in xhci_free_streams()
3561 command = vdev->eps[ep_index].stream_info->free_streams_command; in xhci_free_streams()
3562 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_free_streams()
3564 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3567 return -EINVAL; in xhci_free_streams()
3573 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3574 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); in xhci_free_streams()
3575 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |= in xhci_free_streams()
3578 xhci_endpoint_copy(xhci, command->in_ctx, in xhci_free_streams()
3579 vdev->out_ctx, ep_index); in xhci_free_streams()
3581 &vdev->eps[ep_index]); in xhci_free_streams()
3583 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, in xhci_free_streams()
3584 vdev->out_ctx, ctrl_ctx, in xhci_free_streams()
3586 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3600 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_streams()
3602 ep_index = xhci_get_endpoint_index(&eps[i]->desc); in xhci_free_streams()
3603 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info); in xhci_free_streams()
3604 vdev->eps[ep_index].stream_info = NULL; in xhci_free_streams()
3608 vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS; in xhci_free_streams()
3609 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS; in xhci_free_streams()
3611 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_streams()
3621 * Must be called with xhci->lock held.
3631 if (virt_dev->eps[i].ring) { in xhci_free_device_endpoint_resources()
3636 xhci->num_active_eps -= num_dropped_eps; in xhci_free_device_endpoint_resources()
3642 xhci->num_active_eps); in xhci_free_device_endpoint_resources()
3651 * xhci_address_device(), and then re-set up the configuration. If this is
3653 * settings will be re-installed through the normal bandwidth allocation
3662 * re-initialization during S3/S4. In this case, call xhci_alloc_dev() to
3663 * re-allocate the device.
3681 slot_id = udev->slot_id; in xhci_discover_or_reset_device()
3682 virt_dev = xhci->devs[slot_id]; in xhci_discover_or_reset_device()
3685 "not exist. Re-allocate the device\n", slot_id); in xhci_discover_or_reset_device()
3690 return -EINVAL; in xhci_discover_or_reset_device()
3693 if (virt_dev->tt_info) in xhci_discover_or_reset_device()
3694 old_active_eps = virt_dev->tt_info->active_eps; in xhci_discover_or_reset_device()
3696 if (virt_dev->udev != udev) { in xhci_discover_or_reset_device()
3699 * Re-allocate the device. in xhci_discover_or_reset_device()
3702 "not match the udev. Re-allocate the device\n", in xhci_discover_or_reset_device()
3708 return -EINVAL; in xhci_discover_or_reset_device()
3712 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_discover_or_reset_device()
3713 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_discover_or_reset_device()
3717 if (xhci->quirks & XHCI_ETRON_HOST) { in xhci_discover_or_reset_device()
3722 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_discover_or_reset_device()
3723 xhci_free_virt_device(xhci, udev->slot_id); in xhci_discover_or_reset_device()
3729 ret = -EINVAL; in xhci_discover_or_reset_device()
3746 return -ENOMEM; in xhci_discover_or_reset_device()
3750 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3755 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3759 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3762 wait_for_completion(reset_device_cmd->completion); in xhci_discover_or_reset_device()
3768 ret = reset_device_cmd->status; in xhci_discover_or_reset_device()
3773 ret = -ETIME; in xhci_discover_or_reset_device()
3779 xhci_get_slot_state(xhci, virt_dev->out_ctx)); in xhci_discover_or_reset_device()
3792 ret = -EINVAL; in xhci_discover_or_reset_device()
3797 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_discover_or_reset_device()
3798 spin_lock_irqsave(&xhci->lock, flags); in xhci_discover_or_reset_device()
3801 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_discover_or_reset_device()
3806 struct xhci_virt_ep *ep = &virt_dev->eps[i]; in xhci_discover_or_reset_device()
3808 if (ep->ep_state & EP_HAS_STREAMS) { in xhci_discover_or_reset_device()
3811 xhci_free_stream_info(xhci, ep->stream_info); in xhci_discover_or_reset_device()
3812 ep->stream_info = NULL; in xhci_discover_or_reset_device()
3813 ep->ep_state &= ~EP_HAS_STREAMS; in xhci_discover_or_reset_device()
3816 if (ep->ring) { in xhci_discover_or_reset_device()
3820 if (!list_empty(&virt_dev->eps[i].bw_endpoint_list)) in xhci_discover_or_reset_device()
3822 &virt_dev->eps[i].bw_info, in xhci_discover_or_reset_device()
3823 virt_dev->bw_table, in xhci_discover_or_reset_device()
3825 &virt_dev->eps[i], in xhci_discover_or_reset_device()
3826 virt_dev->tt_info); in xhci_discover_or_reset_device()
3827 xhci_clear_endpoint_bw_info(&virt_dev->eps[i].bw_info); in xhci_discover_or_reset_device()
3831 virt_dev->flags = 0; in xhci_discover_or_reset_device()
3857 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_free_dev()
3858 pm_runtime_put_noidle(hcd->self.controller); in xhci_free_dev()
3864 if (ret <= 0 && ret != -ENODEV) in xhci_free_dev()
3867 virt_dev = xhci->devs[udev->slot_id]; in xhci_free_dev()
3868 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_free_dev()
3873 virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING; in xhci_free_dev()
3874 virt_dev->udev = NULL; in xhci_free_dev()
3875 xhci_disable_slot(xhci, udev->slot_id); in xhci_free_dev()
3877 spin_lock_irqsave(&xhci->lock, flags); in xhci_free_dev()
3878 xhci_free_virt_device(xhci, udev->slot_id); in xhci_free_dev()
3879 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_free_dev()
3892 return -ENOMEM; in xhci_disable_slot()
3896 spin_lock_irqsave(&xhci->lock, flags); in xhci_disable_slot()
3898 state = readl(&xhci->op_regs->status); in xhci_disable_slot()
3899 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || in xhci_disable_slot()
3900 (xhci->xhc_state & XHCI_STATE_HALTED)) { in xhci_disable_slot()
3901 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3903 return -ENODEV; in xhci_disable_slot()
3909 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3914 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_disable_slot()
3916 wait_for_completion(command->completion); in xhci_disable_slot()
3918 if (command->status != COMP_SUCCESS) in xhci_disable_slot()
3920 slot_id, command->status); in xhci_disable_slot()
3931 * Must be called with xhci->lock held.
3935 if (xhci->num_active_eps + 1 > xhci->limit_active_eps) { in xhci_reserve_host_control_ep_resources()
3939 xhci->num_active_eps, xhci->limit_active_eps); in xhci_reserve_host_control_ep_resources()
3940 return -ENOMEM; in xhci_reserve_host_control_ep_resources()
3942 xhci->num_active_eps += 1; in xhci_reserve_host_control_ep_resources()
3945 xhci->num_active_eps); in xhci_reserve_host_control_ep_resources()
3967 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3970 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3976 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
3978 wait_for_completion(command->completion); in xhci_alloc_dev()
3979 slot_id = command->slot_id; in xhci_alloc_dev()
3981 if (!slot_id || command->status != COMP_SUCCESS) { in xhci_alloc_dev()
3983 xhci_trb_comp_code_string(command->status)); in xhci_alloc_dev()
3986 readl(&xhci->cap_regs->hcs_params1))); in xhci_alloc_dev()
3993 if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { in xhci_alloc_dev()
3994 spin_lock_irqsave(&xhci->lock, flags); in xhci_alloc_dev()
3997 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4000 xhci->num_active_eps); in xhci_alloc_dev()
4003 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_alloc_dev()
4013 vdev = xhci->devs[slot_id]; in xhci_alloc_dev()
4014 slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx); in xhci_alloc_dev()
4017 udev->slot_id = slot_id; in xhci_alloc_dev()
4025 if (xhci->quirks & XHCI_RESET_ON_RESUME) in xhci_alloc_dev()
4026 pm_runtime_get_noresume(hcd->self.controller); in xhci_alloc_dev()
4033 xhci_disable_slot(xhci, udev->slot_id); in xhci_alloc_dev()
4034 xhci_free_virt_device(xhci, udev->slot_id); in xhci_alloc_dev()
4040 * xhci_setup_device - issues an Address Device command to assign a unique
4062 mutex_lock(&xhci->mutex); in xhci_setup_device()
4064 if (xhci->xhc_state) { /* dying, removing or halted */ in xhci_setup_device()
4065 ret = -ESHUTDOWN; in xhci_setup_device()
4069 if (!udev->slot_id) { in xhci_setup_device()
4071 "Bad Slot ID %d", udev->slot_id); in xhci_setup_device()
4072 ret = -EINVAL; in xhci_setup_device()
4076 virt_dev = xhci->devs[udev->slot_id]; in xhci_setup_device()
4081 * a zero-dereference was observed once due to virt_dev = 0. in xhci_setup_device()
4085 udev->slot_id); in xhci_setup_device()
4086 ret = -EINVAL; in xhci_setup_device()
4089 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4093 if (GET_SLOT_STATE(le32_to_cpu(slot_ctx->dev_state)) == in xhci_setup_device()
4102 ret = -ENOMEM; in xhci_setup_device()
4106 command->in_ctx = virt_dev->in_ctx; in xhci_setup_device()
4107 command->timeout_ms = timeout_ms; in xhci_setup_device()
4109 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); in xhci_setup_device()
4110 ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); in xhci_setup_device()
4114 ret = -EINVAL; in xhci_setup_device()
4118 * If this is the first Set Address since device plug-in or in xhci_setup_device()
4122 if (!slot_ctx->dev_info) in xhci_setup_device()
4127 ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); in xhci_setup_device()
4128 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4130 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4131 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4134 spin_lock_irqsave(&xhci->lock, flags); in xhci_setup_device()
4136 ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, in xhci_setup_device()
4137 udev->slot_id, setup); in xhci_setup_device()
4139 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4145 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_setup_device()
4148 wait_for_completion(command->completion); in xhci_setup_device()
4154 switch (command->status) { in xhci_setup_device()
4158 ret = -ETIME; in xhci_setup_device()
4163 act, udev->slot_id); in xhci_setup_device()
4164 ret = -EINVAL; in xhci_setup_device()
4167 dev_warn(&udev->dev, "Device not responding to setup %s.\n", act); in xhci_setup_device()
4169 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4170 ret = xhci_disable_slot(xhci, udev->slot_id); in xhci_setup_device()
4171 xhci_free_virt_device(xhci, udev->slot_id); in xhci_setup_device()
4176 kfree(command->completion); in xhci_setup_device()
4178 return -EPROTO; in xhci_setup_device()
4180 dev_warn(&udev->dev, in xhci_setup_device()
4182 ret = -ENODEV; in xhci_setup_device()
4191 act, command->status); in xhci_setup_device()
4192 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); in xhci_setup_device()
4193 ret = -EINVAL; in xhci_setup_device()
4198 temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); in xhci_setup_device()
4203 udev->slot_id, in xhci_setup_device()
4204 &xhci->dcbaa->dev_context_ptrs[udev->slot_id], in xhci_setup_device()
4206 le64_to_cpu(xhci->dcbaa->dev_context_ptrs[udev->slot_id])); in xhci_setup_device()
4209 (unsigned long long)virt_dev->out_ctx->dma); in xhci_setup_device()
4210 trace_xhci_address_ctx(xhci, virt_dev->in_ctx, in xhci_setup_device()
4211 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4216 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, in xhci_setup_device()
4217 le32_to_cpu(slot_ctx->dev_info) >> 27); in xhci_setup_device()
4219 ctrl_ctx->add_flags = 0; in xhci_setup_device()
4220 ctrl_ctx->drop_flags = 0; in xhci_setup_device()
4221 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); in xhci_setup_device()
4222 udev->devaddr = (u8)(le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4226 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); in xhci_setup_device()
4228 mutex_unlock(&xhci->mutex); in xhci_setup_device()
4230 kfree(command->completion); in xhci_setup_device()
4259 return rhub->ports[port1 - 1]->hw_portnum + 1; in xhci_find_raw_port_number()
4278 return -ENOMEM; in xhci_change_max_exit_latency()
4280 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4282 virt_dev = xhci->devs[udev->slot_id]; in xhci_change_max_exit_latency()
4286 * xHC was re-initialized. Exit latency will be set later after in xhci_change_max_exit_latency()
4287 * hub_port_finish_reset() is done and xhci->devs[] are re-allocated in xhci_change_max_exit_latency()
4290 if (!virt_dev || max_exit_latency == virt_dev->current_mel) { in xhci_change_max_exit_latency()
4291 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4297 ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); in xhci_change_max_exit_latency()
4299 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4303 return -ENOMEM; in xhci_change_max_exit_latency()
4306 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); in xhci_change_max_exit_latency()
4307 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4309 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_change_max_exit_latency()
4310 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx); in xhci_change_max_exit_latency()
4311 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT)); in xhci_change_max_exit_latency()
4312 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency); in xhci_change_max_exit_latency()
4313 slot_ctx->dev_state = 0; in xhci_change_max_exit_latency()
4316 "Set up evaluate context for LPM MEL change."); in xhci_change_max_exit_latency()
4323 spin_lock_irqsave(&xhci->lock, flags); in xhci_change_max_exit_latency()
4324 virt_dev->current_mel = max_exit_latency; in xhci_change_max_exit_latency()
4325 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_change_max_exit_latency()
4335 /* BESL to HIRD Encoding array for USB2 LPM */
4347 u2del = HCS_U2_LATENCY(xhci->hcs_params3); in xhci_calculate_hird_besl()
4348 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_hird_besl()
4364 besl_host = (u2del - 51) / 75 + 1; in xhci_calculate_hird_besl()
4382 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_calculate_usb2_hw_lpm_params()
4385 l1 = udev->l1_params.timeout / 256; in xhci_calculate_usb2_hw_lpm_params()
4408 if (xhci->quirks & XHCI_HW_LPM_DISABLE) in xhci_set_usb2_hardware_lpm()
4409 return -EPERM; in xhci_set_usb2_hardware_lpm()
4411 if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || in xhci_set_usb2_hardware_lpm()
4412 !udev->lpm_capable) in xhci_set_usb2_hardware_lpm()
4413 return -EPERM; in xhci_set_usb2_hardware_lpm()
4415 if (!udev->parent || udev->parent->parent || in xhci_set_usb2_hardware_lpm()
4416 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_set_usb2_hardware_lpm()
4417 return -EPERM; in xhci_set_usb2_hardware_lpm()
4419 if (udev->usb2_hw_lpm_capable != 1) in xhci_set_usb2_hardware_lpm()
4420 return -EPERM; in xhci_set_usb2_hardware_lpm()
4422 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4424 ports = xhci->usb2_rhub.ports; in xhci_set_usb2_hardware_lpm()
4425 port_num = udev->portnum - 1; in xhci_set_usb2_hardware_lpm()
4426 pm_addr = ports[port_num]->addr + PORTPMSC; in xhci_set_usb2_hardware_lpm()
4428 hlpm_addr = ports[port_num]->addr + PORTHLPMC; in xhci_set_usb2_hardware_lpm()
4430 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", in xhci_set_usb2_hardware_lpm()
4435 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4440 field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); in xhci_set_usb2_hardware_lpm()
4445 hird = udev->l1_params.besl; in xhci_set_usb2_hardware_lpm()
4448 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4454 spin_lock_irqsave(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4465 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id); in xhci_set_usb2_hardware_lpm()
4477 if (udev->usb2_hw_lpm_besl_capable) { in xhci_set_usb2_hardware_lpm()
4478 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4480 readl_poll_timeout(ports[port_num]->addr, pm_val, in xhci_set_usb2_hardware_lpm()
4487 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_set_usb2_hardware_lpm()
4501 for (i = 0; i < xhci->num_ext_caps; i++) { in xhci_check_usb2_port_capability()
4502 if (xhci->ext_caps[i] & capability) { in xhci_check_usb2_port_capability()
4504 port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1; in xhci_check_usb2_port_capability()
4505 port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]); in xhci_check_usb2_port_capability()
4517 int portnum = udev->portnum - 1; in xhci_update_device()
4519 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable) in xhci_update_device()
4522 /* we only support lpm for non-hub device connected to root hub yet */ in xhci_update_device()
4523 if (!udev->parent || udev->parent->parent || in xhci_update_device()
4524 udev->descriptor.bDeviceClass == USB_CLASS_HUB) in xhci_update_device()
4527 if (xhci->hw_lpm_support == 1 && in xhci_update_device()
4530 udev->usb2_hw_lpm_capable = 1; in xhci_update_device()
4531 udev->l1_params.timeout = XHCI_L1_TIMEOUT; in xhci_update_device()
4532 udev->l1_params.besl = XHCI_DEFAULT_BESL; in xhci_update_device()
4535 udev->usb2_hw_lpm_besl_capable = 1; in xhci_update_device()
4541 /*---------------------- USB 3.0 Link PM functions ------------------------*/
4543 /* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
4547 return (1ULL << (desc->bInterval - 1)) * 125 * 1000; in xhci_service_interval_to_ns()
4561 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4562 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4567 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000); in xhci_get_timeout_no_hub_lpm()
4568 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000); in xhci_get_timeout_no_hub_lpm()
4573 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n", in xhci_get_timeout_no_hub_lpm()
4582 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4586 dev_dbg(&udev->dev, "Device-initiated %s disabled " in xhci_get_timeout_no_hub_lpm()
4593 * - For control endpoints, U1 system exit latency (SEL) * 3
4594 * - For bulk endpoints, U1 SEL * 5
4595 * - For interrupt endpoints:
4596 * - Notification EPs, U1 SEL * 3
4597 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
4598 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
4611 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4614 timeout_ns = udev->u1_params.sel * 5; in xhci_calculate_intel_u1_timeout()
4619 timeout_ns = udev->u1_params.sel * 3; in xhci_calculate_intel_u1_timeout()
4627 if (timeout_ns < udev->u1_params.sel * 2) in xhci_calculate_intel_u1_timeout()
4628 timeout_ns = udev->u1_params.sel * 2; in xhci_calculate_intel_u1_timeout()
4637 /* Returns the hub-encoded U1 timeout value. */
4646 if (xhci_service_interval_to_ns(desc) <= udev->u1_params.mel) { in xhci_calculate_u1_timeout()
4647 dev_dbg(&udev->dev, "Disable U1, ESIT shorter than exit latency\n"); in xhci_calculate_u1_timeout()
4652 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u1_timeout()
4655 timeout_ns = udev->u1_params.sel; in xhci_calculate_u1_timeout()
4666 * USB 3.0 hub, we have to disable hub-initiated U1. in xhci_calculate_u1_timeout()
4670 dev_dbg(&udev->dev, "Hub-initiated U1 disabled " in xhci_calculate_u1_timeout()
4676 * - 10 ms (to avoid the bandwidth impact on the scheduler)
4677 * - largest bInterval of any active periodic endpoint (to avoid going
4679 * - the U2 Exit Latency of the device
4694 u2_del_ns = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat) * 1000ULL; in xhci_calculate_intel_u2_timeout()
4701 /* Returns the hub-encoded U2 timeout value. */
4710 if (xhci_service_interval_to_ns(desc) <= udev->u2_params.mel) { in xhci_calculate_u2_timeout()
4711 dev_dbg(&udev->dev, "Disable U2, ESIT shorter than exit latency\n"); in xhci_calculate_u2_timeout()
4716 if (xhci->quirks & (XHCI_INTEL_HOST | XHCI_ZHAOXIN_HOST)) in xhci_calculate_u2_timeout()
4719 timeout_ns = udev->u2_params.sel; in xhci_calculate_u2_timeout()
4724 * USB 3.0 hub, we have to disable hub-initiated U2. in xhci_calculate_u2_timeout()
4728 dev_dbg(&udev->dev, "Hub-initiated U2 disabled " in xhci_calculate_u2_timeout()
4758 /* If we found we can't enable hub-initiated LPM, and in xhci_update_timeout_for_endpoint()
4760 * device-initiated LPM as well, then we will disable LPM in xhci_update_timeout_for_endpoint()
4765 return -E2BIG; in xhci_update_timeout_for_endpoint()
4780 for (j = 0; j < alt->desc.bNumEndpoints; j++) { in xhci_update_timeout_for_interface()
4782 &alt->endpoint[j].desc, state, timeout)) in xhci_update_timeout_for_interface()
4783 return -E2BIG; in xhci_update_timeout_for_interface()
4792 struct usb_device *parent = udev->parent; in xhci_check_tier_policy()
4796 parent = parent->parent; in xhci_check_tier_policy()
4800 if (xhci->quirks & XHCI_INTEL_HOST && tier > 3) in xhci_check_tier_policy()
4802 if (xhci->quirks & XHCI_ZHAOXIN_HOST && tier > 2) in xhci_check_tier_policy()
4807 dev_dbg(&udev->dev, "Tier policy prevents U1/U2 LPM states for devices at tier %d\n", in xhci_check_tier_policy()
4809 return -E2BIG; in xhci_check_tier_policy()
4813 * If the tier check or timeout setting functions return with a non-zero exit
4831 dev_warn(&udev->dev, "Can't enable unknown link state %i\n", in xhci_calculate_lpm_timeout()
4839 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc, in xhci_calculate_lpm_timeout()
4843 config = udev->actconfig; in xhci_calculate_lpm_timeout()
4847 for (i = 0; i < config->desc.bNumInterfaces; i++) { in xhci_calculate_lpm_timeout()
4849 struct usb_interface *intf = config->interface[i]; in xhci_calculate_lpm_timeout()
4854 /* Check if any currently bound drivers want hub-initiated LPM in xhci_calculate_lpm_timeout()
4857 if (intf->dev.driver) { in xhci_calculate_lpm_timeout()
4858 driver = to_usb_driver(intf->dev.driver); in xhci_calculate_lpm_timeout()
4859 if (driver && driver->disable_hub_initiated_lpm) { in xhci_calculate_lpm_timeout()
4860 dev_dbg(&udev->dev, "Hub-initiated %s disabled at request of driver %s\n", in xhci_calculate_lpm_timeout()
4861 state_name, driver->name); in xhci_calculate_lpm_timeout()
4870 if (!intf->cur_altsetting) in xhci_calculate_lpm_timeout()
4874 intf->cur_altsetting, in xhci_calculate_lpm_timeout()
4906 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) || in calculate_max_exit_latency()
4908 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000); in calculate_max_exit_latency()
4909 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) || in calculate_max_exit_latency()
4911 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000); in calculate_max_exit_latency()
4917 dev_warn(&udev->dev, "Link PM max exit latency of %lluus " in calculate_max_exit_latency()
4919 return -E2BIG; in calculate_max_exit_latency()
4924 /* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
4935 /* The LPM timeout values are pretty host-controller specific, so don't in xhci_enable_usb3_lpm_timeout()
4936 * enable hub-initiated timeouts unless the vendor has provided in xhci_enable_usb3_lpm_timeout()
4939 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_enable_usb3_lpm_timeout()
4940 !xhci->devs[udev->slot_id]) in xhci_enable_usb3_lpm_timeout()
4946 /* If connected to root port then check port can handle lpm */ in xhci_enable_usb3_lpm_timeout()
4947 if (udev->parent && !udev->parent->parent) { in xhci_enable_usb3_lpm_timeout()
4948 port = xhci->usb3_rhub.ports[udev->portnum - 1]; in xhci_enable_usb3_lpm_timeout()
4949 if (port->lpm_incapable) in xhci_enable_usb3_lpm_timeout()
4956 /* Max Exit Latency is too big, disable LPM. */ in xhci_enable_usb3_lpm_timeout()
4974 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) || in xhci_disable_usb3_lpm_timeout()
4975 !xhci->devs[udev->slot_id]) in xhci_disable_usb3_lpm_timeout()
5007 /*-------------------------------------------------------------------------*/
5025 if (!hdev->parent) in xhci_update_hub_device()
5028 vdev = xhci->devs[hdev->slot_id]; in xhci_update_hub_device()
5031 return -EINVAL; in xhci_update_hub_device()
5036 return -ENOMEM; in xhci_update_hub_device()
5038 ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); in xhci_update_hub_device()
5043 return -ENOMEM; in xhci_update_hub_device()
5046 spin_lock_irqsave(&xhci->lock, flags); in xhci_update_hub_device()
5047 if (hdev->speed == USB_SPEED_HIGH && in xhci_update_hub_device()
5051 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5052 return -ENOMEM; in xhci_update_hub_device()
5055 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); in xhci_update_hub_device()
5056 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); in xhci_update_hub_device()
5057 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx); in xhci_update_hub_device()
5058 slot_ctx->dev_info |= cpu_to_le32(DEV_HUB); in xhci_update_hub_device()
5064 if (tt->multi) in xhci_update_hub_device()
5065 slot_ctx->dev_info |= cpu_to_le32(DEV_MTT); in xhci_update_hub_device()
5066 else if (hdev->speed == USB_SPEED_FULL) in xhci_update_hub_device()
5067 slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT); in xhci_update_hub_device()
5069 if (xhci->hci_version > 0x95) { in xhci_update_hub_device()
5072 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5073 slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(hdev->maxchild)); in xhci_update_hub_device()
5074 /* Set TT think time - convert from ns to FS bit times. in xhci_update_hub_device()
5079 * High-spped hub. in xhci_update_hub_device()
5081 think_time = tt->think_time; in xhci_update_hub_device()
5083 think_time = (think_time / 666) - 1; in xhci_update_hub_device()
5084 if (xhci->hci_version < 0x100 || hdev->speed == USB_SPEED_HIGH) in xhci_update_hub_device()
5085 slot_ctx->tt_info |= in xhci_update_hub_device()
5090 (unsigned int) xhci->hci_version); in xhci_update_hub_device()
5092 slot_ctx->dev_state = 0; in xhci_update_hub_device()
5093 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_update_hub_device()
5096 (xhci->hci_version > 0x95) ? in xhci_update_hub_device()
5102 if (xhci->hci_version > 0x95) in xhci_update_hub_device()
5118 return readl(&xhci->run_regs->microframe_index) >> 3; in xhci_get_frame()
5123 xhci->usb2_rhub.hcd = hcd; in xhci_hcd_init_usb2_data()
5124 hcd->speed = HCD_USB2; in xhci_hcd_init_usb2_data()
5125 hcd->self.root_hub->speed = USB_SPEED_HIGH; in xhci_hcd_init_usb2_data()
5131 hcd->has_tt = 1; in xhci_hcd_init_usb2_data()
5139 * Early xHCI 1.1 spec did not mention USB 3.1 capable hosts in xhci_hcd_init_usb3_data()
5141 * is a two digit BCD containig minor and sub-minor numbers. in xhci_hcd_init_usb3_data()
5144 * Some USB 3.1 capable hosts therefore have sbrn 0x30, and in xhci_hcd_init_usb3_data()
5147 if (xhci->usb3_rhub.min_rev == 0x1) in xhci_hcd_init_usb3_data()
5150 minor_rev = xhci->usb3_rhub.min_rev / 0x10; in xhci_hcd_init_usb3_data()
5154 hcd->speed = HCD_USB32; in xhci_hcd_init_usb3_data()
5155 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5156 hcd->self.root_hub->rx_lanes = 2; in xhci_hcd_init_usb3_data()
5157 hcd->self.root_hub->tx_lanes = 2; in xhci_hcd_init_usb3_data()
5158 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x2; in xhci_hcd_init_usb3_data()
5161 hcd->speed = HCD_USB31; in xhci_hcd_init_usb3_data()
5162 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; in xhci_hcd_init_usb3_data()
5163 hcd->self.root_hub->ssp_rate = USB_SSP_GEN_2x1; in xhci_hcd_init_usb3_data()
5169 xhci->usb3_rhub.hcd = hcd; in xhci_hcd_init_usb3_data()
5179 struct device *dev = hcd->self.sysdev; in xhci_gen_setup()
5182 /* Accept arbitrarily long scatter-gather lists */ in xhci_gen_setup()
5183 hcd->self.sg_tablesize = ~0; in xhci_gen_setup()
5186 hcd->self.no_sg_constraint = 1; in xhci_gen_setup()
5189 hcd->self.no_stop_on_short = 1; in xhci_gen_setup()
5198 mutex_init(&xhci->mutex); in xhci_gen_setup()
5199 xhci->main_hcd = hcd; in xhci_gen_setup()
5200 xhci->cap_regs = hcd->regs; in xhci_gen_setup()
5201 xhci->op_regs = hcd->regs + in xhci_gen_setup()
5202 HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5203 xhci->run_regs = hcd->regs + in xhci_gen_setup()
5204 (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); in xhci_gen_setup()
5205 /* Cache read-only capability registers */ in xhci_gen_setup()
5206 xhci->hcs_params1 = readl(&xhci->cap_regs->hcs_params1); in xhci_gen_setup()
5207 xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); in xhci_gen_setup()
5208 xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); in xhci_gen_setup()
5209 xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); in xhci_gen_setup()
5210 xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); in xhci_gen_setup()
5211 if (xhci->hci_version > 0x100) in xhci_gen_setup()
5212 xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); in xhci_gen_setup()
5214 /* xhci-plat or xhci-pci might have set max_interrupters already */ in xhci_gen_setup()
5215 if ((!xhci->max_interrupters) || in xhci_gen_setup()
5216 xhci->max_interrupters > HCS_MAX_INTRS(xhci->hcs_params1)) in xhci_gen_setup()
5217 xhci->max_interrupters = HCS_MAX_INTRS(xhci->hcs_params1); in xhci_gen_setup()
5219 xhci->quirks |= quirks; in xhci_gen_setup()
5228 if (xhci->hci_version > 0x96) in xhci_gen_setup()
5229 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_gen_setup()
5246 * On some xHCI controllers (e.g. R-Car SoCs), the AC64 bit (bit 0) in xhci_gen_setup()
5247 * of HCCPARAMS1 is set to 1. However, the xHCs don't support 64-bit in xhci_gen_setup()
5249 * bit of xhci->hcc_params to call dma_set_coherent_mask(dev, in xhci_gen_setup()
5252 if (xhci->quirks & XHCI_NO_64BIT_SUPPORT) in xhci_gen_setup()
5253 xhci->hcc_params &= ~BIT(0); in xhci_gen_setup()
5255 /* Set dma_mask and coherent_dma_mask to 64-bits, in xhci_gen_setup()
5256 * if xHC supports 64-bit addressing */ in xhci_gen_setup()
5257 if (HCC_64BIT_ADDR(xhci->hcc_params) && in xhci_gen_setup()
5259 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); in xhci_gen_setup()
5263 * This is to avoid error in cases where a 32-bit USB in xhci_gen_setup()
5264 * controller is used on a 64-bit capable system. in xhci_gen_setup()
5269 xhci_dbg(xhci, "Enabling 32-bit DMA addresses.\n"); in xhci_gen_setup()
5286 xhci->hcc_params, xhci->hci_version, xhci->quirks); in xhci_gen_setup()
5303 spin_lock_irqsave(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5304 udev = (struct usb_device *)ep->hcpriv; in xhci_clear_tt_buffer_complete()
5305 slot_id = udev->slot_id; in xhci_clear_tt_buffer_complete()
5306 ep_index = xhci_get_endpoint_index(&ep->desc); in xhci_clear_tt_buffer_complete()
5308 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_CLEARING_TT; in xhci_clear_tt_buffer_complete()
5310 spin_unlock_irqrestore(&xhci->lock, flags); in xhci_clear_tt_buffer_complete()
5314 .description = "xhci-hcd",
5389 drv->hcd_priv_size += over->extra_priv_size; in xhci_init_driver()
5390 if (over->reset) in xhci_init_driver()
5391 drv->reset = over->reset; in xhci_init_driver()
5392 if (over->start) in xhci_init_driver()
5393 drv->start = over->start; in xhci_init_driver()
5394 if (over->add_endpoint) in xhci_init_driver()
5395 drv->add_endpoint = over->add_endpoint; in xhci_init_driver()
5396 if (over->drop_endpoint) in xhci_init_driver()
5397 drv->drop_endpoint = over->drop_endpoint; in xhci_init_driver()
5398 if (over->check_bandwidth) in xhci_init_driver()
5399 drv->check_bandwidth = over->check_bandwidth; in xhci_init_driver()
5400 if (over->reset_bandwidth) in xhci_init_driver()
5401 drv->reset_bandwidth = over->reset_bandwidth; in xhci_init_driver()
5402 if (over->update_hub_device) in xhci_init_driver()
5403 drv->update_hub_device = over->update_hub_device; in xhci_init_driver()
5404 if (over->hub_control) in xhci_init_driver()
5405 drv->hub_control = over->hub_control; in xhci_init_driver()
5435 return -ENODEV; in xhci_hcd_init()